UNPKG

1.38 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.IsNumberString = exports.isNumberString = exports.IS_NUMBER_STRING = void 0;
7const ValidateBy_1 = require("../common/ValidateBy");
8const isNumeric_1 = __importDefault(require("validator/lib/isNumeric"));
9exports.IS_NUMBER_STRING = 'isNumberString';
10/**
11 * Checks if the string is numeric.
12 * If given value is not a string, then it returns false.
13 */
14function isNumberString(value, options) {
15 return typeof value === 'string' && (0, isNumeric_1.default)(value, options);
16}
17exports.isNumberString = isNumberString;
18/**
19 * Checks if the string is numeric.
20 * If given value is not a string, then it returns false.
21 */
22function IsNumberString(options, validationOptions) {
23 return (0, ValidateBy_1.ValidateBy)({
24 name: exports.IS_NUMBER_STRING,
25 constraints: [options],
26 validator: {
27 validate: (value, args) => isNumberString(value, args.constraints[0]),
28 defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a number string', validationOptions),
29 },
30 }, validationOptions);
31}
32exports.IsNumberString = IsNumberString;
33//# sourceMappingURL=IsNumberString.js.map
\No newline at end of file