@voxgig/struct-js 0.1.6 → 0.2.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 +27 -7
- package/package.json +1 -1
- package/src/struct.js +870 -179
package/README.md
CHANGED
|
@@ -56,8 +56,9 @@ module.exports = {
|
|
|
56
56
|
// 6 regex functions
|
|
57
57
|
re_compile, re_find, re_find_all, re_replace, re_test, re_escape,
|
|
58
58
|
|
|
59
|
-
//
|
|
60
|
-
clone,
|
|
59
|
+
// 46 utility functions (52 canonical = these 46 + the 6 re_* above)
|
|
60
|
+
clone, condense, condenseview, expand, iscondensed, delprop, escre,
|
|
61
|
+
escurl, filter, flatten, getdef, getelem,
|
|
61
62
|
getpath, getprop, haskey, inject, isempty, isfunc, iskey, islist,
|
|
62
63
|
ismap, isnode, items, join, jsonify, keysof, merge, pad, pathify,
|
|
63
64
|
select, setpath, setprop, size, slice, strkey, stringify,
|
|
@@ -613,8 +614,27 @@ Used as backtick-quoted strings inside a `validate` spec.
|
|
|
613
614
|
|
|
614
615
|
```
|
|
615
616
|
$MAP $LIST $STRING $NUMBER $INTEGER $DECIMAL $BOOLEAN
|
|
616
|
-
$NULL $NIL $FUNCTION $INSTANCE $ANY $CHILD $
|
|
617
|
-
|
|
617
|
+
$NULL $NIL $FUNCTION $INSTANCE $ANY $CHILD $EXACT
|
|
618
|
+
$NOF $ALL $LEN $RANGE $LIKE
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
`` ['`$NOF`', n, spec, …] `` holds when as many specs admit the value as `n`
|
|
622
|
+
allows, where `n` is an integer or an object with `min`, `max` or both;
|
|
623
|
+
`` ['`$ALL`', spec, …] `` holds when every spec admits it. There is no
|
|
624
|
+
`$ONE`: write `` ['`$ONE`', a, b] `` as `` ['`$NOF`', { min: 1 }, a, b] ``.
|
|
625
|
+
`` ['`$LEN`', n, spec?] `` holds when the value's length is within `n`, a
|
|
626
|
+
bound written as for `$NOF`: a string counts code points (not the UTF-16
|
|
627
|
+
units `.length` counts), an array its elements, and an object its keys.
|
|
628
|
+
`` ['`$RANGE`', bound, spec?] `` holds when the value is a number within
|
|
629
|
+
`bound`, an object of `min` or `gt` and `max` or `lt`.
|
|
630
|
+
`` ['`$LIKE`', pattern, spec?] `` holds when the value is a string the
|
|
631
|
+
pattern finds, with JavaScript's `RegExp`, anywhere in it unless the
|
|
632
|
+
pattern is anchored. `$LEN`, `$RANGE` and `$LIKE` take at most one spec,
|
|
633
|
+
which must also admit the value. `min` and `max` include their bound, while
|
|
634
|
+
`gt` and `lt` exclude it.
|
|
635
|
+
A spec that names any other checker, such as the misspelling
|
|
636
|
+
`` '`$string`' ``, is rejected before any data is read. See the
|
|
637
|
+
[top-level README](../README.md) for what each checker accepts.
|
|
618
638
|
|
|
619
639
|
|
|
620
640
|
## Notes
|
|
@@ -638,7 +658,7 @@ JavaScript arrays satisfy this natively.
|
|
|
638
658
|
|
|
639
659
|
### Difference from canonical TypeScript
|
|
640
660
|
|
|
641
|
-
The exported function surface is identical (
|
|
661
|
+
The exported function surface is identical (52 canonical functions,
|
|
642
662
|
including the six `re_*` regex helpers). The only export difference is
|
|
643
663
|
`Injection`: the JS port exports it as a runtime value, whereas TypeScript
|
|
644
664
|
exports it only as a type. Otherwise functionally identical -- both run on
|
|
@@ -646,7 +666,7 @@ V8.
|
|
|
646
666
|
|
|
647
667
|
### Test status
|
|
648
668
|
|
|
649
|
-
|
|
669
|
+
119/119 tests pass against the shared corpus.
|
|
650
670
|
|
|
651
671
|
|
|
652
672
|
## Regex
|
|
@@ -658,7 +678,7 @@ this is the ECMAScript `RegExp` built-in.
|
|
|
658
678
|
|
|
659
679
|
| Function | Maps to |
|
|
660
680
|
|---|---|
|
|
661
|
-
| `re_compile(pattern, flags?)` | `new RegExp(pattern, flags
|
|
681
|
+
| `re_compile(pattern, flags?)` | `new RegExp(pattern, flags)` |
|
|
662
682
|
| `re_test(pattern, input)` | `pattern.test(input)` |
|
|
663
683
|
| `re_find(pattern, input)` | `input.match(pattern)` (non-global pattern) |
|
|
664
684
|
| `re_find_all(pattern, input)` | `[...input.matchAll(pattern)]` |
|