You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
695 B

4 years ago
  1. 'use strict';
  2. try {
  3. const isValidUTF8 = require('utf-8-validate');
  4. exports.isValidUTF8 =
  5. typeof isValidUTF8 === 'object'
  6. ? isValidUTF8.Validation.isValidUTF8 // utf-8-validate@<3.0.0
  7. : isValidUTF8;
  8. } catch (e) /* istanbul ignore next */ {
  9. exports.isValidUTF8 = () => true;
  10. }
  11. /**
  12. * Checks if a status code is allowed in a close frame.
  13. *
  14. * @param {Number} code The status code
  15. * @return {Boolean} `true` if the status code is valid, else `false`
  16. * @public
  17. */
  18. exports.isValidStatusCode = (code) => {
  19. return (
  20. (code >= 1000 &&
  21. code <= 1013 &&
  22. code !== 1004 &&
  23. code !== 1005 &&
  24. code !== 1006) ||
  25. (code >= 3000 && code <= 4999)
  26. );
  27. };