@asd14/m 8.0.0 → 9.0.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/LICENSE +1 -1
- package/README.md +73 -28
- package/dist/src/all/all.d.ts +53 -0
- package/dist/src/all/all.js +59 -0
- package/dist/src/all/with/all-with.d.ts +47 -0
- package/dist/src/all/with/all-with.js +59 -0
- package/dist/src/any/any.d.ts +62 -0
- package/dist/src/any/any.js +68 -0
- package/dist/src/any/with/any-with.d.ts +47 -0
- package/dist/src/any/with/any-with.js +59 -0
- package/dist/src/converge/converge.d.ts +89 -0
- package/dist/src/converge/converge.js +68 -0
- package/dist/src/count/by/count-by.d.ts +55 -0
- package/dist/src/count/by/count-by.js +62 -0
- package/dist/src/count/count.d.ts +39 -0
- package/dist/src/count/count.js +39 -0
- package/dist/src/count/with/count-with.d.ts +46 -0
- package/dist/src/count/with/count-with.js +59 -0
- package/dist/src/curry/curry.d.ts +43 -0
- package/dist/src/curry/curry.js +52 -0
- package/dist/src/debounce/debounce.d.ts +39 -0
- package/dist/src/debounce/debounce.js +63 -0
- package/dist/src/dec/dec.d.ts +22 -0
- package/dist/src/dec/dec.js +27 -0
- package/dist/src/default-to/default-to.d.ts +44 -0
- package/dist/src/default-to/default-to.js +46 -0
- package/dist/src/distinct/by/distinct-by.d.ts +49 -0
- package/dist/src/distinct/by/distinct-by.js +74 -0
- package/dist/src/distinct/distinct.d.ts +32 -0
- package/dist/src/distinct/distinct.js +39 -0
- package/dist/src/drop/last/drop-last.d.ts +37 -0
- package/dist/src/drop/last/drop-last.js +55 -0
- package/dist/src/escape/escape.d.ts +35 -0
- package/dist/src/escape/escape.js +47 -0
- package/dist/src/escape/html/escape-html.d.ts +26 -0
- package/dist/src/escape/html/escape-html.js +38 -0
- package/dist/src/escape/reg-exp/escape-reg-exp.d.ts +30 -0
- package/dist/src/escape/reg-exp/escape-reg-exp.js +34 -0
- package/dist/src/evolve/deep-by/evolve-deep-by.d.ts +65 -0
- package/dist/src/evolve/deep-by/evolve-deep-by.js +90 -0
- package/dist/src/evolve/evolve.d.ts +61 -0
- package/dist/src/evolve/evolve.js +66 -0
- package/dist/src/evolve/many/evolve-many.d.ts +46 -0
- package/dist/src/evolve/many/evolve-many.js +62 -0
- package/dist/src/evolve/with/evolve-with.d.ts +63 -0
- package/dist/src/evolve/with/evolve-with.js +84 -0
- package/dist/src/filter/filter.d.ts +56 -0
- package/dist/src/filter/filter.js +63 -0
- package/dist/src/filter/with/filter-with.d.ts +46 -0
- package/dist/src/filter/with/filter-with.js +59 -0
- package/dist/src/find/find.d.ts +57 -0
- package/dist/src/find/find.js +64 -0
- package/dist/src/find/index/find-index.d.ts +57 -0
- package/dist/src/find/index/find-index.js +64 -0
- package/dist/src/find/index/with/find-index-with.d.ts +47 -0
- package/dist/src/find/index/with/find-index-with.js +60 -0
- package/dist/src/find/with/find-with.d.ts +47 -0
- package/dist/src/find/with/find-with.js +60 -0
- package/dist/src/first/first.d.ts +37 -0
- package/dist/src/first/first.js +38 -0
- package/dist/src/flatten/flatten.d.ts +65 -0
- package/dist/src/flatten/flatten.js +107 -0
- package/dist/src/for-each/for-each.d.ts +49 -0
- package/dist/src/for-each/for-each.js +56 -0
- package/dist/src/fuzzy-match/fuzzy-match.d.ts +49 -0
- package/dist/src/fuzzy-match/fuzzy-match.js +164 -0
- package/dist/src/group/group-by.d.ts +66 -0
- package/dist/src/group/group-by.js +79 -0
- package/dist/src/i/i.d.ts +23 -0
- package/dist/src/i/i.js +22 -0
- package/dist/src/inc/inc.d.ts +22 -0
- package/dist/src/inc/inc.js +27 -0
- package/dist/src/index.d.ts +79 -0
- package/dist/src/index.js +117 -0
- package/dist/src/is/is.d.ts +177 -0
- package/dist/src/is/is.js +173 -0
- package/dist/src/is-deep-equal/is-deep-equal.d.ts +39 -0
- package/dist/src/is-deep-equal/is-deep-equal.js +141 -0
- package/dist/src/is-equal/is-equal.d.ts +33 -0
- package/dist/src/is-equal/is-equal.js +35 -0
- package/dist/src/is-match/is-match.d.ts +64 -0
- package/dist/src/is-match/is-match.js +69 -0
- package/dist/src/is-uri/is-uri.d.ts +29 -0
- package/dist/src/is-uri/is-uri.js +84 -0
- package/dist/src/join/join.d.ts +33 -0
- package/dist/src/join/join.js +45 -0
- package/dist/src/keys/keys.d.ts +29 -0
- package/dist/src/keys/keys.js +35 -0
- package/dist/src/last/last.d.ts +37 -0
- package/dist/src/last/last.js +38 -0
- package/dist/src/map/indexed/map-indexed.d.ts +54 -0
- package/dist/src/map/indexed/map-indexed.js +61 -0
- package/dist/src/map/map.d.ts +51 -0
- package/dist/src/map/map.js +57 -0
- package/dist/src/map/matrix/map-matrix.d.ts +55 -0
- package/dist/src/map/matrix/map-matrix.js +67 -0
- package/dist/src/merge/by/merge-by.d.ts +48 -0
- package/dist/src/merge/by/merge-by.js +73 -0
- package/dist/src/merge/merge.d.ts +48 -0
- package/dist/src/merge/merge.js +81 -0
- package/dist/src/partition/partition.d.ts +59 -0
- package/dist/src/partition/partition.js +72 -0
- package/dist/src/partition/with/partition-with.d.ts +45 -0
- package/dist/src/partition/with/partition-with.js +58 -0
- package/dist/src/pick/pick.d.ts +39 -0
- package/dist/src/pick/pick.js +59 -0
- package/dist/src/pipe/pipe.d.ts +89 -0
- package/dist/src/pipe/pipe.js +50 -0
- package/dist/src/pipe/promise/pipe-p.d.ts +33 -0
- package/dist/src/pipe/promise/pipe-p.js +44 -0
- package/dist/src/push/push.d.ts +28 -0
- package/dist/src/push/push.js +38 -0
- package/dist/src/read/read.d.ts +55 -0
- package/dist/src/read/read.js +79 -0
- package/dist/src/reduce/reduce.d.ts +40 -0
- package/dist/src/reduce/reduce.js +58 -0
- package/dist/src/remove/remove.d.ts +32 -0
- package/dist/src/remove/remove.js +48 -0
- package/dist/src/remove/with/remove-with.d.ts +44 -0
- package/dist/src/remove/with/remove-with.js +62 -0
- package/dist/src/sort/by/sort-by.d.ts +34 -0
- package/dist/src/sort/by/sort-by.js +46 -0
- package/dist/src/sort/sort.d.ts +43 -0
- package/dist/src/sort/sort.js +72 -0
- package/dist/src/sort/with/sort-with.d.ts +58 -0
- package/dist/src/sort/with/sort-with.js +126 -0
- package/dist/src/split/split.d.ts +33 -0
- package/dist/src/split/split.js +45 -0
- package/dist/src/split-in-groups-of/split-in-groups-of.d.ts +34 -0
- package/dist/src/split-in-groups-of/split-in-groups-of.js +53 -0
- package/dist/src/sum/sum.d.ts +28 -0
- package/dist/src/sum/sum.js +34 -0
- package/dist/src/throttle/throttle.d.ts +46 -0
- package/dist/src/throttle/throttle.js +90 -0
- package/dist/src/to-string/to-string.d.ts +28 -0
- package/dist/src/to-string/to-string.js +27 -0
- package/dist/src/trim/trim.d.ts +48 -0
- package/dist/src/trim/trim.js +79 -0
- package/dist/src/type/type.d.ts +28 -0
- package/dist/src/type/type.js +35 -0
- package/dist/src/unflatten/unflatten.d.ts +44 -0
- package/dist/src/unflatten/unflatten.js +88 -0
- package/dist/src/unite/by/unite-by.d.ts +43 -0
- package/dist/src/unite/by/unite-by.js +63 -0
- package/dist/src/unite/unite.d.ts +42 -0
- package/dist/src/unite/unite.js +58 -0
- package/dist/src/update/update.d.ts +57 -0
- package/dist/src/update/update.js +62 -0
- package/dist/src/update/with/update-with.d.ts +63 -0
- package/dist/src/update/with/update-with.js +84 -0
- package/dist/src/upsert/with/upsert-with.d.ts +57 -0
- package/dist/src/upsert/with/upsert-with.js +87 -0
- package/dist/src/utils/build-match.d.ts +25 -0
- package/dist/src/utils/build-match.js +56 -0
- package/dist/src/utils/build-patch.d.ts +32 -0
- package/dist/src/utils/build-patch.js +59 -0
- package/dist/src/utils/pipe.d.ts +11 -0
- package/dist/src/utils/pipe.js +15 -0
- package/dist/src/utils/set-own.d.ts +20 -0
- package/dist/src/utils/set-own.js +29 -0
- package/dist/src/utils/to-function.d.ts +22 -0
- package/dist/src/utils/to-function.js +32 -0
- package/dist/src/when/when.d.ts +54 -0
- package/dist/src/when/when.js +70 -0
- package/dist/src/zip-to-object/zip-to-object.d.ts +39 -0
- package/dist/src/zip-to-object/zip-to-object.js +58 -0
- package/dist/types/array.d.ts +25 -0
- package/dist/types/basic.d.ts +3 -0
- package/dist/types/function.d.ts +42 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/object.d.ts +70 -0
- package/dist/types/object.matcher.d.ts +22 -0
- package/dist/types/object.patcher.d.ts +34 -0
- package/docs/DECISIONS.md +7 -0
- package/docs/SPEC.md +195 -0
- package/docs/decisions/01.use-manual-currying.md +34 -0
- package/docs/decisions/02.add-runtime-type-checks.md +27 -0
- package/docs/decisions/03.use-c8-over-node-test-runner.md +30 -0
- package/docs/decisions/04.use-relative-types-imports.md +26 -0
- package/docs/decisions/05.read-an-array-as-a-pipe.md +37 -0
- package/docs/explanation/curried-type-inference.md +136 -0
- package/docs/how-to/jsdoc.md +94 -0
- package/docs/how-to/pipe-arrays.md +104 -0
- package/docs/how-to/tape-runtime-tests.md +206 -0
- package/docs/how-to/tstyche-type-tests.md +146 -0
- package/docs/how-to/writing-functions.md +249 -0
- package/docs/spec/pending.md +18 -0
- package/package.json +76 -52
- package/dist/all/all.js +0 -68
- package/dist/all/all.js.map +0 -1
- package/dist/all/all.test.js +0 -66
- package/dist/all/all.test.js.map +0 -1
- package/dist/any/any.js +0 -71
- package/dist/any/any.js.map +0 -1
- package/dist/any/any.test.js +0 -60
- package/dist/any/any.test.js.map +0 -1
- package/dist/append/append.js +0 -31
- package/dist/append/append.js.map +0 -1
- package/dist/append/append.test.js +0 -41
- package/dist/append/append.test.js.map +0 -1
- package/dist/bottom/bottom.js +0 -52
- package/dist/bottom/bottom.js.map +0 -1
- package/dist/bottom/bottom.test.js +0 -57
- package/dist/bottom/bottom.test.js.map +0 -1
- package/dist/cases/cases.js +0 -32
- package/dist/cases/cases.js.map +0 -1
- package/dist/cases/cases.test.js +0 -71
- package/dist/cases/cases.test.js.map +0 -1
- package/dist/clone/clone.js +0 -48
- package/dist/clone/clone.js.map +0 -1
- package/dist/clone/clone.test.js +0 -45
- package/dist/clone/clone.test.js.map +0 -1
- package/dist/compact/compact.js +0 -80
- package/dist/compact/compact.js.map +0 -1
- package/dist/compact/compact.test.js +0 -88
- package/dist/compact/compact.test.js.map +0 -1
- package/dist/contains/contains.js +0 -24
- package/dist/contains/contains.js.map +0 -1
- package/dist/contains/contains.test.js +0 -11
- package/dist/contains/contains.test.js.map +0 -1
- package/dist/converge/converge.js +0 -62
- package/dist/converge/converge.js.map +0 -1
- package/dist/converge/converge.test.js +0 -69
- package/dist/converge/converge.test.js.map +0 -1
- package/dist/count/count.js +0 -113
- package/dist/count/count.js.map +0 -1
- package/dist/count/count.test.js +0 -105
- package/dist/count/count.test.js.map +0 -1
- package/dist/curry/curry.js +0 -39
- package/dist/curry/curry.js.map +0 -1
- package/dist/curry/curry.test.js +0 -13
- package/dist/curry/curry.test.js.map +0 -1
- package/dist/debounce/debounce.js +0 -36
- package/dist/debounce/debounce.js.map +0 -1
- package/dist/debounce/debounce.test.js +0 -49
- package/dist/debounce/debounce.test.js.map +0 -1
- package/dist/dec/dec.js +0 -18
- package/dist/dec/dec.js.map +0 -1
- package/dist/dec/dec.test.js +0 -8
- package/dist/dec/dec.test.js.map +0 -1
- package/dist/deep-equal/deep-equal.bench.js +0 -123
- package/dist/deep-equal/deep-equal.bench.js.map +0 -1
- package/dist/deep-equal/deep-equal.js +0 -47
- package/dist/deep-equal/deep-equal.js.map +0 -1
- package/dist/deep-equal/deep-equal.own.js +0 -97
- package/dist/deep-equal/deep-equal.own.js.map +0 -1
- package/dist/deep-equal/deep-equal.test.js +0 -131
- package/dist/deep-equal/deep-equal.test.js.map +0 -1
- package/dist/distinct/distinct.bench.js +0 -56
- package/dist/distinct/distinct.bench.js.map +0 -1
- package/dist/distinct/distinct.js +0 -36
- package/dist/distinct/distinct.js.map +0 -1
- package/dist/distinct/distinct.test.js +0 -43
- package/dist/distinct/distinct.test.js.map +0 -1
- package/dist/drop-last/drop-last.js +0 -23
- package/dist/drop-last/drop-last.js.map +0 -1
- package/dist/drop-last/drop-last.test.js +0 -38
- package/dist/drop-last/drop-last.test.js.map +0 -1
- package/dist/elapsed-time/elapsed-time.js +0 -42
- package/dist/elapsed-time/elapsed-time.js.map +0 -1
- package/dist/elapsed-time/elapsed-time.test.js +0 -13
- package/dist/elapsed-time/elapsed-time.test.js.map +0 -1
- package/dist/ends-with/ends-with.js +0 -36
- package/dist/ends-with/ends-with.js.map +0 -1
- package/dist/ends-with/ends-with.test.js +0 -33
- package/dist/ends-with/ends-with.test.js.map +0 -1
- package/dist/escape/escape.js +0 -7
- package/dist/escape/escape.js.map +0 -1
- package/dist/escape-html/escape-html.js +0 -14
- package/dist/escape-html/escape-html.js.map +0 -1
- package/dist/escape-html/escape-html.test.js +0 -10
- package/dist/escape-html/escape-html.test.js.map +0 -1
- package/dist/escape-reg-exp/escape-reg-exp.js +0 -17
- package/dist/escape-reg-exp/escape-reg-exp.js.map +0 -1
- package/dist/escape-reg-exp/escape-reg-exp.test.js +0 -13
- package/dist/escape-reg-exp/escape-reg-exp.test.js.map +0 -1
- package/dist/filter/filter.js +0 -45
- package/dist/filter/filter.js.map +0 -1
- package/dist/filter/filter.test.js +0 -101
- package/dist/filter/filter.test.js.map +0 -1
- package/dist/find/find.js +0 -93
- package/dist/find/find.js.map +0 -1
- package/dist/find/find.test.js +0 -77
- package/dist/find/find.test.js.map +0 -1
- package/dist/find-index/find-index.js +0 -43
- package/dist/find-index/find-index.js.map +0 -1
- package/dist/find-index/find-index.test.js +0 -53
- package/dist/find-index/find-index.test.js.map +0 -1
- package/dist/first/first.js +0 -21
- package/dist/first/first.js.map +0 -1
- package/dist/first/first.test.js +0 -17
- package/dist/first/first.test.js.map +0 -1
- package/dist/flatten/flatten.js +0 -46
- package/dist/flatten/flatten.js.map +0 -1
- package/dist/flatten/flatten.test.js +0 -63
- package/dist/flatten/flatten.test.js.map +0 -1
- package/dist/for-each/for-each.js +0 -25
- package/dist/for-each/for-each.js.map +0 -1
- package/dist/for-each/for-each.test.js +0 -41
- package/dist/for-each/for-each.test.js.map +0 -1
- package/dist/group-by/group-by.js +0 -38
- package/dist/group-by/group-by.js.map +0 -1
- package/dist/group-by/group-by.test.js +0 -86
- package/dist/group-by/group-by.test.js.map +0 -1
- package/dist/gt/gt.js +0 -25
- package/dist/gt/gt.js.map +0 -1
- package/dist/gt/gt.test.js +0 -11
- package/dist/gt/gt.test.js.map +0 -1
- package/dist/has-key/has-key.js +0 -8
- package/dist/has-key/has-key.js.map +0 -1
- package/dist/has-key/has-key.test.js +0 -14
- package/dist/has-key/has-key.test.js.map +0 -1
- package/dist/hist/hist.js +0 -73
- package/dist/hist/hist.js.map +0 -1
- package/dist/hist/hist.test.js +0 -47
- package/dist/hist/hist.test.js.map +0 -1
- package/dist/i/i.js +0 -11
- package/dist/i/i.js.map +0 -1
- package/dist/i/i.test.js +0 -21
- package/dist/i/i.test.js.map +0 -1
- package/dist/inc/inc.js +0 -18
- package/dist/inc/inc.js.map +0 -1
- package/dist/inc/inc.test.js +0 -8
- package/dist/inc/inc.test.js.map +0 -1
- package/dist/index-by/index-by.js +0 -36
- package/dist/index-by/index-by.js.map +0 -1
- package/dist/index-by/index-by.test.js +0 -48
- package/dist/index-by/index-by.test.js.map +0 -1
- package/dist/index.js +0 -99
- package/dist/index.js.map +0 -1
- package/dist/index.test.js +0 -10
- package/dist/index.test.js.map +0 -1
- package/dist/intersect/intersect.js +0 -113
- package/dist/intersect/intersect.js.map +0 -1
- package/dist/intersect/intersect.test.js +0 -79
- package/dist/intersect/intersect.test.js.map +0 -1
- package/dist/is/is.js +0 -40
- package/dist/is/is.js.map +0 -1
- package/dist/is/is.test.js +0 -28
- package/dist/is/is.test.js.map +0 -1
- package/dist/is-between/is-between.js +0 -30
- package/dist/is-between/is-between.js.map +0 -1
- package/dist/is-between/is-between.test.js +0 -18
- package/dist/is-between/is-between.test.js.map +0 -1
- package/dist/is-empty/is-empty.js +0 -53
- package/dist/is-empty/is-empty.js.map +0 -1
- package/dist/is-empty/is-empty.test.js +0 -35
- package/dist/is-empty/is-empty.test.js.map +0 -1
- package/dist/is-equal/is-equal.js +0 -31
- package/dist/is-equal/is-equal.js.map +0 -1
- package/dist/is-equal/is-equal.test.js +0 -22
- package/dist/is-equal/is-equal.test.js.map +0 -1
- package/dist/is-match/is-match.js +0 -58
- package/dist/is-match/is-match.js.map +0 -1
- package/dist/is-match/is-match.test.js +0 -72
- package/dist/is-match/is-match.test.js.map +0 -1
- package/dist/is-uri/is-uri.js +0 -24
- package/dist/is-uri/is-uri.js.map +0 -1
- package/dist/is-uri/is-uri.test.js +0 -16
- package/dist/is-uri/is-uri.test.js.map +0 -1
- package/dist/join/join.js +0 -74
- package/dist/join/join.js.map +0 -1
- package/dist/join/join.test.js +0 -99
- package/dist/join/join.test.js.map +0 -1
- package/dist/keys/keys.js +0 -56
- package/dist/keys/keys.js.map +0 -1
- package/dist/keys/keys.test.js +0 -25
- package/dist/keys/keys.test.js.map +0 -1
- package/dist/last/last.js +0 -22
- package/dist/last/last.js.map +0 -1
- package/dist/last/last.test.js +0 -18
- package/dist/last/last.test.js.map +0 -1
- package/dist/lt/lt.js +0 -27
- package/dist/lt/lt.js.map +0 -1
- package/dist/lt/lt.test.js +0 -10
- package/dist/lt/lt.test.js.map +0 -1
- package/dist/map/map.js +0 -40
- package/dist/map/map.js.map +0 -1
- package/dist/map/map.test.js +0 -66
- package/dist/map/map.test.js.map +0 -1
- package/dist/map-matrix/map-matrix.js +0 -43
- package/dist/map-matrix/map-matrix.js.map +0 -1
- package/dist/map-matrix/map-matrix.test.js +0 -82
- package/dist/map-matrix/map-matrix.test.js.map +0 -1
- package/dist/max/max.js +0 -60
- package/dist/max/max.js.map +0 -1
- package/dist/max/max.test.js +0 -50
- package/dist/max/max.test.js.map +0 -1
- package/dist/merge/merge.js +0 -79
- package/dist/merge/merge.js.map +0 -1
- package/dist/merge/merge.test.js +0 -61
- package/dist/merge/merge.test.js.map +0 -1
- package/dist/min/min.js +0 -60
- package/dist/min/min.js.map +0 -1
- package/dist/min/min.test.js +0 -45
- package/dist/min/min.test.js.map +0 -1
- package/dist/move/move.js +0 -48
- package/dist/move/move.js.map +0 -1
- package/dist/move/move.test.js +0 -62
- package/dist/move/move.test.js.map +0 -1
- package/dist/mutate/mutate.js +0 -89
- package/dist/mutate/mutate.js.map +0 -1
- package/dist/mutate/mutate.test.js +0 -114
- package/dist/mutate/mutate.test.js.map +0 -1
- package/dist/page/page.js +0 -26
- package/dist/page/page.js.map +0 -1
- package/dist/page/page.test.js +0 -70
- package/dist/page/page.test.js.map +0 -1
- package/dist/partition/partition.js +0 -60
- package/dist/partition/partition.js.map +0 -1
- package/dist/partition/partition.test.js +0 -104
- package/dist/partition/partition.test.js.map +0 -1
- package/dist/pick/pick.js +0 -42
- package/dist/pick/pick.js.map +0 -1
- package/dist/pick/pick.test.js +0 -26
- package/dist/pick/pick.test.js.map +0 -1
- package/dist/pipe/pipe.js +0 -37
- package/dist/pipe/pipe.js.map +0 -1
- package/dist/pipe/pipe.test.js +0 -15
- package/dist/pipe/pipe.test.js.map +0 -1
- package/dist/pipe-p/pipe-p.js +0 -47
- package/dist/pipe-p/pipe-p.js.map +0 -1
- package/dist/pipe-p/pipe-p.test.js +0 -27
- package/dist/pipe-p/pipe-p.test.js.map +0 -1
- package/dist/pluck/pluck.js +0 -65
- package/dist/pluck/pluck.js.map +0 -1
- package/dist/pluck/pluck.test.js +0 -61
- package/dist/pluck/pluck.test.js.map +0 -1
- package/dist/prepend/prepend.js +0 -28
- package/dist/prepend/prepend.js.map +0 -1
- package/dist/prepend/prepend.test.js +0 -41
- package/dist/prepend/prepend.test.js.map +0 -1
- package/dist/proto-chain/proto-chain.js +0 -21
- package/dist/proto-chain/proto-chain.js.map +0 -1
- package/dist/proto-chain/proto-chain.test.js +0 -25
- package/dist/proto-chain/proto-chain.test.js.map +0 -1
- package/dist/push/push.js +0 -27
- package/dist/push/push.js.map +0 -1
- package/dist/push/push.test.js +0 -22
- package/dist/push/push.test.js.map +0 -1
- package/dist/raise/raise.js +0 -6
- package/dist/raise/raise.js.map +0 -1
- package/dist/raise/raise.test.js +0 -10
- package/dist/raise/raise.test.js.map +0 -1
- package/dist/random/random.js +0 -13
- package/dist/random/random.js.map +0 -1
- package/dist/random/random.test.js +0 -21
- package/dist/random/random.test.js.map +0 -1
- package/dist/read/read.js +0 -80
- package/dist/read/read.js.map +0 -1
- package/dist/read/read.test.js +0 -110
- package/dist/read/read.test.js.map +0 -1
- package/dist/reduce/reduce.js +0 -49
- package/dist/reduce/reduce.js.map +0 -1
- package/dist/reduce/reduce.test.js +0 -49
- package/dist/reduce/reduce.test.js.map +0 -1
- package/dist/remove/remove.js +0 -90
- package/dist/remove/remove.js.map +0 -1
- package/dist/remove/remove.test.js +0 -98
- package/dist/remove/remove.test.js.map +0 -1
- package/dist/rename/rename.js +0 -77
- package/dist/rename/rename.js.map +0 -1
- package/dist/rename/rename.test.js +0 -49
- package/dist/rename/rename.test.js.map +0 -1
- package/dist/rename-file/rename-file.js +0 -23
- package/dist/rename-file/rename-file.js.map +0 -1
- package/dist/rename-file/rename-file.test.js +0 -13
- package/dist/rename-file/rename-file.test.js.map +0 -1
- package/dist/repeat/repeat.js +0 -46
- package/dist/repeat/repeat.js.map +0 -1
- package/dist/repeat/repeat.test.js +0 -33
- package/dist/repeat/repeat.test.js.map +0 -1
- package/dist/replace/replace.js +0 -102
- package/dist/replace/replace.js.map +0 -1
- package/dist/replace/replace.test.js +0 -132
- package/dist/replace/replace.test.js.map +0 -1
- package/dist/same/same.js +0 -13
- package/dist/same/same.js.map +0 -1
- package/dist/same/same.test.js +0 -9
- package/dist/same/same.test.js.map +0 -1
- package/dist/sequence/sequence.js +0 -36
- package/dist/sequence/sequence.js.map +0 -1
- package/dist/sequence/sequence.test.js +0 -139
- package/dist/sequence/sequence.test.js.map +0 -1
- package/dist/sort/sort-with.js +0 -130
- package/dist/sort/sort-with.js.map +0 -1
- package/dist/sort/sort.js +0 -70
- package/dist/sort/sort.js.map +0 -1
- package/dist/sort/sort.test.js +0 -413
- package/dist/sort/sort.test.js.map +0 -1
- package/dist/split/split.js +0 -44
- package/dist/split/split.js.map +0 -1
- package/dist/split/split.test.js +0 -32
- package/dist/split/split.test.js.map +0 -1
- package/dist/split-in-groups-of/split-in-groups-of.js +0 -49
- package/dist/split-in-groups-of/split-in-groups-of.js.map +0 -1
- package/dist/split-in-groups-of/split-in-groups-of.test.js +0 -87
- package/dist/split-in-groups-of/split-in-groups-of.test.js.map +0 -1
- package/dist/spy/spy.js +0 -35
- package/dist/spy/spy.js.map +0 -1
- package/dist/spy/spy.test.js +0 -37
- package/dist/spy/spy.test.js.map +0 -1
- package/dist/starts-with/starts-with.js +0 -35
- package/dist/starts-with/starts-with.js.map +0 -1
- package/dist/starts-with/starts-with.test.js +0 -37
- package/dist/starts-with/starts-with.test.js.map +0 -1
- package/dist/throttle/throttle.js +0 -47
- package/dist/throttle/throttle.js.map +0 -1
- package/dist/throttle/throttle.test.js +0 -41
- package/dist/throttle/throttle.test.js.map +0 -1
- package/dist/to-lower/to-lower.js +0 -21
- package/dist/to-lower/to-lower.js.map +0 -1
- package/dist/to-lower/to-lower.test.js +0 -9
- package/dist/to-lower/to-lower.test.js.map +0 -1
- package/dist/to-upper/to-upper.js +0 -21
- package/dist/to-upper/to-upper.js.map +0 -1
- package/dist/to-upper/to-upper.test.js +0 -9
- package/dist/to-upper/to-upper.test.js.map +0 -1
- package/dist/toggle/toggle.js +0 -35
- package/dist/toggle/toggle.js.map +0 -1
- package/dist/toggle/toggle.test.js +0 -28
- package/dist/toggle/toggle.test.js.map +0 -1
- package/dist/top/top.js +0 -62
- package/dist/top/top.js.map +0 -1
- package/dist/top/top.test.js +0 -51
- package/dist/top/top.test.js.map +0 -1
- package/dist/trim/trim.js +0 -41
- package/dist/trim/trim.js.map +0 -1
- package/dist/trim/trim.test.js +0 -10
- package/dist/trim/trim.test.js.map +0 -1
- package/dist/try-catch/try-catch.js +0 -37
- package/dist/try-catch/try-catch.js.map +0 -1
- package/dist/try-catch/try-catch.test.js +0 -14
- package/dist/try-catch/try-catch.test.js.map +0 -1
- package/dist/type/type.js +0 -29
- package/dist/type/type.js.map +0 -1
- package/dist/type/type.test.js +0 -19
- package/dist/type/type.test.js.map +0 -1
- package/dist/unite/unite.js +0 -22
- package/dist/unite/unite.js.map +0 -1
- package/dist/unite/unite.test.js +0 -12
- package/dist/unite/unite.test.js.map +0 -1
- package/dist/update/update.js +0 -85
- package/dist/update/update.js.map +0 -1
- package/dist/update/update.test.js +0 -99
- package/dist/update/update.test.js.map +0 -1
- package/dist/upsert/upsert.js +0 -19
- package/dist/upsert/upsert.js.map +0 -1
- package/dist/upsert/upsert.test.js +0 -61
- package/dist/upsert/upsert.test.js.map +0 -1
- package/dist/values/values.js +0 -60
- package/dist/values/values.js.map +0 -1
- package/dist/values/values.test.js +0 -25
- package/dist/values/values.test.js.map +0 -1
- package/dist/when/when.js +0 -51
- package/dist/when/when.js.map +0 -1
- package/dist/when/when.test.js +0 -30
- package/dist/when/when.test.js.map +0 -1
- package/dist/write/write.js +0 -28
- package/dist/write/write.js.map +0 -1
- package/dist/write/write.test.js +0 -18
- package/dist/write/write.test.js.map +0 -1
- package/dist/zip-to-object/zip-to-object.js +0 -28
- package/dist/zip-to-object/zip-to-object.js.map +0 -1
- package/dist/zip-to-object/zip-to-object.test.js +0 -33
- package/dist/zip-to-object/zip-to-object.test.js.map +0 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { PlainObject } from "../../../types/object.js";
|
|
2
|
+
import type { Matcher } from "../../../types/object.matcher.js";
|
|
3
|
+
type UpsertWithFn = {
|
|
4
|
+
<T extends PlainObject>(match: Matcher<T>, item: T, input: readonly T[]): T[];
|
|
5
|
+
<T extends PlainObject>(match: Matcher<T>, item: T): (input: readonly T[]) => T[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Replace the first object of an array that satisfies `match` with `item`, or
|
|
9
|
+
* append `item` when none does. A match becomes `{ ...found, ...item }`: a key
|
|
10
|
+
* that the found object has and `item` lacks stays.
|
|
11
|
+
*
|
|
12
|
+
* Only the first match is replaced. `item` is a full object, never a patcher:
|
|
13
|
+
* a function in it is a plain value. To transform a found item, use
|
|
14
|
+
* `updateWith`.
|
|
15
|
+
*
|
|
16
|
+
* A `match` key maps to a value compared with SameValueZero, to a predicate
|
|
17
|
+
* that must return `true`, or to a pipe array ending in a predicate. Prefix a
|
|
18
|
+
* key with `!` to negate it. To match an array value, use a predicate.
|
|
19
|
+
*
|
|
20
|
+
* Input is never mutated - always returns a new array.
|
|
21
|
+
*
|
|
22
|
+
* @param {Object} match - Map of keys to values, predicates or pipe arrays
|
|
23
|
+
* @param {Object} item - Full item to append or merge over the found one
|
|
24
|
+
* @param {Array} input - Array of objects to search
|
|
25
|
+
*
|
|
26
|
+
* @returns {Array} New array, with one item replaced or appended
|
|
27
|
+
*
|
|
28
|
+
* @throws {TypeError} If `match` or `item` is not an Object, the input is not
|
|
29
|
+
* an Array or an input item is not an Object
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const items = [{ id: 1, name: "a" }]
|
|
33
|
+
*
|
|
34
|
+
* upsertWith({ id: 2 }, { id: 2, name: "b" }, items)
|
|
35
|
+
* // => [{ id: 1, name: "a" }, { id: 2, name: "b" }]
|
|
36
|
+
*
|
|
37
|
+
* upsertWith({ id: 1 }, { id: 1, name: "b" }, items)
|
|
38
|
+
* // => [{ id: 1, name: "b" }]
|
|
39
|
+
*
|
|
40
|
+
* upsertWith({ id: 1 }, { id: 1, name: "b" })(items)
|
|
41
|
+
* // => [{ id: 1, name: "b" }]
|
|
42
|
+
*
|
|
43
|
+
* pipe(
|
|
44
|
+
* upsertWith({ id: 1 }, { id: 1, count: 1 }),
|
|
45
|
+
* map(read("count"))
|
|
46
|
+
* )([{ id: 1, count: 0 }])
|
|
47
|
+
* // => [1]
|
|
48
|
+
*
|
|
49
|
+
* @name upsertWith
|
|
50
|
+
* @tag Array
|
|
51
|
+
*
|
|
52
|
+
* @see {@link updateWith}, for a transform of a found item
|
|
53
|
+
* @see {@link update}
|
|
54
|
+
*/
|
|
55
|
+
declare const upsertWith: UpsertWithFn;
|
|
56
|
+
export { upsertWith };
|
|
57
|
+
export type { UpsertWithFn };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { isPlainObject } from "../../is/is.js";
|
|
2
|
+
import { type } from "../../type/type.js";
|
|
3
|
+
import { _buildMatch } from "../../utils/build-match.js";
|
|
4
|
+
const _upsertWith = (predicate, item, input)=>{
|
|
5
|
+
if (!Array.isArray(input)) {
|
|
6
|
+
throw new TypeError(`@asd14/m/upsertWith: expected 'input' to be 'Array', got '${type(input)}'`);
|
|
7
|
+
}
|
|
8
|
+
const items = input;
|
|
9
|
+
const result = [
|
|
10
|
+
...items
|
|
11
|
+
];
|
|
12
|
+
for(let i = 0, length = result.length; i < length; i++){
|
|
13
|
+
if (predicate(result[i])) {
|
|
14
|
+
result[i] = {
|
|
15
|
+
...result[i],
|
|
16
|
+
...item
|
|
17
|
+
};
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
result.push(item);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Replace the first object of an array that satisfies `match` with `item`, or
|
|
26
|
+
* append `item` when none does. A match becomes `{ ...found, ...item }`: a key
|
|
27
|
+
* that the found object has and `item` lacks stays.
|
|
28
|
+
*
|
|
29
|
+
* Only the first match is replaced. `item` is a full object, never a patcher:
|
|
30
|
+
* a function in it is a plain value. To transform a found item, use
|
|
31
|
+
* `updateWith`.
|
|
32
|
+
*
|
|
33
|
+
* A `match` key maps to a value compared with SameValueZero, to a predicate
|
|
34
|
+
* that must return `true`, or to a pipe array ending in a predicate. Prefix a
|
|
35
|
+
* key with `!` to negate it. To match an array value, use a predicate.
|
|
36
|
+
*
|
|
37
|
+
* Input is never mutated - always returns a new array.
|
|
38
|
+
*
|
|
39
|
+
* @param {Object} match - Map of keys to values, predicates or pipe arrays
|
|
40
|
+
* @param {Object} item - Full item to append or merge over the found one
|
|
41
|
+
* @param {Array} input - Array of objects to search
|
|
42
|
+
*
|
|
43
|
+
* @returns {Array} New array, with one item replaced or appended
|
|
44
|
+
*
|
|
45
|
+
* @throws {TypeError} If `match` or `item` is not an Object, the input is not
|
|
46
|
+
* an Array or an input item is not an Object
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const items = [{ id: 1, name: "a" }]
|
|
50
|
+
*
|
|
51
|
+
* upsertWith({ id: 2 }, { id: 2, name: "b" }, items)
|
|
52
|
+
* // => [{ id: 1, name: "a" }, { id: 2, name: "b" }]
|
|
53
|
+
*
|
|
54
|
+
* upsertWith({ id: 1 }, { id: 1, name: "b" }, items)
|
|
55
|
+
* // => [{ id: 1, name: "b" }]
|
|
56
|
+
*
|
|
57
|
+
* upsertWith({ id: 1 }, { id: 1, name: "b" })(items)
|
|
58
|
+
* // => [{ id: 1, name: "b" }]
|
|
59
|
+
*
|
|
60
|
+
* pipe(
|
|
61
|
+
* upsertWith({ id: 1 }, { id: 1, count: 1 }),
|
|
62
|
+
* map(read("count"))
|
|
63
|
+
* )([{ id: 1, count: 0 }])
|
|
64
|
+
* // => [1]
|
|
65
|
+
*
|
|
66
|
+
* @name upsertWith
|
|
67
|
+
* @tag Array
|
|
68
|
+
*
|
|
69
|
+
* @see {@link updateWith}, for a transform of a found item
|
|
70
|
+
* @see {@link update}
|
|
71
|
+
*/ const upsertWith = (...params)=>{
|
|
72
|
+
const predicate = _buildMatch(params[0], {
|
|
73
|
+
fnName: "upsertWith",
|
|
74
|
+
inputName: "input[*]"
|
|
75
|
+
});
|
|
76
|
+
const item = params[1];
|
|
77
|
+
if (!isPlainObject(item)) {
|
|
78
|
+
throw new TypeError(`@asd14/m/upsertWith: expected 'item' to be 'Object', got '${type(item)}'`);
|
|
79
|
+
}
|
|
80
|
+
// @signature (match, item) => (input)
|
|
81
|
+
if (params.length === 2) {
|
|
82
|
+
return (input)=>_upsertWith(predicate, item, input);
|
|
83
|
+
}
|
|
84
|
+
// @signature (match, item, input)
|
|
85
|
+
return _upsertWith(predicate, item, params[2]);
|
|
86
|
+
};
|
|
87
|
+
export { upsertWith };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type BuildMatchOptions = {
|
|
2
|
+
/** The public function to name in the error, eg. `filterWith` */
|
|
3
|
+
fnName: string;
|
|
4
|
+
/** The input to name in the error: `input`, or `input[*]` for an item */
|
|
5
|
+
inputName: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Check a matcher once, and build the predicate that tests an object against
|
|
9
|
+
* it. A function or a pipe array passes when it returns `true`. A plain value
|
|
10
|
+
* passes when it equals the key's value, compared with SameValueZero. A `!`
|
|
11
|
+
* before a key negates its test. Reads only the object's own keys.
|
|
12
|
+
*
|
|
13
|
+
* @throws {TypeError} When the matcher is not a plain object
|
|
14
|
+
* @example
|
|
15
|
+
* const isActiveAdmin = _buildMatch(
|
|
16
|
+
* { role: "admin", "!deletedAt": isSomething },
|
|
17
|
+
* { fnName: "filterWith", inputName: "input[*]" }
|
|
18
|
+
* )
|
|
19
|
+
*
|
|
20
|
+
* isActiveAdmin({ role: "admin" })
|
|
21
|
+
* // => true
|
|
22
|
+
*/
|
|
23
|
+
declare const _buildMatch: (match: unknown, { fnName, inputName }: BuildMatchOptions) => ((input: unknown) => boolean);
|
|
24
|
+
export { _buildMatch };
|
|
25
|
+
export type { BuildMatchOptions };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { _toFunction } from "./to-function.js";
|
|
2
|
+
import { isPlainObject } from "../is/is.js";
|
|
3
|
+
import { isEqual } from "../is-equal/is-equal.js";
|
|
4
|
+
import { type } from "../type/type.js";
|
|
5
|
+
/**
|
|
6
|
+
* Check a matcher once, and build the predicate that tests an object against
|
|
7
|
+
* it. A function or a pipe array passes when it returns `true`. A plain value
|
|
8
|
+
* passes when it equals the key's value, compared with SameValueZero. A `!`
|
|
9
|
+
* before a key negates its test. Reads only the object's own keys.
|
|
10
|
+
*
|
|
11
|
+
* @throws {TypeError} When the matcher is not a plain object
|
|
12
|
+
* @example
|
|
13
|
+
* const isActiveAdmin = _buildMatch(
|
|
14
|
+
* { role: "admin", "!deletedAt": isSomething },
|
|
15
|
+
* { fnName: "filterWith", inputName: "input[*]" }
|
|
16
|
+
* )
|
|
17
|
+
*
|
|
18
|
+
* isActiveAdmin({ role: "admin" })
|
|
19
|
+
* // => true
|
|
20
|
+
*/ const _buildMatch = (match, { fnName, inputName })=>{
|
|
21
|
+
if (!isPlainObject(match)) {
|
|
22
|
+
throw new TypeError(`@asd14/m/${fnName}: expected 'match' to be 'Object', got '${type(match)}'`);
|
|
23
|
+
}
|
|
24
|
+
const keys = Object.keys(match);
|
|
25
|
+
const entries = [];
|
|
26
|
+
for(let index = 0, length = keys.length; index < length; index++){
|
|
27
|
+
const key = keys[index];
|
|
28
|
+
const value = match[key];
|
|
29
|
+
const isFunction = typeof value === "function" || Array.isArray(value);
|
|
30
|
+
const isNegated = key[0] === "!";
|
|
31
|
+
entries.push([
|
|
32
|
+
isNegated ? key.slice(1) : key,
|
|
33
|
+
isFunction ? _toFunction(value, {
|
|
34
|
+
fnName,
|
|
35
|
+
paramName: `match.${key}`
|
|
36
|
+
}) : value,
|
|
37
|
+
isFunction,
|
|
38
|
+
isNegated
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
return (input)=>{
|
|
42
|
+
if (!isPlainObject(input)) {
|
|
43
|
+
throw new TypeError(`@asd14/m/${fnName}: expected '${inputName}' to be 'Object', got '${type(input)}'`);
|
|
44
|
+
}
|
|
45
|
+
for(let index = 0, length = entries.length; index < length; index++){
|
|
46
|
+
const [key, shouldBe, isFunction, isNegated] = entries[index];
|
|
47
|
+
const value = Object.hasOwn(input, key) ? input[key] : undefined;
|
|
48
|
+
const isMatched = isFunction ? shouldBe(value) === true : isEqual(shouldBe, value);
|
|
49
|
+
if (isMatched === isNegated) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export { _buildMatch };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { PlainObject } from "../../types/object.js";
|
|
2
|
+
type BuildPatchOptions = {
|
|
3
|
+
/** The public function to name in the error, eg. `evolveMany` */
|
|
4
|
+
fnName: string;
|
|
5
|
+
/** The input to name in the error: `input`, or `input[*]` for an item */
|
|
6
|
+
inputName: string;
|
|
7
|
+
/**
|
|
8
|
+
* Accept only functions and pipe arrays, and skip a key the input does not
|
|
9
|
+
* have, since it has nothing to transform. `evolve` sets it, `update` does
|
|
10
|
+
* not
|
|
11
|
+
*/
|
|
12
|
+
isTransformOnly: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Check a patcher once, and build the function that applies it to an object.
|
|
16
|
+
* A function or a pipe array transforms a key: it gets the key's value and the
|
|
17
|
+
* whole object. A plain value replaces the key.
|
|
18
|
+
*
|
|
19
|
+
* @throws {TypeError} When the patcher is not a plain object, or, with
|
|
20
|
+
* `isTransformOnly`, a value is not a function or a pipe array
|
|
21
|
+
* @example
|
|
22
|
+
* const patch = _buildPatch(
|
|
23
|
+
* { count: x => x + 1, name: "bar" },
|
|
24
|
+
* { fnName: "update", inputName: "input", isTransformOnly: false }
|
|
25
|
+
* )
|
|
26
|
+
*
|
|
27
|
+
* patch({ count: 1 })
|
|
28
|
+
* // => { count: 2, name: "bar" }
|
|
29
|
+
*/
|
|
30
|
+
declare const _buildPatch: (patcher: unknown, { fnName, inputName, isTransformOnly }: BuildPatchOptions) => ((input: unknown) => PlainObject);
|
|
31
|
+
export { _buildPatch };
|
|
32
|
+
export type { BuildPatchOptions };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { _setOwn } from "./set-own.js";
|
|
2
|
+
import { _toFunction } from "./to-function.js";
|
|
3
|
+
import { isPlainObject } from "../is/is.js";
|
|
4
|
+
import { type } from "../type/type.js";
|
|
5
|
+
/**
|
|
6
|
+
* Check a patcher once, and build the function that applies it to an object.
|
|
7
|
+
* A function or a pipe array transforms a key: it gets the key's value and the
|
|
8
|
+
* whole object. A plain value replaces the key.
|
|
9
|
+
*
|
|
10
|
+
* @throws {TypeError} When the patcher is not a plain object, or, with
|
|
11
|
+
* `isTransformOnly`, a value is not a function or a pipe array
|
|
12
|
+
* @example
|
|
13
|
+
* const patch = _buildPatch(
|
|
14
|
+
* { count: x => x + 1, name: "bar" },
|
|
15
|
+
* { fnName: "update", inputName: "input", isTransformOnly: false }
|
|
16
|
+
* )
|
|
17
|
+
*
|
|
18
|
+
* patch({ count: 1 })
|
|
19
|
+
* // => { count: 2, name: "bar" }
|
|
20
|
+
*/ const _buildPatch = (patcher, { fnName, inputName, isTransformOnly })=>{
|
|
21
|
+
if (!isPlainObject(patcher)) {
|
|
22
|
+
throw new TypeError(`@asd14/m/${fnName}: expected 'patcher' to be 'Object', got '${type(patcher)}'`);
|
|
23
|
+
}
|
|
24
|
+
const keys = Object.keys(patcher);
|
|
25
|
+
const entries = [];
|
|
26
|
+
for(let index = 0, length = keys.length; index < length; index++){
|
|
27
|
+
const key = keys[index];
|
|
28
|
+
const value = patcher[key];
|
|
29
|
+
const isFunction = typeof value === "function" || Array.isArray(value);
|
|
30
|
+
if (isTransformOnly && !isFunction) {
|
|
31
|
+
throw new TypeError(`@asd14/m/${fnName}: expected 'patcher.${key}' to be 'Function' or 'Array', got '${type(value)}'`);
|
|
32
|
+
}
|
|
33
|
+
entries.push([
|
|
34
|
+
key,
|
|
35
|
+
isFunction ? _toFunction(value, {
|
|
36
|
+
fnName,
|
|
37
|
+
paramName: `patcher.${key}`
|
|
38
|
+
}) : value,
|
|
39
|
+
isFunction
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
return (input)=>{
|
|
43
|
+
if (!isPlainObject(input)) {
|
|
44
|
+
throw new TypeError(`@asd14/m/${fnName}: expected '${inputName}' to be 'Object', got '${type(input)}'`);
|
|
45
|
+
}
|
|
46
|
+
const result = {
|
|
47
|
+
...input
|
|
48
|
+
};
|
|
49
|
+
for(let index = 0, length = entries.length; index < length; index++){
|
|
50
|
+
const [key, value, isFunction] = entries[index];
|
|
51
|
+
if (isTransformOnly && !Object.hasOwn(input, key)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
_setOwn(result, key, isFunction ? value(input[key], input) : value);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export { _buildPatch };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AnyMorphism } from "../../types/function.js";
|
|
2
|
+
/**
|
|
3
|
+
* Compose functions left to right, without a check. For a caller that checked
|
|
4
|
+
* each function itself, eg. `pipe` and `_toFunction`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* _pipe([x => x + 1, x => x * 2])(1)
|
|
8
|
+
* // => 4
|
|
9
|
+
*/
|
|
10
|
+
declare const _pipe: (fns: readonly AnyMorphism[]) => (input: unknown) => unknown;
|
|
11
|
+
export { _pipe };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compose functions left to right, without a check. For a caller that checked
|
|
3
|
+
* each function itself, eg. `pipe` and `_toFunction`.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* _pipe([x => x + 1, x => x * 2])(1)
|
|
7
|
+
* // => 4
|
|
8
|
+
*/ const _pipe = (fns)=>(input)=>{
|
|
9
|
+
let acc = fns[0](input);
|
|
10
|
+
for(let index = 1, length = fns.length; index < length; index++){
|
|
11
|
+
acc = fns[index](acc);
|
|
12
|
+
}
|
|
13
|
+
return acc;
|
|
14
|
+
};
|
|
15
|
+
export { _pipe };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PlainObject } from "../../types/object.js";
|
|
2
|
+
/**
|
|
3
|
+
* Set an own key on an object that the caller is building.
|
|
4
|
+
*
|
|
5
|
+
* A plain assignment of `__proto__` calls the setter of `Object.prototype` and
|
|
6
|
+
* changes the prototype in place of setting a key. `__proto__` is the one
|
|
7
|
+
* accessor on `Object.prototype`, so every other key keeps the assignment,
|
|
8
|
+
* which builds an object about 11 times faster than `Object.defineProperty`.
|
|
9
|
+
*
|
|
10
|
+
* Writes into `target`. Pass only an object you created.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const result = {}
|
|
14
|
+
*
|
|
15
|
+
* _setOwn(result, "__proto__", { polluted: true })
|
|
16
|
+
* Object.keys(result)
|
|
17
|
+
* // => ["__proto__"]
|
|
18
|
+
*/
|
|
19
|
+
declare const _setOwn: (target: PlainObject, key: string, value: unknown) => void;
|
|
20
|
+
export { _setOwn };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set an own key on an object that the caller is building.
|
|
3
|
+
*
|
|
4
|
+
* A plain assignment of `__proto__` calls the setter of `Object.prototype` and
|
|
5
|
+
* changes the prototype in place of setting a key. `__proto__` is the one
|
|
6
|
+
* accessor on `Object.prototype`, so every other key keeps the assignment,
|
|
7
|
+
* which builds an object about 11 times faster than `Object.defineProperty`.
|
|
8
|
+
*
|
|
9
|
+
* Writes into `target`. Pass only an object you created.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const result = {}
|
|
13
|
+
*
|
|
14
|
+
* _setOwn(result, "__proto__", { polluted: true })
|
|
15
|
+
* Object.keys(result)
|
|
16
|
+
* // => ["__proto__"]
|
|
17
|
+
*/ const _setOwn = (target, key, value)=>{
|
|
18
|
+
if (key === "__proto__") {
|
|
19
|
+
Object.defineProperty(target, key, {
|
|
20
|
+
value,
|
|
21
|
+
enumerable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
configurable: true
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
target[key] = value;
|
|
28
|
+
};
|
|
29
|
+
export { _setOwn };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AnyMorphism } from "../../types/function.js";
|
|
2
|
+
type ToFunctionOptions = {
|
|
3
|
+
/** The public function to name in the error, eg. `filter` */
|
|
4
|
+
fnName: string;
|
|
5
|
+
/** The parameter to name in the error, eg. `fn` or `patcher.tags` */
|
|
6
|
+
paramName: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Turn the value of a function slot into a function: pass a function through,
|
|
10
|
+
* and compose a pipe array into one. An error names the public function and
|
|
11
|
+
* its parameter, eg. `@asd14/m/filter: expected 'fn[1]' to be 'Function'`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* _toFunction([read("id"), isEqual(1)], { fnName: "filter", paramName: "fn" })({ id: 1 })
|
|
15
|
+
* // => true
|
|
16
|
+
*
|
|
17
|
+
* _toFunction([read("id"), 1], { fnName: "filter", paramName: "fn" })
|
|
18
|
+
* // throws "@asd14/m/filter: expected 'fn[1]' to be 'Function', got 'Number'"
|
|
19
|
+
*/
|
|
20
|
+
declare const _toFunction: (fn: unknown, { fnName, paramName }: ToFunctionOptions) => AnyMorphism;
|
|
21
|
+
export { _toFunction };
|
|
22
|
+
export type { ToFunctionOptions };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { _pipe } from "./pipe.js";
|
|
2
|
+
import { type } from "../type/type.js";
|
|
3
|
+
/**
|
|
4
|
+
* Turn the value of a function slot into a function: pass a function through,
|
|
5
|
+
* and compose a pipe array into one. An error names the public function and
|
|
6
|
+
* its parameter, eg. `@asd14/m/filter: expected 'fn[1]' to be 'Function'`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* _toFunction([read("id"), isEqual(1)], { fnName: "filter", paramName: "fn" })({ id: 1 })
|
|
10
|
+
* // => true
|
|
11
|
+
*
|
|
12
|
+
* _toFunction([read("id"), 1], { fnName: "filter", paramName: "fn" })
|
|
13
|
+
* // throws "@asd14/m/filter: expected 'fn[1]' to be 'Function', got 'Number'"
|
|
14
|
+
*/ const _toFunction = (fn, { fnName, paramName })=>{
|
|
15
|
+
if (typeof fn === "function") {
|
|
16
|
+
return fn;
|
|
17
|
+
}
|
|
18
|
+
if (!Array.isArray(fn)) {
|
|
19
|
+
throw new TypeError(`@asd14/m/${fnName}: expected '${paramName}' to be 'Function' or 'Array', got '${type(fn)}'`);
|
|
20
|
+
}
|
|
21
|
+
if (fn.length === 0) {
|
|
22
|
+
throw new TypeError(`@asd14/m/${fnName}: expected '${paramName}' to be 'NonEmpty', got 'Empty'`);
|
|
23
|
+
}
|
|
24
|
+
for(let index = 0, length = fn.length; index < length; index++){
|
|
25
|
+
if (typeof fn[index] !== "function") {
|
|
26
|
+
throw new TypeError(`@asd14/m/${fnName}: expected '${paramName}[${index}]' to be 'Function', got '${type(fn[index])}'`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Each item is a function, checked above
|
|
30
|
+
return _pipe(fn);
|
|
31
|
+
};
|
|
32
|
+
export { _toFunction };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Primitive } from "../../types/basic.js";
|
|
2
|
+
import type { AnyMorphism, UnaryMorphism, UnaryPredicate } from "../../types/function.js";
|
|
3
|
+
type WhenFn = {
|
|
4
|
+
<T, TThen extends Primitive, TElse extends Primitive>(predicate: UnaryPredicate<T> | AnyMorphism[], thenFn: TThen, elseFn: TElse, input: T): TThen | TElse;
|
|
5
|
+
<T, TThen, TElse>(predicate: UnaryPredicate<T> | AnyMorphism[], thenFn: UnaryMorphism<T, TThen> | AnyMorphism[], elseFn: UnaryMorphism<T, TElse> | AnyMorphism[], input: T): TThen | TElse;
|
|
6
|
+
<T, TThen extends Primitive, TElse extends Primitive>(predicate: UnaryPredicate<T> | AnyMorphism[], thenFn: TThen, elseFn: TElse): (input: T) => TThen | TElse;
|
|
7
|
+
<T, TThen, TElse>(predicate: UnaryPredicate<T> | AnyMorphism[], thenFn: UnaryMorphism<T, TThen> | AnyMorphism[], elseFn: UnaryMorphism<T, TElse> | AnyMorphism[]): (input: T) => TThen | TElse;
|
|
8
|
+
<T, TThen extends Primitive>(predicate: UnaryPredicate<T> | AnyMorphism[], thenFn: TThen): (input: T) => T | TThen;
|
|
9
|
+
<T, TThen>(predicate: UnaryPredicate<T> | AnyMorphism[], thenFn: UnaryMorphism<T, TThen> | AnyMorphism[]): (input: T) => T | TThen;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Run a function on the input when a predicate returns `true`, otherwise run
|
|
13
|
+
* the else function or return the input unchanged. A branch can be a function,
|
|
14
|
+
* a pipe array, or a plain value to return as is.
|
|
15
|
+
*
|
|
16
|
+
* The predicate passes only when it returns `=== true`. Calling `when` with
|
|
17
|
+
* the predicate alone throws.
|
|
18
|
+
*
|
|
19
|
+
* @param {Function|Array} predicate - Predicate or pipe chain ending in one
|
|
20
|
+
* @param {Function|Array|*} thenFn - Branch run when the predicate passes
|
|
21
|
+
* @param {Function|Array|*} [elseFn] - Branch run otherwise, defaults to
|
|
22
|
+
* identity
|
|
23
|
+
* @param {*} [input] - Value to test, omit it to get a function back
|
|
24
|
+
*
|
|
25
|
+
* @returns {*} The branch result, or a function waiting for the input
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* when(x => x % 2 === 1, x => x + 1, x => x - 1, 5)
|
|
29
|
+
* // => 6
|
|
30
|
+
*
|
|
31
|
+
* when(x => x % 2 === 1, "odd", "even", 6)
|
|
32
|
+
* // => "even"
|
|
33
|
+
*
|
|
34
|
+
* when(x => x > 3, x => x * 2)(2)
|
|
35
|
+
* // => 2
|
|
36
|
+
*
|
|
37
|
+
* when([read("age"), x => x >= 18], "adult", "minor")({ age: 20 })
|
|
38
|
+
* // => "adult"
|
|
39
|
+
*
|
|
40
|
+
* pipe(
|
|
41
|
+
* map(when(x => x < 0, x => 0)),
|
|
42
|
+
* sum
|
|
43
|
+
* )([-1, 2, -3, 4])
|
|
44
|
+
* // => 6
|
|
45
|
+
*
|
|
46
|
+
* @name when
|
|
47
|
+
* @tag Function
|
|
48
|
+
*
|
|
49
|
+
* @see {@link i}
|
|
50
|
+
* @see {@link filter}
|
|
51
|
+
*/
|
|
52
|
+
declare const when: WhenFn;
|
|
53
|
+
export { when };
|
|
54
|
+
export type { WhenFn };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { i } from "../i/i.js";
|
|
2
|
+
import { _toFunction } from "../utils/to-function.js";
|
|
3
|
+
const _when = (predicate, thenFn, elseFn, input)=>predicate(input) === true ? thenFn(input) : elseFn(input);
|
|
4
|
+
// A function or a pipe array runs on the input, a plain value is returned
|
|
5
|
+
const _toBranch = (branch, parameterName)=>typeof branch === "function" || Array.isArray(branch) ? _toFunction(branch, {
|
|
6
|
+
fnName: "when",
|
|
7
|
+
paramName: parameterName
|
|
8
|
+
}) : ()=>branch;
|
|
9
|
+
/**
|
|
10
|
+
* Run a function on the input when a predicate returns `true`, otherwise run
|
|
11
|
+
* the else function or return the input unchanged. A branch can be a function,
|
|
12
|
+
* a pipe array, or a plain value to return as is.
|
|
13
|
+
*
|
|
14
|
+
* The predicate passes only when it returns `=== true`. Calling `when` with
|
|
15
|
+
* the predicate alone throws.
|
|
16
|
+
*
|
|
17
|
+
* @param {Function|Array} predicate - Predicate or pipe chain ending in one
|
|
18
|
+
* @param {Function|Array|*} thenFn - Branch run when the predicate passes
|
|
19
|
+
* @param {Function|Array|*} [elseFn] - Branch run otherwise, defaults to
|
|
20
|
+
* identity
|
|
21
|
+
* @param {*} [input] - Value to test, omit it to get a function back
|
|
22
|
+
*
|
|
23
|
+
* @returns {*} The branch result, or a function waiting for the input
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* when(x => x % 2 === 1, x => x + 1, x => x - 1, 5)
|
|
27
|
+
* // => 6
|
|
28
|
+
*
|
|
29
|
+
* when(x => x % 2 === 1, "odd", "even", 6)
|
|
30
|
+
* // => "even"
|
|
31
|
+
*
|
|
32
|
+
* when(x => x > 3, x => x * 2)(2)
|
|
33
|
+
* // => 2
|
|
34
|
+
*
|
|
35
|
+
* when([read("age"), x => x >= 18], "adult", "minor")({ age: 20 })
|
|
36
|
+
* // => "adult"
|
|
37
|
+
*
|
|
38
|
+
* pipe(
|
|
39
|
+
* map(when(x => x < 0, x => 0)),
|
|
40
|
+
* sum
|
|
41
|
+
* )([-1, 2, -3, 4])
|
|
42
|
+
* // => 6
|
|
43
|
+
*
|
|
44
|
+
* @name when
|
|
45
|
+
* @tag Function
|
|
46
|
+
*
|
|
47
|
+
* @see {@link i}
|
|
48
|
+
* @see {@link filter}
|
|
49
|
+
*/ const when = (...params)=>{
|
|
50
|
+
const predicate = _toFunction(params[0], {
|
|
51
|
+
fnName: "when",
|
|
52
|
+
paramName: "predicate"
|
|
53
|
+
});
|
|
54
|
+
if (params.length === 1) {
|
|
55
|
+
throw new TypeError("@asd14/m/when: expected 'thenFn' to be 'Function' or 'Primitive', got 'Missing'");
|
|
56
|
+
}
|
|
57
|
+
const thenFn = _toBranch(params[1], "thenFn");
|
|
58
|
+
// @signature (predicate, thenFn) => (input) => thenFn(input) | input
|
|
59
|
+
if (params.length === 2) {
|
|
60
|
+
return (input)=>_when(predicate, thenFn, i, input);
|
|
61
|
+
}
|
|
62
|
+
const elseFn = _toBranch(params[2], "elseFn");
|
|
63
|
+
// @signature (predicate, thenFn, elseFn) => (input) => thenFn(input) | elseFn(input)
|
|
64
|
+
if (params.length === 3) {
|
|
65
|
+
return (input)=>_when(predicate, thenFn, elseFn, input);
|
|
66
|
+
}
|
|
67
|
+
// @signature (predicate, thenFn, elseFn, input) => thenFn(input) | elseFn(input)
|
|
68
|
+
return _when(predicate, thenFn, elseFn, params[3]);
|
|
69
|
+
};
|
|
70
|
+
export { when };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
type ZipToObjectFn = {
|
|
2
|
+
<K extends string, V>(keys: readonly K[], values: readonly V[]): Record<K, V>;
|
|
3
|
+
<K extends string>(keys: readonly K[]): <V>(values: readonly V[]) => Record<K, V>;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Create an object from two arrays, one containing keys, the other values.
|
|
7
|
+
* Both arrays will be trimmed to the smallest length. A `"__proto__"` key stays
|
|
8
|
+
* an own key.
|
|
9
|
+
*
|
|
10
|
+
* Input is never mutated - always returns a new object.
|
|
11
|
+
*
|
|
12
|
+
* @param {readonly string[]} keys - Array of property names
|
|
13
|
+
* @param {readonly unknown[]} values - Array of property values
|
|
14
|
+
*
|
|
15
|
+
* @returns {Object} An object mapping each key to its corresponding value
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* zipToObject(["a", "b"], [1, 2])
|
|
19
|
+
* // => { a: 1, b: 2 }
|
|
20
|
+
*
|
|
21
|
+
* zipToObject(["a"])([1, 2])
|
|
22
|
+
* // => { a: 1 }
|
|
23
|
+
*
|
|
24
|
+
* // In a pipe - build an object from parallel arrays, then keep some keys
|
|
25
|
+
* pipe(
|
|
26
|
+
* zipToObject(["host", "port", "protocol"]),
|
|
27
|
+
* pick(["host", "port"])
|
|
28
|
+
* )(["localhost", 3000, "https"])
|
|
29
|
+
* // => { host: "localhost", port: 3000 }
|
|
30
|
+
*
|
|
31
|
+
* @name zipToObject
|
|
32
|
+
* @tag Array
|
|
33
|
+
* @alias zipToObj
|
|
34
|
+
*
|
|
35
|
+
* @see {@link pick}
|
|
36
|
+
*/
|
|
37
|
+
declare const zipToObject: ZipToObjectFn;
|
|
38
|
+
export { zipToObject, zipToObject as zipToObj };
|
|
39
|
+
export type { ZipToObjectFn };
|