@jdlien/validator-utils 2.0.0 → 2.1.0
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/LICENSE +7 -0
- package/README.md +53 -3
- package/dist/index.d.ts +1 -0
- package/dist/{validator-utils.d.ts → src/validator-utils.d.ts} +19 -0
- package/dist/validator-utils.cjs +1 -0
- package/dist/validator-utils.js +1 -1
- package/dist/validator-utils.mjs +430 -0
- package/package.json +26 -20
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 JD Lien
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Introduction
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The Validator Utils package is a lightweight (~15KB or ~5KB gzipped) library of utility functions that can validate and sanitize
|
|
6
6
|
dates, times, strings, numbers, and more. This is especially useful in forms. This package is the sole dependency for the [@jdlien/validator package](https://github.com/jdlien/validator).
|
|
7
7
|
|
|
8
8
|
This package was separated from Validator so that it could be used in other projects without
|
|
@@ -12,12 +12,32 @@ pulling in the entire Validator package if you only need some of its validation
|
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
npm install @jdlien/validator-utils
|
|
15
|
+
|
|
16
|
+
# or
|
|
17
|
+
|
|
18
|
+
yarn add @jdlien/validator-utils
|
|
19
|
+
|
|
20
|
+
# or
|
|
21
|
+
|
|
22
|
+
pnpm add @jdlien/validator-utils
|
|
15
23
|
```
|
|
16
24
|
|
|
17
25
|
## Utility Functions
|
|
18
26
|
|
|
19
27
|
Validator includes several utility functions that may be useful in your own code, so they are exported as part of the module.
|
|
20
|
-
If you
|
|
28
|
+
If you're using a bundler:
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
import { parseDate, formatDateTime } from '@jdlien/validator-utils'
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
If you're using CommonJS:
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
const { parseDate, formatDateTime } = require('@jdlien/validator-utils')
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
If you prefer to access the utilities as a single object:
|
|
21
41
|
|
|
22
42
|
```javascript
|
|
23
43
|
import * as validatorUtils from '@jdlien/validator-utils'
|
|
@@ -25,6 +45,21 @@ import * as validatorUtils from '@jdlien/validator-utils'
|
|
|
25
45
|
const { parseDate, formatDateTime } = validatorUtils
|
|
26
46
|
```
|
|
27
47
|
|
|
48
|
+
If you are not using a bundler, you can load a UMD or ESM build directly:
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<!-- UMD (global validatorUtils) -->
|
|
52
|
+
<script src="https://unpkg.com/@jdlien/validator-utils/dist/validator-utils.js"></script>
|
|
53
|
+
<script>
|
|
54
|
+
const { parseDate, formatDateTime } = validatorUtils
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<!-- ESM (module) -->
|
|
58
|
+
<script type="module">
|
|
59
|
+
import { parseDate, formatDateTime } from 'https://unpkg.com/@jdlien/validator-utils/dist/validator-utils.mjs'
|
|
60
|
+
</script>
|
|
61
|
+
```
|
|
62
|
+
|
|
28
63
|
Here is a list of the utility functions:
|
|
29
64
|
|
|
30
65
|
- **isFormControl**: Determines if an element is an HTML input, select, or textarea element.
|
|
@@ -38,7 +73,8 @@ Here is a list of the utility functions:
|
|
|
38
73
|
- **formatDateTime**: Formats a date string or Date object into a string with a specified format.
|
|
39
74
|
- **parseDateToString**: Parses a date string or Date object into a formatted string with the specified moment.js-style date format.
|
|
40
75
|
- **isDate**: Determines if a value is a valid date.
|
|
41
|
-
- **isDateInRange**: Determines if a date falls within a specified range (
|
|
76
|
+
- **isDateInRange**: Determines if a date falls within a specified range. Supports keywords (`past`, `future`, `today`), specific date ranges (`2023-01-01:2023-12-31`), open-ended ranges (`:2025-12-31`, `2020-01-01:`), relative offsets (`-30d:+30d`, `-1y:`, `:+6m`), and date-time bounds (`2024-01-01T12:00:2024-01-01T14:00`).
|
|
77
|
+
- **parseRelativeDate**: Parses a relative date offset (e.g., `-30d`, `+2w`, `30d`, `-6m`, `+1y`) into a Date object.
|
|
42
78
|
- **isTime**: Determines if a value is a valid time.
|
|
43
79
|
- **isEmail**: Determines if a value is a valid email address.
|
|
44
80
|
- **parseNANPTel**: Parses a North American phone number string into a standardized format.
|
|
@@ -46,6 +82,8 @@ Here is a list of the utility functions:
|
|
|
46
82
|
- **parseInteger**: Parses an integer string into a standardized format.
|
|
47
83
|
- **isNumber**: Determines if a value is a valid number.
|
|
48
84
|
- **parseNumber**: Parses a number string into a standardized format.
|
|
85
|
+
- **parseBytes**: Parses a human-readable byte size (e.g., "1.5 MB", "2GiB") into bytes.
|
|
86
|
+
- **formatBytes**: Formats a byte count as a human-readable string (e.g., "1.5 MB", "512 B").
|
|
49
87
|
- **isInteger**: Determines if a value is a valid integer.
|
|
50
88
|
- **parseUrl**: Parses a URL string into a standardized format.
|
|
51
89
|
- **isUrl**: Determines if a value is a valid URL.
|
|
@@ -64,3 +102,15 @@ Install dev dependencies:
|
|
|
64
102
|
```bash
|
|
65
103
|
pnpm install
|
|
66
104
|
```
|
|
105
|
+
|
|
106
|
+
Run tests with coverage (100% required for release):
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pnpm coverage
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Build the project for testing/release:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pnpm build
|
|
116
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isFormControl, isType, monthToNumber, yearToFull, parseDate, parseDateTime, parseTime, parseTimeToString, parseDateTimeToString, formatDateTime, momentToFPFormat, parseDateToString, isDate, isDateInRange, parseRelativeDate, isMeridiem, isDateTime, isTime, isEmail, parseNANPTel, isNANPTel, parseInteger, isNumber, parseNumber, isInteger, parseBytes, formatBytes, parseUrl, isUrl, parseZip, isZip, parsePostalCA, isPostalCA, isColor, parseColor, normalizeValidationResult, } from './src/validator-utils';
|
|
@@ -20,6 +20,11 @@ export declare function parseDateToString(value: string | Date, format?: string)
|
|
|
20
20
|
export declare function parseDateTimeToString(value: string | Date, format?: string): string;
|
|
21
21
|
export declare function parseTimeToString(value: string, format?: string): string;
|
|
22
22
|
export declare function monthToNumber(str: string | number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Parses a relative date offset like "-30d", "+2w", "30d", "-6m", "+1y"
|
|
25
|
+
* Returns a Date object relative to today, or null if invalid
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseRelativeDate(offset: string): Date | null;
|
|
23
28
|
export declare function isDateInRange(date: Date, range: string): boolean;
|
|
24
29
|
export declare function isFormControl(el: any): boolean;
|
|
25
30
|
export declare function isType(el: HTMLInputElement | HTMLTextAreaElement, types: string | string[]): boolean;
|
|
@@ -30,6 +35,20 @@ export declare function parseInteger(value: string): string;
|
|
|
30
35
|
export declare function isInteger(value: string): boolean;
|
|
31
36
|
export declare function parseNumber(value: string): string;
|
|
32
37
|
export declare function isNumber(value: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Parses a human-readable byte size string into bytes.
|
|
40
|
+
* Accepts: 500, 5B, 5K, 5KB, 5KiB, 5Ki, 5M, 5MB, 5MiB, etc.
|
|
41
|
+
* SI units (KB, MB) use powers of 1000; binary units (KiB, MiB) use powers of 1024.
|
|
42
|
+
* Returns NaN for invalid input.
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseBytes(value: string): number;
|
|
45
|
+
/**
|
|
46
|
+
* Formats bytes as a human-readable string.
|
|
47
|
+
* @param bytes - The number of bytes
|
|
48
|
+
* @param decimal - If true (default), uses SI units (1000-based). If false, uses binary (1024-based).
|
|
49
|
+
* @returns Formatted string like "1.5 MB" or "512 B"
|
|
50
|
+
*/
|
|
51
|
+
export declare function formatBytes(bytes: number, decimal?: boolean): string;
|
|
33
52
|
export declare function parseUrl(value: string): string;
|
|
34
53
|
export declare function isUrl(value: string): boolean;
|
|
35
54
|
export declare function parseZip(value: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=/^(?:[a-z+]+:)?\/\//i,C=/^(?:[-a-z+]+:)?\/\//i,R=/^\d{5}(-\d{4})?$/,H=/^[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ] ?[0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]$/,_=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/,I=/^\d{3}-\d{3}-\d{4}$/,B=/^-?\d*$/,L=/^-?\d*\.?\d*$/;function h(e){let t=e.trim().toLowerCase();if(t==="now"){const u=new Date;return{hour:u.getHours(),minute:u.getMinutes(),second:u.getSeconds()}}if(t==="noon")return{hour:12,minute:0,second:0};t=t.replace(/\s+/g,"").replace(/\.+$/g,"");const s=t.replace(/^(\d{1,2})(\d{2})([ap]?m?\.?)$/i,"$1:$2$3").match(/^(\d{1,2})(?::(\d{1,2}))?(?::(\d{1,2}))?\s*([ap])?\.?m?\.?$/i);if(!s)return null;let i=+s[1],a=+(s[2]||0),o=+(s[3]||0);const c=s[4]?.toLowerCase();return c==="p"&&i<12&&(i+=12),c==="a"&&i===12&&(i=0),i>23||a>59||o>59?null:{hour:i,minute:a,second:o}}function P(e){return h(e)!==null}function Z(e){return/^[ap]\.?m?\.?$/i.test(e.replace(/\s/g,""))}const z="jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",A=new RegExp(`(${z})[a-z]*`,"i");function O(e){return new Date(`1 ${e} 2000`).getMonth()}function M(e){if(typeof e=="string"&&(e=parseInt(e.replace(/\D/g,""))),e>99)return e;const t=(new Date().getFullYear()+20)%100;return e+(e<t?2e3:1900)}function T(e){if(e instanceof Date)return e;let t=e.trim().toLowerCase();const n=new Date(new Date().setHours(0,0,0,0));if(/^(now|today)$/.test(t))return n;if(t==="tomorrow")return new Date(n.setDate(n.getDate()+1));t=t.replace(/\b(mon|tue|wed|thu|fri|sat|sun|lun|mar(?:di|tes)|mer|jeu|ven|sam|dim|dom)[a-z]*\.?\b/gi,"").trim();let s=0,i=0,a=0;const o=t.match(/(\d{1,2}:\d{2}(?::\d{2})?\s*[ap]?\.?m?\.?)/i);if(o){const p=h(o[1]);if(p&&({hour:s,minute:i,second:a}=p),t=t.replace(o[0],"").trim(),!t||t.length<=2){const g=new Date;return new Date(g.getFullYear(),g.getMonth(),g.getDate(),s,i,a)}}if(/^\d{8}$/.test(t))return new Date(+t.slice(0,4),+t.slice(4,6)-1,+t.slice(6,8),s,i,a);if(/^\d{6}$/.test(t))return new Date(M(+t.slice(0,2)),+t.slice(2,4)-1,+t.slice(4,6),s,i,a);const c=t.match(A);let u=-1,l=0,r=0;c&&(u=O(c[1]),t=t.replace(c[0]," ").trim());const m=t.match(/'(\d{2})\b/);m&&(l=M(+m[1]),t=t.replace(m[0]," ").trim());const d=t.match(/\d+/g)?.map(Number)||[];if(u>=0)d.length>=2?d[0]>99?(l=d[0],r=d[1]):d[1]>99?(l=d[1],r=d[0]):d[0]>31?(r=d[1],l=M(d[0])):d[1]>31?(r=d[0],l=M(d[1])):(r=d[0],l=l||M(d[1])):d.length===1&&(r=d[0],l=l||new Date().getFullYear());else if(d.length>=3){const[p,g,f]=d;p>31?(l=p,u=g-1,r=f):p>12&&f>12?(r=p,u=g-1,l=f>31?f:M(f)):f>31||f>12?(u=p-1,r=g,l=f>31?f:M(f)):(g>12,u=p-1,r=g,l=M(f))}else d.length===2&&(u=d[0]-1,r=d[1],l=l||new Date().getFullYear());return l&&u>=0&&r&&r>=1&&r<=31?new Date(l>99?l:M(l),u,r,s,i,a):new Date("")}function w(e){if(e instanceof Date)return e;let t=e.trim();if(t.length<3)return null;if(t=t.replace(/(\d)T(\d)/i,"$1 $2"),t=t.replace(/(^|[\sT])(\d{1,2})\.(\d{1,2})(?:\.(\d{1,2}))?(?=\s*[ap]\.?m?\.?\b|(?:\s|$))/gi,(c,u,l,r,m)=>`${u}${m?`${l}:${r}:${m}`:`${l}:${r}`}`),/^now$/i.test(t)){const c=new Date;return c.setMilliseconds(0),c}if(/^noon$/i.test(t)){const c=new Date;return new Date(c.getFullYear(),c.getMonth(),c.getDate(),12,0,0)}let n=null,s=t;const i=[/(\d{1,2}:\d{1,2}(?::\d{2})?)\s*([ap]\.?m?\.?)?/i,/\b(\d{1,2})\s*([ap]\.?m?\.?)\b/i,/\b(\d{3,4})([ap])m?\b/i];for(const c of i){const u=t.match(c);if(u){const l=h(u[0]);if(l){n=l,s=t.replace(u[0]," ").replace(/[\s.]+$/g,"").replace(/\s+/g," ").trim();break}}}if(!n){const c=s.match(/^(\d{4}[\-\/\.\s]\d{1,2}[\-\/\.\s]\d{1,2}|\d{8})\s+(\d{1,6})(\s*[ap]\.?m?\.?)?(?:\s*(?:z|utc|gmt|[+-]\d{2}:?\d{2})\b)?$/i);if(c){const u=c[2],l=(c[3]||"").replace(/\s+/g,"");let r=u+l;u.length===6&&(r=`${u.slice(0,2)}:${u.slice(2,4)}:${u.slice(4,6)}${l}`);const m=h(r);m&&(n=m,s=c[1])}}if(!n){const c=s.match(/^(.+?)\s+(\d{1,2})(\s*[ap]\.?m?\.?)?$/i);if(c){const u=c[2]+(c[3]||""),l=h(u);l&&A.test(c[1])&&(n=l,s=c[1])}}if(n&&(!s||/^,?\s*$/.test(s))){const c=new Date;return new Date(c.getFullYear(),c.getMonth(),c.getDate(),n.hour,n.minute,n.second)}const a=T(s);if(isNaN(a.getTime()))return null;const o=n||{hour:0,minute:0,second:0};return new Date(a.getFullYear(),a.getMonth(),a.getDate(),o.hour,o.minute,o.second)}function Y(e,t="YYYY-MM-DD"){if(typeof e=="string"&&(e=T(e)),isNaN(e.getTime()))return"";const n=e.getFullYear(),s=e.getMonth(),i=e.getDate(),a=e.getDay(),o=e.getHours(),c=e.getMinutes(),u=e.getSeconds(),l=e.getMilliseconds(),r=(b,$=2)=>String(b).padStart($,"0"),m=o%12||12,d=o<12?"AM":"PM",p=["January","February","March","April","May","June","July","August","September","October","November","December"],g=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],f={YYYY:n,YY:String(n).slice(-2),MMMM:p[s],MMM:p[s].slice(0,3),MM:r(s+1),M:s+1,DD:r(i),D:i,dddd:g[a],ddd:g[a].slice(0,3),dd:g[a].slice(0,2),d:a,HH:r(o),H:o,hh:r(m),h:m,mm:r(c),m:c,ss:r(u),s:u,SSS:r(l,3),A:d,a:d.toLowerCase()};return t.replace(/\[([^\]]+)]|YYYY|YY|MMMM|MMM|MM|M|DD|D|dddd|ddd|dd|d|HH|H|hh|h|mm|m|ss|s|SSS|A|a/g,(b,$)=>$??String(f[b]))}const j={YYYY:"Y",YY:"y",MMMM:"F",MMM:"M",MM:"m",M:"n",DD:"d",D:"j",dddd:"l",ddd:"D",dd:"D",d:"w",HH:"H",H:"G",hh:"h",mm:"i",m:"i",ss:"S",s:"s",A:"K",a:"K"},K=/YYYY|YY|MMMM|MMM|MM|M|DD|D|dddd|ddd|dd|d|HH|H|hh|mm|m|ss|s|A|a/g;function U(e){return e.replace(K,t=>j[t])}function x(e){return typeof e!="string"&&!(e instanceof Date)?!1:!isNaN(T(e).getTime())}function G(e){if(typeof e!="string"&&!(e instanceof Date))return!1;const t=w(e);return t!==null&&!isNaN(t.getTime())}function V(e,t="YYYY-MMM-DD"){const n=T(e);return isNaN(n.getTime())?"":Y(n,t)}function k(e,t="YYYY-MMM-DD h:mm A"){const n=w(e);return n&&!isNaN(n.getTime())?Y(n,t):""}function J(e,t="h:mm A"){const n=h(e);if(!n)return"";const s=new Date;return s.setHours(n.hour,n.minute,n.second,0),Y(s,t)}const y={ja:0,en:0,fe:1,fé:1,ap:3,ab:3,av:3,mai:4,juin:5,juil:6,au:7,ag:7,ao:7,se:8,o:9,n:10,d:11};function W(e){if(typeof e=="number")return e-1;const t=parseInt(e);if(!isNaN(t))return t-1;const n=new Date(`1 ${e} 2000`).getMonth();if(!isNaN(n))return n;const s=e.toLowerCase();for(const i in y)if(s.startsWith(i))return y[i];throw new Error("Invalid month name: "+e)}function E(e){const t=e.match(/^([+-])?(\d+)([dwmy])$/i);if(!t)return null;const[,n,s,i]=t,a=parseInt(s)*(n==="-"?-1:1),o=new Date;switch(o.setHours(0,0,0,0),i.toLowerCase()){case"d":o.setDate(o.getDate()+a);break;case"w":o.setDate(o.getDate()+a*7);break;case"m":o.setMonth(o.getMonth()+a);break;case"y":o.setFullYear(o.getFullYear()+a);break}return o}const S=/(\d{1,2}:\d{2}|\d{1,2}\.\d{2}|\b\d{1,2}\s*[ap]\b|\b[ap]\.?m\.?\b|\bnoon\b|\bnow\b|T\d{1,2})/i,X=/(\d{1,2}[-/.]\d{1,2}(?:[-/.]\d{2,4})?|\b\d{4}\b|\b\d{6,8}\b|\b(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)\b|\btoday\b|\btomorrow\b|\byesterday\b)/i;function v(e,t){if(t==="past")return e<=new Date;if(t==="future")return e.getTime()>=new Date().setHours(0,0,0,0);if(t==="today"){const r=new Date;return e.getFullYear()===r.getFullYear()&&e.getMonth()===r.getMonth()&&e.getDate()===r.getDate()}const n=r=>{const m=r.trim();if(!m)return{date:null,hasTime:!1,valid:!0};const d=E(m);if(d)return{date:d,hasTime:!1,valid:!0};const p=m.search(X);if(p===-1)return{date:null,hasTime:!1,valid:!1};const g=m.search(S);if(g!==-1&&g<p)return{date:null,hasTime:!1,valid:!1};const f=w(m);return f&&!isNaN(f.getTime())?{date:f,hasTime:S.test(m),valid:!0}:{date:null,hasTime:!1,valid:!1}};let s=null;if(t.includes(":"))for(let r=0;r<t.length;r+=1){if(t[r]!==":")continue;const m=n(t.slice(0,r)),d=n(t.slice(r+1));if(m.valid&&d.valid){s={start:m,end:d};break}}if(!s){const r=n(t);return r.valid&&r.date?r.hasTime?e.getTime()===r.date.getTime():e.getFullYear()===r.date.getFullYear()&&e.getMonth()===r.date.getMonth()&&e.getDate()===r.date.getDate():!0}const i=s.start,a=s.end,c=i.hasTime||a.hasTime?e.getTime():new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime();let u=null;i.date&&(u=i.hasTime?i.date.getTime():new Date(i.date.getFullYear(),i.date.getMonth(),i.date.getDate()).getTime());let l=null;return a.date&&(l=a.hasTime?a.date.getTime():new Date(a.date.getFullYear(),a.date.getMonth(),a.date.getDate(),23,59,59,999).getTime()),!(u!==null&&c<u||l!==null&&c>l)}function q(e){return e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement}function Q(e,t){return typeof t=="string"&&(t=[t]),t.includes(e.dataset.type||"")||t.includes(e.type)}function ee(e){return e.length<=255&&_.test(e)}function te(e){return e.replace(/^[^2-90]+/g,"").replace(/(\d\d\d).*?(\d\d\d).*?(\d\d\d\d)(.*)/,"$1-$2-$3$4")}function ne(e){return I.test(e)}function re(e){return e.replace(/[^0-9]/g,"")}function se(e){return B.test(e)}function ie(e){const t=e.replace(/[^\-0-9.]/g,"");let n="",s=!1,i=!1;for(let a=0;a<t.length;a+=1){const o=t[a];if(o==="-"){!i&&n.length===0&&(n+="-",i=!0);continue}if(o==="."){s||(n+=".",s=!0);continue}n+=o}return n}function ae(e){return L.test(e)}const oe={"":1,K:1e3,M:1e6,G:1e9,T:1e12},ce={"":1,K:1024,M:1024**2,G:1024**3,T:1024**4};function le(e){const n=e.trim().match(/^(\d+(?:\.\d*)?|\.\d+)\s*(B|Ki?B?|Mi?B?|Gi?B?|Ti?B?)?$/i);if(!n)return NaN;const s=Number.parseFloat(n[1]),i=n[2]?.toUpperCase()||"",a=i.includes("I"),o=i.replace(/I?B$/i,"").replace(/I$/i,"")||"";return s*(a?ce:oe)[o]}function ue(e,t=!0){const n=t?1e3:1024,s=["B","KB","MB","GB","TB"];if(e<n)return`${e} B`;let i=0,a=e;for(;a>=n&&i<s.length-1;)a/=n,i++;let o=Math.round(a*10)/10;return o>=n&&i<s.length-1&&(o=1,i++),`${o%1===0?o.toFixed(0):o.toFixed(1)} ${s[i]}`}function de(e){return e=e.trim(),F.test(e)?e:"https://"+e}function me(e){return C.test(e)}function fe(e){return e=e.replace(/[^0-9]/g,"").replace(/(.{5})(.*)/,"$1-$2").trim(),e.length===6?e.replace(/-/,""):e}function ge(e){return R.test(e)}function pe(e){return e.toUpperCase().replace(/[^A-Z0-9]/g,"").replace(/(.{3})\s*(.*)/,"$1 $2").trim()}function Me(e){return H.test(e)}function he(e){return["transparent","currentColor"].includes(e)?!0:!e.trim()||typeof CSS>"u"||!CSS.supports?!1:CSS.supports("color",e)}let D=null;const N=new Map;function Te(e){if(e=e.trim().toLowerCase(),["transparent","currentcolor"].includes(e))return e;if(N.has(e))return N.get(e);D||(D=document.createElement("canvas"),D.willReadFrequently=!0);const t=D.getContext("2d");t.fillStyle=e,t.fillRect(0,0,1,1);const n=t.getImageData(0,0,1,1).data,s="#"+("000000"+(n[0]<<16|n[1]<<8|n[2]).toString(16)).slice(-6);return N.set(e,s),s}function De(e){if(typeof e=="boolean")return{valid:e,error:!1,messages:[]};if(typeof e=="string")return{valid:!1,error:!1,messages:[e]};const t={valid:e.valid,error:e.error??!1,messages:[]};return typeof e.message=="string"?t.messages=[e.message]:typeof e.messages=="string"?t.messages=[e.messages]:Array.isArray(e.messages)&&(t.messages=e.messages),t}exports.formatBytes=ue;exports.formatDateTime=Y;exports.isColor=he;exports.isDate=x;exports.isDateInRange=v;exports.isDateTime=G;exports.isEmail=ee;exports.isFormControl=q;exports.isInteger=se;exports.isMeridiem=Z;exports.isNANPTel=ne;exports.isNumber=ae;exports.isPostalCA=Me;exports.isTime=P;exports.isType=Q;exports.isUrl=me;exports.isZip=ge;exports.momentToFPFormat=U;exports.monthToNumber=W;exports.normalizeValidationResult=De;exports.parseBytes=le;exports.parseColor=Te;exports.parseDate=T;exports.parseDateTime=w;exports.parseDateTimeToString=k;exports.parseDateToString=V;exports.parseInteger=re;exports.parseNANPTel=te;exports.parseNumber=ie;exports.parsePostalCA=pe;exports.parseRelativeDate=E;exports.parseTime=h;exports.parseTimeToString=J;exports.parseUrl=de;exports.parseZip=fe;exports.yearToFull=M;
|
package/dist/validator-utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(i=typeof globalThis<"u"?globalThis:i||self,T(i.validatorUtils={}))})(this,(function(i){"use strict";const T=/^(?:[a-z+]+:)?\/\//i,C=/^(?:[-a-z+]+:)?\/\//i,H=/^\d{5}(-\d{4})?$/,R=/^[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ] ?[0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]$/,F=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/,P=/^\d{3}-\d{3}-\d{4}$/,_=/^-?\d*$/,L=/^-?\d*\.?\d*$/;function h(e){let t=e.trim().toLowerCase();if(t==="now"){const o=new Date;return{hour:o.getHours(),minute:o.getMinutes(),second:o.getSeconds()}}if(t==="noon")return{hour:12,minute:0,second:0};t=t.replace(/\s+/g,"").replace(/\.+$/g,"");const r=t.replace(/^(\d{1,2})(\d{2})([ap]?m?\.?)$/i,"$1:$2$3").match(/^(\d{1,2})(?::(\d{1,2}))?(?::(\d{1,2}))?\s*([ap])?\.?m?\.?$/i);if(!r)return null;let l=+r[1],f=+(r[2]||0),m=+(r[3]||0);const s=r[4]?.toLowerCase();return s==="p"&&l<12&&(l+=12),s==="a"&&l===12&&(l=0),l>23||f>59||m>59?null:{hour:l,minute:f,second:m}}function I(e){return h(e)!==null}function Z(e){return/^[ap]\.?m?\.?$/i.test(e.replace(/\s/g,""))}const z="jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",b=new RegExp(`(${z})[a-z]*`,"i");function O(e){return new Date(`1 ${e} 2000`).getMonth()}function D(e){if(typeof e=="string"&&(e=parseInt(e.replace(/\D/g,""))),e>99)return e;const t=(new Date().getFullYear()+20)%100;return e+(e<t?2e3:1900)}function Y(e){if(e instanceof Date)return e;let t=e.trim().toLowerCase();const n=new Date(new Date().setHours(0,0,0,0));if(/^(now|today)$/.test(t))return n;if(t==="tomorrow")return new Date(n.setDate(n.getDate()+1));t=t.replace(/\b(mon|tue|wed|thu|fri|sat|sun|lun|mar(?:di|tes)|mer|jeu|ven|sam|dim|dom)[a-z]*\.?\b/gi,"").trim();let r=0,l=0,f=0;const m=t.match(/(\d{1,2}:\d{2}(?::\d{2})?\s*[ap]?\.?m?\.?)/i);if(m){const M=h(m[1]);if(M&&({hour:r,minute:l,second:f}=M),t=t.replace(m[0],"").trim(),!t||t.length<=2){const d=new Date;return new Date(d.getFullYear(),d.getMonth(),d.getDate(),r,l,f)}}if(/^\d{8}$/.test(t))return new Date(+t.slice(0,4),+t.slice(4,6)-1,+t.slice(6,8),r,l,f);if(/^\d{6}$/.test(t))return new Date(D(+t.slice(0,2)),+t.slice(2,4)-1,+t.slice(4,6),r,l,f);const s=t.match(b);let o=-1,a=0,c=0;s&&(o=O(s[1]),t=t.replace(s[0]," ").trim());const p=t.match(/'(\d{2})\b/);p&&(a=D(+p[1]),t=t.replace(p[0]," ").trim());const u=t.match(/\d+/g)?.map(Number)||[];if(o>=0)u.length>=2?u[0]>99?(a=u[0],c=u[1]):u[1]>99?(a=u[1],c=u[0]):u[0]>31?(c=u[1],a=D(u[0])):u[1]>31?(c=u[0],a=D(u[1])):(c=u[0],a=a||D(u[1])):u.length===1&&(c=u[0],a=a||new Date().getFullYear());else if(u.length>=3){const[M,d,g]=u;M>31?(a=M,o=d-1,c=g):M>12&&g>12?(c=M,o=d-1,a=g>31?g:D(g)):g>31||g>12?(o=M-1,c=d,a=g>31?g:D(g)):(d>12,o=M-1,c=d,a=D(g))}else u.length===2&&(o=u[0]-1,c=u[1],a=a||new Date().getFullYear());return a&&o>=0&&c&&c>=1&&c<=31?new Date(a>99?a:D(a),o,c,r,l,f):new Date("")}function N(e){if(e instanceof Date)return e;let t=e.trim();if(t.length<3)return null;if(t=t.replace(/(\d)T(\d)/i,"$1 $2"),t=t.replace(/(^|[\sT])(\d{1,2})\.(\d{1,2})(?:\.(\d{1,2}))?(?=\s*[ap]\.?m?\.?\b|(?:\s|$))/gi,(s,o,a,c,p)=>`${o}${p?`${a}:${c}:${p}`:`${a}:${c}`}`),/^now$/i.test(t)){const s=new Date;return s.setMilliseconds(0),s}if(/^noon$/i.test(t)){const s=new Date;return new Date(s.getFullYear(),s.getMonth(),s.getDate(),12,0,0)}let n=null,r=t;const l=[/(\d{1,2}:\d{1,2}(?::\d{2})?)\s*([ap]\.?m?\.?)?/i,/\b(\d{1,2})\s*([ap]\.?m?\.?)\b/i,/\b(\d{3,4})([ap])m?\b/i];for(const s of l){const o=t.match(s);if(o){const a=h(o[0]);if(a){n=a,r=t.replace(o[0]," ").replace(/[\s.]+$/g,"").replace(/\s+/g," ").trim();break}}}if(!n){const s=r.match(/^(\d{4}[\-\/\.\s]\d{1,2}[\-\/\.\s]\d{1,2}|\d{8})\s+(\d{1,6})(\s*[ap]\.?m?\.?)?(?:\s*(?:z|utc|gmt|[+-]\d{2}:?\d{2})\b)?$/i);if(s){const o=s[2],a=(s[3]||"").replace(/\s+/g,"");let c=o+a;o.length===6&&(c=`${o.slice(0,2)}:${o.slice(2,4)}:${o.slice(4,6)}${a}`);const p=h(c);p&&(n=p,r=s[1])}}if(!n){const s=r.match(/^(.+?)\s+(\d{1,2})(\s*[ap]\.?m?\.?)?$/i);if(s){const o=s[2]+(s[3]||""),a=h(o);a&&b.test(s[1])&&(n=a,r=s[1])}}if(n&&(!r||/^,?\s*$/.test(r))){const s=new Date;return new Date(s.getFullYear(),s.getMonth(),s.getDate(),n.hour,n.minute,n.second)}const f=Y(r);if(isNaN(f.getTime()))return null;const m=n||{hour:0,minute:0,second:0};return new Date(f.getFullYear(),f.getMonth(),f.getDate(),m.hour,m.minute,m.second)}function $(e,t="YYYY-MM-DD"){if(typeof e=="string"&&(e=Y(e)),isNaN(e.getTime()))return"";const n=e.getFullYear(),r=e.getMonth(),l=e.getDate(),f=e.getDay(),m=e.getHours(),s=e.getMinutes(),o=e.getSeconds(),a=e.getMilliseconds(),c=(A,y=2)=>String(A).padStart(y,"0"),p=m%12||12,u=m<12?"AM":"PM",M=["January","February","March","April","May","June","July","August","September","October","November","December"],d=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],g={YYYY:n,YY:String(n).slice(-2),MMMM:M[r],MMM:M[r].slice(0,3),MM:c(r+1),M:r+1,DD:c(l),D:l,dddd:d[f],ddd:d[f].slice(0,3),dd:d[f].slice(0,2),d:f,HH:c(m),H:m,hh:c(p),h:p,mm:c(s),m:s,ss:c(o),s:o,SSS:c(a,3),A:u,a:u.toLowerCase()};return t.replace(/\[([^\]]+)]|YYYY|YY|MMMM|MMM|MM|M|DD|D|dddd|ddd|dd|d|HH|H|hh|h|mm|m|ss|s|SSS|A|a/g,(A,y)=>y??String(g[A]))}const j={YYYY:"Y",YY:"y",MMMM:"F",MMM:"M",MM:"m",M:"n",DD:"d",D:"j",dddd:"l",ddd:"D",dd:"D",d:"w",HH:"H",H:"G",hh:"h",mm:"i",m:"i",ss:"S",s:"s",A:"K",a:"K"},U=/YYYY|YY|MMMM|MMM|MM|M|DD|D|dddd|ddd|dd|d|HH|H|hh|mm|m|ss|s|A|a/g;function J(e){return e.replace(U,t=>j[t])}function K(e){return typeof e!="string"&&!(e instanceof Date)?!1:!isNaN(Y(e).getTime())}function V(e){if(typeof e!="string"&&!(e instanceof Date))return!1;const t=N(e);return t!==null&&!isNaN(t.getTime())}function G(e,t="YYYY-MMM-DD"){const n=Y(e);return isNaN(n.getTime())?"":$(n,t)}function W(e,t="YYYY-MMM-DD h:mm A"){const n=N(e);return n&&!isNaN(n.getTime())?$(n,t):""}function B(e,t="h:mm A"){const n=h(e);if(!n)return"";const r=new Date;return r.setHours(n.hour,n.minute,n.second,0),$(r,t)}const E={ja:0,en:0,fe:1,fé:1,ap:3,ab:3,av:3,mai:4,juin:5,juil:6,au:7,ag:7,ao:7,se:8,o:9,n:10,d:11};function k(e){if(typeof e=="number")return e-1;const t=parseInt(e);if(!isNaN(t))return t-1;const n=new Date(`1 ${e} 2000`).getMonth();if(!isNaN(n))return n;const r=e.toLowerCase();for(const l in E)if(r.startsWith(l))return E[l];throw new Error("Invalid month name: "+e)}function X(e,t){return!(t==="past"&&e>new Date||t==="future"&&e.getTime()<new Date().setHours(0,0,0,0))}function q(e){return e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement}function Q(e,t){return typeof t=="string"&&(t=[t]),t.includes(e.dataset.type||"")||t.includes(e.type)}function v(e){return e.length<=255&&F.test(e)}function x(e){return e.replace(/^[^2-90]+/g,"").replace(/(\d\d\d).*?(\d\d\d).*?(\d\d\d\d)(.*)/,"$1-$2-$3$4")}function ee(e){return P.test(e)}function te(e){return e.replace(/[^0-9]/g,"")}function ne(e){return _.test(e)}function ie(e){const t=e.replace(/[^\-0-9.]/g,"");let n="",r=!1,l=!1;for(let f=0;f<t.length;f+=1){const m=t[f];if(m==="-"){!l&&n.length===0&&(n+="-",l=!0);continue}if(m==="."){r||(n+=".",r=!0);continue}n+=m}return n}function re(e){return L.test(e)}function se(e){return e=e.trim(),T.test(e)?e:"https://"+e}function ae(e){return C.test(e)}function oe(e){return e=e.replace(/[^0-9]/g,"").replace(/(.{5})(.*)/,"$1-$2").trim(),e.length===6?e.replace(/-/,""):e}function ce(e){return H.test(e)}function ue(e){return e.toUpperCase().replace(/[^A-Z0-9]/g,"").replace(/(.{3})\s*(.*)/,"$1 $2").trim()}function le(e){return R.test(e)}function fe(e){return["transparent","currentColor"].includes(e)?!0:!e.trim()||typeof CSS>"u"||!CSS.supports?!1:CSS.supports("color",e)}let w=null;const S=new Map;function me(e){if(e=e.trim().toLowerCase(),["transparent","currentcolor"].includes(e))return e;if(S.has(e))return S.get(e);w||(w=document.createElement("canvas"),w.willReadFrequently=!0);const t=w.getContext("2d");t.fillStyle=e,t.fillRect(0,0,1,1);const n=t.getImageData(0,0,1,1).data,r="#"+("000000"+(n[0]<<16|n[1]<<8|n[2]).toString(16)).slice(-6);return S.set(e,r),r}function de(e){if(typeof e=="boolean")return{valid:e,error:!1,messages:[]};if(typeof e=="string")return{valid:!1,error:!1,messages:[e]};const t={valid:e.valid,error:e.error??!1,messages:[]};return typeof e.message=="string"?t.messages=[e.message]:typeof e.messages=="string"?t.messages=[e.messages]:Array.isArray(e.messages)&&(t.messages=e.messages),t}i.formatDateTime=$,i.isColor=fe,i.isDate=K,i.isDateInRange=X,i.isDateTime=V,i.isEmail=v,i.isFormControl=q,i.isInteger=ne,i.isMeridiem=Z,i.isNANPTel=ee,i.isNumber=re,i.isPostalCA=le,i.isTime=I,i.isType=Q,i.isUrl=ae,i.isZip=ce,i.momentToFPFormat=J,i.monthToNumber=k,i.normalizeValidationResult=de,i.parseColor=me,i.parseDate=Y,i.parseDateTime=N,i.parseDateTimeToString=W,i.parseDateToString=G,i.parseInteger=te,i.parseNANPTel=x,i.parseNumber=ie,i.parsePostalCA=ue,i.parseTime=h,i.parseTimeToString=B,i.parseUrl=se,i.parseZip=oe,i.yearToFull=D,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(a,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(a=typeof globalThis<"u"?globalThis:a||self,D(a.validatorUtils={}))})(this,(function(a){"use strict";const D=/^(?:[a-z+]+:)?\/\//i,R=/^(?:[-a-z+]+:)?\/\//i,H=/^\d{5}(-\d{4})?$/,_=/^[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ] ?[0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]$/,I=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/,B=/^\d{3}-\d{3}-\d{4}$/,L=/^-?\d*$/,P=/^-?\d*\.?\d*$/;function p(e){let t=e.trim().toLowerCase();if(t==="now"){const d=new Date;return{hour:d.getHours(),minute:d.getMinutes(),second:d.getSeconds()}}if(t==="noon")return{hour:12,minute:0,second:0};t=t.replace(/\s+/g,"").replace(/\.+$/g,"");const s=t.replace(/^(\d{1,2})(\d{2})([ap]?m?\.?)$/i,"$1:$2$3").match(/^(\d{1,2})(?::(\d{1,2}))?(?::(\d{1,2}))?\s*([ap])?\.?m?\.?$/i);if(!s)return null;let r=+s[1],o=+(s[2]||0),c=+(s[3]||0);const l=s[4]?.toLowerCase();return l==="p"&&r<12&&(r+=12),l==="a"&&r===12&&(r=0),r>23||o>59||c>59?null:{hour:r,minute:o,second:c}}function Z(e){return p(e)!==null}function z(e){return/^[ap]\.?m?\.?$/i.test(e.replace(/\s/g,""))}const j="jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",A=new RegExp(`(${j})[a-z]*`,"i");function O(e){return new Date(`1 ${e} 2000`).getMonth()}function T(e){if(typeof e=="string"&&(e=parseInt(e.replace(/\D/g,""))),e>99)return e;const t=(new Date().getFullYear()+20)%100;return e+(e<t?2e3:1900)}function w(e){if(e instanceof Date)return e;let t=e.trim().toLowerCase();const n=new Date(new Date().setHours(0,0,0,0));if(/^(now|today)$/.test(t))return n;if(t==="tomorrow")return new Date(n.setDate(n.getDate()+1));t=t.replace(/\b(mon|tue|wed|thu|fri|sat|sun|lun|mar(?:di|tes)|mer|jeu|ven|sam|dim|dom)[a-z]*\.?\b/gi,"").trim();let s=0,r=0,o=0;const c=t.match(/(\d{1,2}:\d{2}(?::\d{2})?\s*[ap]?\.?m?\.?)/i);if(c){const h=p(c[1]);if(h&&({hour:s,minute:r,second:o}=h),t=t.replace(c[0],"").trim(),!t||t.length<=2){const M=new Date;return new Date(M.getFullYear(),M.getMonth(),M.getDate(),s,r,o)}}if(/^\d{8}$/.test(t))return new Date(+t.slice(0,4),+t.slice(4,6)-1,+t.slice(6,8),s,r,o);if(/^\d{6}$/.test(t))return new Date(T(+t.slice(0,2)),+t.slice(2,4)-1,+t.slice(4,6),s,r,o);const l=t.match(A);let d=-1,u=0,i=0;l&&(d=O(l[1]),t=t.replace(l[0]," ").trim());const f=t.match(/'(\d{2})\b/);f&&(u=T(+f[1]),t=t.replace(f[0]," ").trim());const m=t.match(/\d+/g)?.map(Number)||[];if(d>=0)m.length>=2?m[0]>99?(u=m[0],i=m[1]):m[1]>99?(u=m[1],i=m[0]):m[0]>31?(i=m[1],u=T(m[0])):m[1]>31?(i=m[0],u=T(m[1])):(i=m[0],u=u||T(m[1])):m.length===1&&(i=m[0],u=u||new Date().getFullYear());else if(m.length>=3){const[h,M,g]=m;h>31?(u=h,d=M-1,i=g):h>12&&g>12?(i=h,d=M-1,u=g>31?g:T(g)):g>31||g>12?(d=h-1,i=M,u=g>31?g:T(g)):(M>12,d=h-1,i=M,u=T(g))}else m.length===2&&(d=m[0]-1,i=m[1],u=u||new Date().getFullYear());return u&&d>=0&&i&&i>=1&&i<=31?new Date(u>99?u:T(u),d,i,s,r,o):new Date("")}function Y(e){if(e instanceof Date)return e;let t=e.trim();if(t.length<3)return null;if(t=t.replace(/(\d)T(\d)/i,"$1 $2"),t=t.replace(/(^|[\sT])(\d{1,2})\.(\d{1,2})(?:\.(\d{1,2}))?(?=\s*[ap]\.?m?\.?\b|(?:\s|$))/gi,(l,d,u,i,f)=>`${d}${f?`${u}:${i}:${f}`:`${u}:${i}`}`),/^now$/i.test(t)){const l=new Date;return l.setMilliseconds(0),l}if(/^noon$/i.test(t)){const l=new Date;return new Date(l.getFullYear(),l.getMonth(),l.getDate(),12,0,0)}let n=null,s=t;const r=[/(\d{1,2}:\d{1,2}(?::\d{2})?)\s*([ap]\.?m?\.?)?/i,/\b(\d{1,2})\s*([ap]\.?m?\.?)\b/i,/\b(\d{3,4})([ap])m?\b/i];for(const l of r){const d=t.match(l);if(d){const u=p(d[0]);if(u){n=u,s=t.replace(d[0]," ").replace(/[\s.]+$/g,"").replace(/\s+/g," ").trim();break}}}if(!n){const l=s.match(/^(\d{4}[\-\/\.\s]\d{1,2}[\-\/\.\s]\d{1,2}|\d{8})\s+(\d{1,6})(\s*[ap]\.?m?\.?)?(?:\s*(?:z|utc|gmt|[+-]\d{2}:?\d{2})\b)?$/i);if(l){const d=l[2],u=(l[3]||"").replace(/\s+/g,"");let i=d+u;d.length===6&&(i=`${d.slice(0,2)}:${d.slice(2,4)}:${d.slice(4,6)}${u}`);const f=p(i);f&&(n=f,s=l[1])}}if(!n){const l=s.match(/^(.+?)\s+(\d{1,2})(\s*[ap]\.?m?\.?)?$/i);if(l){const d=l[2]+(l[3]||""),u=p(d);u&&A.test(l[1])&&(n=u,s=l[1])}}if(n&&(!s||/^,?\s*$/.test(s))){const l=new Date;return new Date(l.getFullYear(),l.getMonth(),l.getDate(),n.hour,n.minute,n.second)}const o=w(s);if(isNaN(o.getTime()))return null;const c=n||{hour:0,minute:0,second:0};return new Date(o.getFullYear(),o.getMonth(),o.getDate(),c.hour,c.minute,c.second)}function b(e,t="YYYY-MM-DD"){if(typeof e=="string"&&(e=w(e)),isNaN(e.getTime()))return"";const n=e.getFullYear(),s=e.getMonth(),r=e.getDate(),o=e.getDay(),c=e.getHours(),l=e.getMinutes(),d=e.getSeconds(),u=e.getMilliseconds(),i=(y,S=2)=>String(y).padStart(S,"0"),f=c%12||12,m=c<12?"AM":"PM",h=["January","February","March","April","May","June","July","August","September","October","November","December"],M=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],g={YYYY:n,YY:String(n).slice(-2),MMMM:h[s],MMM:h[s].slice(0,3),MM:i(s+1),M:s+1,DD:i(r),D:r,dddd:M[o],ddd:M[o].slice(0,3),dd:M[o].slice(0,2),d:o,HH:i(c),H:c,hh:i(f),h:f,mm:i(l),m:l,ss:i(d),s:d,SSS:i(u,3),A:m,a:m.toLowerCase()};return t.replace(/\[([^\]]+)]|YYYY|YY|MMMM|MMM|MM|M|DD|D|dddd|ddd|dd|d|HH|H|hh|h|mm|m|ss|s|SSS|A|a/g,(y,S)=>S??String(g[y]))}const U={YYYY:"Y",YY:"y",MMMM:"F",MMM:"M",MM:"m",M:"n",DD:"d",D:"j",dddd:"l",ddd:"D",dd:"D",d:"w",HH:"H",H:"G",hh:"h",mm:"i",m:"i",ss:"S",s:"s",A:"K",a:"K"},K=/YYYY|YY|MMMM|MMM|MM|M|DD|D|dddd|ddd|dd|d|HH|H|hh|mm|m|ss|s|A|a/g;function G(e){return e.replace(K,t=>U[t])}function V(e){return typeof e!="string"&&!(e instanceof Date)?!1:!isNaN(w(e).getTime())}function k(e){if(typeof e!="string"&&!(e instanceof Date))return!1;const t=Y(e);return t!==null&&!isNaN(t.getTime())}function J(e,t="YYYY-MMM-DD"){const n=w(e);return isNaN(n.getTime())?"":b(n,t)}function W(e,t="YYYY-MMM-DD h:mm A"){const n=Y(e);return n&&!isNaN(n.getTime())?b(n,t):""}function v(e,t="h:mm A"){const n=p(e);if(!n)return"";const s=new Date;return s.setHours(n.hour,n.minute,n.second,0),b(s,t)}const E={ja:0,en:0,fe:1,fé:1,ap:3,ab:3,av:3,mai:4,juin:5,juil:6,au:7,ag:7,ao:7,se:8,o:9,n:10,d:11};function X(e){if(typeof e=="number")return e-1;const t=parseInt(e);if(!isNaN(t))return t-1;const n=new Date(`1 ${e} 2000`).getMonth();if(!isNaN(n))return n;const s=e.toLowerCase();for(const r in E)if(s.startsWith(r))return E[r];throw new Error("Invalid month name: "+e)}function F(e){const t=e.match(/^([+-])?(\d+)([dwmy])$/i);if(!t)return null;const[,n,s,r]=t,o=parseInt(s)*(n==="-"?-1:1),c=new Date;switch(c.setHours(0,0,0,0),r.toLowerCase()){case"d":c.setDate(c.getDate()+o);break;case"w":c.setDate(c.getDate()+o*7);break;case"m":c.setMonth(c.getMonth()+o);break;case"y":c.setFullYear(c.getFullYear()+o);break}return c}const C=/(\d{1,2}:\d{2}|\d{1,2}\.\d{2}|\b\d{1,2}\s*[ap]\b|\b[ap]\.?m\.?\b|\bnoon\b|\bnow\b|T\d{1,2})/i,q=/(\d{1,2}[-/.]\d{1,2}(?:[-/.]\d{2,4})?|\b\d{4}\b|\b\d{6,8}\b|\b(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)\b|\btoday\b|\btomorrow\b|\byesterday\b)/i;function Q(e,t){if(t==="past")return e<=new Date;if(t==="future")return e.getTime()>=new Date().setHours(0,0,0,0);if(t==="today"){const i=new Date;return e.getFullYear()===i.getFullYear()&&e.getMonth()===i.getMonth()&&e.getDate()===i.getDate()}const n=i=>{const f=i.trim();if(!f)return{date:null,hasTime:!1,valid:!0};const m=F(f);if(m)return{date:m,hasTime:!1,valid:!0};const h=f.search(q);if(h===-1)return{date:null,hasTime:!1,valid:!1};const M=f.search(C);if(M!==-1&&M<h)return{date:null,hasTime:!1,valid:!1};const g=Y(f);return g&&!isNaN(g.getTime())?{date:g,hasTime:C.test(f),valid:!0}:{date:null,hasTime:!1,valid:!1}};let s=null;if(t.includes(":"))for(let i=0;i<t.length;i+=1){if(t[i]!==":")continue;const f=n(t.slice(0,i)),m=n(t.slice(i+1));if(f.valid&&m.valid){s={start:f,end:m};break}}if(!s){const i=n(t);return i.valid&&i.date?i.hasTime?e.getTime()===i.date.getTime():e.getFullYear()===i.date.getFullYear()&&e.getMonth()===i.date.getMonth()&&e.getDate()===i.date.getDate():!0}const r=s.start,o=s.end,l=r.hasTime||o.hasTime?e.getTime():new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime();let d=null;r.date&&(d=r.hasTime?r.date.getTime():new Date(r.date.getFullYear(),r.date.getMonth(),r.date.getDate()).getTime());let u=null;return o.date&&(u=o.hasTime?o.date.getTime():new Date(o.date.getFullYear(),o.date.getMonth(),o.date.getDate(),23,59,59,999).getTime()),!(d!==null&&l<d||u!==null&&l>u)}function x(e){return e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement}function ee(e,t){return typeof t=="string"&&(t=[t]),t.includes(e.dataset.type||"")||t.includes(e.type)}function te(e){return e.length<=255&&I.test(e)}function ne(e){return e.replace(/^[^2-90]+/g,"").replace(/(\d\d\d).*?(\d\d\d).*?(\d\d\d\d)(.*)/,"$1-$2-$3$4")}function ie(e){return B.test(e)}function se(e){return e.replace(/[^0-9]/g,"")}function re(e){return L.test(e)}function ae(e){const t=e.replace(/[^\-0-9.]/g,"");let n="",s=!1,r=!1;for(let o=0;o<t.length;o+=1){const c=t[o];if(c==="-"){!r&&n.length===0&&(n+="-",r=!0);continue}if(c==="."){s||(n+=".",s=!0);continue}n+=c}return n}function oe(e){return P.test(e)}const ce={"":1,K:1e3,M:1e6,G:1e9,T:1e12},le={"":1,K:1024,M:1024**2,G:1024**3,T:1024**4};function ue(e){const n=e.trim().match(/^(\d+(?:\.\d*)?|\.\d+)\s*(B|Ki?B?|Mi?B?|Gi?B?|Ti?B?)?$/i);if(!n)return NaN;const s=Number.parseFloat(n[1]),r=n[2]?.toUpperCase()||"",o=r.includes("I"),c=r.replace(/I?B$/i,"").replace(/I$/i,"")||"";return s*(o?le:ce)[c]}function de(e,t=!0){const n=t?1e3:1024,s=["B","KB","MB","GB","TB"];if(e<n)return`${e} B`;let r=0,o=e;for(;o>=n&&r<s.length-1;)o/=n,r++;let c=Math.round(o*10)/10;return c>=n&&r<s.length-1&&(c=1,r++),`${c%1===0?c.toFixed(0):c.toFixed(1)} ${s[r]}`}function me(e){return e=e.trim(),D.test(e)?e:"https://"+e}function fe(e){return R.test(e)}function ge(e){return e=e.replace(/[^0-9]/g,"").replace(/(.{5})(.*)/,"$1-$2").trim(),e.length===6?e.replace(/-/,""):e}function Me(e){return H.test(e)}function he(e){return e.toUpperCase().replace(/[^A-Z0-9]/g,"").replace(/(.{3})\s*(.*)/,"$1 $2").trim()}function Te(e){return _.test(e)}function pe(e){return["transparent","currentColor"].includes(e)?!0:!e.trim()||typeof CSS>"u"||!CSS.supports?!1:CSS.supports("color",e)}let $=null;const N=new Map;function De(e){if(e=e.trim().toLowerCase(),["transparent","currentcolor"].includes(e))return e;if(N.has(e))return N.get(e);$||($=document.createElement("canvas"),$.willReadFrequently=!0);const t=$.getContext("2d");t.fillStyle=e,t.fillRect(0,0,1,1);const n=t.getImageData(0,0,1,1).data,s="#"+("000000"+(n[0]<<16|n[1]<<8|n[2]).toString(16)).slice(-6);return N.set(e,s),s}function we(e){if(typeof e=="boolean")return{valid:e,error:!1,messages:[]};if(typeof e=="string")return{valid:!1,error:!1,messages:[e]};const t={valid:e.valid,error:e.error??!1,messages:[]};return typeof e.message=="string"?t.messages=[e.message]:typeof e.messages=="string"?t.messages=[e.messages]:Array.isArray(e.messages)&&(t.messages=e.messages),t}a.formatBytes=de,a.formatDateTime=b,a.isColor=pe,a.isDate=V,a.isDateInRange=Q,a.isDateTime=k,a.isEmail=te,a.isFormControl=x,a.isInteger=re,a.isMeridiem=z,a.isNANPTel=ie,a.isNumber=oe,a.isPostalCA=Te,a.isTime=Z,a.isType=ee,a.isUrl=fe,a.isZip=Me,a.momentToFPFormat=G,a.monthToNumber=X,a.normalizeValidationResult=we,a.parseBytes=ue,a.parseColor=De,a.parseDate=w,a.parseDateTime=Y,a.parseDateTimeToString=W,a.parseDateToString=J,a.parseInteger=se,a.parseNANPTel=ne,a.parseNumber=ae,a.parsePostalCA=he,a.parseRelativeDate=F,a.parseTime=p,a.parseTimeToString=v,a.parseUrl=me,a.parseZip=ge,a.yearToFull=T,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
const E = /^(?:[a-z+]+:)?\/\//i, F = /^(?:[-a-z+]+:)?\/\//i, H = /^\d{5}(-\d{4})?$/, _ = /^[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ] ?[0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]$/, C = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/, R = /^\d{3}-\d{3}-\d{4}$/, I = /^-?\d*$/, B = /^-?\d*\.?\d*$/;
|
|
2
|
+
function h(e) {
|
|
3
|
+
let t = e.trim().toLowerCase();
|
|
4
|
+
if (t === "now") {
|
|
5
|
+
const l = /* @__PURE__ */ new Date();
|
|
6
|
+
return { hour: l.getHours(), minute: l.getMinutes(), second: l.getSeconds() };
|
|
7
|
+
}
|
|
8
|
+
if (t === "noon") return { hour: 12, minute: 0, second: 0 };
|
|
9
|
+
t = t.replace(/\s+/g, "").replace(/\.+$/g, "");
|
|
10
|
+
const s = t.replace(/^(\d{1,2})(\d{2})([ap]?m?\.?)$/i, "$1:$2$3").match(/^(\d{1,2})(?::(\d{1,2}))?(?::(\d{1,2}))?\s*([ap])?\.?m?\.?$/i);
|
|
11
|
+
if (!s) return null;
|
|
12
|
+
let i = +s[1], a = +(s[2] || 0), o = +(s[3] || 0);
|
|
13
|
+
const c = s[4]?.toLowerCase();
|
|
14
|
+
return c === "p" && i < 12 && (i += 12), c === "a" && i === 12 && (i = 0), i > 23 || a > 59 || o > 59 ? null : { hour: i, minute: a, second: o };
|
|
15
|
+
}
|
|
16
|
+
function U(e) {
|
|
17
|
+
return h(e) !== null;
|
|
18
|
+
}
|
|
19
|
+
function G(e) {
|
|
20
|
+
return /^[ap]\.?m?\.?$/i.test(e.replace(/\s/g, ""));
|
|
21
|
+
}
|
|
22
|
+
const L = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec", A = new RegExp(`(${L})[a-z]*`, "i");
|
|
23
|
+
function P(e) {
|
|
24
|
+
return (/* @__PURE__ */ new Date(`1 ${e} 2000`)).getMonth();
|
|
25
|
+
}
|
|
26
|
+
function M(e) {
|
|
27
|
+
if (typeof e == "string" && (e = parseInt(e.replace(/\D/g, ""))), e > 99) return e;
|
|
28
|
+
const t = ((/* @__PURE__ */ new Date()).getFullYear() + 20) % 100;
|
|
29
|
+
return e + (e < t ? 2e3 : 1900);
|
|
30
|
+
}
|
|
31
|
+
function T(e) {
|
|
32
|
+
if (e instanceof Date) return e;
|
|
33
|
+
let t = e.trim().toLowerCase();
|
|
34
|
+
const n = new Date((/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0));
|
|
35
|
+
if (/^(now|today)$/.test(t)) return n;
|
|
36
|
+
if (t === "tomorrow") return new Date(n.setDate(n.getDate() + 1));
|
|
37
|
+
t = t.replace(/\b(mon|tue|wed|thu|fri|sat|sun|lun|mar(?:di|tes)|mer|jeu|ven|sam|dim|dom)[a-z]*\.?\b/gi, "").trim();
|
|
38
|
+
let s = 0, i = 0, a = 0;
|
|
39
|
+
const o = t.match(/(\d{1,2}:\d{2}(?::\d{2})?\s*[ap]?\.?m?\.?)/i);
|
|
40
|
+
if (o) {
|
|
41
|
+
const p = h(o[1]);
|
|
42
|
+
if (p && ({ hour: s, minute: i, second: a } = p), t = t.replace(o[0], "").trim(), !t || t.length <= 2) {
|
|
43
|
+
const g = /* @__PURE__ */ new Date();
|
|
44
|
+
return new Date(g.getFullYear(), g.getMonth(), g.getDate(), s, i, a);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (/^\d{8}$/.test(t))
|
|
48
|
+
return new Date(+t.slice(0, 4), +t.slice(4, 6) - 1, +t.slice(6, 8), s, i, a);
|
|
49
|
+
if (/^\d{6}$/.test(t))
|
|
50
|
+
return new Date(M(+t.slice(0, 2)), +t.slice(2, 4) - 1, +t.slice(4, 6), s, i, a);
|
|
51
|
+
const c = t.match(A);
|
|
52
|
+
let l = -1, u = 0, r = 0;
|
|
53
|
+
c && (l = P(c[1]), t = t.replace(c[0], " ").trim());
|
|
54
|
+
const f = t.match(/'(\d{2})\b/);
|
|
55
|
+
f && (u = M(+f[1]), t = t.replace(f[0], " ").trim());
|
|
56
|
+
const d = t.match(/\d+/g)?.map(Number) || [];
|
|
57
|
+
if (l >= 0)
|
|
58
|
+
d.length >= 2 ? d[0] > 99 ? (u = d[0], r = d[1]) : d[1] > 99 ? (u = d[1], r = d[0]) : d[0] > 31 ? (r = d[1], u = M(d[0])) : d[1] > 31 ? (r = d[0], u = M(d[1])) : (r = d[0], u = u || M(d[1])) : d.length === 1 && (r = d[0], u = u || (/* @__PURE__ */ new Date()).getFullYear());
|
|
59
|
+
else if (d.length >= 3) {
|
|
60
|
+
const [p, g, m] = d;
|
|
61
|
+
p > 31 ? (u = p, l = g - 1, r = m) : p > 12 && m > 12 ? (r = p, l = g - 1, u = m > 31 ? m : M(m)) : m > 31 || m > 12 ? (l = p - 1, r = g, u = m > 31 ? m : M(m)) : (g > 12, l = p - 1, r = g, u = M(m));
|
|
62
|
+
} else d.length === 2 && (l = d[0] - 1, r = d[1], u = u || (/* @__PURE__ */ new Date()).getFullYear());
|
|
63
|
+
return u && l >= 0 && r && r >= 1 && r <= 31 ? new Date(u > 99 ? u : M(u), l, r, s, i, a) : /* @__PURE__ */ new Date("");
|
|
64
|
+
}
|
|
65
|
+
function b(e) {
|
|
66
|
+
if (e instanceof Date) return e;
|
|
67
|
+
let t = e.trim();
|
|
68
|
+
if (t.length < 3) return null;
|
|
69
|
+
if (t = t.replace(/(\d)T(\d)/i, "$1 $2"), t = t.replace(
|
|
70
|
+
/(^|[\sT])(\d{1,2})\.(\d{1,2})(?:\.(\d{1,2}))?(?=\s*[ap]\.?m?\.?\b|(?:\s|$))/gi,
|
|
71
|
+
(c, l, u, r, f) => `${l}${f ? `${u}:${r}:${f}` : `${u}:${r}`}`
|
|
72
|
+
), /^now$/i.test(t)) {
|
|
73
|
+
const c = /* @__PURE__ */ new Date();
|
|
74
|
+
return c.setMilliseconds(0), c;
|
|
75
|
+
}
|
|
76
|
+
if (/^noon$/i.test(t)) {
|
|
77
|
+
const c = /* @__PURE__ */ new Date();
|
|
78
|
+
return new Date(c.getFullYear(), c.getMonth(), c.getDate(), 12, 0, 0);
|
|
79
|
+
}
|
|
80
|
+
let n = null, s = t;
|
|
81
|
+
const i = [
|
|
82
|
+
/(\d{1,2}:\d{1,2}(?::\d{2})?)\s*([ap]\.?m?\.?)?/i,
|
|
83
|
+
// 14:30, 2:30pm, 1:5
|
|
84
|
+
/\b(\d{1,2})\s*([ap]\.?m?\.?)\b/i,
|
|
85
|
+
// 2pm, 2p.m., 2 PM, 1P
|
|
86
|
+
/\b(\d{3,4})([ap])m?\b/i
|
|
87
|
+
// 1430pm, 230p, 1200AM
|
|
88
|
+
];
|
|
89
|
+
for (const c of i) {
|
|
90
|
+
const l = t.match(c);
|
|
91
|
+
if (l) {
|
|
92
|
+
const u = h(l[0]);
|
|
93
|
+
if (u) {
|
|
94
|
+
n = u, s = t.replace(l[0], " ").replace(/[\s.]+$/g, "").replace(/\s+/g, " ").trim();
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!n) {
|
|
100
|
+
const c = s.match(
|
|
101
|
+
/^(\d{4}[\-\/\.\s]\d{1,2}[\-\/\.\s]\d{1,2}|\d{8})\s+(\d{1,6})(\s*[ap]\.?m?\.?)?(?:\s*(?:z|utc|gmt|[+-]\d{2}:?\d{2})\b)?$/i
|
|
102
|
+
);
|
|
103
|
+
if (c) {
|
|
104
|
+
const l = c[2], u = (c[3] || "").replace(/\s+/g, "");
|
|
105
|
+
let r = l + u;
|
|
106
|
+
l.length === 6 && (r = `${l.slice(0, 2)}:${l.slice(2, 4)}:${l.slice(4, 6)}${u}`);
|
|
107
|
+
const f = h(r);
|
|
108
|
+
f && (n = f, s = c[1]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!n) {
|
|
112
|
+
const c = s.match(/^(.+?)\s+(\d{1,2})(\s*[ap]\.?m?\.?)?$/i);
|
|
113
|
+
if (c) {
|
|
114
|
+
const l = c[2] + (c[3] || ""), u = h(l);
|
|
115
|
+
u && A.test(c[1]) && (n = u, s = c[1]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (n && (!s || /^,?\s*$/.test(s))) {
|
|
119
|
+
const c = /* @__PURE__ */ new Date();
|
|
120
|
+
return new Date(c.getFullYear(), c.getMonth(), c.getDate(), n.hour, n.minute, n.second);
|
|
121
|
+
}
|
|
122
|
+
const a = T(s);
|
|
123
|
+
if (isNaN(a.getTime())) return null;
|
|
124
|
+
const o = n || { hour: 0, minute: 0, second: 0 };
|
|
125
|
+
return new Date(a.getFullYear(), a.getMonth(), a.getDate(), o.hour, o.minute, o.second);
|
|
126
|
+
}
|
|
127
|
+
function N(e, t = "YYYY-MM-DD") {
|
|
128
|
+
if (typeof e == "string" && (e = T(e)), isNaN(e.getTime())) return "";
|
|
129
|
+
const n = e.getFullYear(), s = e.getMonth(), i = e.getDate(), a = e.getDay(), o = e.getHours(), c = e.getMinutes(), l = e.getSeconds(), u = e.getMilliseconds(), r = (w, Y = 2) => String(w).padStart(Y, "0"), f = o % 12 || 12, d = o < 12 ? "AM" : "PM", p = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], g = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], m = {
|
|
130
|
+
YYYY: n,
|
|
131
|
+
YY: String(n).slice(-2),
|
|
132
|
+
MMMM: p[s],
|
|
133
|
+
MMM: p[s].slice(0, 3),
|
|
134
|
+
MM: r(s + 1),
|
|
135
|
+
M: s + 1,
|
|
136
|
+
DD: r(i),
|
|
137
|
+
D: i,
|
|
138
|
+
dddd: g[a],
|
|
139
|
+
ddd: g[a].slice(0, 3),
|
|
140
|
+
dd: g[a].slice(0, 2),
|
|
141
|
+
d: a,
|
|
142
|
+
HH: r(o),
|
|
143
|
+
H: o,
|
|
144
|
+
hh: r(f),
|
|
145
|
+
h: f,
|
|
146
|
+
mm: r(c),
|
|
147
|
+
m: c,
|
|
148
|
+
ss: r(l),
|
|
149
|
+
s: l,
|
|
150
|
+
SSS: r(u, 3),
|
|
151
|
+
A: d,
|
|
152
|
+
a: d.toLowerCase()
|
|
153
|
+
};
|
|
154
|
+
return t.replace(
|
|
155
|
+
/\[([^\]]+)]|YYYY|YY|MMMM|MMM|MM|M|DD|D|dddd|ddd|dd|d|HH|H|hh|h|mm|m|ss|s|SSS|A|a/g,
|
|
156
|
+
(w, Y) => Y ?? String(m[w])
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
const z = {
|
|
160
|
+
YYYY: "Y",
|
|
161
|
+
YY: "y",
|
|
162
|
+
MMMM: "F",
|
|
163
|
+
MMM: "M",
|
|
164
|
+
MM: "m",
|
|
165
|
+
M: "n",
|
|
166
|
+
DD: "d",
|
|
167
|
+
D: "j",
|
|
168
|
+
dddd: "l",
|
|
169
|
+
ddd: "D",
|
|
170
|
+
dd: "D",
|
|
171
|
+
d: "w",
|
|
172
|
+
HH: "H",
|
|
173
|
+
H: "G",
|
|
174
|
+
hh: "h",
|
|
175
|
+
mm: "i",
|
|
176
|
+
m: "i",
|
|
177
|
+
ss: "S",
|
|
178
|
+
s: "s",
|
|
179
|
+
A: "K",
|
|
180
|
+
a: "K"
|
|
181
|
+
}, Z = /YYYY|YY|MMMM|MMM|MM|M|DD|D|dddd|ddd|dd|d|HH|H|hh|mm|m|ss|s|A|a/g;
|
|
182
|
+
function k(e) {
|
|
183
|
+
return e.replace(Z, (t) => z[t]);
|
|
184
|
+
}
|
|
185
|
+
function V(e) {
|
|
186
|
+
return typeof e != "string" && !(e instanceof Date) ? !1 : !isNaN(T(e).getTime());
|
|
187
|
+
}
|
|
188
|
+
function J(e) {
|
|
189
|
+
if (typeof e != "string" && !(e instanceof Date)) return !1;
|
|
190
|
+
const t = b(e);
|
|
191
|
+
return t !== null && !isNaN(t.getTime());
|
|
192
|
+
}
|
|
193
|
+
function W(e, t = "YYYY-MMM-DD") {
|
|
194
|
+
const n = T(e);
|
|
195
|
+
return isNaN(n.getTime()) ? "" : N(n, t);
|
|
196
|
+
}
|
|
197
|
+
function X(e, t = "YYYY-MMM-DD h:mm A") {
|
|
198
|
+
const n = b(e);
|
|
199
|
+
return n && !isNaN(n.getTime()) ? N(n, t) : "";
|
|
200
|
+
}
|
|
201
|
+
function q(e, t = "h:mm A") {
|
|
202
|
+
const n = h(e);
|
|
203
|
+
if (!n) return "";
|
|
204
|
+
const s = /* @__PURE__ */ new Date();
|
|
205
|
+
return s.setHours(n.hour, n.minute, n.second, 0), N(s, t);
|
|
206
|
+
}
|
|
207
|
+
const y = {
|
|
208
|
+
ja: 0,
|
|
209
|
+
en: 0,
|
|
210
|
+
fe: 1,
|
|
211
|
+
fé: 1,
|
|
212
|
+
ap: 3,
|
|
213
|
+
ab: 3,
|
|
214
|
+
av: 3,
|
|
215
|
+
mai: 4,
|
|
216
|
+
juin: 5,
|
|
217
|
+
juil: 6,
|
|
218
|
+
au: 7,
|
|
219
|
+
ag: 7,
|
|
220
|
+
ao: 7,
|
|
221
|
+
se: 8,
|
|
222
|
+
o: 9,
|
|
223
|
+
n: 10,
|
|
224
|
+
d: 11
|
|
225
|
+
};
|
|
226
|
+
function v(e) {
|
|
227
|
+
if (typeof e == "number") return e - 1;
|
|
228
|
+
const t = parseInt(e);
|
|
229
|
+
if (!isNaN(t)) return t - 1;
|
|
230
|
+
const n = (/* @__PURE__ */ new Date(`1 ${e} 2000`)).getMonth();
|
|
231
|
+
if (!isNaN(n)) return n;
|
|
232
|
+
const s = e.toLowerCase();
|
|
233
|
+
for (const i in y) if (s.startsWith(i)) return y[i];
|
|
234
|
+
throw new Error("Invalid month name: " + e);
|
|
235
|
+
}
|
|
236
|
+
function x(e) {
|
|
237
|
+
const t = e.match(/^([+-])?(\d+)([dwmy])$/i);
|
|
238
|
+
if (!t) return null;
|
|
239
|
+
const [, n, s, i] = t, a = parseInt(s) * (n === "-" ? -1 : 1), o = /* @__PURE__ */ new Date();
|
|
240
|
+
switch (o.setHours(0, 0, 0, 0), i.toLowerCase()) {
|
|
241
|
+
case "d":
|
|
242
|
+
o.setDate(o.getDate() + a);
|
|
243
|
+
break;
|
|
244
|
+
case "w":
|
|
245
|
+
o.setDate(o.getDate() + a * 7);
|
|
246
|
+
break;
|
|
247
|
+
case "m":
|
|
248
|
+
o.setMonth(o.getMonth() + a);
|
|
249
|
+
break;
|
|
250
|
+
case "y":
|
|
251
|
+
o.setFullYear(o.getFullYear() + a);
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
return o;
|
|
255
|
+
}
|
|
256
|
+
const S = /(\d{1,2}:\d{2}|\d{1,2}\.\d{2}|\b\d{1,2}\s*[ap]\b|\b[ap]\.?m\.?\b|\bnoon\b|\bnow\b|T\d{1,2})/i, K = /(\d{1,2}[-/.]\d{1,2}(?:[-/.]\d{2,4})?|\b\d{4}\b|\b\d{6,8}\b|\b(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)\b|\btoday\b|\btomorrow\b|\byesterday\b)/i;
|
|
257
|
+
function Q(e, t) {
|
|
258
|
+
if (t === "past")
|
|
259
|
+
return e <= /* @__PURE__ */ new Date();
|
|
260
|
+
if (t === "future")
|
|
261
|
+
return e.getTime() >= (/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0);
|
|
262
|
+
if (t === "today") {
|
|
263
|
+
const r = /* @__PURE__ */ new Date();
|
|
264
|
+
return e.getFullYear() === r.getFullYear() && e.getMonth() === r.getMonth() && e.getDate() === r.getDate();
|
|
265
|
+
}
|
|
266
|
+
const n = (r) => {
|
|
267
|
+
const f = r.trim();
|
|
268
|
+
if (!f) return { date: null, hasTime: !1, valid: !0 };
|
|
269
|
+
const d = x(f);
|
|
270
|
+
if (d) return { date: d, hasTime: !1, valid: !0 };
|
|
271
|
+
const p = f.search(K);
|
|
272
|
+
if (p === -1) return { date: null, hasTime: !1, valid: !1 };
|
|
273
|
+
const g = f.search(S);
|
|
274
|
+
if (g !== -1 && g < p) return { date: null, hasTime: !1, valid: !1 };
|
|
275
|
+
const m = b(f);
|
|
276
|
+
return m && !isNaN(m.getTime()) ? { date: m, hasTime: S.test(f), valid: !0 } : { date: null, hasTime: !1, valid: !1 };
|
|
277
|
+
};
|
|
278
|
+
let s = null;
|
|
279
|
+
if (t.includes(":"))
|
|
280
|
+
for (let r = 0; r < t.length; r += 1) {
|
|
281
|
+
if (t[r] !== ":") continue;
|
|
282
|
+
const f = n(t.slice(0, r)), d = n(t.slice(r + 1));
|
|
283
|
+
if (f.valid && d.valid) {
|
|
284
|
+
s = { start: f, end: d };
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (!s) {
|
|
289
|
+
const r = n(t);
|
|
290
|
+
return r.valid && r.date ? r.hasTime ? e.getTime() === r.date.getTime() : e.getFullYear() === r.date.getFullYear() && e.getMonth() === r.date.getMonth() && e.getDate() === r.date.getDate() : !0;
|
|
291
|
+
}
|
|
292
|
+
const i = s.start, a = s.end, c = i.hasTime || a.hasTime ? e.getTime() : new Date(e.getFullYear(), e.getMonth(), e.getDate()).getTime();
|
|
293
|
+
let l = null;
|
|
294
|
+
i.date && (l = i.hasTime ? i.date.getTime() : new Date(i.date.getFullYear(), i.date.getMonth(), i.date.getDate()).getTime());
|
|
295
|
+
let u = null;
|
|
296
|
+
return a.date && (u = a.hasTime ? a.date.getTime() : new Date(a.date.getFullYear(), a.date.getMonth(), a.date.getDate(), 23, 59, 59, 999).getTime()), !(l !== null && c < l || u !== null && c > u);
|
|
297
|
+
}
|
|
298
|
+
function ee(e) {
|
|
299
|
+
return e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement;
|
|
300
|
+
}
|
|
301
|
+
function te(e, t) {
|
|
302
|
+
return typeof t == "string" && (t = [t]), t.includes(e.dataset.type || "") || t.includes(e.type);
|
|
303
|
+
}
|
|
304
|
+
function ne(e) {
|
|
305
|
+
return e.length <= 255 && C.test(e);
|
|
306
|
+
}
|
|
307
|
+
function re(e) {
|
|
308
|
+
return e.replace(/^[^2-90]+/g, "").replace(/(\d\d\d).*?(\d\d\d).*?(\d\d\d\d)(.*)/, "$1-$2-$3$4");
|
|
309
|
+
}
|
|
310
|
+
function se(e) {
|
|
311
|
+
return R.test(e);
|
|
312
|
+
}
|
|
313
|
+
function ie(e) {
|
|
314
|
+
return e.replace(/[^0-9]/g, "");
|
|
315
|
+
}
|
|
316
|
+
function ae(e) {
|
|
317
|
+
return I.test(e);
|
|
318
|
+
}
|
|
319
|
+
function oe(e) {
|
|
320
|
+
const t = e.replace(/[^\-0-9.]/g, "");
|
|
321
|
+
let n = "", s = !1, i = !1;
|
|
322
|
+
for (let a = 0; a < t.length; a += 1) {
|
|
323
|
+
const o = t[a];
|
|
324
|
+
if (o === "-") {
|
|
325
|
+
!i && n.length === 0 && (n += "-", i = !0);
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (o === ".") {
|
|
329
|
+
s || (n += ".", s = !0);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
n += o;
|
|
333
|
+
}
|
|
334
|
+
return n;
|
|
335
|
+
}
|
|
336
|
+
function ce(e) {
|
|
337
|
+
return B.test(e);
|
|
338
|
+
}
|
|
339
|
+
const O = { "": 1, K: 1e3, M: 1e6, G: 1e9, T: 1e12 }, j = { "": 1, K: 1024, M: 1024 ** 2, G: 1024 ** 3, T: 1024 ** 4 };
|
|
340
|
+
function ue(e) {
|
|
341
|
+
const n = e.trim().match(/^(\d+(?:\.\d*)?|\.\d+)\s*(B|Ki?B?|Mi?B?|Gi?B?|Ti?B?)?$/i);
|
|
342
|
+
if (!n) return NaN;
|
|
343
|
+
const s = Number.parseFloat(n[1]), i = n[2]?.toUpperCase() || "", a = i.includes("I"), o = i.replace(/I?B$/i, "").replace(/I$/i, "") || "";
|
|
344
|
+
return s * (a ? j : O)[o];
|
|
345
|
+
}
|
|
346
|
+
function le(e, t = !0) {
|
|
347
|
+
const n = t ? 1e3 : 1024, s = ["B", "KB", "MB", "GB", "TB"];
|
|
348
|
+
if (e < n) return `${e} B`;
|
|
349
|
+
let i = 0, a = e;
|
|
350
|
+
for (; a >= n && i < s.length - 1; )
|
|
351
|
+
a /= n, i++;
|
|
352
|
+
let o = Math.round(a * 10) / 10;
|
|
353
|
+
return o >= n && i < s.length - 1 && (o = 1, i++), `${o % 1 === 0 ? o.toFixed(0) : o.toFixed(1)} ${s[i]}`;
|
|
354
|
+
}
|
|
355
|
+
function de(e) {
|
|
356
|
+
return e = e.trim(), E.test(e) ? e : "https://" + e;
|
|
357
|
+
}
|
|
358
|
+
function fe(e) {
|
|
359
|
+
return F.test(e);
|
|
360
|
+
}
|
|
361
|
+
function me(e) {
|
|
362
|
+
return e = e.replace(/[^0-9]/g, "").replace(/(.{5})(.*)/, "$1-$2").trim(), e.length === 6 ? e.replace(/-/, "") : e;
|
|
363
|
+
}
|
|
364
|
+
function ge(e) {
|
|
365
|
+
return H.test(e);
|
|
366
|
+
}
|
|
367
|
+
function pe(e) {
|
|
368
|
+
return e.toUpperCase().replace(/[^A-Z0-9]/g, "").replace(/(.{3})\s*(.*)/, "$1 $2").trim();
|
|
369
|
+
}
|
|
370
|
+
function Me(e) {
|
|
371
|
+
return _.test(e);
|
|
372
|
+
}
|
|
373
|
+
function he(e) {
|
|
374
|
+
return ["transparent", "currentColor"].includes(e) ? !0 : !e.trim() || typeof CSS > "u" || !CSS.supports ? !1 : CSS.supports("color", e);
|
|
375
|
+
}
|
|
376
|
+
let D = null;
|
|
377
|
+
const $ = /* @__PURE__ */ new Map();
|
|
378
|
+
function De(e) {
|
|
379
|
+
if (e = e.trim().toLowerCase(), ["transparent", "currentcolor"].includes(e)) return e;
|
|
380
|
+
if ($.has(e)) return $.get(e);
|
|
381
|
+
D || (D = document.createElement("canvas"), D.willReadFrequently = !0);
|
|
382
|
+
const t = D.getContext("2d");
|
|
383
|
+
t.fillStyle = e, t.fillRect(0, 0, 1, 1);
|
|
384
|
+
const n = t.getImageData(0, 0, 1, 1).data, s = "#" + ("000000" + (n[0] << 16 | n[1] << 8 | n[2]).toString(16)).slice(-6);
|
|
385
|
+
return $.set(e, s), s;
|
|
386
|
+
}
|
|
387
|
+
function Te(e) {
|
|
388
|
+
if (typeof e == "boolean") return { valid: e, error: !1, messages: [] };
|
|
389
|
+
if (typeof e == "string") return { valid: !1, error: !1, messages: [e] };
|
|
390
|
+
const t = { valid: e.valid, error: e.error ?? !1, messages: [] };
|
|
391
|
+
return typeof e.message == "string" ? t.messages = [e.message] : typeof e.messages == "string" ? t.messages = [e.messages] : Array.isArray(e.messages) && (t.messages = e.messages), t;
|
|
392
|
+
}
|
|
393
|
+
export {
|
|
394
|
+
le as formatBytes,
|
|
395
|
+
N as formatDateTime,
|
|
396
|
+
he as isColor,
|
|
397
|
+
V as isDate,
|
|
398
|
+
Q as isDateInRange,
|
|
399
|
+
J as isDateTime,
|
|
400
|
+
ne as isEmail,
|
|
401
|
+
ee as isFormControl,
|
|
402
|
+
ae as isInteger,
|
|
403
|
+
G as isMeridiem,
|
|
404
|
+
se as isNANPTel,
|
|
405
|
+
ce as isNumber,
|
|
406
|
+
Me as isPostalCA,
|
|
407
|
+
U as isTime,
|
|
408
|
+
te as isType,
|
|
409
|
+
fe as isUrl,
|
|
410
|
+
ge as isZip,
|
|
411
|
+
k as momentToFPFormat,
|
|
412
|
+
v as monthToNumber,
|
|
413
|
+
Te as normalizeValidationResult,
|
|
414
|
+
ue as parseBytes,
|
|
415
|
+
De as parseColor,
|
|
416
|
+
T as parseDate,
|
|
417
|
+
b as parseDateTime,
|
|
418
|
+
X as parseDateTimeToString,
|
|
419
|
+
W as parseDateToString,
|
|
420
|
+
ie as parseInteger,
|
|
421
|
+
re as parseNANPTel,
|
|
422
|
+
oe as parseNumber,
|
|
423
|
+
pe as parsePostalCA,
|
|
424
|
+
x as parseRelativeDate,
|
|
425
|
+
h as parseTime,
|
|
426
|
+
q as parseTimeToString,
|
|
427
|
+
de as parseUrl,
|
|
428
|
+
me as parseZip,
|
|
429
|
+
M as yearToFull
|
|
430
|
+
};
|
package/package.json
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jdlien/validator-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"
|
|
6
|
-
"module": "dist/validator-utils.
|
|
7
|
-
"
|
|
8
|
-
"
|
|
5
|
+
"main": "dist/validator-utils.cjs",
|
|
6
|
+
"module": "dist/validator-utils.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/validator-utils.mjs",
|
|
12
|
+
"require": "./dist/validator-utils.cjs",
|
|
13
|
+
"default": "./dist/validator-utils.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
9
16
|
"files": [
|
|
10
17
|
"dist"
|
|
11
18
|
],
|
|
19
|
+
"unpkg": "dist/validator-utils.js",
|
|
20
|
+
"jsdelivr": "dist/validator-utils.js",
|
|
12
21
|
"description": "Validation and sanitization functions used by @jdlien/Validator.",
|
|
13
|
-
"scripts": {
|
|
14
|
-
"dev": "vite",
|
|
15
|
-
"build": "vite build && tsc --emitDeclarationOnly",
|
|
16
|
-
"size:wire": "node scripts/measure-wire-size.mjs",
|
|
17
|
-
"preview": "vite preview",
|
|
18
|
-
"test": "vitest",
|
|
19
|
-
"coverage": "vitest --coverage"
|
|
20
|
-
},
|
|
21
22
|
"repository": {
|
|
22
23
|
"type": "git",
|
|
23
24
|
"url": "git+https://github.com/jdlien/validator-utils.git"
|
|
@@ -27,7 +28,7 @@
|
|
|
27
28
|
},
|
|
28
29
|
"keywords": [
|
|
29
30
|
"validation",
|
|
30
|
-
"
|
|
31
|
+
"utilities",
|
|
31
32
|
"sanitization",
|
|
32
33
|
"date",
|
|
33
34
|
"time",
|
|
@@ -51,10 +52,15 @@
|
|
|
51
52
|
"vitest": "^4.0.18"
|
|
52
53
|
},
|
|
53
54
|
"sideEffects": false,
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
"scripts": {
|
|
56
|
+
"dev": "vite",
|
|
57
|
+
"build:lib": "pnpm build:lib:esm && pnpm build:lib:compat && tsc --emitDeclarationOnly",
|
|
58
|
+
"build:lib:esm": "vite build",
|
|
59
|
+
"build:lib:compat": "vite build --mode compat",
|
|
60
|
+
"build": "pnpm build:lib",
|
|
61
|
+
"size:wire": "node scripts/measure-wire-size.mjs",
|
|
62
|
+
"preview": "vite preview",
|
|
63
|
+
"test": "vitest",
|
|
64
|
+
"coverage": "vitest --coverage"
|
|
59
65
|
}
|
|
60
|
-
}
|
|
66
|
+
}
|