UNPKG

1.51 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.IsHash = exports.isHash = exports.IS_HASH = void 0;
7const ValidateBy_1 = require("../common/ValidateBy");
8const isHash_1 = __importDefault(require("validator/lib/isHash"));
9exports.IS_HASH = 'isHash';
10/**
11 * Check if the string is a hash of type algorithm.
12 * Algorithm is one of ['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128',
13 * 'tiger160', 'tiger192', 'crc32', 'crc32b']
14 */
15function isHash(value, algorithm) {
16 return typeof value === 'string' && (0, isHash_1.default)(value, algorithm);
17}
18exports.isHash = isHash;
19/**
20 * Check if the string is a hash of type algorithm.
21 * Algorithm is one of ['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128',
22 * 'tiger160', 'tiger192', 'crc32', 'crc32b']
23 */
24function IsHash(algorithm, validationOptions) {
25 return (0, ValidateBy_1.ValidateBy)({
26 name: exports.IS_HASH,
27 constraints: [algorithm],
28 validator: {
29 validate: (value, args) => isHash(value, args.constraints[0]),
30 defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a hash of type $constraint1', validationOptions),
31 },
32 }, validationOptions);
33}
34exports.IsHash = IsHash;
35//# sourceMappingURL=IsHash.js.map
\No newline at end of file