UNPKG

nowjs-core

Version:

NowCanDo Javascript Core [nowjs-core] is a library written by TypeScript code maintains under Apache 2.0 licence

25 lines (24 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../index"); const index_2 = require("./index"); exports.VALIDATOR_NUMERIC_METADATA_KEY = Symbol('validation:validator:isNumeric'); function isNumeric(style = 'integer', errorMessage) { return (target, propertyKey, descriptor) => { const original = descriptor.value; Reflect.defineMetadata(exports.VALIDATOR_NUMERIC_METADATA_KEY, null, target, propertyKey); Reflect.defineMetadata(index_1.VALIDATOR_METADATA_KEY, new NumericValidator(style, errorMessage), target, propertyKey); }; } exports.isNumeric = isNumeric; exports.PATTERN_NUMERIC = /^[\-\+]?\d+\.?\d*$/gi; class NumericValidator extends index_2.PatternValidatorBase { constructor(style = 'integer', errorMessage = 'The value of ${DisplayName} must have numeric pattern : ${Pattern} .') { super('Numeric', exports.PATTERN_NUMERIC, errorMessage); this.style = style; } get Style() { return this.style; } } exports.NumericValidator = NumericValidator;