1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var ipAddress = require('ip-address');
|
6 | var uuid = require('uuid');
|
7 | var JSON5 = require('json5');
|
8 | var jwtDecode = require('jwt-decode');
|
9 |
|
10 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
11 |
|
12 | var JSON5__default = _interopDefaultLegacy(JSON5);
|
13 | var jwtDecode__default = _interopDefaultLegacy(jwtDecode);
|
14 |
|
15 | function inferDatetime(value) {
|
16 | const rfc3339Match = inferRFC3339(value);
|
17 | if (rfc3339Match) {
|
18 | return rfc3339Match;
|
19 | }
|
20 | const rfc2822Match = inferRFC2822(value);
|
21 | if (rfc2822Match) {
|
22 | return rfc2822Match;
|
23 | }
|
24 | return undefined;
|
25 | }
|
26 | const rfc3339WithYmd = /^([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?(?:[T\s](\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?(?:(Z?)|([+-]\d\d)(?::?(\d\d))?))?(?:\[([A-Za-z/_-]+)\])?(?:\[(u-ca=(?:buddhist|chinese|coptic|dangi|ethioaa|ethiopic|gregory|hebrew|indian|islamic|islamic-umalqura|islamic-tbla|islamic-civil|islamic-rgsa|islamicc|iso8601|japanese|persian|roc))\])?$/;
|
27 | const rfc3339WithWeekIndex = /^(\d{4})-?W(\d\d)(?:-?(\d))?(?:[T\s](\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?(?:(Z?)|([+-]\d\d)(?::?(\d\d))?))?(?:\[([A-Za-z/_-]+)\])?(?:\[(u-ca=(?:buddhist|chinese|coptic|dangi|ethioaa|ethiopic|gregory|hebrew|indian|islamic|islamic-umalqura|islamic-tbla|islamic-civil|islamic-rgsa|islamicc|iso8601|japanese|persian|roc))\])?$/;
|
28 | const rfc3339WithOrdinal = /^(\d{4})-?(\d{3})?(?:[T\s](\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?(?:(Z?)|([+-]\d\d)(?::?(\d\d))?))?(?:\[([A-Za-z/_-]+)\])?(?:\[(u-ca=(?:buddhist|chinese|coptic|dangi|ethioaa|ethiopic|gregory|hebrew|indian|islamic|islamic-umalqura|islamic-tbla|islamic-civil|islamic-rgsa|islamicc|iso8601|japanese|persian|roc))\])?$/;
|
29 | const rfc3339TimeOnly = /^(?:(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?(?:(Z?)|([+-]\d\d)(?::?(\d\d))?))?(?:\[([A-Za-z/_-]+)\])?(?:\[(u-ca=(?:buddhist|chinese|coptic|dangi|ethioaa|ethiopic|gregory|hebrew|indian|islamic|islamic-umalqura|islamic-tbla|islamic-civil|islamic-rgsa|islamicc|iso8601|japanese|persian|roc))\])?$/;
|
30 | const rfc3339 = [
|
31 | {
|
32 | matches: rfc3339WithYmd,
|
33 | parts: rfc3339Parts,
|
34 | extensions: rfc3339Extensions(11, 12),
|
35 | },
|
36 | {
|
37 | matches: rfc3339WithWeekIndex,
|
38 | parts: rfc3339Parts,
|
39 | extensions: rfc3339Extensions(11, 12),
|
40 | },
|
41 | {
|
42 | matches: rfc3339WithOrdinal,
|
43 | parts: rfc3339WithOrdinalParts,
|
44 | extensions: rfc3339Extensions(10, 11),
|
45 | },
|
46 | {
|
47 | matches: rfc3339TimeOnly,
|
48 | parts: () => "time",
|
49 | extensions: rfc3339Extensions(8, 9),
|
50 | },
|
51 | ];
|
52 | function matchFilter(matches) {
|
53 | if (!matches) {
|
54 | return false;
|
55 | }
|
56 | const truthyMatches = matches.filter((match) => !!match);
|
57 | return truthyMatches.length > 2;
|
58 | }
|
59 | function inferRFC3339(value) {
|
60 | const rfc3339Matches = rfc3339
|
61 | .map((rfc) => {
|
62 | return {
|
63 | matches: rfc.matches.exec(value),
|
64 | parts: rfc.parts,
|
65 | extensions: rfc.extensions,
|
66 | };
|
67 | })
|
68 | .filter((rfc) => matchFilter(rfc.matches));
|
69 | const rfc3339BestMatch = rfc3339Matches.sort(
|
70 |
|
71 | (a, b) => b.matches.length - a.matches.length)[0];
|
72 | if (rfc3339BestMatch) {
|
73 | return {
|
74 | name: "datetime",
|
75 |
|
76 | parts: rfc3339BestMatch.parts(rfc3339BestMatch.matches),
|
77 | variant: "rfc3339",
|
78 |
|
79 | extensions: rfc3339BestMatch.extensions(rfc3339BestMatch.matches),
|
80 | };
|
81 | }
|
82 | return undefined;
|
83 | }
|
84 | function rfc3339Parts(match) {
|
85 | const dateParts = [1, 2, 3];
|
86 | const timeParts = [4, 5, 6, 7];
|
87 | const hasSomeDateParts = dateParts.some((i) => match[i] !== undefined);
|
88 | const hasSomeTimeParts = timeParts.some((i) => match[i] !== undefined);
|
89 | if (hasSomeDateParts && hasSomeTimeParts) {
|
90 | return "datetime";
|
91 | }
|
92 | return "date";
|
93 | }
|
94 | function rfc3339Extensions(timezoneIndex = 11, calendarIndex = 12) {
|
95 | return (match) => {
|
96 | const extensions = [];
|
97 | if (match[timezoneIndex] !== undefined) {
|
98 | extensions.push("timezone");
|
99 | }
|
100 | if (match[calendarIndex] !== undefined) {
|
101 | extensions.push("calendar");
|
102 | }
|
103 | return extensions.length > 0 ? extensions : undefined;
|
104 | };
|
105 | }
|
106 | function rfc3339WithOrdinalParts(match) {
|
107 | const dateParts = [1, 2];
|
108 | const timeParts = [3, 4, 5, 6];
|
109 | const hasSomeDateParts = dateParts.some((i) => match[i] !== undefined);
|
110 | const hasSomeTimeParts = timeParts.some((i) => match[i] !== undefined);
|
111 | if (hasSomeDateParts && hasSomeTimeParts) {
|
112 | return "datetime";
|
113 | }
|
114 | return "date";
|
115 | }
|
116 | const rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/;
|
117 | function inferRFC2822(value) {
|
118 | const rfc2822Matches = rfc2822.exec(value);
|
119 | if (rfc2822Matches) {
|
120 | return {
|
121 | name: "datetime",
|
122 | parts: "datetime",
|
123 | variant: "rfc2822",
|
124 | };
|
125 | }
|
126 | return undefined;
|
127 | }
|
128 |
|
129 | const timestampSecondsSinceEpoch = /^\d{10}$/;
|
130 | const timestampMsSinceEpoch = /^\d{13}$/;
|
131 | const timestampNanoSinceEpoch = /^\d{19}$/;
|
132 |
|
133 | function inRangeOfNow(msSinceEpoch) {
|
134 | const now = new Date().getTime();
|
135 | const acceptableRange = 2 * 365 * 24 * 60 * 60 * 1000;
|
136 | const lowerBound = msSinceEpoch - acceptableRange;
|
137 | const upperBound = msSinceEpoch + acceptableRange;
|
138 | return now >= lowerBound && now <= upperBound;
|
139 | }
|
140 | function inferTimestamp(value) {
|
141 | if (timestampSecondsSinceEpoch.test(value)) {
|
142 | const seconds = parseInt(value);
|
143 | if (inRangeOfNow(seconds * 1000)) {
|
144 | return {
|
145 | name: "timestamp",
|
146 | variant: "secondsSinceEpoch",
|
147 | };
|
148 | }
|
149 | }
|
150 | if (timestampMsSinceEpoch.test(value)) {
|
151 | const milliseconds = parseInt(value);
|
152 | if (inRangeOfNow(milliseconds)) {
|
153 | return {
|
154 | name: "timestamp",
|
155 | variant: "millisecondsSinceEpoch",
|
156 | };
|
157 | }
|
158 | }
|
159 | if (timestampNanoSinceEpoch.test(value)) {
|
160 | const nanoseconds = parseInt(value);
|
161 | if (inRangeOfNow(nanoseconds / 1000000)) {
|
162 | return {
|
163 | name: "timestamp",
|
164 | variant: "nanosecondsSinceEpoch",
|
165 | };
|
166 | }
|
167 | }
|
168 | return undefined;
|
169 | }
|
170 |
|
171 | const rfc5321AddressRegex = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
|
172 | const rfc5321Regex = new RegExp(`^${rfc5321AddressRegex.source}$`);
|
173 | const rfc5322Regex = new RegExp(`^[^"]+<${rfc5321AddressRegex.source}>$`);
|
174 | function inferEmail(value) {
|
175 | if (rfc5321Regex.exec(value)) {
|
176 | return { name: "email", variant: "rfc5321" };
|
177 | }
|
178 | if (rfc5322Regex.exec(value)) {
|
179 | return { name: "email", variant: "rfc5322" };
|
180 | }
|
181 | return undefined;
|
182 | }
|
183 |
|
184 | const iso4217Regex = /^(?:(AED|AFN|ALL|AMD|ANG|AOA|ARS|AUD|AWG|AZN|BAM|BBD|BDT|BGN|BHD|BIF|BMD|BND|BOB|BOV|BRL|BSD|BTC|BTN|BWP|BYN|BZD|CAD|CDF|CHE|CHF|CHW|CLF|CLP|CNY|COP|COU|CRC|CUC|CUP|CVE|CZK|DJF|DKK|DOP|DZD|EGP|ERN|ETB|EUR|FJD|FKP|GBP|GEL|GHS|GIP|GMD|GNF|GTQ|GYD|HKD|HNL|HRK|HTG|HUF|IDR|ILS|INR|IQD|IRR|ISK|JMD|JOD|JPY|KES|KGS|KHR|KMF|KPW|KRW|KWD|KYD|KZT|LAK|LBP|LKR|LRD|LSL|LYD|MAD|MDL|MGA|MKD|MMK|MNT|MOP|MRU|MUR|MVR|MWK|MXN|MXV|MYR|MZN|NAD|NGN|NIO|NOK|NPR|NZD|OMR|PAB|PEN|PGK|PHP|PKR|PLN|PYG|QAR|RON|RSD|RUB|RWF|SAR|SBD|SCR|SDG|SEK|SGD|SHP|SLL|SOS|SRD|SSP|STN|SVC|SYP|SZL|THB|TJS|TMT|TND|TOP|TRY|TTD|TWD|TZS|UAH|UGX|USD|USN|UYI|UYU|UYW|UZS|VED|VES|VND|VUV|WST|XAF|XAG|XAU|XBA|XBB|XBC|XBD|XCD|XDR|XOF|XPD|XPF|XPT|XSU|XTS|XUA|XXX|YER|ZAR|ZMW|ZWL))$/i;
|
185 | const cryptoRegex = /^(?:(XBT|XDG|XLM|XMR|XRP|XZC|ETH|LTC|BNB|USDT|SOL|ADA|USDC|LUNA|AVAX|DOT|DOGE|SHIB|MATIC|CRO|BUSD|WBTC|UNI|LINK|UST|DAI|ALGO|BCH))$/;
|
186 | const englishNamesRegex = /^(?:(U.?S.?\sDollar|Euro|United\sStates\sdollar|Japanese\sYen|Swiss\sFranc|Australian\sDollar|British\sPound|Canadian\sDollar|South\sAfrican\sRand))$/;
|
187 | const symbolRegex = /^(?:(\$|£|€|¥|R\$|₿))$/;
|
188 | function inferCurrency(value) {
|
189 | if (iso4217Regex.exec(value)) {
|
190 | return {
|
191 | name: "currency",
|
192 | variant: "iso4217",
|
193 | };
|
194 | }
|
195 | if (cryptoRegex.exec(value)) {
|
196 | return {
|
197 | name: "currency",
|
198 | variant: "crypto",
|
199 | };
|
200 | }
|
201 | if (englishNamesRegex.exec(value)) {
|
202 | return {
|
203 | name: "currency",
|
204 | variant: "english",
|
205 | };
|
206 | }
|
207 | if (symbolRegex.exec(value)) {
|
208 | return {
|
209 | name: "currency",
|
210 | variant: "symbol",
|
211 | };
|
212 | }
|
213 | return undefined;
|
214 | }
|
215 |
|
216 | const iso31663Regex = /^(?:(AFG|ALB|DZA|ASM|AND|AGO|AIA|ATA|ATG|ARG|ARM|ABW|AUS|AUT|AZE|BHS|BHR|BGD|BRB|BLR|BEL|BLZ|BEN|BMU|BTN|BOL|BES|BIH|BWA|BVT|BRA|IOT|BRN|BGR|BFA|BDI|CPV|KHM|CMR|CAN|CYM|CAF|TCD|CHL|CHN|CXR|CCK|COL|COM|COD|COG|COK|CRI|HRV|CUB|CUW|CYP|CZE|CIV|DNK|DJI|DMA|DOM|ECU|EGY|SLV|GNQ|ERI|EST|SWZ|ETH|FLK|FRO|FJI|FIN|FRA|GUF|PYF|ATF|GAB|GMB|GEO|DEU|GHA|GIB|GRC|GRL|GRD|GLP|GUM|GTM|GGY|GIN|GNB|GUY|HTI|HMD|VAT|HND|HKG|HUN|ISL|IND|IDN|IRN|IRQ|IRL|IMN|ISR|ITA|JAM|JPN|JEY|JOR|KAZ|KEN|KIR|PRK|KOR|KWT|KGZ|LAO|LVA|LBN|LSO|LBR|LBY|LIE|LTU|LUX|MAC|MDG|MWI|MYS|MDV|MLI|MLT|MHL|MTQ|MRT|MUS|MYT|MEX|FSM|MDA|MCO|MNG|MNE|MSR|MAR|MOZ|MMR|NAM|NRU|NPL|NLD|NCL|NZL|NIC|NER|NGA|NIU|NFK|MNP|NOR|OMN|PAK|PLW|PSE|PAN|PNG|PRY|PER|PHL|PCN|POL|PRT|PRI|QAT|MKD|ROU|RUS|RWA|REU|BLM|SHN|KNA|LCA|MAF|SPM|VCT|WSM|SMR|STP|SAU|SEN|SRB|SYC|SLE|SGP|SXM|SVK|SVN|SLB|SOM|ZAF|SGS|SSD|ESP|LKA|SDN|SUR|SJM|SWE|CHE|SYR|TWN|TJK|TZA|THA|TLS|TGO|TKL|TON|TTO|TUN|TUR|TKM|TCA|TUV|UGA|UKR|ARE|GBR|UMI|USA|URY|UZB|VUT|VEN|VNM|VGB|VIR|WLF|ESH|YEM|ZMB|ZWE|ALA))$/;
|
217 | const iso31662Regex = /^(?:(AF|AL|DZ|AS|AD|AO|AI|AQ|AG|AR|AM|AW|AU|AT|AZ|BS|BH|BD|BB|BY|BE|BZ|BJ|BM|BT|BO|BQ|BA|BW|BV|BR|IO|BN|BG|BF|BI|CV|KH|CM|CA|KY|CF|TD|CL|CN|CX|CC|CO|KM|CD|CG|CK|CR|HR|CU|CW|CY|CZ|CI|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|SZ|ET|FK|FO|FJ|FI|FR|GF|PF|TF|GA|GM|GE|DE|GH|GI|GR|GL|GD|GP|GU|GT|GG|GN|GW|GY|HT|HM|VA|HN|HK|HU|IS|IN|ID|IR|IQ|IE|IM|IL|IT|JM|JP|JE|JO|KZ|KE|KI|KP|KR|KW|KG|LA|LV|LB|LS|LR|LY|LI|LT|LU|MO|MG|MW|MY|MV|ML|MT|MH|MQ|MR|MU|YT|MX|FM|MD|MC|MN|ME|MS|MA|MZ|MM|NA|NR|NP|NL|NC|NZ|NI|NE|NG|NU|NF|MP|NO|OM|PK|PW|PS|PA|PG|PY|PE|PH|PN|PL|PT|PR|QA|MK|RO|RU|RW|RE|BL|SH|KN|LC|MF|PM|VC|WS|SM|ST|SA|SN|RS|SC|SL|SG|SX|SK|SI|SB|SO|ZA|GS|SS|ES|LK|SD|SR|SJ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|UM|US|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW|AX))$/;
|
218 | function inferCountry(value) {
|
219 | if (iso31663Regex.exec(value)) {
|
220 | return {
|
221 | name: "country",
|
222 | variant: "iso3166-3",
|
223 | };
|
224 | }
|
225 | if (iso31662Regex.exec(value)) {
|
226 | return {
|
227 | name: "country",
|
228 | variant: "iso3166-2",
|
229 | };
|
230 | }
|
231 | return undefined;
|
232 | }
|
233 |
|
234 | function inferTld(value) {
|
235 | const tldRegex = /^\.\w{2,14}(\.\w{2,14})*$/i;
|
236 | if (tldRegex.test(value)) {
|
237 | return {
|
238 | name: "tld",
|
239 | };
|
240 | }
|
241 | return undefined;
|
242 | }
|
243 |
|
244 | function inferIpAddress(value) {
|
245 | try {
|
246 | const ipv6 = new ipAddress.Address6(value);
|
247 | if (ipv6) {
|
248 | return {
|
249 | name: "ip",
|
250 | variant: "v6",
|
251 | };
|
252 | }
|
253 | }
|
254 | catch (error) {
|
255 |
|
256 | }
|
257 | try {
|
258 | const ipv4 = new ipAddress.Address4(value);
|
259 | if (ipv4) {
|
260 | return {
|
261 | name: "ip",
|
262 | variant: "v4",
|
263 | };
|
264 | }
|
265 | }
|
266 | catch (error) {
|
267 |
|
268 | }
|
269 | return undefined;
|
270 | }
|
271 |
|
272 | const iso693Regex = /^(?:(aa|ab|ae|af|ak|am|an|ar|as|av|ay|az|ba|be|bg|bi|bm|bn|bo|br|bs|ca|ce|ch|co|cr|cs|cu|cv|cy|da|de|dv|dz|ee|el|en|eo|es|et|eu|fa|ff|fi|fj|fo|fr|fy|ga|gd|gl|gn|gu|gv|ha|he|hi|ho|hr|ht|hu|hy|hz|ia|id|ie|ig|ii|ik|io|is|it|iu|ja|jv|ka|kg|ki|kj|kk|kl|km|kn|ko|kr|ks|ku|kv|kw|ky|la|lb|lg|li|ln|lo|lt|lu|lv|mg|mh|mi|mk|ml|mn|mr|ms|mt|my|na|nb|nd|ne|ng|nl|nn|no|nr|nv|ny|oc|oj|om|or|os|pa|pi|pl|ps|pt|qu|rm|rn|ro|ru|rw|sa|sc|sd|se|sg|si|sk|sl|sm|sn|so|sq|sr|ss|st|su|sv|sw|ta|te|tg|th|ti|tk|tl|tn|to|tr|ts|tt|tw|ty|ug|uk|ur|uz|ve|vi|vo|wa|wo|xh|yi|yo|za|zh|zu))$/;
|
273 | const iso6932Regex = /^(?:(aar|abk|ave|afr|aka|amh|arg|ara|asm|ava|aym|aze|bak|bel|bul|bis|bam|ben|bod|bre|bos|cat|che|cha|cos|cre|ces|chu|chv|cym|dan|deu|div|dzo|ewe|ell|eng|epo|spa|est|eus|fas|ful|fin|fij|fao|fra|fry|gle|gla|glg|grn|guj|glv|hau|heb|hin|hmo|hrv|hat|hun|hye|her|ina|ind|ile|ibo|iii|ipk|ido|isl|ita|iku|jpn|jav|kat|kon|kik|kua|kaz|kal|khm|kan|kor|kau|kas|kur|kom|cor|kir|lat|ltz|lug|lim|lin|lao|lit|lub|lav|mlg|mah|mri|mkd|mal|mon|mar|msa|mlt|mya|nau|nob|nde|nep|ndo|nld|nno|nor|nbl|nav|nya|oci|oji|orm|ori|oss|pan|pli|pol|pus|por|que|roh|run|ron|rus|kin|san|srd|snd|sme|sag|sin|slk|slv|smo|sna|som|sqi|srp|ssw|sot|sun|swe|swa|tam|tel|tgk|tha|tir|tuk|tgl|tsn|ton|tur|tso|tat|twi|tah|uig|ukr|urd|uzb|ven|vie|vol|wln|wol|xho|yid|yor|zha|zho|zul))$/;
|
274 | const iso693EnglishNames = [
|
275 | "Catalan, Valencian",
|
276 | "Chichewa, Chewa, Nyanja",
|
277 | "Church Slavic, Old Slavonic, Church Slavonic, Old Bulgarian, Old Church Slavonic",
|
278 | "Divehi, Dhivehi, Maldivian",
|
279 | "Dutch, Flemish",
|
280 | "Gaelic, Scottish Gaelic",
|
281 | "Greek, Modern (1453–)",
|
282 | "Haitian, Haitian Creole",
|
283 | "Interlingue, Occidental",
|
284 | "Kalaallisut, Greenlandic",
|
285 | "Kikuyu, Gikuyu",
|
286 | "Kirghiz, Kyrgyz",
|
287 | "Kuanyama, Kwanyama",
|
288 | "Limburgan, Limburger, Limburgish",
|
289 | "Luxembourgish, Letzeburgesch",
|
290 | "Navajo, Navaho",
|
291 | "Ossetian, Ossetic",
|
292 | "Pashto, Pushto",
|
293 | "Punjabi, Panjabi",
|
294 | "Romanian, Moldavian, Moldovan",
|
295 | "Sichuan Yi, Nuosu",
|
296 | "Sinhala, Sinhalese",
|
297 | "Spanish, Castilian",
|
298 | "Uighur, Uyghur",
|
299 | "Zhuang, Chuang",
|
300 | "Abkhazian",
|
301 | "Afar",
|
302 | "Afrikaans",
|
303 | "Akan",
|
304 | "Albanian",
|
305 | "Amharic",
|
306 | "Arabic",
|
307 | "Aragonese",
|
308 | "Armenian",
|
309 | "Assamese",
|
310 | "Avaric",
|
311 | "Avestan",
|
312 | "Aymara",
|
313 | "Azerbaijani",
|
314 | "Bambara",
|
315 | "Bashkir",
|
316 | "Basque",
|
317 | "Belarusian",
|
318 | "Bengali",
|
319 | "Bislama",
|
320 | "Bosnian",
|
321 | "Breton",
|
322 | "Bulgarian",
|
323 | "Burmese",
|
324 | "Central Khmer",
|
325 | "Chamorro",
|
326 | "Chechen",
|
327 | "Chinese",
|
328 | "Chuvash",
|
329 | "Cornish",
|
330 | "Corsican",
|
331 | "Cree",
|
332 | "Croatian",
|
333 | "Czech",
|
334 | "Danish",
|
335 | "Dzongkha",
|
336 | "English",
|
337 | "Esperanto",
|
338 | "Estonian",
|
339 | "Ewe",
|
340 | "Faroese",
|
341 | "Fijian",
|
342 | "Finnish",
|
343 | "French",
|
344 | "Fulah",
|
345 | "Galician",
|
346 | "Ganda",
|
347 | "Georgian",
|
348 | "German",
|
349 | "Guarani",
|
350 | "Gujarati",
|
351 | "Hausa",
|
352 | "Hebrew",
|
353 | "Herero",
|
354 | "Hindi",
|
355 | "Hiri Motu",
|
356 | "Hungarian",
|
357 | "Icelandic",
|
358 | "Ido",
|
359 | "Igbo",
|
360 | "Indonesian",
|
361 | "Interlingua (International Auxiliary Language Association)",
|
362 | "Inuktitut",
|
363 | "Inupiaq",
|
364 | "Irish",
|
365 | "ISO language name",
|
366 | "Italian",
|
367 | "Japanese",
|
368 | "Javanese",
|
369 | "Kannada",
|
370 | "Kanuri",
|
371 | "Kashmiri",
|
372 | "Kazakh",
|
373 | "Kinyarwanda",
|
374 | "Komi",
|
375 | "Kongo",
|
376 | "Korean",
|
377 | "Kurdish",
|
378 | "Lao",
|
379 | "Latin",
|
380 | "Latvian",
|
381 | "Lingala",
|
382 | "Lithuanian",
|
383 | "Luba-Katanga",
|
384 | "Macedonian",
|
385 | "Malagasy",
|
386 | "Malay",
|
387 | "Malayalam",
|
388 | "Maltese",
|
389 | "Manx",
|
390 | "Maori",
|
391 | "Marathi",
|
392 | "Marshallese",
|
393 | "Mongolian",
|
394 | "Nauru",
|
395 | "Ndonga",
|
396 | "Nepali",
|
397 | "North Ndebele",
|
398 | "Northern Sami",
|
399 | "Norwegian",
|
400 | "Norwegian Bokmål",
|
401 | "Norwegian Nynorsk",
|
402 | "Occitan",
|
403 | "Ojibwa",
|
404 | "Oriya",
|
405 | "Oromo",
|
406 | "Pali",
|
407 | "Persian",
|
408 | "Polish",
|
409 | "Portuguese",
|
410 | "Quechua",
|
411 | "Romansh",
|
412 | "Rundi",
|
413 | "Russian",
|
414 | "Samoan",
|
415 | "Sango",
|
416 | "Sanskrit",
|
417 | "Sardinian",
|
418 | "Serbian",
|
419 | "Shona",
|
420 | "Sindhi",
|
421 | "Slovak",
|
422 | "Slovenian",
|
423 | "Somali",
|
424 | "South Ndebele",
|
425 | "Southern Sotho",
|
426 | "Sundanese",
|
427 | "Swahili",
|
428 | "Swati",
|
429 | "Swedish",
|
430 | "Tagalog",
|
431 | "Tahitian",
|
432 | "Tajik",
|
433 | "Tamil",
|
434 | "Tatar",
|
435 | "Telugu",
|
436 | "Thai",
|
437 | "Tibetan",
|
438 | "Tigrinya",
|
439 | "Tonga (Tonga Islands)",
|
440 | "Tsonga",
|
441 | "Tswana",
|
442 | "Turkish",
|
443 | "Turkmen",
|
444 | "Twi",
|
445 | "Ukrainian",
|
446 | "Urdu",
|
447 | "Uzbek",
|
448 | "Venda",
|
449 | "Vietnamese",
|
450 | "Volapük",
|
451 | "Walloon",
|
452 | "Welsh",
|
453 | "Western Frisian",
|
454 | "Wolof",
|
455 | "Xhosa",
|
456 | "Yiddish",
|
457 | "Yoruba",
|
458 | "Zulu",
|
459 | ];
|
460 | const iso693NativeNames = [
|
461 | "(originally:) Occidental, (after WWII:) Interlingue",
|
462 | "azərbaycan dili, تۆرکجه",
|
463 | "Bahasa Melayu, بهاس ملايو",
|
464 | "català, valencià",
|
465 | "čeština, český jazyk",
|
466 | "chiCheŵa, chinyanja",
|
467 | "corsu, lingua corsa",
|
468 | "eesti, eesti keel",
|
469 | "euskara, euskera",
|
470 | "Fulfulde, Pulaar, Pular",
|
471 | "Gaelg, Gailck",
|
472 | "Iñupiaq, Iñupiatun",
|
473 | "język polski, polszczyzna",
|
474 | "kalaallisut, kalaallit oqaasii",
|
475 | "Kurdî, کوردی",
|
476 | "latine, lingua latina",
|
477 | "Nederlands, Vlaams",
|
478 | "occitan, lenga d'òc",
|
479 | "Oʻzbek, Ўзбек, أۇزبېك",
|
480 | "Română, Moldovenească",
|
481 | "Runa Simi, Kichwa",
|
482 | "Saɯ cueŋƅ, Saw cuengh",
|
483 | "slovenčina, slovenský jazyk",
|
484 | "Slovenski jezik, Slovenščina",
|
485 | "Soomaaliga, af Soomaali",
|
486 | "suomi, suomen kieli",
|
487 | "Türkmençe, Türkmen dili",
|
488 | "авар мацӀ, магӀарул мацӀ",
|
489 | "аҧсуа бызшәа, аҧсшәа",
|
490 | "Кыргызча, Кыргыз тили",
|
491 | "татар теле, tatar tele",
|
492 | "тоҷикӣ, toçikī, تاجیکی",
|
493 | "ئۇيغۇرچە, Uyghurche",
|
494 | "कॉशुर, کٲشُر",
|
495 | "पालि, पाळि",
|
496 | "संस्कृतम्, 𑌸𑌂𑌸𑍍𑌕𑍃𑌤𑌮𑍍",
|
497 | "सिंधी, سنڌي",
|
498 | "हिन्दी, हिंदी",
|
499 | "ਪੰਜਾਬੀ, پنجابی",
|
500 | "ខ្មែរ, ខេមរភាសា, ភាសាខ្មែរ",
|
501 | "ꦧꦱꦗꦮ, Basa Jawa",
|
502 | "中文 (Zhōngwén), 汉语, 漢語",
|
503 | "(Hausa) هَوُسَ",
|
504 | "Afaan Oromoo",
|
505 | "Afaraf",
|
506 | "Afrikaans",
|
507 | "Akan",
|
508 | "aragonés",
|
509 | "Asụsụ Igbo",
|
510 | "Avañe'ẽ",
|
511 | "avesta",
|
512 | "aymar aru",
|
513 | "Bahasa Indonesia",
|
514 | "bamanankan",
|
515 | "Basa Sunda",
|
516 | "Bislama",
|
517 | "bosanski jezik",
|
518 | "brezhoneg",
|
519 | "Chamoru",
|
520 | "chiShona",
|
521 | "Cymraeg",
|
522 | "dansk",
|
523 | "Davvisámegiella",
|
524 | "Deutsch",
|
525 | "Diné bizaad",
|
526 | "Dorerin Naoero",
|
527 | "English",
|
528 | "Español",
|
529 | "Esperanto",
|
530 | "Eʋegbe",
|
531 | "Faka Tonga",
|
532 | "fiteny malagasy",
|
533 | "føroyskt",
|
534 | "français",
|
535 | "Frysk",
|
536 | "Gaeilge",
|
537 | "gagana fa'a Samoa",
|
538 | "Gàidhlig",
|
539 | "Galego",
|
540 | "Gĩkũyũ",
|
541 | "Hiri Motu",
|
542 | "hrvatski jezik",
|
543 | "Ido",
|
544 | "Ikinyarwanda",
|
545 | "Ikirundi",
|
546 | "Interlingua",
|
547 | "isiNdebele",
|
548 | "isiNdebele",
|
549 | "isiXhosa",
|
550 | "isiZulu",
|
551 | "Íslenska",
|
552 | "Italiano",
|
553 | "Kajin M̧ajeļ",
|
554 | "Kanuri",
|
555 | "Kernewek",
|
556 | "Kikongo",
|
557 | "Kiluba",
|
558 | "Kiswahili",
|
559 | "Kreyòl ayisyen",
|
560 | "Kuanyama",
|
561 | "latviešu valoda",
|
562 | "Lëtzebuergesch",
|
563 | "lietuvių kalba",
|
564 | "Limburgs",
|
565 | "Lingála",
|
566 | "Luganda",
|
567 | "magyar",
|
568 | "Malti",
|
569 | "Norsk",
|
570 | "Norsk Bokmål",
|
571 | "Norsk Nynorsk",
|
572 | "Otjiherero",
|
573 | "Owambo",
|
574 | "Português",
|
575 | "Reo Tahiti",
|
576 | "Rumantsch Grischun",
|
577 | "sardu",
|
578 | "Sesotho",
|
579 | "Setswana",
|
580 | "Shqip",
|
581 | "SiSwati",
|
582 | "Svenska",
|
583 | "te reo Māori",
|
584 | "Tiếng Việt",
|
585 | "Tshivenḓa",
|
586 | "Türkçe",
|
587 | "Twi",
|
588 | "Volapük",
|
589 | "vosa Vakaviti",
|
590 | "Walon",
|
591 | "Wikang Tagalog",
|
592 | "Wollof",
|
593 | "Xitsonga",
|
594 | "yângâ tî sängö",
|
595 | "Yorùbá",
|
596 | "Ελληνικά",
|
597 | "башҡорт теле",
|
598 | "беларуская мова",
|
599 | "български език",
|
600 | "ирон ӕвзаг",
|
601 | "коми кыв",
|
602 | "қазақ тілі",
|
603 | "македонски јазик",
|
604 | "Монгол хэл",
|
605 | "нохчийн мотт",
|
606 | "русский",
|
607 | "српски језик",
|
608 | "Українська",
|
609 | "чӑваш чӗлхи",
|
610 | "ѩзыкъ словѣньскъ",
|
611 | "ქართული",
|
612 | "Հայերեն",
|
613 | "ትግርኛ",
|
614 | "አማርኛ",
|
615 | "नेपाली",
|
616 | "मराठी",
|
617 | "অসমীয়া",
|
618 | "বাংলা",
|
619 | "ગુજરાતી",
|
620 | "ଓଡ଼ିଆ",
|
621 | "தமிழ்",
|
622 | "తెలుగు",
|
623 | "ಕನ್ನಡ",
|
624 | "മലയാളം",
|
625 | "සිංහල",
|
626 | "ไทย",
|
627 | "ພາສາລາວ",
|
628 | "བོད་ཡིག",
|
629 | "རྫོང་ཁ",
|
630 | "ဗမာစာ",
|
631 | "ᐃᓄᒃᑎᑐᑦ",
|
632 | "ᐊᓂᔑᓈᐯᒧᐎᓐ",
|
633 | "ᓀᐦᐃᔭᐍᐏᐣ",
|
634 | "한국어",
|
635 | "ꆈꌠ꒿ Nuosuhxop",
|
636 | "日本語 (にほんご)",
|
637 | ];
|
638 | function inferLanguage(value) {
|
639 | if (iso693Regex.test(value)) {
|
640 | return {
|
641 | name: "language",
|
642 | variant: "iso693-1",
|
643 | };
|
644 | }
|
645 | if (iso6932Regex.test(value)) {
|
646 | return {
|
647 | name: "language",
|
648 | variant: "iso693-2",
|
649 | };
|
650 | }
|
651 | if (iso693EnglishNames.includes(value)) {
|
652 | return {
|
653 | name: "language",
|
654 | variant: "english",
|
655 | };
|
656 | }
|
657 | if (iso693NativeNames.includes(value)) {
|
658 | return {
|
659 | name: "language",
|
660 | variant: "native",
|
661 | };
|
662 | }
|
663 | return undefined;
|
664 | }
|
665 |
|
666 | const phoneNumberRegex = /^\+[0-9]{6,15}$/;
|
667 | function inferPhoneNumber(value) {
|
668 | const cleanedValue = value.replace(/[\s-()]/g, "");
|
669 | if (phoneNumberRegex.test(cleanedValue)) {
|
670 | return {
|
671 | name: "phoneNumber",
|
672 | variant: "e.164",
|
673 | };
|
674 | }
|
675 | }
|
676 |
|
677 | function lookupMimeType(ext) {
|
678 | if (ext === undefined) {
|
679 | return undefined;
|
680 | }
|
681 | const extensionToMimeType = {
|
682 | json: "application/json",
|
683 | js: "application/javascript",
|
684 | html: "text/html",
|
685 | css: "text/css",
|
686 | txt: "text/plain",
|
687 | ts: "text/typescript",
|
688 | tsx: "text/typescript",
|
689 | aac: "audio/aac",
|
690 | abw: "application/x-abiword",
|
691 | arc: "application/x-freearc",
|
692 | avi: "video/x-msvideo",
|
693 | azw: "application/vnd.amazon.ebook",
|
694 | bin: "application/octet-stream",
|
695 | bmp: "image/bmp",
|
696 | bz: "application/x-bzip",
|
697 | bz2: "application/x-bzip2",
|
698 | cda: "application/x-cdf",
|
699 | csh: "application/x-csh",
|
700 | csv: "text/csv",
|
701 | doc: "application/msword",
|
702 | docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
703 | eot: "application/vnd.ms-fontobject",
|
704 | epub: "application/epub+zip",
|
705 | gz: "application/gzip",
|
706 | gif: "image/gif",
|
707 | htm: "text/html",
|
708 | ico: "image/vnd.microsoft.icon",
|
709 | ics: "text/calendar",
|
710 | jar: "application/java-archive",
|
711 | jpeg: "image/jpeg",
|
712 | jpg: "image/jpeg",
|
713 | jsonld: "application/ld+json",
|
714 | mid: "audio/midi",
|
715 | midi: "audio/midi",
|
716 | mjs: "text/javascript",
|
717 | mp3: "audio/mpeg",
|
718 | mp4: "video/mp4",
|
719 | mpeg: "video/mpeg",
|
720 | mpkg: "application/vnd.apple.installer+xml",
|
721 | odp: "application/vnd.oasis.opendocument.presentation",
|
722 | ods: "application/vnd.oasis.opendocument.spreadsheet",
|
723 | odt: "application/vnd.oasis.opendocument.text",
|
724 | oga: "audio/ogg",
|
725 | ogv: "video/ogg",
|
726 | ogx: "application/ogg",
|
727 | opus: "audio/opus",
|
728 | otf: "font/otf",
|
729 | png: "image/png",
|
730 | pdf: "application/pdf",
|
731 | php: "application/x-httpd-php",
|
732 | ppt: "application/vnd.ms-powerpoint",
|
733 | pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
734 | rar: "application/vnd.rar",
|
735 | rtf: "application/rtf",
|
736 | sh: "application/x-sh",
|
737 | svg: "image/svg+xml",
|
738 | swf: "application/x-shockwave-flash",
|
739 | tar: "application/x-tar",
|
740 | tif: "image/tiff",
|
741 | tiff: "image/tiff",
|
742 | ttf: "font/ttf",
|
743 | vsd: "application/vnd.visio",
|
744 | wav: "audio/wav",
|
745 | weba: "audio/webm",
|
746 | webm: "video/webm",
|
747 | webp: "image/webp",
|
748 | woff: "font/woff",
|
749 | woff2: "font/woff2",
|
750 | xhtml: "application/xhtml+xml",
|
751 | xls: "application/vnd.ms-excel",
|
752 | xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
753 | xml: "application/xml",
|
754 | xul: "application/vnd.mozilla.xul+xml",
|
755 | zip: "application/zip",
|
756 | "3gp": "video/3gpp",
|
757 | "3g2": "video/3gpp2",
|
758 | "7z": "application/x-7z-compressed",
|
759 | md: "text/markdown",
|
760 | };
|
761 | return extensionToMimeType[ext];
|
762 | }
|
763 | function inferUri(value) {
|
764 | try {
|
765 | const url = new URL(value);
|
766 | if (url.hostname === "") {
|
767 | return undefined;
|
768 | }
|
769 |
|
770 | const ext = url.pathname.split(".").pop();
|
771 | const mimeType = lookupMimeType(ext);
|
772 | return {
|
773 | name: "uri",
|
774 | contentType: mimeType ? mimeType : undefined,
|
775 | };
|
776 | }
|
777 | catch (_) {
|
778 |
|
779 | }
|
780 | return undefined;
|
781 | }
|
782 |
|
783 | function validateVersion(uuid$1, versionNumber) {
|
784 | return uuid.validate(uuid$1) && uuid.version(uuid$1) === versionNumber;
|
785 | }
|
786 | function inferUuid(value) {
|
787 | if (validateVersion(value, 1)) {
|
788 | return {
|
789 | name: "uuid",
|
790 | variant: "v1",
|
791 | };
|
792 | }
|
793 | if (validateVersion(value, 4)) {
|
794 | return {
|
795 | name: "uuid",
|
796 | variant: "v4",
|
797 | };
|
798 | }
|
799 | if (validateVersion(value, 5)) {
|
800 | return {
|
801 | name: "uuid",
|
802 | variant: "v5",
|
803 | };
|
804 | }
|
805 | return undefined;
|
806 | }
|
807 |
|
808 | function inferFilesize(value) {
|
809 | if (value.match(/^[0-9.]+\s?(?:(B|MB|K|GB|TB|PB|MiB|KB|kB))$/)) {
|
810 | return {
|
811 | name: "filesize",
|
812 | variant: "human",
|
813 | };
|
814 | }
|
815 | return undefined;
|
816 | }
|
817 |
|
818 | const tlds = [
|
819 | "com",
|
820 | "org",
|
821 | "net",
|
822 | "edu",
|
823 | "gov",
|
824 | "mil",
|
825 | "co",
|
826 | "io",
|
827 | "ac",
|
828 | "dev",
|
829 | "info",
|
830 | "biz",
|
831 | "name",
|
832 | "uk",
|
833 | "me",
|
834 | "ca",
|
835 | "tv",
|
836 | "ir",
|
837 | "au",
|
838 | ];
|
839 | function containsTld(value) {
|
840 | const extname = value.split(".").pop();
|
841 | if (!extname) {
|
842 | return false;
|
843 | }
|
844 | return tlds.includes(extname);
|
845 | }
|
846 | function isValidHostname(value, allowUnderscore = false) {
|
847 | if (value.length === 0) {
|
848 | return false;
|
849 | }
|
850 | if (value === "localhost") {
|
851 | return true;
|
852 | }
|
853 | if (!value.includes(".")) {
|
854 | return false;
|
855 | }
|
856 | const validHostnameChars = new RegExp(`^[a-zA-Z0-9-.${allowUnderscore ? "_" : ""}]{1,253}.?$`, "g");
|
857 | if (!validHostnameChars.test(value)) {
|
858 | return false;
|
859 | }
|
860 | if (value.endsWith(".")) {
|
861 | value = value.slice(0, value.length - 1);
|
862 | }
|
863 | const labels = value.split(".");
|
864 | const isValid = labels.every(function (label) {
|
865 | const validLabelChars = new RegExp(`^([a-zA-Z0-9-${allowUnderscore ? "_" : ""}]+)$`, "g");
|
866 | const validLabel = validLabelChars.test(label) &&
|
867 | label.length < 64 &&
|
868 | !label.startsWith("-") &&
|
869 | !label.endsWith("-");
|
870 | return validLabel;
|
871 | });
|
872 | return isValid && containsTld(value);
|
873 | }
|
874 | function inferHostname(value) {
|
875 | if (isValidHostname(value)) {
|
876 | return {
|
877 | name: "hostname",
|
878 | variant: "rfc1123",
|
879 | };
|
880 | }
|
881 | if (isValidHostname(value, true)) {
|
882 | return {
|
883 | name: "hostname",
|
884 | variant: "rfc5890",
|
885 | };
|
886 | }
|
887 | return undefined;
|
888 | }
|
889 |
|
890 | function inferJson(value) {
|
891 | try {
|
892 | const parsedValue = JSON.parse(value);
|
893 | if (typeof parsedValue === "object") {
|
894 | return {
|
895 | name: "json",
|
896 | variant: "ecma262",
|
897 | };
|
898 | }
|
899 | }
|
900 | catch {
|
901 |
|
902 | }
|
903 | try {
|
904 | const parsedValue = JSON5__default["default"].parse(value);
|
905 | if (typeof parsedValue === "object") {
|
906 | return {
|
907 | name: "json",
|
908 | variant: "json5",
|
909 | };
|
910 | }
|
911 | }
|
912 | catch {
|
913 |
|
914 | }
|
915 | return undefined;
|
916 | }
|
917 |
|
918 | const rfc6901Regex = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
|
919 | function inferJsonPointer(value) {
|
920 | if (rfc6901Regex.exec(value)) {
|
921 | return { name: "jsonPointer", variant: "rfc6901" };
|
922 | }
|
923 | return undefined;
|
924 | }
|
925 |
|
926 | const emojiRegex = /^(\p{Extended_Pictographic}|\p{Emoji_Modifier}|\p{Emoji_Modifier_Base})*$/u;
|
927 | function inferEmoji(value) {
|
928 | if (emojiRegex.test(value)) {
|
929 | return {
|
930 | name: "emoji",
|
931 | };
|
932 | }
|
933 | return undefined;
|
934 | }
|
935 |
|
936 | const regex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
937 | function inferSemver(value) {
|
938 | if (regex.test(value)) {
|
939 | return { name: "semver" };
|
940 | }
|
941 | return undefined;
|
942 | }
|
943 |
|
944 | function isFirestoreTimestamp(value) {
|
945 | return (typeof value === "object" &&
|
946 | value !== null &&
|
947 | typeof value._seconds === "number" &&
|
948 | typeof value._nanoseconds === "number");
|
949 | }
|
950 | function inferFirestoreTimestamp(value) {
|
951 | if (isFirestoreTimestamp(value)) {
|
952 | return {
|
953 | name: "firestoreTimestamp",
|
954 | };
|
955 | }
|
956 | return undefined;
|
957 | }
|
958 |
|
959 | function inferJWT(value) {
|
960 | try {
|
961 | const token = jwtDecode__default["default"](value);
|
962 | if (token) {
|
963 | return {
|
964 | name: "jwt",
|
965 | };
|
966 | }
|
967 | }
|
968 | catch {
|
969 |
|
970 | }
|
971 | return undefined;
|
972 | }
|
973 |
|
974 | const hexRegex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
975 | const rgbRegex = /^rgba?\((\d{1,3})(,|\s+)\s*(\d{1,3})(,|\s+)\s*(\d{1,3})(,\s*0?.\d{1,3})?(\s+\/\s+0?.\d{1,3})?\)$/;
|
976 | const hslRegex = /^hsla?\((\d{1,3})(,|\s+)\s*(\d{1,3}%)(,|\s+)\s*(\d{1,3}%)(,\s*0?.\d{1,3})?(\s+\/\s+0?.\d{1,3})?\)$/;
|
977 | function inferColor(value) {
|
978 | if (hexRegex.test(value)) {
|
979 | return {
|
980 | name: "color",
|
981 | variant: "hex",
|
982 | };
|
983 | }
|
984 | if (rgbRegex.test(value)) {
|
985 | return {
|
986 | name: "color",
|
987 | variant: "rgb",
|
988 | };
|
989 | }
|
990 | if (hslRegex.test(value)) {
|
991 | return {
|
992 | name: "color",
|
993 | variant: "hsl",
|
994 | };
|
995 | }
|
996 | return undefined;
|
997 | }
|
998 |
|
999 | const visaRegex = /^4[0-9]{12}(?:[0-9]{3})?$/;
|
1000 | const amexRegex = /^3[47][0-9]{13}$/;
|
1001 | const discoverRegex = /^6(?:011|5[0-9]{2})[0-9]{12}$/;
|
1002 | const masterCardRegex = /^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/;
|
1003 | const dinersClubRegex = /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/;
|
1004 | function inferCreditCard(value) {
|
1005 | const withoutWhitespace = value.replace(/\s/g, "");
|
1006 | if (visaRegex.test(withoutWhitespace)) {
|
1007 | return {
|
1008 | name: "creditcard",
|
1009 | variant: "visa",
|
1010 | };
|
1011 | }
|
1012 | else if (amexRegex.test(withoutWhitespace)) {
|
1013 | return {
|
1014 | name: "creditcard",
|
1015 | variant: "amex",
|
1016 | };
|
1017 | }
|
1018 | else if (discoverRegex.test(withoutWhitespace)) {
|
1019 | return {
|
1020 | name: "creditcard",
|
1021 | variant: "discover",
|
1022 | };
|
1023 | }
|
1024 | else if (masterCardRegex.test(withoutWhitespace)) {
|
1025 | return {
|
1026 | name: "creditcard",
|
1027 | variant: "mastercard",
|
1028 | };
|
1029 | }
|
1030 | else if (dinersClubRegex.test(withoutWhitespace)) {
|
1031 | return {
|
1032 | name: "creditcard",
|
1033 | variant: "dinersclub",
|
1034 | };
|
1035 | }
|
1036 | return undefined;
|
1037 | }
|
1038 |
|
1039 |
|
1040 | const formats = [
|
1041 | inferUri,
|
1042 | inferTld,
|
1043 | inferHostname,
|
1044 | inferEmail,
|
1045 | inferDatetime,
|
1046 | inferIpAddress,
|
1047 | inferPhoneNumber,
|
1048 | inferCurrency,
|
1049 | inferCountry,
|
1050 | inferLanguage,
|
1051 | inferUuid,
|
1052 | inferFilesize,
|
1053 | inferTimestamp,
|
1054 | inferJson,
|
1055 | inferJsonPointer,
|
1056 | inferEmoji,
|
1057 | inferSemver,
|
1058 | inferJWT,
|
1059 | inferColor,
|
1060 | inferCreditCard,
|
1061 | ];
|
1062 | function inferFormat(value) {
|
1063 | if (value.trim() === "") {
|
1064 | return undefined;
|
1065 | }
|
1066 | for (const [, format] of Object.entries(formats)) {
|
1067 | const result = format(value);
|
1068 | if (result) {
|
1069 | return result;
|
1070 | }
|
1071 | }
|
1072 | return undefined;
|
1073 | }
|
1074 | const objectFormats = [inferFirestoreTimestamp];
|
1075 | function inferObjectFormat(value) {
|
1076 | for (const [, format] of Object.entries(objectFormats)) {
|
1077 | const result = format(value);
|
1078 | if (result) {
|
1079 | return result;
|
1080 | }
|
1081 | }
|
1082 | return undefined;
|
1083 | }
|
1084 |
|
1085 | function inferType(value) {
|
1086 | if (value == null) {
|
1087 | return { name: "null", value: null };
|
1088 | }
|
1089 | if (typeof value === "boolean") {
|
1090 | return { name: "bool", value };
|
1091 | }
|
1092 | if (typeof value === "number") {
|
1093 | if (Number.isInteger(value)) {
|
1094 | return { name: "int", value };
|
1095 | }
|
1096 | else {
|
1097 | return { name: "float", value };
|
1098 | }
|
1099 | }
|
1100 | if (typeof value === "object") {
|
1101 | if (Array.isArray(value)) {
|
1102 | return {
|
1103 | name: "array",
|
1104 | value,
|
1105 | };
|
1106 | }
|
1107 | return {
|
1108 | name: "object",
|
1109 | format: inferObjectFormat(value),
|
1110 | value,
|
1111 | };
|
1112 | }
|
1113 | if (typeof value === "string") {
|
1114 | return {
|
1115 | name: "string",
|
1116 | value,
|
1117 | format: inferFormat(value),
|
1118 | };
|
1119 | }
|
1120 | return { name: "null", value: null };
|
1121 | }
|
1122 |
|
1123 | exports.inferType = inferType;
|