validation.js 695 B

123456789101112131415161718192021222324252627282930
  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. };