UNPKG

@resk/core

Version:

An innovative TypeScript framework that empowers developers to build applications with a fully decorator-based architecture for efficient resource management. By combining the power of decorators with a resource-oriented design, DecorRes enhances code cla

1 lines 1.16 kB
'use strict';var i18n=require('../../i18n'),utils=require('../../utils'),validator=require('../validator');var I=Object.defineProperty;var i=Object.getOwnPropertySymbols;var d=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable;var n=(e,t,o)=>t in e?I(e,t,{enumerable:true,configurable:true,writable:true,value:o}):e[t]=o,u=(e,t)=>{for(var o in t||(t={}))d.call(t,o)&&n(e,o,t[o]);if(i)for(var o of i(t))f.call(t,o)&&n(e,o,t[o]);return e};var V=(e,t)=>{var o={};for(var a in e)d.call(e,a)&&t.indexOf(a)<0&&(o[a]=e[a]);if(e!=null&&i)for(var a of i(e))t.indexOf(a)<0&&f.call(e,a)&&(o[a]=e[a]);return o};function w(y){var s=y,{value:e,fieldName:t,translatedPropertyName:o}=s,a=V(s,["value","fieldName","translatedPropertyName"]);return new Promise((m,p)=>{const B=[true,false,1,0,"1","0"];let l=e;if(typeof e=="string"){const r=e.toLowerCase();r==="true"?l=true:r==="false"?l=false:l=e;}if(B.includes(l))m(true);else {const r=i18n.i18n.t("validator.Boolean",u({field:utils.defaultStr(o,t),value:e},a));p(r);}})}const S=validator.Validator.createPropertyDecorator(["Boolean"]);validator.Validator.registerRule("Boolean",w);exports.IsBoolean=S;