You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
737 B
JavaScript

"use strict";
const { validateValue } = require("@validatem/core");
const isNumeric = require("./");
console.log(validateValue("42", [ isNumeric() ])); // 42
console.log(validateValue("42.42", [ isNumeric({ allowDecimal: true }) ])); // 42.42
try {
console.log(validateValue("foo", [ isNumeric({ allowDecimal: true }) ]));
} catch (error) {
console.log(error.stack); /*
AggregrateValidationError: One or more validation errors occurred:
- At (root): Must be a string representing a positive, ungrouped number
*/
}
console.log(validateValue("42.42", [ isNumeric() ])); /*
AggregrateValidationError: One or more validation errors occurred:
- At (root): Must be a string representing a whole, positive, ungrouped number
*/