decoders 2.6.1 → 2.7.1
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/README.md +1 -1
- package/dist/index.cjs +44 -49
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +43 -48
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<img alt="Decoders logo" src="./docs/assets/logo@2x.png" style="width: 100%; max-width: 830px; max-height: 248px" width="830" /><br />
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/decoders)
|
|
4
|
-
[](https://github.com/nvie/decoders/actions)
|
|
5
5
|
[](https://pkg-size.dev/decoders)
|
|
6
6
|
|
|
7
7
|
Elegant and battle-tested validation library for type-safe input data for
|
package/dist/index.cjs
CHANGED
|
@@ -114,7 +114,7 @@ function indent(s, prefix = INDENT) {
|
|
|
114
114
|
}
|
|
115
115
|
var quotePattern = /'/g;
|
|
116
116
|
function quote(value) {
|
|
117
|
-
return typeof value === "string" ? "'" + value.replace(quotePattern, "\\'") + "'" : JSON.stringify(value);
|
|
117
|
+
return typeof value === "string" ? "'" + value.replace(quotePattern, "\\'") + "'" : value === void 0 ? "undefined" : JSON.stringify(value);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// src/core/format.ts
|
|
@@ -311,11 +311,8 @@ ${formatted}`);
|
|
|
311
311
|
}
|
|
312
312
|
function define(fn) {
|
|
313
313
|
function decode(blob) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
ok,
|
|
317
|
-
(msg) => err(isAnnotation(msg) ? msg : public_annotate(blob, msg))
|
|
318
|
-
);
|
|
314
|
+
const makeFlexErr = (msg) => err(isAnnotation(msg) ? msg : public_annotate(blob, msg));
|
|
315
|
+
return fn(blob, ok, makeFlexErr);
|
|
319
316
|
}
|
|
320
317
|
function verify(blob, formatter = formatInline) {
|
|
321
318
|
const result = decode(blob);
|
|
@@ -342,6 +339,9 @@ function define(fn) {
|
|
|
342
339
|
)
|
|
343
340
|
);
|
|
344
341
|
}
|
|
342
|
+
function refineType() {
|
|
343
|
+
return self;
|
|
344
|
+
}
|
|
345
345
|
function then(next) {
|
|
346
346
|
return define((blob, ok2, err2) => {
|
|
347
347
|
const r1 = decode(blob);
|
|
@@ -369,12 +369,13 @@ function define(fn) {
|
|
|
369
369
|
}
|
|
370
370
|
});
|
|
371
371
|
}
|
|
372
|
-
|
|
372
|
+
const unregistered = {
|
|
373
373
|
verify,
|
|
374
374
|
value,
|
|
375
375
|
decode,
|
|
376
376
|
transform,
|
|
377
377
|
refine,
|
|
378
|
+
refineType,
|
|
378
379
|
reject,
|
|
379
380
|
describe,
|
|
380
381
|
then,
|
|
@@ -392,7 +393,9 @@ function define(fn) {
|
|
|
392
393
|
}
|
|
393
394
|
}
|
|
394
395
|
}
|
|
395
|
-
}
|
|
396
|
+
};
|
|
397
|
+
const self = brand2(unregistered);
|
|
398
|
+
return self;
|
|
396
399
|
}
|
|
397
400
|
var kDecoderRegistry = Symbol.for("decoders.kDecoderRegistry");
|
|
398
401
|
var _register2 = globalThis[kDecoderRegistry] ??= /* @__PURE__ */ new WeakSet();
|
|
@@ -411,30 +414,28 @@ var poja = define((blob, ok2, err2) => {
|
|
|
411
414
|
}
|
|
412
415
|
return ok2(blob);
|
|
413
416
|
});
|
|
414
|
-
function all(items, blobs, ok2, err2) {
|
|
415
|
-
const results = [];
|
|
416
|
-
for (let index = 0; index < items.length; ++index) {
|
|
417
|
-
const result = items[index];
|
|
418
|
-
if (result.ok) {
|
|
419
|
-
results.push(result.value);
|
|
420
|
-
} else {
|
|
421
|
-
const ann = result.error;
|
|
422
|
-
const clone = blobs.slice();
|
|
423
|
-
clone.splice(
|
|
424
|
-
index,
|
|
425
|
-
1,
|
|
426
|
-
public_annotate(ann, ann.text ? `${ann.text} (at index ${index})` : `index ${index}`)
|
|
427
|
-
);
|
|
428
|
-
return err2(public_annotate(clone));
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
return ok2(results);
|
|
432
|
-
}
|
|
433
417
|
function array(decoder) {
|
|
434
418
|
const decodeFn = decoder.decode;
|
|
435
|
-
return poja.then((
|
|
436
|
-
const results =
|
|
437
|
-
|
|
419
|
+
return poja.then((inputs, ok2, err2) => {
|
|
420
|
+
const results = [];
|
|
421
|
+
for (let i = 0; i < inputs.length; ++i) {
|
|
422
|
+
const blob = inputs[i];
|
|
423
|
+
const result = decodeFn(blob);
|
|
424
|
+
if (result.ok) {
|
|
425
|
+
results.push(result.value);
|
|
426
|
+
} else {
|
|
427
|
+
results.length = 0;
|
|
428
|
+
const ann = result.error;
|
|
429
|
+
const clone = inputs.slice();
|
|
430
|
+
clone.splice(
|
|
431
|
+
i,
|
|
432
|
+
1,
|
|
433
|
+
public_annotate(ann, ann.text ? `${ann.text} (at index ${i})` : `index ${i}`)
|
|
434
|
+
);
|
|
435
|
+
return err2(public_annotate(clone));
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return ok2(results);
|
|
438
439
|
});
|
|
439
440
|
}
|
|
440
441
|
function isNonEmpty(arr) {
|
|
@@ -533,9 +534,7 @@ function object(decoders) {
|
|
|
533
534
|
if (rawValue === void 0) {
|
|
534
535
|
missingKeys.add(key);
|
|
535
536
|
} else {
|
|
536
|
-
|
|
537
|
-
errors = /* @__PURE__ */ new Map();
|
|
538
|
-
}
|
|
537
|
+
errors ??= /* @__PURE__ */ new Map();
|
|
539
538
|
errors.set(key, ann);
|
|
540
539
|
}
|
|
541
540
|
}
|
|
@@ -614,9 +613,9 @@ function either(...decoders) {
|
|
|
614
613
|
}
|
|
615
614
|
function oneOf(constants) {
|
|
616
615
|
return define((blob, ok2, err2) => {
|
|
617
|
-
const
|
|
618
|
-
if (
|
|
619
|
-
return ok2(
|
|
616
|
+
const index = constants.indexOf(blob);
|
|
617
|
+
if (index !== -1) {
|
|
618
|
+
return ok2(constants[index]);
|
|
620
619
|
}
|
|
621
620
|
return err2(`Must be one of ${constants.map((value) => quote(value)).join(", ")}`);
|
|
622
621
|
});
|
|
@@ -820,19 +819,14 @@ var iso8601_re = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:[.]\d+)?(?:Z|[+-]\d{2}:
|
|
|
820
819
|
var date = define((blob, ok2, err2) => {
|
|
821
820
|
return isDate(blob) ? ok2(blob) : err2("Must be a Date");
|
|
822
821
|
});
|
|
823
|
-
var
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
if (isNaN(date2.getTime())) {
|
|
830
|
-
throw new Error("Must be valid date/time value");
|
|
831
|
-
}
|
|
832
|
-
return date2;
|
|
833
|
-
}
|
|
834
|
-
)
|
|
822
|
+
var dateString = regex(
|
|
823
|
+
iso8601_re,
|
|
824
|
+
"Must be ISO8601 format"
|
|
825
|
+
).refine(
|
|
826
|
+
(value) => !isNaN(new Date(value).getTime()),
|
|
827
|
+
"Must be valid date/time value"
|
|
835
828
|
);
|
|
829
|
+
var iso8601 = dateString.transform((value) => new Date(value));
|
|
836
830
|
var datelike = either(date, iso8601).describe("Must be a Date or date string");
|
|
837
831
|
|
|
838
832
|
// src/numbers.ts
|
|
@@ -940,4 +934,5 @@ var json = either(
|
|
|
940
934
|
|
|
941
935
|
|
|
942
936
|
|
|
943
|
-
|
|
937
|
+
|
|
938
|
+
exports.always = always; exports.anyNumber = anyNumber; exports.array = array; exports.bigint = bigint; exports.boolean = boolean; exports.constant = constant; exports.date = date; exports.dateString = dateString; exports.datelike = datelike; exports.decimal = decimal; exports.define = define; exports.dict = dict; exports.either = either; exports.email = email; exports.endsWith = endsWith; exports.enum_ = enum_; exports.err = err; exports.exact = exact; exports.fail = fail; exports.formatInline = formatInline; exports.formatShort = formatShort; exports.hardcoded = hardcoded; exports.hexadecimal = hexadecimal; exports.httpsUrl = httpsUrl; exports.identifier = identifier; exports.inexact = inexact; exports.instanceOf = instanceOf; exports.integer = integer; exports.iso8601 = iso8601; exports.json = json; exports.jsonArray = jsonArray; exports.jsonObject = jsonObject; exports.lazy = lazy; exports.mapping = mapping; exports.maybe = maybe; exports.mixed = mixed; exports.nanoid = nanoid; exports.never = never; exports.nonEmptyArray = nonEmptyArray; exports.nonEmptyString = nonEmptyString; exports.null_ = null_; exports.nullable = nullable; exports.nullish = nullish; exports.number = number; exports.numeric = numeric; exports.object = object; exports.ok = ok; exports.oneOf = oneOf; exports.optional = optional; exports.poja = poja; exports.pojo = pojo; exports.positiveInteger = positiveInteger; exports.positiveNumber = positiveNumber; exports.prep = prep; exports.record = record; exports.regex = regex; exports.select = select; exports.set = set; exports.setFromArray = setFromArray; exports.startsWith = startsWith; exports.string = string; exports.taggedUnion = taggedUnion; exports.truthy = truthy; exports.tuple = tuple; exports.undefined_ = undefined_; exports.unknown = unknown; exports.url = url; exports.uuid = uuid; exports.uuidv1 = uuidv1; exports.uuidv4 = uuidv4;
|
package/dist/index.d.cts
CHANGED
|
@@ -130,6 +130,11 @@ interface Decoder<T> {
|
|
|
130
130
|
*/
|
|
131
131
|
refine<N extends T>(predicate: (value: T) => value is N, msg: string): Decoder<N>;
|
|
132
132
|
refine(predicate: (value: T) => boolean, msg: string): Decoder<T>;
|
|
133
|
+
/**
|
|
134
|
+
* Cast the return type of this read-only decoder to a narrower type. This is
|
|
135
|
+
* useful to return "branded" types. This method has no runtime effect.
|
|
136
|
+
*/
|
|
137
|
+
refineType<SubT extends T>(): Decoder<SubT>;
|
|
133
138
|
/**
|
|
134
139
|
* Build a new decoder from the current one, with an extra rejection
|
|
135
140
|
* criterium.
|
|
@@ -365,6 +370,10 @@ declare function mapping<T>(decoder: Decoder<T>): Decoder<Map<string, T>>;
|
|
|
365
370
|
* Accepts and returns `Date` instances.
|
|
366
371
|
*/
|
|
367
372
|
declare const date: Decoder<Date>;
|
|
373
|
+
/**
|
|
374
|
+
* Accepts and returns [ISO8601](https://en.wikipedia.org/wiki/ISO_8601)-formatted strings.
|
|
375
|
+
*/
|
|
376
|
+
declare const dateString: Decoder<string>;
|
|
368
377
|
/**
|
|
369
378
|
* Accepts [ISO8601](https://en.wikipedia.org/wiki/ISO_8601)-formatted strings,
|
|
370
379
|
* returns them as `Date` instances.
|
|
@@ -659,4 +668,4 @@ declare function taggedUnion<O extends Record<string, Decoder<unknown>>>(field:
|
|
|
659
668
|
*/
|
|
660
669
|
declare function select<T, D extends Decoder<unknown>>(scout: Decoder<T>, selectFn: (result: T) => D): Decoder<DecoderType<D>>;
|
|
661
670
|
|
|
662
|
-
export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, type SizeOptions, always, anyNumber, array, bigint, boolean, constant, date, datelike, decimal, define, dict, either, email, endsWith, enum_, err, exact, fail, formatInline, formatShort, hardcoded, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, nanoid, never, nonEmptyArray, nonEmptyString, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, set, setFromArray, startsWith, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
|
|
671
|
+
export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, type SizeOptions, always, anyNumber, array, bigint, boolean, constant, date, dateString, datelike, decimal, define, dict, either, email, endsWith, enum_, err, exact, fail, formatInline, formatShort, hardcoded, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, nanoid, never, nonEmptyArray, nonEmptyString, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, set, setFromArray, startsWith, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
|
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,11 @@ interface Decoder<T> {
|
|
|
130
130
|
*/
|
|
131
131
|
refine<N extends T>(predicate: (value: T) => value is N, msg: string): Decoder<N>;
|
|
132
132
|
refine(predicate: (value: T) => boolean, msg: string): Decoder<T>;
|
|
133
|
+
/**
|
|
134
|
+
* Cast the return type of this read-only decoder to a narrower type. This is
|
|
135
|
+
* useful to return "branded" types. This method has no runtime effect.
|
|
136
|
+
*/
|
|
137
|
+
refineType<SubT extends T>(): Decoder<SubT>;
|
|
133
138
|
/**
|
|
134
139
|
* Build a new decoder from the current one, with an extra rejection
|
|
135
140
|
* criterium.
|
|
@@ -365,6 +370,10 @@ declare function mapping<T>(decoder: Decoder<T>): Decoder<Map<string, T>>;
|
|
|
365
370
|
* Accepts and returns `Date` instances.
|
|
366
371
|
*/
|
|
367
372
|
declare const date: Decoder<Date>;
|
|
373
|
+
/**
|
|
374
|
+
* Accepts and returns [ISO8601](https://en.wikipedia.org/wiki/ISO_8601)-formatted strings.
|
|
375
|
+
*/
|
|
376
|
+
declare const dateString: Decoder<string>;
|
|
368
377
|
/**
|
|
369
378
|
* Accepts [ISO8601](https://en.wikipedia.org/wiki/ISO_8601)-formatted strings,
|
|
370
379
|
* returns them as `Date` instances.
|
|
@@ -659,4 +668,4 @@ declare function taggedUnion<O extends Record<string, Decoder<unknown>>>(field:
|
|
|
659
668
|
*/
|
|
660
669
|
declare function select<T, D extends Decoder<unknown>>(scout: Decoder<T>, selectFn: (result: T) => D): Decoder<DecoderType<D>>;
|
|
661
670
|
|
|
662
|
-
export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, type SizeOptions, always, anyNumber, array, bigint, boolean, constant, date, datelike, decimal, define, dict, either, email, endsWith, enum_, err, exact, fail, formatInline, formatShort, hardcoded, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, nanoid, never, nonEmptyArray, nonEmptyString, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, set, setFromArray, startsWith, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
|
|
671
|
+
export { type DecodeResult, type Decoder, type DecoderType, type Err, type Formatter, type JSONArray, type JSONObject, type JSONValue, type Ok, type Result, type Scalar, type SizeOptions, always, anyNumber, array, bigint, boolean, constant, date, dateString, datelike, decimal, define, dict, either, email, endsWith, enum_, err, exact, fail, formatInline, formatShort, hardcoded, hexadecimal, httpsUrl, identifier, inexact, instanceOf, integer, iso8601, json, jsonArray, jsonObject, lazy, mapping, maybe, mixed, nanoid, never, nonEmptyArray, nonEmptyString, null_, nullable, nullish, number, numeric, object, ok, oneOf, optional, poja, pojo, positiveInteger, positiveNumber, prep, record, regex, select, set, setFromArray, startsWith, string, taggedUnion, truthy, tuple, undefined_, unknown, url, uuid, uuidv1, uuidv4 };
|
package/dist/index.js
CHANGED
|
@@ -114,7 +114,7 @@ function indent(s, prefix = INDENT) {
|
|
|
114
114
|
}
|
|
115
115
|
var quotePattern = /'/g;
|
|
116
116
|
function quote(value) {
|
|
117
|
-
return typeof value === "string" ? "'" + value.replace(quotePattern, "\\'") + "'" : JSON.stringify(value);
|
|
117
|
+
return typeof value === "string" ? "'" + value.replace(quotePattern, "\\'") + "'" : value === void 0 ? "undefined" : JSON.stringify(value);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// src/core/format.ts
|
|
@@ -311,11 +311,8 @@ ${formatted}`);
|
|
|
311
311
|
}
|
|
312
312
|
function define(fn) {
|
|
313
313
|
function decode(blob) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
ok,
|
|
317
|
-
(msg) => err(isAnnotation(msg) ? msg : public_annotate(blob, msg))
|
|
318
|
-
);
|
|
314
|
+
const makeFlexErr = (msg) => err(isAnnotation(msg) ? msg : public_annotate(blob, msg));
|
|
315
|
+
return fn(blob, ok, makeFlexErr);
|
|
319
316
|
}
|
|
320
317
|
function verify(blob, formatter = formatInline) {
|
|
321
318
|
const result = decode(blob);
|
|
@@ -342,6 +339,9 @@ function define(fn) {
|
|
|
342
339
|
)
|
|
343
340
|
);
|
|
344
341
|
}
|
|
342
|
+
function refineType() {
|
|
343
|
+
return self;
|
|
344
|
+
}
|
|
345
345
|
function then(next) {
|
|
346
346
|
return define((blob, ok2, err2) => {
|
|
347
347
|
const r1 = decode(blob);
|
|
@@ -369,12 +369,13 @@ function define(fn) {
|
|
|
369
369
|
}
|
|
370
370
|
});
|
|
371
371
|
}
|
|
372
|
-
|
|
372
|
+
const unregistered = {
|
|
373
373
|
verify,
|
|
374
374
|
value,
|
|
375
375
|
decode,
|
|
376
376
|
transform,
|
|
377
377
|
refine,
|
|
378
|
+
refineType,
|
|
378
379
|
reject,
|
|
379
380
|
describe,
|
|
380
381
|
then,
|
|
@@ -392,7 +393,9 @@ function define(fn) {
|
|
|
392
393
|
}
|
|
393
394
|
}
|
|
394
395
|
}
|
|
395
|
-
}
|
|
396
|
+
};
|
|
397
|
+
const self = brand2(unregistered);
|
|
398
|
+
return self;
|
|
396
399
|
}
|
|
397
400
|
var kDecoderRegistry = Symbol.for("decoders.kDecoderRegistry");
|
|
398
401
|
var _register2 = globalThis[kDecoderRegistry] ??= /* @__PURE__ */ new WeakSet();
|
|
@@ -411,30 +414,28 @@ var poja = define((blob, ok2, err2) => {
|
|
|
411
414
|
}
|
|
412
415
|
return ok2(blob);
|
|
413
416
|
});
|
|
414
|
-
function all(items, blobs, ok2, err2) {
|
|
415
|
-
const results = [];
|
|
416
|
-
for (let index = 0; index < items.length; ++index) {
|
|
417
|
-
const result = items[index];
|
|
418
|
-
if (result.ok) {
|
|
419
|
-
results.push(result.value);
|
|
420
|
-
} else {
|
|
421
|
-
const ann = result.error;
|
|
422
|
-
const clone = blobs.slice();
|
|
423
|
-
clone.splice(
|
|
424
|
-
index,
|
|
425
|
-
1,
|
|
426
|
-
public_annotate(ann, ann.text ? `${ann.text} (at index ${index})` : `index ${index}`)
|
|
427
|
-
);
|
|
428
|
-
return err2(public_annotate(clone));
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
return ok2(results);
|
|
432
|
-
}
|
|
433
417
|
function array(decoder) {
|
|
434
418
|
const decodeFn = decoder.decode;
|
|
435
|
-
return poja.then((
|
|
436
|
-
const results =
|
|
437
|
-
|
|
419
|
+
return poja.then((inputs, ok2, err2) => {
|
|
420
|
+
const results = [];
|
|
421
|
+
for (let i = 0; i < inputs.length; ++i) {
|
|
422
|
+
const blob = inputs[i];
|
|
423
|
+
const result = decodeFn(blob);
|
|
424
|
+
if (result.ok) {
|
|
425
|
+
results.push(result.value);
|
|
426
|
+
} else {
|
|
427
|
+
results.length = 0;
|
|
428
|
+
const ann = result.error;
|
|
429
|
+
const clone = inputs.slice();
|
|
430
|
+
clone.splice(
|
|
431
|
+
i,
|
|
432
|
+
1,
|
|
433
|
+
public_annotate(ann, ann.text ? `${ann.text} (at index ${i})` : `index ${i}`)
|
|
434
|
+
);
|
|
435
|
+
return err2(public_annotate(clone));
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return ok2(results);
|
|
438
439
|
});
|
|
439
440
|
}
|
|
440
441
|
function isNonEmpty(arr) {
|
|
@@ -533,9 +534,7 @@ function object(decoders) {
|
|
|
533
534
|
if (rawValue === void 0) {
|
|
534
535
|
missingKeys.add(key);
|
|
535
536
|
} else {
|
|
536
|
-
|
|
537
|
-
errors = /* @__PURE__ */ new Map();
|
|
538
|
-
}
|
|
537
|
+
errors ??= /* @__PURE__ */ new Map();
|
|
539
538
|
errors.set(key, ann);
|
|
540
539
|
}
|
|
541
540
|
}
|
|
@@ -614,9 +613,9 @@ function either(...decoders) {
|
|
|
614
613
|
}
|
|
615
614
|
function oneOf(constants) {
|
|
616
615
|
return define((blob, ok2, err2) => {
|
|
617
|
-
const
|
|
618
|
-
if (
|
|
619
|
-
return ok2(
|
|
616
|
+
const index = constants.indexOf(blob);
|
|
617
|
+
if (index !== -1) {
|
|
618
|
+
return ok2(constants[index]);
|
|
620
619
|
}
|
|
621
620
|
return err2(`Must be one of ${constants.map((value) => quote(value)).join(", ")}`);
|
|
622
621
|
});
|
|
@@ -820,19 +819,14 @@ var iso8601_re = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:[.]\d+)?(?:Z|[+-]\d{2}:
|
|
|
820
819
|
var date = define((blob, ok2, err2) => {
|
|
821
820
|
return isDate(blob) ? ok2(blob) : err2("Must be a Date");
|
|
822
821
|
});
|
|
823
|
-
var
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
if (isNaN(date2.getTime())) {
|
|
830
|
-
throw new Error("Must be valid date/time value");
|
|
831
|
-
}
|
|
832
|
-
return date2;
|
|
833
|
-
}
|
|
834
|
-
)
|
|
822
|
+
var dateString = regex(
|
|
823
|
+
iso8601_re,
|
|
824
|
+
"Must be ISO8601 format"
|
|
825
|
+
).refine(
|
|
826
|
+
(value) => !isNaN(new Date(value).getTime()),
|
|
827
|
+
"Must be valid date/time value"
|
|
835
828
|
);
|
|
829
|
+
var iso8601 = dateString.transform((value) => new Date(value));
|
|
836
830
|
var datelike = either(date, iso8601).describe("Must be a Date or date string");
|
|
837
831
|
|
|
838
832
|
// src/numbers.ts
|
|
@@ -878,6 +872,7 @@ export {
|
|
|
878
872
|
boolean,
|
|
879
873
|
constant,
|
|
880
874
|
date,
|
|
875
|
+
dateString,
|
|
881
876
|
datelike,
|
|
882
877
|
decimal,
|
|
883
878
|
define,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decoders",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"description": "Elegant and battle-tested validation library for type-safe input data for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -61,26 +61,26 @@
|
|
|
61
61
|
],
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@arethetypeswrong/cli": "^0.17.4",
|
|
64
|
-
"@eslint/js": "^9.
|
|
64
|
+
"@eslint/js": "^9.23.0",
|
|
65
65
|
"@release-it/keep-a-changelog": "^6.0.0",
|
|
66
66
|
"@standard-schema/spec": "^1.0.0",
|
|
67
|
-
"@vitest/coverage-istanbul": "^3.0.
|
|
68
|
-
"eslint": "^9.
|
|
67
|
+
"@vitest/coverage-istanbul": "^3.0.9",
|
|
68
|
+
"eslint": "^9.23.0",
|
|
69
69
|
"eslint-plugin-import": "^2.31.0",
|
|
70
70
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
71
|
-
"fast-check": "^
|
|
71
|
+
"fast-check": "^4.0.0",
|
|
72
72
|
"itertools": "^2.4.1",
|
|
73
|
-
"pkg-pr-new": "^0.0.
|
|
74
|
-
"prettier": "^3.5.
|
|
75
|
-
"publint": "^0.3.
|
|
73
|
+
"pkg-pr-new": "^0.0.41",
|
|
74
|
+
"prettier": "^3.5.3",
|
|
75
|
+
"publint": "^0.3.9",
|
|
76
76
|
"release-it": "^18.1.2",
|
|
77
77
|
"ts-morph": "^25.0.1",
|
|
78
78
|
"tsd": "^0.31.2",
|
|
79
|
-
"tsup": "^8.
|
|
80
|
-
"typescript": "^5.
|
|
81
|
-
"typescript-eslint": "^8.
|
|
79
|
+
"tsup": "^8.4.0",
|
|
80
|
+
"typescript": "^5.8.2",
|
|
81
|
+
"typescript-eslint": "^8.28.0",
|
|
82
82
|
"vite-tsconfig-paths": "^5.1.4",
|
|
83
|
-
"vitest": "^3.0.
|
|
83
|
+
"vitest": "^3.0.9"
|
|
84
84
|
},
|
|
85
85
|
"githubUrl": "https://github.com/nvie/decoders",
|
|
86
86
|
"sideEffects": false
|