@jarenjs/formats 0.8.3 → 0.9.2

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/dist/index.js DELETED
@@ -1,679 +0,0 @@
1
- // ../core/src/index.js
2
- function isStringType(data) {
3
- return typeof data === "string";
4
- }
5
- function isNumberType(data) {
6
- return data != null && typeof data === "number";
7
- }
8
- function isIntegerType(data) {
9
- return Number.isInteger(data);
10
- }
11
- function isObjectOfClass(data, type) {
12
- return data != null && data.constructor === type;
13
- }
14
- var TypedArray = Object.getPrototypeOf(Uint8Array);
15
- function getInclusiveExclusiveBounds(getType, inclusive, exclusive) {
16
- const includes = getType(inclusive);
17
- const excludes = exclusive === true ? includes : getType(exclusive);
18
- return excludes === void 0 ? [includes, void 0] : [void 0, excludes];
19
- }
20
-
21
- // ../core/src/dates.js
22
- var CONST_TICKS_SECOND = 1e3;
23
- var CONST_TICKS_HOUR = CONST_TICKS_SECOND * 60 * 60;
24
- var CONST_TICKS_DAY = CONST_TICKS_HOUR * 24;
25
- var CONST_TIME_INSERTDATE = "1970-01-01T";
26
- var CONST_RFC3339_DAYS = Object.freeze(
27
- [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
28
- );
29
- var CONST_RFC3339_REGEX_ISDATE = /^(\d\d\d\d)-([0-1]\d)-([0-3]\d)z?$/i;
30
- var CONST_RFC3339_REGEX_ISTIME = /^(\d\d):(\d\d):(\d\d)(\.\d{1,6})?(z|(([+-])(\d\d):(\d\d)))$/i;
31
- function isDateType(data) {
32
- return isObjectOfClass(data, Date);
33
- }
34
- function isLeapYear(year) {
35
- return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
36
- }
37
- function isDateOnlyInRange(year = 0, month = 0, day = 0) {
38
- return month >= 1 && month <= 12 && day >= 1 && day <= (month === 2 && isLeapYear(year) ? 29 : CONST_RFC3339_DAYS[month]);
39
- }
40
- function isDateOnlyRFC3339(str) {
41
- if (!isStringType(str))
42
- return false;
43
- const r = str.match(CONST_RFC3339_REGEX_ISDATE);
44
- if (r == null)
45
- return false;
46
- const y = parseInt(r[1], 10) | 0;
47
- const m = parseInt(r[2], 10) | 0;
48
- const d = parseInt(r[3], 10) | 0;
49
- return isDateOnlyInRange(y, m, d);
50
- }
51
- function isTimeOnlyInRange(hrs = 0, min = 0, sec = 0, tzh = 0, tzm = 0) {
52
- return (hrs === 23 && min === 59 && sec === 60 || hrs >= 0 && hrs <= 23 && min >= 0 && min <= 59 && sec >= 0 && sec <= 59) && (tzh >= 0 && tzh <= 23 && tzm >= 0 && tzm <= 59);
53
- }
54
- function isTimeOnlyRFC3339(str) {
55
- if (!isStringType(str))
56
- return false;
57
- const r = str.match(CONST_RFC3339_REGEX_ISTIME);
58
- if (r == null)
59
- return false;
60
- const h = parseInt(r[1], 10) | 0;
61
- const m = parseInt(r[2], 10) | 0;
62
- const s = parseInt(r[3], 10) | 0;
63
- const th = parseInt(r[8], 10) | 0;
64
- const tm = parseInt(r[9], 10) | 0;
65
- return isTimeOnlyInRange(h, m, s, th, tm);
66
- }
67
- function isDateTimeRFC3339(str) {
68
- if (!isStringType(str)) return false;
69
- const dateTime = str.split(/t|\s/i);
70
- return dateTime.length === 2 && isDateOnlyRFC3339(dateTime[0]) && isTimeOnlyRFC3339(dateTime[1]);
71
- }
72
- function getDateTypeOfDateOnlyRFC3339(str, def = void 0) {
73
- return isDateOnlyRFC3339(str) ? new Date(Date.parse(str)) : def;
74
- }
75
- function getDateTypeOfTimeOnlyRFC3339(str, def = void 0) {
76
- return isTimeOnlyRFC3339(str) ? new Date(Date.parse(CONST_TIME_INSERTDATE + str)) : def;
77
- }
78
- function getDateTypeOfDateTimeRFC3339(str, def = void 0) {
79
- return isDateTimeRFC3339(str) ? new Date(Date.parse(str)) : def;
80
- }
81
-
82
- // src/datetime.js
83
- function compileFormatMinimumByType(parseType, schemaObj, jsonSchema) {
84
- const [min, emin] = getInclusiveExclusiveBounds(
85
- parseType,
86
- jsonSchema.formatMinimum,
87
- jsonSchema.formatExclusiveMinimum
88
- );
89
- if (emin != null) {
90
- const addError = schemaObj.createErrorHandler(emin, "formatExclusiveMinimum");
91
- return function isFormatExclusiveMinimum(date, dataPath) {
92
- return date > emin || addError(date, dataPath);
93
- };
94
- } else if (min) {
95
- const addError = schemaObj.createErrorHandler(min, "formatMinimum");
96
- return function isFormatMinimum(date, dataPath) {
97
- return date >= min || addError(date, dataPath);
98
- };
99
- }
100
- return void 0;
101
- }
102
- function compileFormatMaximumByType(parseType, schemaObj, jsonSchema) {
103
- const [max, emax] = getInclusiveExclusiveBounds(
104
- parseType,
105
- jsonSchema.formatMaximum,
106
- jsonSchema.formatExclusiveMaximum
107
- );
108
- if (emax != null) {
109
- const addError = schemaObj.createErrorHandler(emax, "formatExclusiveMaximum");
110
- return function isFormatExclusiveMaximum(date, dataPath) {
111
- return date < emax || addError(date, dataPath);
112
- };
113
- } else if (max != null) {
114
- const addError = schemaObj.createErrorHandler(max, "formatMaximum");
115
- return function isFormatMaximum(date, dataPath) {
116
- return date <= max || addError(date, dataPath);
117
- };
118
- }
119
- return void 0;
120
- }
121
- function compileFormatByType(name, parseType, schemaObj, jsonSchema) {
122
- if (jsonSchema.format !== name)
123
- throw new Error("ERROR: This should not happen!");
124
- const addError = schemaObj.createErrorHandler(jsonSchema.format, "format");
125
- const validateMin = compileFormatMinimumByType(
126
- parseType,
127
- schemaObj,
128
- jsonSchema
129
- );
130
- const validateMax = compileFormatMaximumByType(
131
- parseType,
132
- schemaObj,
133
- jsonSchema
134
- );
135
- if (validateMin != null && validateMax != null) {
136
- return function validateFormatBetween(data, dataPath) {
137
- if (isStringType(data)) {
138
- const date = parseType(data);
139
- return date == null ? addError(data, dataPath) : validateMin(date, dataPath) && validateMax(date, dataPath);
140
- } else if (isDateType(data))
141
- return validateMin(data, dataPath) && validateMax(data, dataPath);
142
- else
143
- return true;
144
- };
145
- }
146
- if (validateMin != null) {
147
- return function validateFormatMinimum(data, dataPath) {
148
- if (isStringType(data)) {
149
- const date = parseType(data);
150
- return date == null ? addError(data, dataPath) : validateMin(date, dataPath);
151
- } else if (isDateType(data))
152
- return validateMin(data, dataPath);
153
- else
154
- return true;
155
- };
156
- }
157
- if (validateMax != null) {
158
- return function validateFormatMaximum(data, dataPath) {
159
- if (isStringType(data)) {
160
- const date = parseType(data);
161
- return date == null ? addError(data, dataPath) : validateMax(date);
162
- } else if (isDateType(data))
163
- return validateMax(data, dataPath);
164
- else
165
- return true;
166
- };
167
- }
168
- return function validateDateTime(data, dataPath) {
169
- if (isStringType(data)) {
170
- const date = parseType(data);
171
- return date == null ? addError(data, dataPath) : true;
172
- } else
173
- return true;
174
- };
175
- }
176
- function compileDateTimeFormat(schemaObj, jsonSchema) {
177
- return compileFormatByType(
178
- "date-time",
179
- getDateTypeOfDateTimeRFC3339,
180
- schemaObj,
181
- jsonSchema
182
- );
183
- }
184
- function compileDateOnlyFormat(schemaObj, jsonSchema) {
185
- return compileFormatByType(
186
- "date",
187
- getDateTypeOfDateOnlyRFC3339,
188
- schemaObj,
189
- jsonSchema
190
- );
191
- }
192
- function compileTimeOnlyFormat(schemaObj, jsonSchema) {
193
- return compileFormatByType(
194
- "time",
195
- getDateTypeOfTimeOnlyRFC3339,
196
- schemaObj,
197
- jsonSchema
198
- );
199
- }
200
- var formatValidators = {
201
- "date-time": compileDateTimeFormat,
202
- date: compileDateOnlyFormat,
203
- time: compileTimeOnlyFormat
204
- };
205
-
206
- // ../core/src/string.js
207
- function isStringUpperCase(str) {
208
- return str === str.toUpperCase();
209
- }
210
- function isStringLowerCase(str) {
211
- return str === str.toLowerCase();
212
- }
213
- function isRegExpType(data) {
214
- return isObjectOfClass(data, RegExp);
215
- }
216
- function isStringRegExp(str) {
217
- try {
218
- return createRegExp(str) != null;
219
- } catch (e) {
220
- return false;
221
- }
222
- }
223
- function createRegExp(pattern) {
224
- if (pattern == null)
225
- return void 0;
226
- if (isRegExpType(pattern))
227
- return pattern;
228
- if (isStringType(pattern)) {
229
- if (pattern[0] === "/") {
230
- const e = pattern.lastIndexOf("/");
231
- if (e >= 0) {
232
- const r = pattern.substring(1, e);
233
- const g = pattern.substring(e + 1);
234
- return new RegExp(r, g);
235
- }
236
- } else
237
- return new RegExp(pattern);
238
- }
239
- throw new Error(`Unknown Regular Expression Pattern Type: ${pattern}`);
240
- }
241
-
242
- // ../core/src/text/punycode.js
243
- var maxInt = 2147483647;
244
- var base = 36;
245
- var tMin = 1;
246
- var tMax = 26;
247
- var skew = 38;
248
- var damp = 700;
249
- var initialBias = 72;
250
- var initialN = 128;
251
- var delimiter = "-";
252
- var regexNonASCII = /[^\0-\x7E]/;
253
- var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g;
254
- var errors = {
255
- "overflow": "Overflow: input needs wider integers to process",
256
- "not-basic": "Illegal input >= 0x80 (not a basic code point)",
257
- "invalid-input": "Invalid input"
258
- };
259
- var baseMinusTMin = base - tMin;
260
- var floor = Math.floor;
261
- var stringFromCharCode = String.fromCharCode;
262
- function error(type) {
263
- throw new RangeError(errors[type]);
264
- }
265
- function map(array, fn) {
266
- const result = [];
267
- let length = array.length;
268
- while (length--) {
269
- result[length] = fn(array[length]);
270
- }
271
- return result;
272
- }
273
- function mapDomain(domain, fn) {
274
- const parts = domain.split("@");
275
- let result = "";
276
- if (parts.length > 1) {
277
- result = parts[0] + "@";
278
- domain = parts[1];
279
- }
280
- domain = domain.replace(regexSeparators, ".");
281
- const labels = domain.split(".");
282
- const encoded = map(labels, fn).join(".");
283
- return result + encoded;
284
- }
285
- function ucs2decode(string) {
286
- const output = [];
287
- let counter = 0;
288
- const length = string.length;
289
- while (counter < length) {
290
- const value = string.charCodeAt(counter++);
291
- if (value >= 55296 && value <= 56319 && counter < length) {
292
- const extra = string.charCodeAt(counter++);
293
- if ((extra & 64512) === 56320) {
294
- output.push(((value & 1023) << 10) + (extra & 1023) + 65536);
295
- } else {
296
- output.push(value);
297
- counter--;
298
- }
299
- } else {
300
- output.push(value);
301
- }
302
- }
303
- return output;
304
- }
305
- function digitToBasic(digit, flag) {
306
- return digit + 22 + 75 * (digit < 26) - ((flag !== 0) << 5);
307
- }
308
- function adapt(delta, numPoints, firstTime) {
309
- let k = 0;
310
- delta = firstTime ? floor(delta / damp) : delta >> 1;
311
- delta += floor(delta / numPoints);
312
- for (; delta > baseMinusTMin * tMax >> 1; k += base) {
313
- delta = floor(delta / baseMinusTMin);
314
- }
315
- return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
316
- }
317
- function encode(str) {
318
- const output = [];
319
- const input = ucs2decode(str);
320
- const inputLength = input.length;
321
- let n = initialN;
322
- let delta = 0;
323
- let bias = initialBias;
324
- for (const currentValue of input) {
325
- if (currentValue < 128) {
326
- output.push(stringFromCharCode(currentValue));
327
- }
328
- }
329
- const basicLength = output.length;
330
- let handledCPCount = basicLength;
331
- if (basicLength) {
332
- output.push(delimiter);
333
- }
334
- while (handledCPCount < inputLength) {
335
- let m = maxInt;
336
- for (const currentValue of input) {
337
- if (currentValue >= n && currentValue < m) {
338
- m = currentValue;
339
- }
340
- }
341
- const handledCPCountPlusOne = handledCPCount + 1;
342
- if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
343
- error("overflow");
344
- }
345
- delta += (m - n) * handledCPCountPlusOne;
346
- n = m;
347
- for (const currentValue of input) {
348
- if (currentValue < n && ++delta > maxInt) {
349
- error("overflow");
350
- }
351
- if (currentValue === n) {
352
- let q = delta;
353
- for (let k = base; ; k += base) {
354
- const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
355
- if (q < t) {
356
- break;
357
- }
358
- const qMinusT = q - t;
359
- const baseMinusT = base - t;
360
- output.push(
361
- stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
362
- );
363
- q = floor(qMinusT / baseMinusT);
364
- }
365
- output.push(stringFromCharCode(digitToBasic(q, 0)));
366
- bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength);
367
- delta = 0;
368
- ++handledCPCount;
369
- }
370
- }
371
- ++delta;
372
- ++n;
373
- }
374
- return output.join("");
375
- }
376
- function toASCII(input) {
377
- return mapDomain(input, function iterateMapDomain(string) {
378
- return regexNonASCII.test(string) ? "xn--" + encode(string) : string;
379
- });
380
- }
381
-
382
- // ../core/src/text/index.js
383
- var CONST_REGEXP_ALPHA = /^[a-zA-Z]+$/;
384
- function isValidAlpha(str) {
385
- return CONST_REGEXP_ALPHA.test(str);
386
- }
387
- var CONST_REGEXP_ALPHANUMERIC = /^[a-zA-Z0-9]+$/;
388
- function isValidAlphaNumeric(str) {
389
- return CONST_REGEXP_ALPHANUMERIC.test(str);
390
- }
391
- var CONST_REGEXP_NUMERIC = /^[0-9]+$/;
392
- function isValidNumeric(str) {
393
- return CONST_REGEXP_NUMERIC.test(str);
394
- }
395
- var CONST_REGEXP_HEXADECIMAL = /^[a-fA-F0-9]+$/;
396
- function isValidHexaDecimal(str) {
397
- return CONST_REGEXP_HEXADECIMAL.test(str);
398
- }
399
- var CONST_REGEXP_HEXCOLOR = /^#(?:[0-9a-f]{3}){1,2}\b$/i;
400
- function isValidHexColor(str) {
401
- return CONST_REGEXP_HEXCOLOR.test(str);
402
- }
403
- var CONST_REGEXP_UUID = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
404
- function isValidUUID(str) {
405
- return CONST_REGEXP_UUID.test(str);
406
- }
407
- var CONST_REGEXP_GUID = /^({)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
408
- function isValidGUID(str) {
409
- return CONST_REGEXP_GUID.test(str);
410
- }
411
- var CONST_REGEXP_IDENTIFIER = /^[_a-zA-Z]+\w{0,30}$/;
412
- function isValidIdentifier(str) {
413
- return (
414
- /* str != null && */
415
- CONST_REGEXP_IDENTIFIER.test(str)
416
- );
417
- }
418
- var CONST_REGEXP_HTML_IDENTIFIER = /^[A-Za-z]+[\w\-\:\.]{0,30}$/;
419
- function isValidHtmlIdentifier(str) {
420
- return (
421
- /* str != null && */
422
- CONST_REGEXP_HTML_IDENTIFIER.test(str)
423
- );
424
- }
425
- var CONST_REGEXP_CSS_IDENTIFIER = /^-?[_a-zA-Z]+[\w-]{0,30}$/;
426
- function isValidCssIdentifier(str) {
427
- return (
428
- /* str != null && */
429
- CONST_REGEXP_CSS_IDENTIFIER.test(str)
430
- );
431
- }
432
- var CONST_REGEXP_MAC_ADDR = /^(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})(?:(?:\1|\.)(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})){2}$/;
433
- function isValidMACAddr(str) {
434
- return CONST_REGEXP_MAC_ADDR.test(str);
435
- }
436
- var CONST_REGEXP_IPV4 = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
437
- function isValidIPv4(str) {
438
- return CONST_REGEXP_IPV4.test(str);
439
- }
440
- var CONST_REGEXP_IPV6 = /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i;
441
- function isValidIPv6(str) {
442
- return CONST_REGEXP_IPV6.test(str);
443
- }
444
- var CONST_REGEXP_HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i;
445
- function isValidHostname(str) {
446
- return str.length <= 255 && CONST_REGEXP_HOSTNAME.test(str);
447
- }
448
- var CONST_REGEXP_ACEHOSTNAME = /^(?!-)(xn--)?[a-zA-Z0-9][a-zA-Z0-9-_]{0,61}[a-zA-Z0-9]{0,1}\.(?!-)(xn--)?([a-zA-Z0-9\-]{1,50}|[a-zA-Z0-9-]{1,30}\.[a-zA-Z]{2,})$/;
449
- function isValidIdnHostname(str) {
450
- const punycode = toASCII(str);
451
- return CONST_REGEXP_ACEHOSTNAME.test(punycode);
452
- }
453
- var CONST_REGEXP_URL = /^[(http(s)?):\/\/(www\.)?\w-/=#%&\.\?]{2,}\.[a-z]{2,}([\w-/=#%&\.\?]*)$/i;
454
- function isValidUrl(str) {
455
- return CONST_REGEXP_URL.test(str);
456
- }
457
- var CONST_REGEXP_NOT_URI_FRAGMENT = /\/|:/;
458
- var CONST_REGEXP_URI_FAST = /^(?:[a-z][a-z0-9+-.]*:)(?:\/?\/)?[^\s]*$/i;
459
- function isValidUri(str) {
460
- return CONST_REGEXP_NOT_URI_FRAGMENT.test(str) && CONST_REGEXP_URI_FAST.test(str);
461
- }
462
- var CONST_REGEXP_URI_FULL = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
463
- function isValidUriFull(str) {
464
- return CONST_REGEXP_NOT_URI_FRAGMENT.test(str) && CONST_REGEXP_URI_FULL.test(str);
465
- }
466
- var CONST_REGEXP_URIREF_FAST = /^(?:(?:[a-z][a-z0-9+-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(?:#[^\\\s]*)?$/i;
467
- function isValidUriRef(str) {
468
- return CONST_REGEXP_URIREF_FAST.test(str);
469
- }
470
- var CONST_REGEXP_URIREF_FULL = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
471
- function isValidUriRefFull(str) {
472
- return CONST_REGEXP_URIREF_FULL.test(str);
473
- }
474
- var CONST_REGEXP_URITEMPLATE = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i;
475
- function isValidUriTemplate(str) {
476
- return CONST_REGEXP_URITEMPLATE.test(str);
477
- }
478
- var CONST_REGEXP_ABSOLUTE_IRI = /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
479
- function isValidIRI(str) {
480
- return CONST_REGEXP_ABSOLUTE_IRI.test(str);
481
- }
482
- function isValidIRIRef(str) {
483
- return isValidUriRef(str);
484
- }
485
- var CONST_REGEXP_JSON_POINTER = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
486
- function isValidJSONPointer(str) {
487
- return CONST_REGEXP_JSON_POINTER.test(str);
488
- }
489
- var CONST_REGEXP_JSON_POINTER_URI_FRAGMENT = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
490
- function isValidJSONPointerUriFragment(str) {
491
- return CONST_REGEXP_JSON_POINTER_URI_FRAGMENT.test(str);
492
- }
493
- var CONST_REGEXP_RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
494
- function isValidRelativeJSONPointer(str) {
495
- return CONST_REGEXP_RELATIVE_JSON_POINTER.test(str);
496
- }
497
- var CONST_REGEXP_EMAIL_FAST = /^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i;
498
- function isValidEmail(str) {
499
- return CONST_REGEXP_EMAIL_FAST.test(str);
500
- }
501
- var CONST_REGEXP_EMAIL_FULL = /^[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;
502
- function isValidEmailFull(str) {
503
- return CONST_REGEXP_EMAIL_FULL.test(str);
504
- }
505
- var CONST_REGEXP_IDNEMAIL = /^[^@]+@[^@]+\.[^@]+$/;
506
- function isValidIdnEmail(str) {
507
- return CONST_REGEXP_IDNEMAIL.test(str);
508
- }
509
- var CONST_REGPEXP_ISBN10 = /^(?:ISBN(?:-10)?:?\ *((?=\d{1,5}([ -]?)\d{1,7}\2?\d{1,6}\2?\d)(?:\d\2*){9}[\dX]))$/i;
510
- function isValidISBN10(str) {
511
- return CONST_REGPEXP_ISBN10.test(str);
512
- }
513
- var CONST_REGEXP_ISBN13 = /^(?:ISBN(?:-13)?:?\ *(97(?:8|9)([ -]?)(?=\d{1,5}\2?\d{1,7}\2?\d{1,6}\2?\d)(?:\d\2*){9}\d))$/i;
514
- function isValidISBN13(str) {
515
- return CONST_REGEXP_ISBN13.test(str);
516
- }
517
- var CONST_REGEXP_BASE64 = /^(?:[a-zA-Z0-9+\/]{4})*(?:|(?:[a-zA-Z0-9+\/]{3}=)|(?:[a-zA-Z0-9+\/]{2}==)|(?:[a-zA-Z0-9+\/]{1}===))$/;
518
- function isValidBase64(str) {
519
- return CONST_REGEXP_BASE64.test(str);
520
- }
521
- var CONST_REGEXP_COUNTRY_ALPHA2 = /^(AF|AX|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|KH|CM|CA|CV|KY|CF|TD|CL|CN|CX|CC|CO|KM|CG|CD|CK|CR|CI|HR|CU|CW|CY|CZ|DK|DJ|DM|DO|EC|EG|SV|GQ|ER|EE|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|MK|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|RE|RO|RU|RW|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|SZ|SE|CH|SY|TW|TJ|TZ|TH|TL|TG|TK|TO|TT|TN|TR|TM|TC|TV|UG|UA|AE|GB|US|UM|UY|UZ|VU|VE|VN|VG|VI|WF|EH|YE|ZM|ZW|XK)/i;
522
- function isValidCountryAlpha2(str) {
523
- return CONST_REGEXP_COUNTRY_ALPHA2.test(str);
524
- }
525
- var CONST_REGEXP_IBAN = /^([A-Z]{2}[ '+'\\\\'+'-]?[0-9]{2})(?=(?:[ '+'\\\\'+'-]?[A-Z0-9]){9,30}\$)((?:[ '+'\\\\'+'-]?[A-Z0-9]{3,5}){2,7})([ '+'\\\\'+'-]?[A-Z0-9]{1,3})?\$/i;
526
- function isValidIBAN(str) {
527
- return CONST_REGEXP_IBAN.test(str);
528
- }
529
-
530
- // src/string.js
531
- function createStringFormatCompiler(formatName, isFormatTest) {
532
- return function compileStringFormat(schemaObj, jsonSchema) {
533
- if (jsonSchema.format !== formatName)
534
- throw new Error("Format is not equal to jsonSchema (should not happen!)");
535
- const addError = schemaObj.createErrorHandler(formatName, "format", isFormatTest.constructor.name);
536
- return function validateStringFormat(data, dataPath) {
537
- return isStringType(data) ? isFormatTest(data) || addError(data, dataPath) : true;
538
- };
539
- };
540
- }
541
- var formatValidators2 = {
542
- "alpha": createStringFormatCompiler("alpha", isValidAlpha),
543
- "alphanumeric": createStringFormatCompiler("alphanumeric", isValidAlphaNumeric),
544
- "identifier": createStringFormatCompiler("identifier", isValidIdentifier),
545
- "html-identifier": createStringFormatCompiler("html-identifier", isValidHtmlIdentifier),
546
- "css-identifier": createStringFormatCompiler("css-identifier", isValidCssIdentifier),
547
- "hexadecimal": createStringFormatCompiler("hexadecimal", isValidHexaDecimal),
548
- "numeric": createStringFormatCompiler("numeric", isValidNumeric),
549
- "uppercase": createStringFormatCompiler("uppercase", isStringUpperCase),
550
- "lowercase": createStringFormatCompiler("lowercase", isStringLowerCase),
551
- "color": createStringFormatCompiler("color", isValidHexColor),
552
- "regex": createStringFormatCompiler("regex", isStringRegExp),
553
- "uri": createStringFormatCompiler("uri", isValidUri),
554
- "uri--full": createStringFormatCompiler("uri--full", isValidUriFull),
555
- "uri-reference": createStringFormatCompiler("uri-reference", isValidUriRef),
556
- "uri-reference--full": createStringFormatCompiler("uri-reference--full", isValidUriRefFull),
557
- "uri-template": createStringFormatCompiler("uri-template", isValidUriTemplate),
558
- "url": createStringFormatCompiler("url", isValidUrl),
559
- "url--full": createStringFormatCompiler("url--full", isValidUrl),
560
- "email": createStringFormatCompiler("email", isValidEmail),
561
- "email--full": createStringFormatCompiler("email--full", isValidEmailFull),
562
- "hostname": createStringFormatCompiler("hostname", isValidHostname),
563
- "idn-email": createStringFormatCompiler("idn-email", isValidIdnEmail),
564
- "idn-hostname": createStringFormatCompiler("idn-hostname", isValidIdnHostname),
565
- "ipv4": createStringFormatCompiler("ipv4", isValidIPv4),
566
- "ipv6": createStringFormatCompiler("ipv6", isValidIPv6),
567
- "uuid": createStringFormatCompiler("uuid", isValidUUID),
568
- "guid": createStringFormatCompiler("guid", isValidGUID),
569
- "json-pointer": createStringFormatCompiler("json-pointer", isValidJSONPointer),
570
- "json-pointer-uri-fragment": createStringFormatCompiler("json-pointer-uri-fragment", isValidJSONPointerUriFragment),
571
- "relative-json-pointer": createStringFormatCompiler("relative-json-pointer", isValidRelativeJSONPointer),
572
- "iri": createStringFormatCompiler("iri", isValidIRI),
573
- "iri-reference": createStringFormatCompiler("iri-reference", isValidIRIRef),
574
- "isbn10": createStringFormatCompiler("isbn10", isValidISBN10),
575
- "isbn13": createStringFormatCompiler("isbn13", isValidISBN13),
576
- "mac": createStringFormatCompiler("mac", isValidMACAddr),
577
- "base64": createStringFormatCompiler("base64", isValidBase64),
578
- "byte": createStringFormatCompiler("byte", isValidBase64),
579
- "country2": createStringFormatCompiler("country2", isValidCountryAlpha2),
580
- "iban": createStringFormatCompiler("iban", isValidIBAN)
581
- };
582
-
583
- // ../core/src/integer.js
584
- var INT8_MIN = -128;
585
- var INT8_MAX = 127;
586
- function isValidInt8(value) {
587
- return isIntegerType(value) && value >= INT8_MIN && value <= INT8_MAX;
588
- }
589
- var UINT8_MIN = 0;
590
- var UINT8_MAX = 255;
591
- function isValidUInt8(value) {
592
- return isIntegerType(value) && value >= UINT8_MIN && value <= UINT8_MAX;
593
- }
594
- var INT16_MIN = -32768;
595
- var INT16_MAX = 32767;
596
- function isValidInt16(value) {
597
- return isIntegerType(value) && value >= INT16_MIN && value <= INT16_MAX;
598
- }
599
- var UINT16_MIN = 0;
600
- var UINT16_MAX = 65535;
601
- function isValidUInt16(value) {
602
- return isIntegerType(value) && value >= UINT16_MIN && value <= UINT16_MAX;
603
- }
604
- var INT32_MIN = -(2 ** 31);
605
- var INT32_MAX = 2 ** 31 - 1;
606
- function isValidInt32(value) {
607
- return isIntegerType(value) && value >= INT32_MIN && value <= INT32_MAX;
608
- }
609
- var UINT32_MIN = 0;
610
- var UINT32_MAX = 2 ** 32 - 1;
611
- function isValidUInt32(value) {
612
- return isIntegerType(value) && value >= UINT32_MIN && value <= UINT32_MAX;
613
- }
614
- var INT64_MIN = Number.MIN_SAFE_INTEGER;
615
- var INT64_MAX = Number.MAX_SAFE_INTEGER;
616
- function isValidInt64(value) {
617
- return isIntegerType(value) && value >= INT64_MIN && value <= INT64_MAX;
618
- }
619
- var UINT64_MIN = 0;
620
- var UINT64_MAX = Number.MAX_SAFE_INTEGER;
621
- function isValidUInt64(value) {
622
- return isIntegerType(value) && value >= UINT64_MIN && value <= UINT64_MAX;
623
- }
624
-
625
- // ../core/src/float.js
626
- var FLOAT16_MAX = 65504;
627
- function isValidFloat16(value) {
628
- return isNumberType(value) && !Number.isNaN(value) && value >= -FLOAT16_MAX && value <= FLOAT16_MAX;
629
- }
630
- var FLOAT32_MAX = 34028234663852886e22;
631
- function isValidFloat32(value) {
632
- return isNumberType(value) && !Number.isNaN(value) && value >= -FLOAT32_MAX && value <= FLOAT32_MAX;
633
- }
634
- var FLOAT64_MAX = Number.MAX_VALUE;
635
- var FLOAT64_MIN = Number.MIN_VALUE;
636
- var FLOAT64_EPS = Number.EPSILON;
637
- function isValidFloat64(value) {
638
- return isNumberType(value) && !Number.isNaN(value) && value >= -FLOAT64_MAX && value <= FLOAT64_MAX;
639
- }
640
-
641
- // src/number.js
642
- function createNumberFormatCompiler(formatName, isNumberTest, strictFormat = false) {
643
- return function compileNumberFormat(schemaObj, jsonSchema) {
644
- if (jsonSchema.format !== formatName)
645
- throw new Error("Format is not equal to jsonSchema (should not happen!)");
646
- const addError = schemaObj.createErrorHandler(formatName, "format");
647
- if (strictFormat === true)
648
- return function validateNumberStrictFormat(data, dataPath) {
649
- return data == null || isNumberTest(data) || addError(data, dataPath);
650
- };
651
- else
652
- return function validateNumberFormat(data, dataPath) {
653
- return data == null || isNumberTest(Number(data)) || addError(data, dataPath);
654
- };
655
- };
656
- }
657
- var formatValidators3 = {
658
- // integer types
659
- int8: createNumberFormatCompiler("int8", isValidInt8),
660
- uint8: createNumberFormatCompiler("uint8", isValidUInt8),
661
- int16: createNumberFormatCompiler("int16", isValidInt16),
662
- uint16: createNumberFormatCompiler("uint16", isValidUInt16),
663
- int32: createNumberFormatCompiler("int32", isValidInt32),
664
- uint32: createNumberFormatCompiler("uint32", isValidUInt32),
665
- int64: createNumberFormatCompiler("int64", isValidInt64),
666
- uint64: createNumberFormatCompiler("uint64", isValidUInt64),
667
- // floating point types
668
- float16: createNumberFormatCompiler("float16", isValidFloat16),
669
- float32: createNumberFormatCompiler("float32", isValidFloat32),
670
- float64: createNumberFormatCompiler("float64", isValidFloat64),
671
- float: createNumberFormatCompiler("float", isValidFloat32),
672
- double: createNumberFormatCompiler("double", isValidFloat64)
673
- };
674
- export {
675
- formatValidators as dateTimeFormats,
676
- formatValidators3 as numberFormats,
677
- formatValidators2 as stringFormats
678
- };
679
- //# sourceMappingURL=index.js.map