UNPKG

2.11 kBSource Map (JSON)View Raw
1{"version":3,"file":"IsByteLength.js","sourceRoot":"","sources":["../../../../src/decorator/string/IsByteLength.ts"],"names":[],"mappings":";;;;;;AACA,qDAAgE;AAChE,8EAA+D;AAElD,QAAA,cAAc,GAAG,cAAc,CAAC;AAE7C;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAc,EAAE,GAAW,EAAE,GAAY;IACpE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAA,sBAAqB,EAAC,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;AACjF,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,GAAW,EAAE,GAAY,EAAE,iBAAqC;IAC3F,OAAO,IAAA,uBAAU,EACf;QACE,IAAI,EAAE,sBAAc;QACpB,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;QACvB,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAW,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YACjG,cAAc,EAAE,IAAA,yBAAY,EAC1B,UAAU,CAAC,EAAE,CAAC,UAAU,GAAG,2EAA2E,EACtG,iBAAiB,CAClB;SACF;KACF,EACD,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAfD,oCAeC","sourcesContent":["import { ValidationOptions } from '../ValidationOptions';\nimport { buildMessage, ValidateBy } from '../common/ValidateBy';\nimport isByteLengthValidator from 'validator/lib/isByteLength';\n\nexport const IS_BYTE_LENGTH = 'isByteLength';\n\n/**\n * Checks if the string's length (in bytes) falls in a range.\n * If given value is not a string, then it returns false.\n */\nexport function isByteLength(value: unknown, min: number, max?: number): boolean {\n return typeof value === 'string' && isByteLengthValidator(value, { min, max });\n}\n\n/**\n * Checks if the string's length (in bytes) falls in a range.\n * If given value is not a string, then it returns false.\n */\nexport function IsByteLength(min: number, max?: number, validationOptions?: ValidationOptions): PropertyDecorator {\n return ValidateBy(\n {\n name: IS_BYTE_LENGTH,\n constraints: [min, max],\n validator: {\n validate: (value, args): boolean => isByteLength(value, args.constraints[0], args.constraints[1]),\n defaultMessage: buildMessage(\n eachPrefix => eachPrefix + \"$property's byte length must fall into ($constraint1, $constraint2) range\",\n validationOptions\n ),\n },\n },\n validationOptions\n );\n}\n"]}
\No newline at end of file