@voxgig/struct 0.3.6 → 0.4.0
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 +19 -1
- package/dist/StructUtility.d.ts +2 -8
- package/dist/StructUtility.js +494 -497
- package/dist/StructUtility.js.map +1 -1
- package/package.json +2 -2
- package/src/StructUtility.ts +617 -584
package/README.md
CHANGED
|
@@ -769,8 +769,26 @@ Quote inside a `validate` spec, e.g. `` '`$STRING`' ``.
|
|
|
769
769
|
| `$INSTANCE` | A class instance. |
|
|
770
770
|
| `$ANY` | Any value (placeholder for "no constraint"). |
|
|
771
771
|
| `$CHILD` | Apply a sub-spec to every direct child. |
|
|
772
|
-
| `$ONE` | Match exactly one of a list of alternative sub-specs. |
|
|
773
772
|
| `$EXACT` | Match a literal value exactly (no shape coercion). |
|
|
773
|
+
| `$NOF` | `` ['`$NOF`', n, spec, …] ``: as many specs admit the value as `n` allows, where `n` is an integer or a map with `min`, `max` or both. |
|
|
774
|
+
| `$ALL` | `` ['`$ALL`', spec, …] ``: every spec admits the value. |
|
|
775
|
+
| `$LEN` | `` ['`$LEN`', n, spec?] ``: a length within `n`, a bound written as for `$NOF`. Strings count code points, lists elements, maps keys. |
|
|
776
|
+
| `$RANGE` | `` ['`$RANGE`', bound, spec?] ``: a number within the bound, a map of `min` or `gt` and `max` or `lt`. |
|
|
777
|
+
| `$LIKE` | `` ['`$LIKE`', pattern, spec?] ``: a string the pattern finds, with JavaScript's `RegExp`. |
|
|
778
|
+
|
|
779
|
+
A spec admits a value when validating the value against it finds no error
|
|
780
|
+
and gives back every member of the value unchanged. There is no `$ONE`:
|
|
781
|
+
write `` ['`$ONE`', a, b] `` as `` ['`$NOF`', {min: 1}, a, b] ``. `$LEN`,
|
|
782
|
+
`$RANGE` and `$LIKE` take at most one spec, which must also admit the value.
|
|
783
|
+
`min` and `max` include their bound, while `gt` and `lt` exclude it. A
|
|
784
|
+
`$LIKE` pattern is compiled with no flags and matches anywhere unless
|
|
785
|
+
anchored.
|
|
786
|
+
|
|
787
|
+
A spec that names a checker `validate` does not define is rejected before
|
|
788
|
+
any data is read, and nothing is validated. The whole-string reference
|
|
789
|
+
`` '`$FOO`' `` names a checker, and so does a misspelling of a defined one
|
|
790
|
+
in another case, such as `` '`$string`' ``. The message is
|
|
791
|
+
`Unknown validator $FOO at field a.`
|
|
774
792
|
|
|
775
793
|
|
|
776
794
|
## `StructUtility` class
|
package/dist/StructUtility.d.ts
CHANGED
|
@@ -29,15 +29,9 @@ type Indexable = {
|
|
|
29
29
|
[key: number]: any;
|
|
30
30
|
};
|
|
31
31
|
type InjectMode = number;
|
|
32
|
-
type Injector = (inj: Injection, //
|
|
33
|
-
val: any, // Injection value specification.
|
|
34
|
-
ref: string, // Original injection reference string.
|
|
32
|
+
type Injector = (inj: Injection, val: any, ref: string, // Original injection reference string.
|
|
35
33
|
store: any) => any;
|
|
36
|
-
type Modify = (val: any,
|
|
37
|
-
key?: PropKey, // Value key, if any,
|
|
38
|
-
parent?: any, // Parent node, if any.
|
|
39
|
-
inj?: Injection, // Injection state, if any.
|
|
40
|
-
store?: any) => void;
|
|
34
|
+
type Modify = (val: any, key?: PropKey, parent?: any, inj?: Injection, store?: any) => void;
|
|
41
35
|
type WalkApply = (key: string | number | undefined, val: any, parent: any, path: string[]) => any;
|
|
42
36
|
declare function typename(t: number): any;
|
|
43
37
|
declare function getdef(val: any, alt: any): any;
|