validation.js 687 B

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