UNPKG

validlyjs

Version:

A high-performance Laravel-inspired validation library for TypeScript/JavaScript

12 lines (11 loc) 1.79 kB
"use strict" var e=require("./index-CwS8y5AW.js") const t={name:"integer",validate:e=>"number"==typeof e?(0|e)===e:Number.isInteger(+e),message:"The {field} must be an integer.",priority:0},r={name:"date",validate:t=>{if(t&&"object"==typeof t&&t.constructor===Date)return t.getTime()==t.getTime() if("string"==typeof t){const r=e.p(t) return r&&r.getTime()==r.getTime()}return!1},message:"The {field} must be a valid date.",priority:0} exports.arrayRule={name:"array",validate:e=>e&&"object"==typeof e&&"number"==typeof e.length,message:"The {field} must be an array.",priority:0},exports.booleanRule={name:"boolean",validate:e=>"boolean"==typeof e,message:"The {field} must be true or false.",priority:0},exports.dateRule=r,exports.fileRule={name:"file",validate:e=>{if(!e||"object"!=typeof e)return!1 const t=e.constructor return!(!t||"File"!==t.name&&"FileList"!==t.name)||"name"in e&&"size"in e&&"type"in e},message:"The {field} must be a file.",priority:0},exports.integerRule=t,exports.numberRule={name:"number",validate:e=>"number"==typeof e&&e==e&&e!==1/0&&e!==-1/0,message:"The {field} must be a number.",priority:0},exports.numericRule={name:"numeric",validate:e=>{if("number"==typeof e)return e==e&&e!==1/0&&e!==-1/0 if("string"==typeof e){const t=+e return t==t&&t!==1/0&&t!==-1/0}return!1},message:"The {field} must be numeric.",priority:0},exports.objectRule={name:"object",validate:e=>e&&"object"==typeof e&&"number"!=typeof e.length,message:"The {field} must be an object.",priority:0},exports.scalarRule={name:"scalar",validate:e=>{const t=typeof e return"string"===t||"number"===t||"boolean"===t},message:"The {field} must be a scalar value.",priority:0},exports.stringRule={name:"string",validate:e=>"string"==typeof e,message:"The {field} must be a string.",priority:0}