1 | import { Address6, Address4 } from 'ip-address';
|
2 | import { URL } from 'universal-url';
|
3 | import mime from 'mime-types';
|
4 | import path from 'path';
|
5 | import { validate, version } from 'uuid';
|
6 | import JSON5 from 'json5';
|
7 |
|
8 | function inferDatetime(value) {
|
9 | var rfc3339Match = inferRFC3339(value);
|
10 | if (rfc3339Match) {
|
11 | return rfc3339Match;
|
12 | }
|
13 | var rfc2822Match = inferRFC2822(value);
|
14 | if (rfc2822Match) {
|
15 | return rfc2822Match;
|
16 | }
|
17 | return undefined;
|
18 | }
|
19 | var 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))?))?$/;
|
20 | var rfc3339WithWeekIndex = /^(\d{4})-?W(\d\d)(?:-?(\d))?(?:[T\s](\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?(?:(Z?)|([+-]\d\d)(?::?(\d\d))?))?$/;
|
21 | var rfc3339WithOrdinal = /^(\d{4})-?(\d{3})?(?:[T\s](\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?(?:(Z?)|([+-]\d\d)(?::?(\d\d))?))?$/;
|
22 | var rfc3339TimeOnly = /^(?:(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?(?:(Z?)|([+-]\d\d)(?::?(\d\d))?))?$/;
|
23 | var rfc3339 = [
|
24 | {
|
25 | matches: rfc3339WithYmd,
|
26 | parts: rfc3339Parts,
|
27 | },
|
28 | {
|
29 | matches: rfc3339WithWeekIndex,
|
30 | parts: rfc3339Parts,
|
31 | },
|
32 | {
|
33 | matches: rfc3339WithOrdinal,
|
34 | parts: rfc3339WithOrdinalParts,
|
35 | },
|
36 | {
|
37 | matches: rfc3339TimeOnly,
|
38 | parts: function () { return "time"; },
|
39 | },
|
40 | ];
|
41 | function inferRFC3339(value) {
|
42 | var rfc3339Matches = rfc3339
|
43 | .map(function (rfc) {
|
44 | return {
|
45 | matches: rfc.matches.exec(value),
|
46 | parts: rfc.parts,
|
47 | };
|
48 | })
|
49 | .filter(function (rfc) { return rfc.matches !== null && rfc.matches.some(function (i) { return i; }); });
|
50 | var rfc3339BestMatch = rfc3339Matches.sort(
|
51 |
|
52 | function (a, b) { return b.matches.length - a.matches.length; })[0];
|
53 | if (rfc3339BestMatch) {
|
54 | return {
|
55 | name: "datetime",
|
56 |
|
57 | parts: rfc3339BestMatch.parts(rfc3339BestMatch.matches),
|
58 | variant: "rfc3339",
|
59 | };
|
60 | }
|
61 | return undefined;
|
62 | }
|
63 | function rfc3339Parts(match) {
|
64 | var dateParts = [1, 2, 3];
|
65 | var timeParts = [4, 5, 6, 7];
|
66 | var hasSomeDateParts = dateParts.some(function (i) { return match[i] !== undefined; });
|
67 | var hasSomeTimeParts = timeParts.some(function (i) { return match[i] !== undefined; });
|
68 | if (hasSomeDateParts && hasSomeTimeParts) {
|
69 | return "datetime";
|
70 | }
|
71 | return "date";
|
72 | }
|
73 | function rfc3339WithOrdinalParts(match) {
|
74 | var dateParts = [1, 2];
|
75 | var timeParts = [3, 4, 5, 6];
|
76 | var hasSomeDateParts = dateParts.some(function (i) { return match[i] !== undefined; });
|
77 | var hasSomeTimeParts = timeParts.some(function (i) { return match[i] !== undefined; });
|
78 | if (hasSomeDateParts && hasSomeTimeParts) {
|
79 | return "datetime";
|
80 | }
|
81 | return "date";
|
82 | }
|
83 | var 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)))$/;
|
84 | function inferRFC2822(value) {
|
85 | var rfc2822Matches = rfc2822.exec(value);
|
86 | if (rfc2822Matches) {
|
87 | return {
|
88 | name: "datetime",
|
89 | parts: "datetime",
|
90 | variant: "rfc2822",
|
91 | };
|
92 | }
|
93 | return undefined;
|
94 | }
|
95 |
|
96 | var timestampSecondsSinceEpoch = /^\d{10}$/;
|
97 | var timestampMsSinceEpoch = /^\d{13}$/;
|
98 | var timestampNanoSinceEpoch = /^\d{19}$/;
|
99 | function inferTimestamp(value) {
|
100 | if (timestampSecondsSinceEpoch.test(value)) {
|
101 | return {
|
102 | name: "timestamp",
|
103 | variant: "secondsSinceEpoch",
|
104 | };
|
105 | }
|
106 | if (timestampMsSinceEpoch.test(value)) {
|
107 | return {
|
108 | name: "timestamp",
|
109 | variant: "millisecondsSinceEpoch",
|
110 | };
|
111 | }
|
112 | if (timestampNanoSinceEpoch.test(value)) {
|
113 | return {
|
114 | name: "timestamp",
|
115 | variant: "nanosecondsSinceEpoch",
|
116 | };
|
117 | }
|
118 | return undefined;
|
119 | }
|
120 |
|
121 | var 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;
|
122 | var rfc5321Regex = new RegExp("^".concat(rfc5321AddressRegex.source, "$"));
|
123 | var rfc5322Regex = new RegExp("^[^\"]+<".concat(rfc5321AddressRegex.source, ">$"));
|
124 | function inferEmail(value) {
|
125 | if (rfc5321Regex.exec(value)) {
|
126 | return { name: "email", variant: "rfc5321" };
|
127 | }
|
128 | if (rfc5322Regex.exec(value)) {
|
129 | return { name: "email", variant: "rfc5322" };
|
130 | }
|
131 | return undefined;
|
132 | }
|
133 |
|
134 | var 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))$/;
|
135 | var 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))$/;
|
136 | var englishNamesRegex = /^(?:(U.?S.?\sDollar|Euro|United\sStates\sdollar|Japanese\sYen|Swiss\sFranc|Australian\sDollar|British\sPound|Canadian\sDollar|South\sAfrican\sRand))$/;
|
137 | function inferCurrency(value) {
|
138 | if (iso4217Regex.exec(value)) {
|
139 | return {
|
140 | name: "currency",
|
141 | variant: "iso4217",
|
142 | };
|
143 | }
|
144 | if (cryptoRegex.exec(value)) {
|
145 | return {
|
146 | name: "currency",
|
147 | variant: "crypto",
|
148 | };
|
149 | }
|
150 | if (englishNamesRegex.exec(value)) {
|
151 | return {
|
152 | name: "currency",
|
153 | variant: "english",
|
154 | };
|
155 | }
|
156 | return undefined;
|
157 | }
|
158 |
|
159 | var 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))$/;
|
160 | var 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))$/;
|
161 | function inferCountry(value) {
|
162 | if (iso31663Regex.exec(value)) {
|
163 | return {
|
164 | name: "country",
|
165 | variant: "iso3166-3",
|
166 | };
|
167 | }
|
168 | if (iso31662Regex.exec(value)) {
|
169 | return {
|
170 | name: "country",
|
171 | variant: "iso3166-2",
|
172 | };
|
173 | }
|
174 | return undefined;
|
175 | }
|
176 |
|
177 | function inferTld(value) {
|
178 | var tldRegex = /^\.\w{2,14}(\.\w{2,14})*$/i;
|
179 | if (tldRegex.test(value)) {
|
180 | return {
|
181 | name: "tld",
|
182 | };
|
183 | }
|
184 | return undefined;
|
185 | }
|
186 |
|
187 | function inferIpAddress(value) {
|
188 | try {
|
189 | var ipv6 = new Address6(value);
|
190 | if (ipv6) {
|
191 | return {
|
192 | name: "ip",
|
193 | variant: "v6",
|
194 | };
|
195 | }
|
196 | }
|
197 | catch (error) {
|
198 |
|
199 | }
|
200 | try {
|
201 | var ipv4 = new Address4(value);
|
202 | if (ipv4) {
|
203 | return {
|
204 | name: "ip",
|
205 | variant: "v4",
|
206 | };
|
207 | }
|
208 | }
|
209 | catch (error) {
|
210 |
|
211 | }
|
212 | return undefined;
|
213 | }
|
214 |
|
215 | var 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))$/;
|
216 | var 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))$/;
|
217 | var iso693EnglishNames = [
|
218 | "Catalan, Valencian",
|
219 | "Chichewa, Chewa, Nyanja",
|
220 | "Church Slavic, Old Slavonic, Church Slavonic, Old Bulgarian, Old Church Slavonic",
|
221 | "Divehi, Dhivehi, Maldivian",
|
222 | "Dutch, Flemish",
|
223 | "Gaelic, Scottish Gaelic",
|
224 | "Greek, Modern (1453–)",
|
225 | "Haitian, Haitian Creole",
|
226 | "Interlingue, Occidental",
|
227 | "Kalaallisut, Greenlandic",
|
228 | "Kikuyu, Gikuyu",
|
229 | "Kirghiz, Kyrgyz",
|
230 | "Kuanyama, Kwanyama",
|
231 | "Limburgan, Limburger, Limburgish",
|
232 | "Luxembourgish, Letzeburgesch",
|
233 | "Navajo, Navaho",
|
234 | "Ossetian, Ossetic",
|
235 | "Pashto, Pushto",
|
236 | "Punjabi, Panjabi",
|
237 | "Romanian, Moldavian, Moldovan",
|
238 | "Sichuan Yi, Nuosu",
|
239 | "Sinhala, Sinhalese",
|
240 | "Spanish, Castilian",
|
241 | "Uighur, Uyghur",
|
242 | "Zhuang, Chuang",
|
243 | "Abkhazian",
|
244 | "Afar",
|
245 | "Afrikaans",
|
246 | "Akan",
|
247 | "Albanian",
|
248 | "Amharic",
|
249 | "Arabic",
|
250 | "Aragonese",
|
251 | "Armenian",
|
252 | "Assamese",
|
253 | "Avaric",
|
254 | "Avestan",
|
255 | "Aymara",
|
256 | "Azerbaijani",
|
257 | "Bambara",
|
258 | "Bashkir",
|
259 | "Basque",
|
260 | "Belarusian",
|
261 | "Bengali",
|
262 | "Bislama",
|
263 | "Bosnian",
|
264 | "Breton",
|
265 | "Bulgarian",
|
266 | "Burmese",
|
267 | "Central Khmer",
|
268 | "Chamorro",
|
269 | "Chechen",
|
270 | "Chinese",
|
271 | "Chuvash",
|
272 | "Cornish",
|
273 | "Corsican",
|
274 | "Cree",
|
275 | "Croatian",
|
276 | "Czech",
|
277 | "Danish",
|
278 | "Dzongkha",
|
279 | "English",
|
280 | "Esperanto",
|
281 | "Estonian",
|
282 | "Ewe",
|
283 | "Faroese",
|
284 | "Fijian",
|
285 | "Finnish",
|
286 | "French",
|
287 | "Fulah",
|
288 | "Galician",
|
289 | "Ganda",
|
290 | "Georgian",
|
291 | "German",
|
292 | "Guarani",
|
293 | "Gujarati",
|
294 | "Hausa",
|
295 | "Hebrew",
|
296 | "Herero",
|
297 | "Hindi",
|
298 | "Hiri Motu",
|
299 | "Hungarian",
|
300 | "Icelandic",
|
301 | "Ido",
|
302 | "Igbo",
|
303 | "Indonesian",
|
304 | "Interlingua (International Auxiliary Language Association)",
|
305 | "Inuktitut",
|
306 | "Inupiaq",
|
307 | "Irish",
|
308 | "ISO language name",
|
309 | "Italian",
|
310 | "Japanese",
|
311 | "Javanese",
|
312 | "Kannada",
|
313 | "Kanuri",
|
314 | "Kashmiri",
|
315 | "Kazakh",
|
316 | "Kinyarwanda",
|
317 | "Komi",
|
318 | "Kongo",
|
319 | "Korean",
|
320 | "Kurdish",
|
321 | "Lao",
|
322 | "Latin",
|
323 | "Latvian",
|
324 | "Lingala",
|
325 | "Lithuanian",
|
326 | "Luba-Katanga",
|
327 | "Macedonian",
|
328 | "Malagasy",
|
329 | "Malay",
|
330 | "Malayalam",
|
331 | "Maltese",
|
332 | "Manx",
|
333 | "Maori",
|
334 | "Marathi",
|
335 | "Marshallese",
|
336 | "Mongolian",
|
337 | "Nauru",
|
338 | "Ndonga",
|
339 | "Nepali",
|
340 | "North Ndebele",
|
341 | "Northern Sami",
|
342 | "Norwegian",
|
343 | "Norwegian Bokmål",
|
344 | "Norwegian Nynorsk",
|
345 | "Occitan",
|
346 | "Ojibwa",
|
347 | "Oriya",
|
348 | "Oromo",
|
349 | "Pali",
|
350 | "Persian",
|
351 | "Polish",
|
352 | "Portuguese",
|
353 | "Quechua",
|
354 | "Romansh",
|
355 | "Rundi",
|
356 | "Russian",
|
357 | "Samoan",
|
358 | "Sango",
|
359 | "Sanskrit",
|
360 | "Sardinian",
|
361 | "Serbian",
|
362 | "Shona",
|
363 | "Sindhi",
|
364 | "Slovak",
|
365 | "Slovenian",
|
366 | "Somali",
|
367 | "South Ndebele",
|
368 | "Southern Sotho",
|
369 | "Sundanese",
|
370 | "Swahili",
|
371 | "Swati",
|
372 | "Swedish",
|
373 | "Tagalog",
|
374 | "Tahitian",
|
375 | "Tajik",
|
376 | "Tamil",
|
377 | "Tatar",
|
378 | "Telugu",
|
379 | "Thai",
|
380 | "Tibetan",
|
381 | "Tigrinya",
|
382 | "Tonga (Tonga Islands)",
|
383 | "Tsonga",
|
384 | "Tswana",
|
385 | "Turkish",
|
386 | "Turkmen",
|
387 | "Twi",
|
388 | "Ukrainian",
|
389 | "Urdu",
|
390 | "Uzbek",
|
391 | "Venda",
|
392 | "Vietnamese",
|
393 | "Volapük",
|
394 | "Walloon",
|
395 | "Welsh",
|
396 | "Western Frisian",
|
397 | "Wolof",
|
398 | "Xhosa",
|
399 | "Yiddish",
|
400 | "Yoruba",
|
401 | "Zulu",
|
402 | ];
|
403 | var iso693NativeNames = [
|
404 | "(originally:) Occidental, (after WWII:) Interlingue",
|
405 | "azərbaycan dili, تۆرکجه",
|
406 | "Bahasa Melayu, بهاس ملايو",
|
407 | "català, valencià",
|
408 | "čeština, český jazyk",
|
409 | "chiCheŵa, chinyanja",
|
410 | "corsu, lingua corsa",
|
411 | "eesti, eesti keel",
|
412 | "euskara, euskera",
|
413 | "Fulfulde, Pulaar, Pular",
|
414 | "Gaelg, Gailck",
|
415 | "Iñupiaq, Iñupiatun",
|
416 | "język polski, polszczyzna",
|
417 | "kalaallisut, kalaallit oqaasii",
|
418 | "Kurdî, کوردی",
|
419 | "latine, lingua latina",
|
420 | "Nederlands, Vlaams",
|
421 | "occitan, lenga d'òc",
|
422 | "Oʻzbek, Ўзбек, أۇزبېك",
|
423 | "Română, Moldovenească",
|
424 | "Runa Simi, Kichwa",
|
425 | "Saɯ cueŋƅ, Saw cuengh",
|
426 | "slovenčina, slovenský jazyk",
|
427 | "Slovenski jezik, Slovenščina",
|
428 | "Soomaaliga, af Soomaali",
|
429 | "suomi, suomen kieli",
|
430 | "Türkmençe, Türkmen dili",
|
431 | "авар мацӀ, магӀарул мацӀ",
|
432 | "аҧсуа бызшәа, аҧсшәа",
|
433 | "Кыргызча, Кыргыз тили",
|
434 | "татар теле, tatar tele",
|
435 | "тоҷикӣ, toçikī, تاجیکی",
|
436 | "ئۇيغۇرچە, Uyghurche",
|
437 | "कॉशुर, کٲشُر",
|
438 | "पालि, पाळि",
|
439 | "संस्कृतम्, 𑌸𑌂𑌸𑍍𑌕𑍃𑌤𑌮𑍍",
|
440 | "सिंधी, سنڌي",
|
441 | "हिन्दी, हिंदी",
|
442 | "ਪੰਜਾਬੀ, پنجابی",
|
443 | "ខ្មែរ, ខេមរភាសា, ភាសាខ្មែរ",
|
444 | "ꦧꦱꦗꦮ, Basa Jawa",
|
445 | "中文 (Zhōngwén), 汉语, 漢語",
|
446 | "(Hausa) هَوُسَ",
|
447 | "Afaan Oromoo",
|
448 | "Afaraf",
|
449 | "Afrikaans",
|
450 | "Akan",
|
451 | "aragonés",
|
452 | "Asụsụ Igbo",
|
453 | "Avañe'ẽ",
|
454 | "avesta",
|
455 | "aymar aru",
|
456 | "Bahasa Indonesia",
|
457 | "bamanankan",
|
458 | "Basa Sunda",
|
459 | "Bislama",
|
460 | "bosanski jezik",
|
461 | "brezhoneg",
|
462 | "Chamoru",
|
463 | "chiShona",
|
464 | "Cymraeg",
|
465 | "dansk",
|
466 | "Davvisámegiella",
|
467 | "Deutsch",
|
468 | "Diné bizaad",
|
469 | "Dorerin Naoero",
|
470 | "English",
|
471 | "Español",
|
472 | "Esperanto",
|
473 | "Eʋegbe",
|
474 | "Faka Tonga",
|
475 | "fiteny malagasy",
|
476 | "føroyskt",
|
477 | "français",
|
478 | "Frysk",
|
479 | "Gaeilge",
|
480 | "gagana fa'a Samoa",
|
481 | "Gàidhlig",
|
482 | "Galego",
|
483 | "Gĩkũyũ",
|
484 | "Hiri Motu",
|
485 | "hrvatski jezik",
|
486 | "Ido",
|
487 | "Ikinyarwanda",
|
488 | "Ikirundi",
|
489 | "Interlingua",
|
490 | "isiNdebele",
|
491 | "isiNdebele",
|
492 | "isiXhosa",
|
493 | "isiZulu",
|
494 | "Íslenska",
|
495 | "Italiano",
|
496 | "Kajin M̧ajeļ",
|
497 | "Kanuri",
|
498 | "Kernewek",
|
499 | "Kikongo",
|
500 | "Kiluba",
|
501 | "Kiswahili",
|
502 | "Kreyòl ayisyen",
|
503 | "Kuanyama",
|
504 | "latviešu valoda",
|
505 | "Lëtzebuergesch",
|
506 | "lietuvių kalba",
|
507 | "Limburgs",
|
508 | "Lingála",
|
509 | "Luganda",
|
510 | "magyar",
|
511 | "Malti",
|
512 | "Norsk",
|
513 | "Norsk Bokmål",
|
514 | "Norsk Nynorsk",
|
515 | "Otjiherero",
|
516 | "Owambo",
|
517 | "Português",
|
518 | "Reo Tahiti",
|
519 | "Rumantsch Grischun",
|
520 | "sardu",
|
521 | "Sesotho",
|
522 | "Setswana",
|
523 | "Shqip",
|
524 | "SiSwati",
|
525 | "Svenska",
|
526 | "te reo Māori",
|
527 | "Tiếng Việt",
|
528 | "Tshivenḓa",
|
529 | "Türkçe",
|
530 | "Twi",
|
531 | "Volapük",
|
532 | "vosa Vakaviti",
|
533 | "Walon",
|
534 | "Wikang Tagalog",
|
535 | "Wollof",
|
536 | "Xitsonga",
|
537 | "yângâ tî sängö",
|
538 | "Yorùbá",
|
539 | "Ελληνικά",
|
540 | "башҡорт теле",
|
541 | "беларуская мова",
|
542 | "български език",
|
543 | "ирон ӕвзаг",
|
544 | "коми кыв",
|
545 | "қазақ тілі",
|
546 | "македонски јазик",
|
547 | "Монгол хэл",
|
548 | "нохчийн мотт",
|
549 | "русский",
|
550 | "српски језик",
|
551 | "Українська",
|
552 | "чӑваш чӗлхи",
|
553 | "ѩзыкъ словѣньскъ",
|
554 | "ქართული",
|
555 | "Հայերեն",
|
556 | "ትግርኛ",
|
557 | "አማርኛ",
|
558 | "नेपाली",
|
559 | "मराठी",
|
560 | "অসমীয়া",
|
561 | "বাংলা",
|
562 | "ગુજરાતી",
|
563 | "ଓଡ଼ିଆ",
|
564 | "தமிழ்",
|
565 | "తెలుగు",
|
566 | "ಕನ್ನಡ",
|
567 | "മലയാളം",
|
568 | "සිංහල",
|
569 | "ไทย",
|
570 | "ພາສາລາວ",
|
571 | "བོད་ཡིག",
|
572 | "རྫོང་ཁ",
|
573 | "ဗမာစာ",
|
574 | "ᐃᓄᒃᑎᑐᑦ",
|
575 | "ᐊᓂᔑᓈᐯᒧᐎᓐ",
|
576 | "ᓀᐦᐃᔭᐍᐏᐣ",
|
577 | "한국어",
|
578 | "ꆈꌠ꒿ Nuosuhxop",
|
579 | "日本語 (にほんご)",
|
580 | ];
|
581 | function inferLanguage(value) {
|
582 | if (iso693Regex.test(value)) {
|
583 | return {
|
584 | name: "language",
|
585 | variant: "iso693-1",
|
586 | };
|
587 | }
|
588 | if (iso6932Regex.test(value)) {
|
589 | return {
|
590 | name: "language",
|
591 | variant: "iso693-2",
|
592 | };
|
593 | }
|
594 | if (iso693EnglishNames.includes(value)) {
|
595 | return {
|
596 | name: "language",
|
597 | variant: "english",
|
598 | };
|
599 | }
|
600 | if (iso693NativeNames.includes(value)) {
|
601 | return {
|
602 | name: "language",
|
603 | variant: "native",
|
604 | };
|
605 | }
|
606 | return undefined;
|
607 | }
|
608 |
|
609 | var phoneNumberRegex = /^\+[0-9]{6,15}$/;
|
610 | function inferPhoneNumber(value) {
|
611 | var cleanedValue = value.replace(/[\s-()]/g, "");
|
612 | if (phoneNumberRegex.test(cleanedValue)) {
|
613 | return {
|
614 | name: "phoneNumber",
|
615 | variant: "e.164",
|
616 | };
|
617 | }
|
618 | }
|
619 |
|
620 | function inferUri(value) {
|
621 | try {
|
622 | var url = new URL(value);
|
623 |
|
624 | var ext = path.extname(url.pathname);
|
625 | var mimeType = mime.lookup(ext);
|
626 | return {
|
627 | name: "uri",
|
628 | contentType: mimeType ? mimeType : undefined,
|
629 | };
|
630 | }
|
631 | catch (_) {
|
632 |
|
633 | }
|
634 | return undefined;
|
635 | }
|
636 |
|
637 | function validateVersion(uuid, versionNumber) {
|
638 | return validate(uuid) && version(uuid) === versionNumber;
|
639 | }
|
640 | function inferUuid(value) {
|
641 | if (validateVersion(value, 1)) {
|
642 | return {
|
643 | name: "uuid",
|
644 | variant: "v1",
|
645 | };
|
646 | }
|
647 | if (validateVersion(value, 4)) {
|
648 | return {
|
649 | name: "uuid",
|
650 | variant: "v4",
|
651 | };
|
652 | }
|
653 | if (validateVersion(value, 5)) {
|
654 | return {
|
655 | name: "uuid",
|
656 | variant: "v5",
|
657 | };
|
658 | }
|
659 | return undefined;
|
660 | }
|
661 |
|
662 | function inferFilesize(value) {
|
663 | if (value.match(/^[0-9.]+\s?(?:(B|MB|K|GB|TB|PB|MiB|KB|kB))$/)) {
|
664 | return {
|
665 | name: "filesize",
|
666 | variant: "human",
|
667 | };
|
668 | }
|
669 | return undefined;
|
670 | }
|
671 |
|
672 | var filenameExtensions = [
|
673 | ".7z",
|
674 | ".aac",
|
675 | ".au",
|
676 | ".avi",
|
677 | ".bmp",
|
678 | ".bz2",
|
679 | ".css",
|
680 | ".csv",
|
681 | ".dmg",
|
682 | ".doc",
|
683 | ".docx",
|
684 | ".eot",
|
685 | ".epub",
|
686 | ".flac",
|
687 | ".flv",
|
688 | ".gif",
|
689 | ".gz",
|
690 | ".htm",
|
691 | ".html",
|
692 | ".ico",
|
693 | ".jpeg",
|
694 | ".jpg",
|
695 | ".js",
|
696 | ".json",
|
697 | ".key",
|
698 | ".m2v",
|
699 | ".m4a",
|
700 | ".m4v",
|
701 | ".m4v",
|
702 | ".md",
|
703 | ".mov",
|
704 | ".mp2",
|
705 | ".mp3",
|
706 | ".mp4",
|
707 | ".mpe",
|
708 | ".mpeg",
|
709 | ".mpeg",
|
710 | ".mpg",
|
711 | ".mpg",
|
712 | ".mpv",
|
713 | ".mxf",
|
714 | ".numbers",
|
715 | ".odt",
|
716 | ".ogg",
|
717 | ".ogv",
|
718 | ".pages",
|
719 | ".pdf",
|
720 | ".png",
|
721 | ".ppt",
|
722 | ".pptx",
|
723 | ".psd",
|
724 | ".rar",
|
725 | ".raw",
|
726 | ".rtf",
|
727 | ".svg",
|
728 | ".swf",
|
729 | ".tar",
|
730 | ".tgz",
|
731 | ".tif",
|
732 | ".tiff",
|
733 | ".ts",
|
734 | ".tsv",
|
735 | ".ttf",
|
736 | ".txt",
|
737 | ".wav",
|
738 | ".webp",
|
739 | ".wmv",
|
740 | ".woff",
|
741 | ".woff2",
|
742 | ".xls",
|
743 | ".xlsx",
|
744 | ".xml",
|
745 | ".xz",
|
746 | ".yaml",
|
747 | ".yml",
|
748 | ".z",
|
749 | ".zip",
|
750 | ];
|
751 | function isNotFilename(value) {
|
752 | var extname = path.extname(value);
|
753 | return extname === "" || !filenameExtensions.includes(extname);
|
754 | }
|
755 | function isValidHostname(value, allowUnderscore) {
|
756 | if (allowUnderscore === void 0) { allowUnderscore = false; }
|
757 | if (value.length === 0) {
|
758 | return false;
|
759 | }
|
760 | if (value === "localhost") {
|
761 | return true;
|
762 | }
|
763 | if (!value.includes(".")) {
|
764 | return false;
|
765 | }
|
766 | var validHostnameChars = new RegExp("^[a-zA-Z0-9-.".concat(allowUnderscore ? "_" : "", "]{1,253}.?$"), "g");
|
767 | if (!validHostnameChars.test(value)) {
|
768 | return false;
|
769 | }
|
770 | if (value.endsWith(".")) {
|
771 | value = value.slice(0, value.length - 1);
|
772 | }
|
773 | var labels = value.split(".");
|
774 | var isValid = labels.every(function (label) {
|
775 | var validLabelChars = new RegExp("^([a-zA-Z0-9-".concat(allowUnderscore ? "_" : "", "]+)$"), "g");
|
776 | var validLabel = validLabelChars.test(label) &&
|
777 | label.length < 64 &&
|
778 | !label.startsWith("-") &&
|
779 | !label.endsWith("-");
|
780 | return validLabel;
|
781 | });
|
782 | return isValid && isNotFilename(value);
|
783 | }
|
784 | function inferHostname(value) {
|
785 | if (isValidHostname(value)) {
|
786 | return {
|
787 | name: "hostname",
|
788 | variant: "rfc1123",
|
789 | };
|
790 | }
|
791 | if (isValidHostname(value, true)) {
|
792 | return {
|
793 | name: "hostname",
|
794 | variant: "rfc5890",
|
795 | };
|
796 | }
|
797 | return undefined;
|
798 | }
|
799 |
|
800 | function inferJson(value) {
|
801 | try {
|
802 | JSON.parse(value);
|
803 | return {
|
804 | name: "json",
|
805 | variant: "ecma262",
|
806 | };
|
807 | }
|
808 | catch (_a) {
|
809 |
|
810 | }
|
811 | try {
|
812 | JSON5.parse(value);
|
813 | return {
|
814 | name: "json",
|
815 | variant: "json5",
|
816 | };
|
817 | }
|
818 | catch (_b) {
|
819 |
|
820 | }
|
821 | return undefined;
|
822 | }
|
823 |
|
824 |
|
825 | var formats = [
|
826 | inferDatetime,
|
827 | inferTimestamp,
|
828 | inferEmail,
|
829 | inferCurrency,
|
830 | inferCountry,
|
831 | inferTld,
|
832 | inferIpAddress,
|
833 | inferLanguage,
|
834 | inferPhoneNumber,
|
835 | inferUri,
|
836 | inferUuid,
|
837 | inferFilesize,
|
838 | inferHostname,
|
839 | inferJson,
|
840 | ];
|
841 | function inferFormat(value) {
|
842 | for (var _i = 0, _a = Object.entries(formats); _i < _a.length; _i++) {
|
843 | var _b = _a[_i], format = _b[1];
|
844 | var result = format(value);
|
845 | if (result) {
|
846 | return result;
|
847 | }
|
848 | }
|
849 | return undefined;
|
850 | }
|
851 |
|
852 | function inferType(value) {
|
853 | if (value === null) {
|
854 | return { name: "null", value: null };
|
855 | }
|
856 | if (typeof value === "boolean") {
|
857 | return { name: "bool", value: value };
|
858 | }
|
859 | if (typeof value === "number") {
|
860 | if (Number.isInteger(value)) {
|
861 | return { name: "int", value: value };
|
862 | }
|
863 | else {
|
864 | return { name: "float", value: value };
|
865 | }
|
866 | }
|
867 | if (typeof value === "string") {
|
868 | return { name: "string", value: value, format: inferFormat(value) };
|
869 | }
|
870 | if (typeof value === "object") {
|
871 | if (Array.isArray(value)) {
|
872 | return {
|
873 | name: "array",
|
874 | value: value,
|
875 | };
|
876 | }
|
877 | return {
|
878 | name: "object",
|
879 | value: value,
|
880 | };
|
881 | }
|
882 | return { name: "null", value: null };
|
883 | }
|
884 |
|
885 | export { inferType };
|