Add ability to provide descriptor of other types
Allow Descriptors, primitive strings, regexps and functions. Other values will be added to throw "unknown validation" error.set
validator
When supplied validation
is a string, it is substituted by { [validator]: validation }
descriptor (there has to be a validation-to-validator(s) map):
valur(42).as("integer");
// same as valur(42).as({ number: "integer" });
// only "number" validator has "integer" validation
valur(42).as("number");
// same as valur(42).as({ typeOf: "number" });
// only "typeOf" validator has "number" validation
When supplied validation
is function
, it is substituted by { custom: validation }
descriptor:
valur(42).as(v => !(v % 1));
// same as valur(42).as({ custom: v => !(v % 1) });
valur(42).as(RegExp);
// same as valur(42).as({ custom: RegExp });
// there is no way at the moment to definitively tell classes from plain functions 🙁
When supplied validation
is a regular expression, it is substituted by { pattern: validation }
descriptor:
valur("text").as(/regex/);
// same as valur("text").as({ pattern: /regex/ });
Other values will throw "unknown validation" error:
valur(42).as("nubmer");
// Unknown validation: <string> nubmer
Edited by Dmytro Parzhytskyi