typedconverter
Version:
Convert object into classes match with TypeScript type annotation
218 lines (217 loc) • 9.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.val = void 0;
const tslib_1 = require("tslib");
const validator_1 = tslib_1.__importDefault(require("validator"));
const v = tslib_1.__importStar(require("./validation"));
var val;
(function (val) {
function check(validator, message) {
return v.createValidation(x => !validator(x) ? message : undefined);
}
function after(opt) {
return check(x => validator_1.default.isAfter(x, opt && opt.date), opt && opt.message || `Date must be greater than ${opt && opt.date || "today"}`);
}
val.after = after;
function alpha(opt) {
return check(x => validator_1.default.isAlpha(x, opt && opt.locale), opt && opt.message || "Invalid alpha");
}
val.alpha = alpha;
function alphanumeric(opt) {
return check(x => validator_1.default.isAlphanumeric(x, opt && opt.locale), opt && opt.message || "Invalid alpha numeric");
}
val.alphanumeric = alphanumeric;
function ascii(opt) {
return check(x => validator_1.default.isAscii(x), opt && opt.message || "Invalid ascii");
}
val.ascii = ascii;
function base64(opt) {
return check(x => validator_1.default.isBase64(x), opt && opt.message || "Invalid base 64");
}
val.base64 = base64;
function before(opt) {
return check(x => validator_1.default.isBefore(x, opt && opt.date), opt && opt.message || `Date must be less than ${opt && opt.date || "today"}`);
}
val.before = before;
function byteLength(opt) {
return check(x => validator_1.default.isByteLength(x, opt), opt && opt.message || "Invalid byte length");
}
val.byteLength = byteLength;
function creditCard(opt) {
return check(x => validator_1.default.isCreditCard(x), opt && opt.message || "Invalid credit card number");
}
val.creditCard = creditCard;
function currency(opt) {
return check(x => validator_1.default.isCurrency(x, opt), opt && opt.message || "Invalid currency");
}
val.currency = currency;
function dataURI(opt) {
return check(x => validator_1.default.isDataURI(x), opt && opt.message || "Invalid data URI");
}
val.dataURI = dataURI;
function decimal(opt) {
return check(x => validator_1.default.isDecimal(x, opt), opt && opt.message || "Invalid decimal");
}
val.decimal = decimal;
function divisibleBy(opt) {
return check(x => validator_1.default.isDivisibleBy(x, opt.num), opt && opt.message || `Not divisible by ${opt.num}`);
}
val.divisibleBy = divisibleBy;
function email(opt) {
return check(x => validator_1.default.isEmail(x, opt), opt && opt.message || "Invalid email address");
}
val.email = email;
function fqdn(opt) {
return check(x => validator_1.default.isFQDN(x, opt), opt && opt.message || "Invalid FQDN");
}
val.fqdn = fqdn;
function float(opt) {
return check(x => validator_1.default.isFloat(x, opt), opt && opt.message || "Invalid float number");
}
val.float = float;
function fullWidth(opt) {
return check(x => validator_1.default.isFullWidth(x), opt && opt.message || "Invalid value provided");
}
val.fullWidth = fullWidth;
function halfWidth(opt) {
return check(x => validator_1.default.isHalfWidth(x), opt && opt.message || "Invalid value provided");
}
val.halfWidth = halfWidth;
function hash(opt) {
return check(x => validator_1.default.isHash(x, opt.algorithm), opt && opt.message || "Invalid hash");
}
val.hash = hash;
function hexColor(opt) {
return check(x => validator_1.default.isHexColor(x), opt && opt.message || "Invalid hex color");
}
val.hexColor = hexColor;
function hexadecimal(opt) {
return check(x => validator_1.default.isHexadecimal(x), opt && opt.message || "Invalid hexadecimal");
}
val.hexadecimal = hexadecimal;
function ip(opt) {
return check(x => validator_1.default.isIP(x, opt && opt.version), opt && opt.message || "Invalid IP address");
}
val.ip = ip;
function isbn(opt) {
return check(x => validator_1.default.isISBN(x, opt && opt.version), opt && opt.message || "Invalid ISBN");
}
val.isbn = isbn;
function isin(opt) {
return check(x => validator_1.default.isISIN(x), opt && opt.message || "Invalid ISIN");
}
val.isin = isin;
function iso31661Alpha2(opt) {
return check(x => validator_1.default.isISO31661Alpha2(x), opt && opt.message || "Invalid ISO 31661 Alpha 2");
}
val.iso31661Alpha2 = iso31661Alpha2;
function iso8601(opt) {
return check(x => validator_1.default.isISO8601(x), opt && opt.message || "Invalid ISO 8601 date");
}
val.iso8601 = iso8601;
function isrc(opt) {
return check(x => validator_1.default.isISRC(x), opt && opt.message || "Invalid ISRC");
}
val.isrc = isrc;
function issn(opt) {
return check(x => validator_1.default.isISSN(x, opt), opt && opt.message || "Invalid ISSN");
}
val.issn = issn;
function int(opt) {
return check(x => validator_1.default.isInt(x, opt), opt && opt.message || "Invalid integer");
}
val.int = int;
function json(opt) {
return check(x => validator_1.default.isJSON(x), opt && opt.message || "Invalid JSON");
}
val.json = json;
function latLong(opt) {
return check(x => validator_1.default.isLatLong(x), opt && opt.message || "Invalid lat long");
}
val.latLong = latLong;
function length(opt) {
return check(x => validator_1.default.isLength(x, opt), opt && opt.message || "Invalid length");
}
val.length = length;
function lowerCase(opt) {
return check(x => validator_1.default.isLowercase(x), opt && opt.message || "Invalid lower case");
}
val.lowerCase = lowerCase;
function macAddress(opt) {
return check(x => validator_1.default.isMACAddress(x), opt && opt.message || "Invalid MAC address");
}
val.macAddress = macAddress;
function matches(opt) {
return check(x => validator_1.default.matches(x, opt.pattern, opt.modifier), opt.message || "Invalid string");
}
val.matches = matches;
function md5(opt) {
return check(x => validator_1.default.isMD5(x), opt && opt.message || "Invalid MD5 hash");
}
val.md5 = md5;
function mimeType(opt) {
return check(x => validator_1.default.isMimeType(x), opt && opt.message || "Invalid mime type");
}
val.mimeType = mimeType;
function mobilePhone(opt) {
return check(x => validator_1.default.isMobilePhone(x, opt && opt.locale, opt && opt.options), opt && opt.message || "Invalid mobile phone");
}
val.mobilePhone = mobilePhone;
function mongoId(opt) {
return check(x => validator_1.default.isMongoId(x), opt && opt.message || "Invalid MongoDb id");
}
val.mongoId = mongoId;
function multibyte(opt) {
return check(x => validator_1.default.isMultibyte(x), opt && opt.message || "Invalid multi byte");
}
val.multibyte = multibyte;
function numeric(opt) {
return check(x => validator_1.default.isNumeric(x), opt && opt.message || "Invalid numeric");
}
val.numeric = numeric;
function port(opt) {
return check(x => validator_1.default.isPort(x), opt && opt.message || "Invalid port");
}
val.port = port;
function postalCode(opt) {
return check(x => validator_1.default.isPostalCode(x, opt && opt.locale || "any"), opt && opt.message || "Invalid postal code");
}
val.postalCode = postalCode;
function slug(opt) {
return check(x => validator_1.default.isSlug(x), opt && opt.message || "Invalid slug");
}
val.slug = slug;
function surrogatePair(opt) {
return check(x => validator_1.default.isSurrogatePair(x), opt && opt.message || "Invalid surrogate pair");
}
val.surrogatePair = surrogatePair;
function url(opt) {
return check(x => validator_1.default.isURL(x, opt), opt && opt.message || "Invalid url");
}
val.url = url;
function UUID(opt) {
return check(x => validator_1.default.isUUID(x), opt && opt.message || "Invalid UUID");
}
val.UUID = UUID;
function uppercase(opt) {
return check(x => validator_1.default.isUppercase(x), opt && opt.message || "Invalid uppercase");
}
val.uppercase = uppercase;
function variableWidth(opt) {
return check(x => validator_1.default.isVariableWidth(x), opt && opt.message || "Invalid variable width");
}
val.variableWidth = variableWidth;
function whiteListed(opt) {
return check(x => validator_1.default.isWhitelisted(x, opt && opt.chars), opt && opt.message || "Invalid white listed");
}
val.whiteListed = whiteListed;
function required() {
return v.required();
}
val.required = required;
function partial(typ) {
return v.partial(typ);
}
val.partial = partial;
})(val || (val = {}));
exports.val = val;