najwer23morsels 1.11.2 → 1.11.3
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/lib/validator/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { validator } from './validator';
|
|
2
|
+
import { VALIDATOR_MESSAGE_COLORS } from './validator.const';
|
|
2
3
|
import { ValidatorOptions } from './validator.types';
|
|
3
4
|
export type { ValidatorOptions };
|
|
4
|
-
export { validator };
|
|
5
|
+
export { VALIDATOR_MESSAGE_COLORS, validator };
|
package/lib/validator/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>""===e||(e=>{const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;const n=Number(t[1]),r=Number(t[2]),u=Number(t[3]);if(r<1||r>12)return!1;const l=[31,28,31,30,31,30,31,31,30,31,30,31];return(n%400==0||n%100!=0&&n%4==0)&&(l[1]=29),u>=1&&u<=l[r-1]})(e),t={empty:e=>""===e.trim()||null===e.trim()?"The field cannot be empty.":null,equal:(e,t)=>{const n=t?.ref?.current?.value;return e&&n&&e!==n?"Values do not match.":null},email:e=>/^(?!.*\.{2})(?!.*\.$)(?!^\.)([a-zA-Z0-9._%+-]+)@([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(e)?null:"Incorrect email address.",numberInRange:(e,t)=>{const n=Number(e),r=t?.min??0,u=t?.max??1e4;return isNaN(n)||n<r||n>u?`The number must be between ${r} and ${u}.`:null},date:t=>e(t)?null:"The date is invalid.",existsInOptions:(e,t)=>{const n=t?.options??[],r=t?.matchBy??"value";return n.some(t=>"value"===r?t.value===e:t.label===e)?null:"Please select a value from the list."},json:e=>{try{const t=JSON.parse(e);return null===t||"object"!=typeof t&&!Array.isArray(t)?"The value must be a valid JSON":null}catch{return"The value must be a valid JSON."}},naturalNumber:e=>{if(""===e)return null;if(!/^([1-9][0-9]*|0)$/.test(e))return"The number must be a natural number (positive integer).";const t=Number(e);return isNaN(t)||t<=0||!Number.isInteger(t)?"The number must be a natural number (positive integer).":null},decimalDigits:(e,t)=>{if(""===e)return null;const n=Number(e);if(isNaN(n))return"The value must be a valid number.";if(void 0===t?.digits)return null;if(!e.includes("."))return`The number must have exactly ${t.digits} digit(s) after the decimal point.`;return e.split(".")[1].length!==t.digits?`The number must have exactly ${t.digits} digit(s) after the decimal point.`:null}},n=(e,n)=>n.map(n=>"options"in n?t[n.type](e,n.options):t[n.type](e)).filter(e=>null!=e);export{n as validator};
|
|
1
|
+
export{V as VALIDATOR_MESSAGE_COLORS}from"../validator.const-LBF9whmW.js";const e=e=>""===e||(e=>{const t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;const n=Number(t[1]),r=Number(t[2]),u=Number(t[3]);if(r<1||r>12)return!1;const l=[31,28,31,30,31,30,31,31,30,31,30,31];return(n%400==0||n%100!=0&&n%4==0)&&(l[1]=29),u>=1&&u<=l[r-1]})(e),t={empty:e=>""===e.trim()||null===e.trim()?"The field cannot be empty.":null,equal:(e,t)=>{const n=t?.ref?.current?.value;return e&&n&&e!==n?"Values do not match.":null},email:e=>/^(?!.*\.{2})(?!.*\.$)(?!^\.)([a-zA-Z0-9._%+-]+)@([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(e)?null:"Incorrect email address.",numberInRange:(e,t)=>{const n=Number(e),r=t?.min??0,u=t?.max??1e4;return isNaN(n)||n<r||n>u?`The number must be between ${r} and ${u}.`:null},date:t=>e(t)?null:"The date is invalid.",existsInOptions:(e,t)=>{const n=t?.options??[],r=t?.matchBy??"value";return n.some(t=>"value"===r?t.value===e:t.label===e)?null:"Please select a value from the list."},json:e=>{try{const t=JSON.parse(e);return null===t||"object"!=typeof t&&!Array.isArray(t)?"The value must be a valid JSON":null}catch{return"The value must be a valid JSON."}},naturalNumber:e=>{if(""===e)return null;if(!/^([1-9][0-9]*|0)$/.test(e))return"The number must be a natural number (positive integer).";const t=Number(e);return isNaN(t)||t<=0||!Number.isInteger(t)?"The number must be a natural number (positive integer).":null},decimalDigits:(e,t)=>{if(""===e)return null;const n=Number(e);if(isNaN(n))return"The value must be a valid number.";if(void 0===t?.digits)return null;if(!e.includes("."))return`The number must have exactly ${t.digits} digit(s) after the decimal point.`;return e.split(".")[1].length!==t.digits?`The number must have exactly ${t.digits} digit(s) after the decimal point.`:null}},n=(e,n)=>n.map(n=>"options"in n?t[n.type](e,n.options):t[n.type](e)).filter(e=>null!=e);export{n as validator};
|