buddy

node MVC discord bot
Log | Files | Refs | README

validation.js (695B)


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