decoders 2.6.0 → 2.6.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/dist/index.cjs +16 -11
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +16 -11
- package/package.json +13 -15
package/dist/index.cjs
CHANGED
|
@@ -18,7 +18,8 @@ function isPojo(value) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// src/core/annotate.ts
|
|
21
|
-
var
|
|
21
|
+
var kAnnotationRegistry = Symbol.for("decoders.kAnnotationRegistry");
|
|
22
|
+
var _register = globalThis[kAnnotationRegistry] ??= /* @__PURE__ */ new WeakSet();
|
|
22
23
|
function brand(ann) {
|
|
23
24
|
_register.add(ann);
|
|
24
25
|
return ann;
|
|
@@ -102,7 +103,7 @@ function public_annotateObject(obj, text) {
|
|
|
102
103
|
// src/lib/text.ts
|
|
103
104
|
var INDENT = " ";
|
|
104
105
|
function isMultiline(s) {
|
|
105
|
-
return s.
|
|
106
|
+
return s.includes("\n");
|
|
106
107
|
}
|
|
107
108
|
function indent(s, prefix = INDENT) {
|
|
108
109
|
if (isMultiline(s)) {
|
|
@@ -166,7 +167,7 @@ function serializeArray(annotation, prefix) {
|
|
|
166
167
|
const result = [];
|
|
167
168
|
for (const item of items) {
|
|
168
169
|
const [ser, ann] = serializeAnnotation(item, `${prefix}${INDENT}`);
|
|
169
|
-
result.push(`${prefix}${INDENT}${ser}
|
|
170
|
+
result.push(`${prefix}${INDENT}${ser},`);
|
|
170
171
|
if (ann !== void 0) {
|
|
171
172
|
result.push(indent(ann, `${prefix}${INDENT}`));
|
|
172
173
|
}
|
|
@@ -393,7 +394,8 @@ function define(fn) {
|
|
|
393
394
|
}
|
|
394
395
|
});
|
|
395
396
|
}
|
|
396
|
-
var
|
|
397
|
+
var kDecoderRegistry = Symbol.for("decoders.kDecoderRegistry");
|
|
398
|
+
var _register2 = globalThis[kDecoderRegistry] ??= /* @__PURE__ */ new WeakSet();
|
|
397
399
|
function brand2(decoder) {
|
|
398
400
|
_register2.add(decoder);
|
|
399
401
|
return decoder;
|
|
@@ -466,7 +468,10 @@ function tuple(...decoders) {
|
|
|
466
468
|
// src/misc.ts
|
|
467
469
|
function instanceOf(klass) {
|
|
468
470
|
return define(
|
|
469
|
-
(blob, ok2, err2) =>
|
|
471
|
+
(blob, ok2, err2) => (
|
|
472
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
473
|
+
blob instanceof klass ? ok2(blob) : err2(`Must be ${klass.name} instance`)
|
|
474
|
+
)
|
|
470
475
|
);
|
|
471
476
|
}
|
|
472
477
|
function lazy(decoderFn) {
|
|
@@ -595,8 +600,8 @@ function either(...decoders) {
|
|
|
595
600
|
}
|
|
596
601
|
return define((blob, _, err2) => {
|
|
597
602
|
const errors = [];
|
|
598
|
-
for (
|
|
599
|
-
const result =
|
|
603
|
+
for (const decoder of decoders) {
|
|
604
|
+
const result = decoder.decode(blob);
|
|
600
605
|
if (result.ok) {
|
|
601
606
|
return result;
|
|
602
607
|
} else {
|
|
@@ -697,7 +702,7 @@ var truthy = define((blob, ok2, _) => ok2(!!blob));
|
|
|
697
702
|
// src/collections.ts
|
|
698
703
|
function record(fst, snd) {
|
|
699
704
|
const keyDecoder = snd !== void 0 ? fst : void 0;
|
|
700
|
-
const valueDecoder = snd
|
|
705
|
+
const valueDecoder = _nullishCoalesce(snd, () => ( fst));
|
|
701
706
|
return pojo.then((input, ok2, err2) => {
|
|
702
707
|
let rv = {};
|
|
703
708
|
const errors = /* @__PURE__ */ new Map();
|
|
@@ -738,9 +743,9 @@ function mapping(decoder) {
|
|
|
738
743
|
|
|
739
744
|
// src/lib/size-options.ts
|
|
740
745
|
function bySizeOptions(options) {
|
|
741
|
-
const size =
|
|
742
|
-
const min = _nullishCoalesce(size, () => (
|
|
743
|
-
const max = _nullishCoalesce(size, () => (
|
|
746
|
+
const size = options.size;
|
|
747
|
+
const min = _nullishCoalesce(size, () => ( options.min));
|
|
748
|
+
const max = _nullishCoalesce(size, () => ( options.max));
|
|
744
749
|
const atLeast = min === max ? "" : "at least ";
|
|
745
750
|
const atMost = min === max ? "" : "at most ";
|
|
746
751
|
const tooShort = min !== void 0 && `Too short, must be ${atLeast}${min} chars`;
|
package/dist/index.d.cts
CHANGED
|
@@ -168,8 +168,7 @@ interface Decoder<T> {
|
|
|
168
168
|
*
|
|
169
169
|
* string.pipe((s) => s.startsWith('@') ? username : email)
|
|
170
170
|
*/
|
|
171
|
-
pipe<V, D extends Decoder<V>>(next: D): Decoder<DecoderType<D>>;
|
|
172
|
-
pipe<V, D extends Decoder<V>>(next: (blob: T) => D): Decoder<DecoderType<D>>;
|
|
171
|
+
pipe<V, D extends Decoder<V>>(next: D | ((blob: T) => D)): Decoder<DecoderType<D>>;
|
|
173
172
|
/**
|
|
174
173
|
* The Standard Schema interface for this decoder.
|
|
175
174
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -168,8 +168,7 @@ interface Decoder<T> {
|
|
|
168
168
|
*
|
|
169
169
|
* string.pipe((s) => s.startsWith('@') ? username : email)
|
|
170
170
|
*/
|
|
171
|
-
pipe<V, D extends Decoder<V>>(next: D): Decoder<DecoderType<D>>;
|
|
172
|
-
pipe<V, D extends Decoder<V>>(next: (blob: T) => D): Decoder<DecoderType<D>>;
|
|
171
|
+
pipe<V, D extends Decoder<V>>(next: D | ((blob: T) => D)): Decoder<DecoderType<D>>;
|
|
173
172
|
/**
|
|
174
173
|
* The Standard Schema interface for this decoder.
|
|
175
174
|
*/
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,8 @@ function isPojo(value) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// src/core/annotate.ts
|
|
21
|
-
var
|
|
21
|
+
var kAnnotationRegistry = Symbol.for("decoders.kAnnotationRegistry");
|
|
22
|
+
var _register = globalThis[kAnnotationRegistry] ??= /* @__PURE__ */ new WeakSet();
|
|
22
23
|
function brand(ann) {
|
|
23
24
|
_register.add(ann);
|
|
24
25
|
return ann;
|
|
@@ -102,7 +103,7 @@ function public_annotateObject(obj, text) {
|
|
|
102
103
|
// src/lib/text.ts
|
|
103
104
|
var INDENT = " ";
|
|
104
105
|
function isMultiline(s) {
|
|
105
|
-
return s.
|
|
106
|
+
return s.includes("\n");
|
|
106
107
|
}
|
|
107
108
|
function indent(s, prefix = INDENT) {
|
|
108
109
|
if (isMultiline(s)) {
|
|
@@ -166,7 +167,7 @@ function serializeArray(annotation, prefix) {
|
|
|
166
167
|
const result = [];
|
|
167
168
|
for (const item of items) {
|
|
168
169
|
const [ser, ann] = serializeAnnotation(item, `${prefix}${INDENT}`);
|
|
169
|
-
result.push(`${prefix}${INDENT}${ser}
|
|
170
|
+
result.push(`${prefix}${INDENT}${ser},`);
|
|
170
171
|
if (ann !== void 0) {
|
|
171
172
|
result.push(indent(ann, `${prefix}${INDENT}`));
|
|
172
173
|
}
|
|
@@ -393,7 +394,8 @@ function define(fn) {
|
|
|
393
394
|
}
|
|
394
395
|
});
|
|
395
396
|
}
|
|
396
|
-
var
|
|
397
|
+
var kDecoderRegistry = Symbol.for("decoders.kDecoderRegistry");
|
|
398
|
+
var _register2 = globalThis[kDecoderRegistry] ??= /* @__PURE__ */ new WeakSet();
|
|
397
399
|
function brand2(decoder) {
|
|
398
400
|
_register2.add(decoder);
|
|
399
401
|
return decoder;
|
|
@@ -466,7 +468,10 @@ function tuple(...decoders) {
|
|
|
466
468
|
// src/misc.ts
|
|
467
469
|
function instanceOf(klass) {
|
|
468
470
|
return define(
|
|
469
|
-
(blob, ok2, err2) =>
|
|
471
|
+
(blob, ok2, err2) => (
|
|
472
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
473
|
+
blob instanceof klass ? ok2(blob) : err2(`Must be ${klass.name} instance`)
|
|
474
|
+
)
|
|
470
475
|
);
|
|
471
476
|
}
|
|
472
477
|
function lazy(decoderFn) {
|
|
@@ -595,8 +600,8 @@ function either(...decoders) {
|
|
|
595
600
|
}
|
|
596
601
|
return define((blob, _, err2) => {
|
|
597
602
|
const errors = [];
|
|
598
|
-
for (
|
|
599
|
-
const result =
|
|
603
|
+
for (const decoder of decoders) {
|
|
604
|
+
const result = decoder.decode(blob);
|
|
600
605
|
if (result.ok) {
|
|
601
606
|
return result;
|
|
602
607
|
} else {
|
|
@@ -697,7 +702,7 @@ var truthy = define((blob, ok2, _) => ok2(!!blob));
|
|
|
697
702
|
// src/collections.ts
|
|
698
703
|
function record(fst, snd) {
|
|
699
704
|
const keyDecoder = snd !== void 0 ? fst : void 0;
|
|
700
|
-
const valueDecoder = snd
|
|
705
|
+
const valueDecoder = snd ?? fst;
|
|
701
706
|
return pojo.then((input, ok2, err2) => {
|
|
702
707
|
let rv = {};
|
|
703
708
|
const errors = /* @__PURE__ */ new Map();
|
|
@@ -738,9 +743,9 @@ function mapping(decoder) {
|
|
|
738
743
|
|
|
739
744
|
// src/lib/size-options.ts
|
|
740
745
|
function bySizeOptions(options) {
|
|
741
|
-
const size = options
|
|
742
|
-
const min = size ?? options
|
|
743
|
-
const max = size ?? options
|
|
746
|
+
const size = options.size;
|
|
747
|
+
const min = size ?? options.min;
|
|
748
|
+
const max = size ?? options.max;
|
|
744
749
|
const atLeast = min === max ? "" : "at least ";
|
|
745
750
|
const atMost = min === max ? "" : "at most ";
|
|
746
751
|
const tooShort = min !== void 0 && `Too short, must be ${atLeast}${min} chars`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decoders",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "Elegant and battle-tested validation library for type-safe input data for TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
},
|
|
15
15
|
"type": "module",
|
|
16
16
|
"main": "./dist/index.cjs",
|
|
17
|
-
"module": "./dist/index.js",
|
|
18
17
|
"types": "./dist/index.d.cts",
|
|
19
18
|
"exports": {
|
|
20
19
|
".": {
|
|
@@ -61,28 +60,27 @@
|
|
|
61
60
|
"verify"
|
|
62
61
|
],
|
|
63
62
|
"devDependencies": {
|
|
64
|
-
"@arethetypeswrong/cli": "^0.17.
|
|
63
|
+
"@arethetypeswrong/cli": "^0.17.4",
|
|
64
|
+
"@eslint/js": "^9.21.0",
|
|
65
65
|
"@release-it/keep-a-changelog": "^6.0.0",
|
|
66
66
|
"@standard-schema/spec": "^1.0.0",
|
|
67
|
-
"@
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"eslint": "^8.57.0",
|
|
72
|
-
"eslint-plugin-import": "^2.29.1",
|
|
73
|
-
"eslint-plugin-simple-import-sort": "^12.1.0",
|
|
67
|
+
"@vitest/coverage-istanbul": "^3.0.7",
|
|
68
|
+
"eslint": "^9.21.0",
|
|
69
|
+
"eslint-plugin-import": "^2.31.0",
|
|
70
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
74
71
|
"fast-check": "^3.23.2",
|
|
75
|
-
"itertools": "^2.
|
|
72
|
+
"itertools": "^2.4.1",
|
|
76
73
|
"pkg-pr-new": "^0.0.39",
|
|
77
|
-
"prettier": "^3.
|
|
78
|
-
"publint": "^0.3.
|
|
74
|
+
"prettier": "^3.5.2",
|
|
75
|
+
"publint": "^0.3.6",
|
|
79
76
|
"release-it": "^18.1.2",
|
|
80
|
-
"ts-morph": "^25.0.
|
|
77
|
+
"ts-morph": "^25.0.1",
|
|
81
78
|
"tsd": "^0.31.2",
|
|
82
79
|
"tsup": "^8.3.6",
|
|
83
80
|
"typescript": "^5.7.3",
|
|
81
|
+
"typescript-eslint": "^8.25.0",
|
|
84
82
|
"vite-tsconfig-paths": "^5.1.4",
|
|
85
|
-
"vitest": "^3.0.
|
|
83
|
+
"vitest": "^3.0.7"
|
|
86
84
|
},
|
|
87
85
|
"githubUrl": "https://github.com/nvie/decoders",
|
|
88
86
|
"sideEffects": false
|