@kklab/fortress-validator 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +202 -0
- package/dist/FieldValidator.d.ts +272 -0
- package/dist/FormValidator.d.ts +19 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +919 -0
- package/dist/index.umd.js +1 -0
- package/dist/locales/en.d.ts +3 -0
- package/dist/locales/index.d.ts +3 -0
- package/dist/locales/zh-TW.d.ts +3 -0
- package/dist/rules/accepted.d.ts +3 -0
- package/dist/rules/alpha.d.ts +3 -0
- package/dist/rules/alphaDash.d.ts +3 -0
- package/dist/rules/alphaDashDot.d.ts +3 -0
- package/dist/rules/alphaNum.d.ts +3 -0
- package/dist/rules/array.d.ts +3 -0
- package/dist/rules/ascii.d.ts +3 -0
- package/dist/rules/between.d.ts +7 -0
- package/dist/rules/betweenLength.d.ts +7 -0
- package/dist/rules/boolean.d.ts +3 -0
- package/dist/rules/containsAll.d.ts +6 -0
- package/dist/rules/containsAny.d.ts +6 -0
- package/dist/rules/declined.d.ts +3 -0
- package/dist/rules/different.d.ts +7 -0
- package/dist/rules/distinct.d.ts +3 -0
- package/dist/rules/domain.d.ts +3 -0
- package/dist/rules/email.d.ts +3 -0
- package/dist/rules/endsWith.d.ts +6 -0
- package/dist/rules/equals.d.ts +6 -0
- package/dist/rules/file.d.ts +3 -0
- package/dist/rules/fileBetweenSize.d.ts +7 -0
- package/dist/rules/fileMaxSize.d.ts +6 -0
- package/dist/rules/fileMinSize.d.ts +6 -0
- package/dist/rules/fileSize.d.ts +6 -0
- package/dist/rules/http.d.ts +3 -0
- package/dist/rules/https.d.ts +3 -0
- package/dist/rules/in.d.ts +6 -0
- package/dist/rules/index.d.ts +3 -0
- package/dist/rules/integer.d.ts +3 -0
- package/dist/rules/json.d.ts +3 -0
- package/dist/rules/length.d.ts +6 -0
- package/dist/rules/lowercase.d.ts +3 -0
- package/dist/rules/max.d.ts +6 -0
- package/dist/rules/maxLength.d.ts +6 -0
- package/dist/rules/min.d.ts +6 -0
- package/dist/rules/minLength.d.ts +6 -0
- package/dist/rules/notEquals.d.ts +6 -0
- package/dist/rules/notIn.d.ts +6 -0
- package/dist/rules/number.d.ts +3 -0
- package/dist/rules/numeric.d.ts +3 -0
- package/dist/rules/regex.d.ts +6 -0
- package/dist/rules/required.d.ts +3 -0
- package/dist/rules/same.d.ts +7 -0
- package/dist/rules/size.d.ts +6 -0
- package/dist/rules/startsWith.d.ts +6 -0
- package/dist/rules/string.d.ts +3 -0
- package/dist/rules/stringBetweenLength.d.ts +7 -0
- package/dist/rules/stringLength.d.ts +6 -0
- package/dist/rules/stringMaxLength.d.ts +6 -0
- package/dist/rules/stringMinLength.d.ts +6 -0
- package/dist/rules/unique.d.ts +7 -0
- package/dist/rules/uppercase.d.ts +3 -0
- package/dist/rules/url.d.ts +3 -0
- package/dist/types/Conditions.d.ts +4 -0
- package/dist/types/FieldValidatorArguments.d.ts +9 -0
- package/dist/types/FormValidatorArguments.d.ts +7 -0
- package/dist/types/index.d.ts +4 -0
- package/package.json +65 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(u,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(u=typeof globalThis<"u"?globalThis:u||self,l(u.Fortress={}))})(this,function(u){"use strict";var ce=Object.defineProperty;var fe=(u,l,n)=>l in u?ce(u,l,{enumerable:!0,configurable:!0,writable:!0,value:n}):u[l]=n;var h=(u,l,n)=>(fe(u,typeof l!="symbol"?l+"":l,n),n);const l=t=>t.replace(/([^\x20-\x7E])([\x20-\x7E])/gu,"$1 $2").replace(/([\x20-\x7E])([^\x20-\x7E])/gu,"$1 $2").replace(/ +/g," "),n=(t,e=0)=>new Intl.NumberFormat(void 0,{minimumFractionDigits:e,maximumFractionDigits:e}).format(t),z=t=>Object.prototype.toString.call(t).toLowerCase().slice(8,-1),i=t=>t==null||t===""||Array.isArray(t)&&t.length<1;class b{constructor({name:e,locale:r,fallbackLocale:s,locales:a,rules:o}){h(this,"name");h(this,"locale");h(this,"fallbackLocale");h(this,"locales");h(this,"rules");h(this,"ruleFunctions",[]);h(this,"conditions",{});h(this,"shouldSkip",!1);this.name=e,this.locale=r,this.fallbackLocale=s,this.locales=a,this.rules=o}get formattedName(){return this.name.toLowerCase()}get messages(){return this.locales[this.locale]||{}}get fallbackMessages(){return this.locales[this.fallbackLocale]||{}}get mandatoryRules(){return[this.required.name,this.string.name,this.array.name,this.equals.name,this.notEquals.name]}getMessage(e){return this.messages[e]||this.fallbackMessages[e]||(r=>`The ${r} field is invalid.`)}getRule(e){if(!(e in this.rules))throw new Error(`The "${e}" rule is not registered.`);return this.rules[e]}buildRuleFunction(e,r){return s=>{if(i(s)&&!this.mandatoryRules.includes(e))return!0;const a=this.getRule(e)(r)(s);return typeof a=="string"?a:a===!0?!0:this.buildRuleFunctionMessage(e,r,s)}}buildRuleFunctionMessage(e,r,s){const a=this.getMessage(e)(this.formattedName,r);if(typeof a=="object"){const o=z(s);if(!(o in a))throw new Error(`The message for the "${e}" rule of the "${o}" type is missing.`);return l(a[o])}return l(a)}pushRuleFunction(e,r){if(e in this.conditions&&!this.conditions[e])return this;const s=this.buildRuleFunction(e,r);return this.ruleFunctions.push(s),this}getRuleFunctions(){return this.ruleFunctions}collect(){return this.shouldSkip?[]:this.getRuleFunctions()}validate(e){if(this.shouldSkip)return!0;for(const r of this.ruleFunctions){const s=r(e);if(typeof s=="string")return s}return!0}apply(e,r={}){return this.pushRuleFunction(e,r)}accepted(){return this.apply(this.accepted.name)}after(e,r,s,a=!0){return this.apply(this.after.name,{date:e,format:r,displayFormat:s,strict:a})}alpha(){return this.apply(this.alpha.name)}alphaDash(){return this.apply(this.alphaDash.name)}alphaDashDot(){return this.apply(this.alphaDashDot.name)}alphaNum(){return this.apply(this.alphaNum.name)}array(){return this.apply(this.array.name)}ascii(){return this.apply(this.ascii.name)}before(e,r,s,a=!0){return this.apply(this.before.name,{date:e,format:r,displayFormat:s,strict:a})}between(e,r){return this.apply(this.between.name,{min:e,max:r})}betweenLength(e,r){return this.apply(this.betweenLength.name,{min:e,max:r})}boolean(){return this.apply(this.boolean.name)}containsAll(e){return this.apply(this.containsAll.name,{values:e})}containsAny(e){return this.apply(this.containsAny.name,{values:e})}date(e,r=!0){return this.apply(this.date.name,{format:e,strict:r})}declined(){return this.apply(this.declined.name)}different(e,r){return this.apply(this.different.name,{field:e,value:r})}distinct(){return this.apply(this.distinct.name)}domain(){return this.apply(this.domain.name)}email(){return this.apply(this.email.name)}endsWith(e){return this.apply(this.endsWith.name,{value:e})}equals(e){return this.apply(this.equals.name,{value:e})}file(){return this.apply(this.file.name)}fileBetweenSize(e,r){return this.apply(this.fileBetweenSize.name,{min:e,max:r})}fileMaxSize(e){return this.apply(this.fileMaxSize.name,{size:e})}fileMinSize(e){return this.apply(this.fileMinSize.name,{size:e})}fileSize(e){return this.apply(this.fileSize.name,{size:e})}http(){return this.apply(this.http.name)}https(){return this.apply(this.https.name)}in(e){return this.apply(this.in.name,{values:e})}integer(){return this.apply(this.integer.name)}iso8601(){return this.apply(this.iso8601.name)}json(){return this.apply(this.json.name)}jsonSchema(e){return this.apply(this.jsonSchema.name,{schema:e,locale:this.locale,field:this.name})}length(e){return this.apply(this.length.name,{length:e})}lowercase(){return this.apply(this.lowercase.name)}max(e){return this.apply(this.max.name,{max:e})}maxLength(e){return this.apply(this.maxLength.name,{length:e})}min(e){return this.apply(this.min.name,{min:e})}minLength(e){return this.apply(this.minLength.name,{length:e})}notEquals(e){return this.apply(this.notEquals.name,{value:e})}notIn(e){return this.apply(this.notIn.name,{values:e})}number(){return this.apply(this.number.name)}numeric(){return this.apply(this.numeric.name)}regex(e){return this.apply(this.regex.name,{expression:e})}required(){return this.apply(this.required.name)}requiredWhen(e){return this.when({required:e}).required()}same(e,r){return this.apply(this.same.name,{field:e,value:r})}size(e){return this.apply(this.size.name,{size:e})}startsWith(e){return this.apply(this.startsWith.name,{value:e})}string(){return this.apply(this.string.name)}stringBetweenLength(e,r){return this.apply(this.stringBetweenLength.name,{min:e,max:r})}stringLength(e){return this.apply(this.stringLength.name,{length:e})}stringMaxLength(e){return this.apply(this.stringMaxLength.name,{length:e})}stringMinLength(e){return this.apply(this.stringMinLength.name,{length:e})}unique(e,r=[]){return this.apply(this.unique.name,{values:e,ignored:r})}uppercase(){return this.apply(this.uppercase.name)}url(){return this.apply(this.url.name)}when(e){return typeof e=="object"?(this.conditions=e,this):(e||(this.shouldSkip=!0),this)}}const x={en:{accepted:t=>`The ${t} field must be accepted.`,alpha:t=>`The ${t} field must only contain letters.`,alphaDash:t=>`The ${t} field must only contain letters, numbers, dashes and underscores.`,alphaDashDot:t=>`The ${t} field must only contain letters, numbers, dashes, underscores and dots.`,alphaNum:t=>`The ${t} field must only contain letters and numbers.`,array:t=>`The ${t} field must be an array.`,ascii:t=>`The ${t} field must only contain ASCII characters and symbols.`,between:(t,e)=>{const{min:r,max:s}=e;return{number:`The ${t} field must be between ${n(r)} and ${n(s)}.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(s)}.`}},betweenLength:(t,e)=>{const{min:r,max:s}=e;return`The ${t} field must be between ${n(r)} and ${n(s)} items.`},boolean:t=>`The ${t} field must be a boolean value.`,containsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must contain all of the following: ${r.join(", ")}.`},containsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must contain at least one of the following: ${r.join(", ")}.`},declined:t=>`The ${t} field must be declined.`,different:(t,e)=>{const{field:r}=e;return`The ${t} and ${r} fields must be different.`},distinct:t=>`The ${t} field must not contain duplicate values.`,domain:t=>`The ${t} field must be a valid domain.`,email:t=>`The ${t} field must be a valid email address.`,endsWith:(t,e)=>{const{value:r}=e;return`The ${t} field must end with ${r}.`},equals:(t,e)=>{const{value:r}=e;return`The ${t} field must be equal to ${r}.`},file:t=>`The ${t} field must be a file.`,fileBetweenSize:(t,e)=>{const{min:r,max:s}=e;return{file:`The ${t} field must be between ${n(r)} and ${n(s)} kilobytes.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(s)} kilobytes.`}},fileMaxSize:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must not be greater than ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is not greater than ${n(r)} kilobytes.`}},fileMinSize:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be at least ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is at least ${n(r)} kilobytes.`}},fileSize:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is ${n(r)} kilobytes.`}},http:t=>`The ${t} field must start with either "http://" or "https://".`,https:t=>`The ${t} field must start with "http://".`,in:(t,e)=>{const{values:r}=e;return`The ${t} field must be one of the following: ${r.join(", ")}.`},integer:t=>`The ${t} field must be an integer.`,json:t=>`The ${t} field must be a valid JSON string.`,length:(t,e)=>{const{length:r}=e;return`The ${t} field must be ${n(r)} items.`},lowercase:t=>`The ${t} field must be lowercase.`,max:(t,e)=>{const{max:r}=e;return{number:`The ${t} field must not be greater than ${n(r)}.`,array:`The ${t} field must contain items where each item is not greater than ${n(r)}.`}},maxLength:(t,e)=>{const{length:r}=e;return`The ${t} field must not be greater than ${n(r)} items.`},min:(t,e)=>{const{min:r}=e;return{number:`The ${t} field must be at least ${n(r)}.`,array:`The ${t} field must contain items where each item is at least ${n(r)}.`}},minLength:(t,e)=>{const{length:r}=e;return`The ${t} field must be at least ${n(r)} items.`},notEquals:(t,e)=>{const{value:r}=e;return`The ${t} field must not be equal to ${r}.`},notIn:(t,e)=>{const{values:r}=e;return`The ${t} field must not be one of the following: ${r.join(", ")}.`},number:t=>`The ${t} field must be a number.`,numeric:t=>`The ${t} field must be a number.`,regex:t=>`The ${t} field must match the required format.`,required:t=>`The ${t} field is required.`,same:(t,e)=>{const{field:r}=e;return`The ${t} and ${r} fields must match.`},size:(t,e)=>{const{size:r}=e;return{number:`The ${t} field must be ${n(r)}.`,array:`The ${t} field must contain items where each item is ${n(r)}.`}},startsWith:(t,e)=>{const{value:r}=e;return`The ${t} field must start with ${r}.`},string:t=>`The ${t} field must be a string.`,stringBetweenLength:(t,e)=>{const{min:r,max:s}=e;return{string:`The ${t} field must be between ${n(r)} and ${n(s)} characters.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(s)} characters.`}},stringLength:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be ${n(r)} characters.`,array:`The ${t} field must contain items where each item is ${n(r)} characters.`}},stringMaxLength:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must not be greater than ${n(r)} characters.`,array:`The ${t} field must contain items where each item is not greater than ${n(r)} characters.`}},stringMinLength:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be at least ${n(r)} characters.`,array:`The ${t} field must contain items where each item is at least ${n(r)} characters.`}},unique:t=>`The ${t} field has already been taken.`,uppercase:t=>`The ${t} field must be uppercase.`,url:t=>`The ${t} field must be a valid URL.`},"zh-TW":{accepted:()=>"此欄位必須被同意",alpha:()=>"此欄位只能包含字母",alphaDash:()=>"此欄位只能包含字母、數字、連接號和底線",alphaDashDot:()=>"此欄位只能包含字母、數字、連接號、底線和點",alphaNum:()=>"此欄位只能包含字母和數字",array:()=>"此欄位必須是一個陣列",ascii:()=>"此欄位只能包含ASCII字元和符號",between:(t,e)=>{const{min:r,max:s}=e;return{number:`此欄位必須介於${n(r)}到${n(s)}`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(s)}`}},betweenLength:(t,e)=>{const{min:r,max:s}=e;return`此欄位必須介於${n(r)}到${n(s)}個項目之間`},boolean:()=>"此欄位必須是一個布林值",containsAll:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下所有項目:${r.join(", ")}`},containsAny:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下其中一個項目:${r.join(", ")}`},declined:()=>"此欄位必須被拒絕",different:(t,e)=>{const{field:r}=e;return`此欄位必須和${r}欄位不同`},distinct:()=>"此欄位不能包含重複的值",domain:()=>"此欄位必須是有效的網域",email:()=>"此欄位必須是有效的電子郵件地址",endsWith:(t,e)=>{const{value:r}=e;return`此欄位必須以${r}結尾`},equals:(t,e)=>{const{value:r}=e;return`此欄位必須是${r}`},file:()=>"此欄位必須是檔案",fileBetweenSize:(t,e)=>{const{min:r,max:s}=e;return{file:`此欄位必須介於${n(r)}到${n(s)} KB之間`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(s)} KB之間`}},fileMaxSize:(t,e)=>{const{size:r}=e;return{file:`此欄位不能大於${n(r)} KB`,array:`此欄位中的每個項目都不能大於${n(r)} KB`}},fileMinSize:(t,e)=>{const{size:r}=e;return{file:`此欄位不能小於${n(r)} KB`,array:`此欄位中的每個項目都不能小於${n(r)} KB`}},fileSize:(t,e)=>{const{size:r}=e;return{file:`此欄位必須是${n(r)} KB`,array:`此欄位中的每個項目都必須是${n(r)} KB`}},http:()=>"此欄位必須以 http:// 或 https:// 開頭",https:()=>"此欄位必須以 https:// 開頭",in:(t,e)=>{const{values:r}=e;return`此欄位必須是以下之一:${r.join(", ")}`},integer:()=>"此欄位必須是整數",json:()=>"此欄位必須是有效的 JSON 字串",length:(t,e)=>{const{length:r}=e;return`此欄位必須包含${n(r)}個項目`},lowercase:()=>"此欄位必須是小寫",max:(t,e)=>{const{max:r}=e;return{number:`此欄位不能大於${n(r)}`,array:`此欄位中的每個項目都不能大於${n(r)}`}},min:(t,e)=>{const{min:r}=e;return{number:`此欄位不能小於${n(r)}`,array:`此欄位中的每個項目都不能小於${n(r)}`}},notEquals:(t,e)=>{const{value:r}=e;return`此欄位不能是${r}`},notIn:(t,e)=>{const{values:r}=e;return`此欄位不能是以下之一:${r.join(", ")}`},number:()=>"此欄位必須是數字",numeric:()=>"此欄位必須是數字",regex:()=>"此欄位必須符合所需的格式",required:()=>"此欄位為必填",same:(t,e)=>{const{field:r}=e;return`此欄位必須與${r}欄位相同`},size:(t,e)=>{const{size:r}=e;return{number:`此欄位必須是${n(r)}`,array:`此欄位中的每個項目都必須是${n(r)}`}},startsWith:(t,e)=>{const{value:r}=e;return`此欄位必須以${r}開頭`},string:()=>"此欄位必須是字串",stringBetweenLength:(t,e)=>{const{min:r,max:s}=e;return{string:`此欄位必須介於${n(r)}到${n(s)}個字元之間`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(s)}個字元之間`}},stringLength:(t,e)=>{const{length:r}=e;return{string:`此欄位必須是${n(r)}個字元`,array:`此欄位中的每個項目都必須是${n(r)}個字元`}},stringMaxLength:(t,e)=>{const{length:r}=e;return{string:`此欄位不能大於${n(r)}個字元`,array:`此欄位中的每個項目都不能大於${n(r)}個字元`}},stringMinLength:(t,e)=>{const{length:r}=e;return{string:`此欄位不能小於${n(r)}個字元`,array:`此欄位中的每個項目都不能小於${n(r)}個字元`}},unique:()=>"此欄位已經存在",uppercase:()=>"此欄位必須是大寫",url:()=>"此欄位必須是有效的網址"}},v=()=>t=>i(t)?!1:["y","yes","on","1","true"].includes(String(t).toLowerCase()),q=()=>t=>i(t)?!1:/^[a-zA-Z]+$/.test(String(t)),M=()=>t=>i(t)?!1:/^[a-zA-Z0-9-_]+$/.test(String(t)),F=()=>t=>i(t)?!1:/^[a-zA-Z0-9-_.]+$/.test(String(t)),_=()=>t=>i(t)?!1:/^[a-zA-Z0-9]+$/.test(String(t)),k=()=>t=>Array.isArray(t),j=()=>t=>i(t)?!1:/^[\x20-\x7E]+$/.test(String(t)),f=({max:t})=>e=>i(e)?!1:typeof e=="number"?e<=t:Array.isArray(e)?e.every(r=>f({max:t})(r)):!1,m=({min:t})=>e=>i(e)?!1:typeof e=="number"?e>=t:Array.isArray(e)?e.every(r=>m({min:t})(r)):!1,B=({min:t,max:e})=>r=>i(r)?!1:m({min:t})(r)&&f({max:e})(r),w=({length:t})=>e=>i(e)?!1:Array.isArray(e)?e.length<=t:!1,T=({length:t})=>e=>i(e)?!1:Array.isArray(e)?e.length>=t:!1,D=({min:t,max:e})=>r=>i(r)?!1:T({length:t})(r)&&w({length:e})(r),E=()=>t=>i(t)?!1:typeof t=="boolean",W=({values:t})=>e=>i(e)||!Array.isArray(e)?!1:t.every(r=>e.includes(r)),I=({values:t})=>e=>i(e)||!Array.isArray(e)?!1:t.some(r=>e.includes(r)),Z=()=>t=>i(t)?!1:["n","no","off","0","false"].includes(String(t).toLowerCase()),C=({value:t})=>e=>i(e)?!1:e!==t,K=()=>t=>i(t)?!1:Array.isArray(t)?new Set(t).size===t.length:!0,N=()=>t=>i(t)?!1:/^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)),O=()=>t=>i(t)?!1:/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)),V=({value:t})=>e=>i(e)?!1:String(e).endsWith(t),J=({value:t})=>e=>e===t,P=()=>t=>t instanceof File,d=({size:t})=>e=>i(e)?!1:e instanceof File?e.size<=t*1024:Array.isArray(e)?e.every(r=>d({size:t})(r)):!1,g=({size:t})=>e=>i(e)?!1:e instanceof File?e.size>=t*1024:Array.isArray(e)?e.every(r=>g({size:t})(r)):!1,U=({min:t,max:e})=>r=>i(r)?!1:g({size:t})(r)&&d({size:e})(r),R=({size:t})=>e=>{if(i(e))return!1;if(e instanceof File){const r=t*1024,s=(t+1)*1024;return e.size>=r&&e.size<s}return Array.isArray(e)?e.every(r=>R({size:t})(r)):!1},c=({value:t})=>e=>i(e)?!1:String(e).startsWith(t),G=()=>t=>i(t)?!1:c({value:"http://"})(t)||c({value:"https://"})(t),H=()=>t=>i(t)?!1:c({value:"https://"})(t),Q=({values:t})=>e=>i(e)?!1:Array.isArray(e)?e.every(r=>t.includes(r)):t.includes(e),y=()=>t=>i(t)?!1:typeof t=="number",X=()=>t=>i(t)?!1:y()(t)&&Number.isInteger(t),Y=()=>t=>{if(i(t))return!1;try{return JSON.parse(String(t)),!0}catch{return!1}},ee=({length:t})=>e=>i(e)?!1:Array.isArray(e)?e.length===t:!1,te=()=>t=>i(t)?!1:String(t)===String(t).toLowerCase(),re=({value:t})=>e=>e!==t,ne=({values:t})=>e=>i(e)?!1:Array.isArray(e)?e.every(r=>!t.includes(r)):!t.includes(e),A=()=>t=>typeof t=="string",se=()=>t=>i(t)?!1:A()(t)?/^-?\d+(\.\d+)?$/.test(String(t)):y()(t),ie=({expression:t})=>e=>{if(i(e))return!1;if(!(t instanceof RegExp))throw new TypeError("The expression provided is not a valid RegExp.");return t.test(String(e))},ae=()=>t=>!i(t),le=({value:t})=>e=>i(e)?!1:Array.isArray(e)?e.every(r=>r===t):e===t,L=({size:t})=>e=>i(e)?!1:typeof e=="number"?e===t:Array.isArray(e)?e.every(r=>L({size:t})(r)):!1,$=({length:t})=>e=>i(e)?!1:typeof e=="string"?e.length<=t:Array.isArray(e)?e.every(r=>$({length:t})(r)):!1,p=({length:t})=>e=>i(e)?!1:typeof e=="string"?e.length>=t:Array.isArray(e)?e.every(r=>p({length:t})(r)):!1,ue=({min:t,max:e})=>r=>i(r)?!1:p({length:t})(r)&&$({length:e})(r),S=({length:t})=>e=>i(e)?!1:typeof e=="string"?e.length===t:Array.isArray(e)?e.every(r=>S({length:t})(r)):!1,he={accepted:v,alpha:q,alphaDash:M,alphaDashDot:F,alphaNum:_,array:k,ascii:j,between:B,betweenLength:D,boolean:E,containsAll:W,containsAny:I,declined:Z,different:C,distinct:K,domain:N,email:O,endsWith:V,equals:J,file:P,fileBetweenSize:U,fileMaxSize:d,fileMinSize:g,fileSize:R,http:G,https:H,in:Q,integer:X,json:Y,length:ee,lowercase:te,max:f,maxLength:w,min:m,minLength:T,notEquals:re,notIn:ne,number:y,numeric:se,regex:ie,required:ae,same:le,size:L,startsWith:c,string:A,stringBetweenLength:ue,stringLength:S,stringMaxLength:$,stringMinLength:p,unique:({values:t,ignored:e=[]})=>r=>i(r)?!1:(Array.isArray(e)?e:[e]).some(s=>s===r)?!0:!t.some(s=>s===r),uppercase:()=>t=>i(t)?!1:String(t)===String(t).toUpperCase(),url:()=>t=>i(t)?!1:/^(https?):\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}.*$/.test(String(t))};class oe{constructor({fallbackLocale:e,locale:r,plugins:s}={}){h(this,"locale","en");h(this,"fallbackLocale","en");h(this,"locales",{});h(this,"rules",{});this.registerLocales(x),this.registerRules(he),e&&this.setFallbackLocale(e),r&&this.setLocale(r),s&&s.forEach(a=>this.registerPlugin(a))}getLocale(){return this.locale}getFallbackLocale(){return this.fallbackLocale}setLocale(e){if(!(e in this.locales))throw new Error(`The "${e}" locale is not registered.`);return this.locale=e,this}setFallbackLocale(e){if(!(e in this.locales))throw new Error(`The "${e}" fallback locale is not registered.`);return this.fallbackLocale=e,this}defineField(e){return new b({name:e,locale:this.locale,fallbackLocale:this.fallbackLocale,locales:this.locales,rules:this.rules})}registerLocales(e){return this.locales=Object.keys(e).reduce((r,s)=>(r[s]={...this.locales[s],...e[s]},r),{...this.locales}),this}registerRules(e){return this.rules={...this.rules,...e},this}registerPlugin(e){if(!e||!e.locales||!e.rules)throw new Error('The plugin must have "locales" and "rules" properties.');return this.registerLocales(e.locales).registerRules(e.rules)}}u.FieldValidator=b,u.FormValidator=oe,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
+
export interface BetweenLengthRuleArguments extends RuleArguments {
|
|
3
|
+
min: number;
|
|
4
|
+
max: number;
|
|
5
|
+
}
|
|
6
|
+
declare const betweenLengthRule: Rule<BetweenLengthRuleArguments>;
|
|
7
|
+
export default betweenLengthRule;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
+
export interface DifferentRuleArguments extends RuleArguments {
|
|
3
|
+
field: string;
|
|
4
|
+
value: unknown;
|
|
5
|
+
}
|
|
6
|
+
declare const differentRule: Rule<DifferentRuleArguments>;
|
|
7
|
+
export default differentRule;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
+
export interface FileBetweenSizeRuleArguments extends RuleArguments {
|
|
3
|
+
min: number;
|
|
4
|
+
max: number;
|
|
5
|
+
}
|
|
6
|
+
declare const fileBetweenSizeRule: Rule<FileBetweenSizeRuleArguments>;
|
|
7
|
+
export default fileBetweenSizeRule;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
+
export interface StringBetweenLengthRuleArguments extends RuleArguments {
|
|
3
|
+
min: number;
|
|
4
|
+
max: number;
|
|
5
|
+
}
|
|
6
|
+
declare const stringBetweenLengthRule: Rule<StringBetweenLengthRuleArguments>;
|
|
7
|
+
export default stringBetweenLengthRule;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
+
export interface StringMaxLengthRuleArguments extends RuleArguments {
|
|
3
|
+
length: number;
|
|
4
|
+
}
|
|
5
|
+
declare const stringMaxLengthRule: Rule<StringMaxLengthRuleArguments>;
|
|
6
|
+
export default stringMaxLengthRule;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
+
export interface StringMinLengthRuleArguments extends RuleArguments {
|
|
3
|
+
length: number;
|
|
4
|
+
}
|
|
5
|
+
declare const stringMinLengthRule: Rule<StringMinLengthRuleArguments>;
|
|
6
|
+
export default stringMinLengthRule;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
+
export interface UniqueRuleArguments extends RuleArguments {
|
|
3
|
+
values: unknown[];
|
|
4
|
+
ignored?: unknown[] | unknown;
|
|
5
|
+
}
|
|
6
|
+
declare const uniqueRule: Rule<UniqueRuleArguments>;
|
|
7
|
+
export default uniqueRule;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { default as Conditions } from './Conditions';
|
|
2
|
+
import { default as FieldValidatorArguments } from './FieldValidatorArguments';
|
|
3
|
+
import { default as FormValidatorArguments } from './FormValidatorArguments';
|
|
4
|
+
export type { Conditions, FieldValidatorArguments, FormValidatorArguments, };
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kklab/fortress-validator",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "1.0.9",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "tsc -p ./tsconfig.build.json && vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"lint": "eslint lib",
|
|
11
|
+
"test": "npm run test:unit -- --run && npm run test:integration",
|
|
12
|
+
"test:unit": "vitest",
|
|
13
|
+
"test:integration": "playwright test",
|
|
14
|
+
"release": "npm run test && npm run build && npm publish --access public"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@kklab/fortress-validator-utils": "^1.0.1"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@kklab/fortress-validator-plugin-date": "^1.0.4",
|
|
21
|
+
"@kklab/fortress-validator-plugin-json-schema": "^1.0.4"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@eslint/js": "^9.7.0",
|
|
25
|
+
"@kklab/fortress-validator-types": "^1.0.0",
|
|
26
|
+
"@playwright/test": "^1.48.2",
|
|
27
|
+
"@stylistic/eslint-plugin": "^2.9.0",
|
|
28
|
+
"@types/eslint__js": "^8.42.3",
|
|
29
|
+
"@types/node": "^20.14.12",
|
|
30
|
+
"@vitejs/plugin-vue": "^4.6.2",
|
|
31
|
+
"ajv": "^8.17.1",
|
|
32
|
+
"dayjs": "^1.11.13",
|
|
33
|
+
"eslint": "^8.57.0",
|
|
34
|
+
"globals": "^15.8.0",
|
|
35
|
+
"jsdom": "^24.1.1",
|
|
36
|
+
"typescript": "^5.0.2",
|
|
37
|
+
"typescript-eslint": "^7.17.0",
|
|
38
|
+
"vite": "^4.4.5",
|
|
39
|
+
"vite-plugin-dts": "^4.2.3",
|
|
40
|
+
"vitest": "^2.1.2",
|
|
41
|
+
"vue": "^3.4.33",
|
|
42
|
+
"vue-tsc": "^2.0.28",
|
|
43
|
+
"vuetify": "^3.6.13"
|
|
44
|
+
},
|
|
45
|
+
"main": "dist/index.js",
|
|
46
|
+
"types": "dist/index.d.ts",
|
|
47
|
+
"files": [
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
50
|
+
"exports": {
|
|
51
|
+
".": {
|
|
52
|
+
"import": "./dist/index.js",
|
|
53
|
+
"require": "./dist/index.umd.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "https://gitlab.com/kklab-com/vd/0-1-lab/chemi/fortress-validator"
|
|
59
|
+
},
|
|
60
|
+
"keywords": [
|
|
61
|
+
"form",
|
|
62
|
+
"validation",
|
|
63
|
+
"validator"
|
|
64
|
+
]
|
|
65
|
+
}
|