validlyjs
Version:
A high-performance Laravel-inspired validation library for TypeScript/JavaScript
11 lines (10 loc) • 1.77 kB
JavaScript
import{p as e}from"./index-Ci9AjmGp.js"
const t={name:"string",validate:e=>"string"==typeof e,message:"The {field} must be a string.",priority:0},r={name:"number",validate:e=>"number"==typeof e&&e==e&&e!==1/0&&e!==-1/0,message:"The {field} must be a number.",priority:0},a={name:"integer",validate:e=>"number"==typeof e?(0|e)===e:Number.isInteger(+e),message:"The {field} must be an integer.",priority:0},i={name:"boolean",validate:e=>"boolean"==typeof e,message:"The {field} must be true or false.",priority:0},n={name:"array",validate:e=>e&&"object"==typeof e&&"number"==typeof e.length,message:"The {field} must be an array.",priority:0},s={name:"object",validate:e=>e&&"object"==typeof e&&"number"!=typeof e.length,message:"The {field} must be an object.",priority:0},o={name:"date",validate:t=>{if(t&&"object"==typeof t&&t.constructor===Date)return t.getTime()==t.getTime()
if("string"==typeof t){const r=e(t)
return r&&r.getTime()==r.getTime()}return!1},message:"The {field} must be a valid date.",priority:0},m={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},f={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},l={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}
export{n as arrayRule,i as booleanRule,o as dateRule,m as fileRule,a as integerRule,r as numberRule,f as numericRule,s as objectRule,l as scalarRule,t as stringRule}