@asd14/m 8.1.0 → 9.1.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/drop.d.ts +38 -0
- package/dist/src/drop/drop.js +56 -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 +75 -0
- package/dist/src/group/group-by.js +88 -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-by/index-by.d.ts +67 -0
- package/dist/src/index-by/index-by.js +73 -0
- package/dist/src/index.d.ts +91 -0
- package/dist/src/index.js +121 -0
- package/dist/src/intersect/by/intersect-by.d.ts +45 -0
- package/dist/src/intersect/by/intersect-by.js +72 -0
- package/dist/src/intersect/intersect.d.ts +42 -0
- package/dist/src/intersect/intersect.js +63 -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/max/by/max-by.d.ts +52 -0
- package/dist/src/max/by/max-by.js +69 -0
- package/dist/src/max/max.d.ts +34 -0
- package/dist/src/max/max.js +49 -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/min/by/min-by.d.ts +52 -0
- package/dist/src/min/by/min-by.js +69 -0
- package/dist/src/min/min.d.ts +34 -0
- package/dist/src/min/min.js +49 -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 +56 -0
- package/dist/src/read/read.js +80 -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/take/last/take-last.d.ts +38 -0
- package/dist/src/take/last/take-last.js +56 -0
- package/dist/src/take/take.d.ts +38 -0
- package/dist/src/take/take.js +56 -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/values/values.d.ts +42 -0
- package/dist/src/values/values.js +46 -0
- package/dist/src/when/when.d.ts +54 -0
- package/dist/src/when/when.js +70 -0
- package/dist/src/write/write.d.ts +53 -0
- package/dist/src/write/write.js +104 -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 +115 -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 +196 -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
package/dist/replace/replace.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { map } from "../map/map.js";
|
|
2
|
-
import { isMatch } from "../is-match/is-match.js";
|
|
3
|
-
import { type } from "../type/type.js";
|
|
4
|
-
/**
|
|
5
|
-
* Replace substring in string
|
|
6
|
-
*
|
|
7
|
-
* @param {string} oldString The old string
|
|
8
|
-
* @param {string} newString The new string
|
|
9
|
-
*
|
|
10
|
-
* @returns {string}
|
|
11
|
-
*/ var replaceString = function(oldString, newString) {
|
|
12
|
-
return function(input) {
|
|
13
|
-
return String.prototype.replace.call(input, oldString, newString);
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Replace element in array (shallow equal)
|
|
18
|
-
*
|
|
19
|
-
* @param {any} oldElm
|
|
20
|
-
* @param {any} newElm
|
|
21
|
-
*
|
|
22
|
-
* @returns {Array}
|
|
23
|
-
*/ var replaceArray = function(oldElm, newElm) {
|
|
24
|
-
return function(input) {
|
|
25
|
-
var result = [];
|
|
26
|
-
for(var i = 0, length = input.length - 1; i <= length; i++){
|
|
27
|
-
if (oldElm === input[i]) {
|
|
28
|
-
result.push(newElm);
|
|
29
|
-
} else {
|
|
30
|
-
result.push(input[i]);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Replace substring if source is string, replace element (shallow equal) if
|
|
38
|
-
* source is Array
|
|
39
|
-
*
|
|
40
|
-
* @param {string|any} oldElm
|
|
41
|
-
* @param {string|any} newElm
|
|
42
|
-
* @param {string|Array} source
|
|
43
|
-
*
|
|
44
|
-
* @returns {string|Array}
|
|
45
|
-
*
|
|
46
|
-
* @tag String,Array
|
|
47
|
-
* @signature (oldElm: string|any, newElm: string|any) => (source: Array): Array
|
|
48
|
-
*
|
|
49
|
-
*/ var replace = function(oldElm, newElm) {
|
|
50
|
-
return function(input) {
|
|
51
|
-
var inputType = type(input);
|
|
52
|
-
var byType = {
|
|
53
|
-
String: replaceString,
|
|
54
|
-
Array: replaceArray
|
|
55
|
-
};
|
|
56
|
-
return byType[inputType](oldElm, newElm)(input);
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Replace object element in array using filter object
|
|
61
|
-
*
|
|
62
|
-
* @tag Array
|
|
63
|
-
* @signature (filter: Obj, replace: Obj|Function) => (source: Obj[]): Obj[]
|
|
64
|
-
*
|
|
65
|
-
* @param {Object} filter Filter object to match against each element
|
|
66
|
-
* @param {Object} newValue Object to replace matching elements
|
|
67
|
-
* @param {Object[]} source
|
|
68
|
-
*
|
|
69
|
-
* @returns {Array}
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* replaceWith(
|
|
73
|
-
* {id: 2},
|
|
74
|
-
* {id: 2, title: "boss", isBoss: true}
|
|
75
|
-
* )([
|
|
76
|
-
* {id: 2, title:"minion"}
|
|
77
|
-
* {id: 3, title:"minion"}
|
|
78
|
-
* ])
|
|
79
|
-
* // => [
|
|
80
|
-
* // {id: 2, title:"boss", isBoss: true},
|
|
81
|
-
* // {id: 3, title:"minion"}
|
|
82
|
-
* // ]
|
|
83
|
-
*
|
|
84
|
-
* replaceWith({ id: 2 }, item => ({
|
|
85
|
-
* ...item,
|
|
86
|
-
* content: ["new", "updated", "field"],
|
|
87
|
-
* }))([
|
|
88
|
-
* { id: 1, name: "foo", content: [] },
|
|
89
|
-
* { id: 2, name: "bar", content: [] },
|
|
90
|
-
* ])
|
|
91
|
-
* // [
|
|
92
|
-
* // { id: 1, name: "foo", content: [] },
|
|
93
|
-
* // { id: 2, name: "bar", content: ["new", "updated", "field"] },
|
|
94
|
-
* // ],
|
|
95
|
-
*/ var replaceWith = function(filter, newValue) {
|
|
96
|
-
return map(function(item) {
|
|
97
|
-
return isMatch(filter)(item) ? typeof newValue === "function" ? newValue(item) : newValue : item;
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
export { replace, replaceWith };
|
|
101
|
-
|
|
102
|
-
//# sourceMappingURL=replace.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/replace/replace.js"],"sourcesContent":["import { map } from \"../map/map.js\"\nimport { isMatch } from \"../is-match/is-match.js\"\nimport { type } from \"../type/type.js\"\n\n/**\n * Replace substring in string\n *\n * @param {string} oldString The old string\n * @param {string} newString The new string\n *\n * @returns {string}\n */\nconst replaceString = (oldString, newString) => input =>\n String.prototype.replace.call(input, oldString, newString)\n\n/**\n * Replace element in array (shallow equal)\n *\n * @param {any} oldElm\n * @param {any} newElm\n *\n * @returns {Array}\n */\nconst replaceArray = (oldElm, newElm) => input => {\n const result = []\n\n for (let i = 0, length = input.length - 1; i <= length; i++) {\n if (oldElm === input[i]) {\n result.push(newElm)\n } else {\n result.push(input[i])\n }\n }\n\n return result\n}\n\n/**\n * Replace substring if source is string, replace element (shallow equal) if\n * source is Array\n *\n * @param {string|any} oldElm\n * @param {string|any} newElm\n * @param {string|Array} source\n *\n * @returns {string|Array}\n *\n * @tag String,Array\n * @signature (oldElm: string|any, newElm: string|any) => (source: Array): Array\n *\n */\nconst replace = (oldElm, newElm) => input => {\n const inputType = type(input)\n const byType = {\n String: replaceString,\n Array: replaceArray,\n }\n\n return byType[inputType](oldElm, newElm)(input)\n}\n\n/**\n * Replace object element in array using filter object\n *\n * @tag Array\n * @signature (filter: Obj, replace: Obj|Function) => (source: Obj[]): Obj[]\n *\n * @param {Object} filter Filter object to match against each element\n * @param {Object} newValue Object to replace matching elements\n * @param {Object[]} source\n *\n * @returns {Array}\n *\n * @example\n * replaceWith(\n * {id: 2},\n * {id: 2, title: \"boss\", isBoss: true}\n * )([\n * {id: 2, title:\"minion\"}\n * {id: 3, title:\"minion\"}\n * ])\n * // => [\n * // {id: 2, title:\"boss\", isBoss: true},\n * // {id: 3, title:\"minion\"}\n * // ]\n *\n * replaceWith({ id: 2 }, item => ({\n * ...item,\n * content: [\"new\", \"updated\", \"field\"],\n * }))([\n * { id: 1, name: \"foo\", content: [] },\n * { id: 2, name: \"bar\", content: [] },\n * ])\n * // [\n * // { id: 1, name: \"foo\", content: [] },\n * // { id: 2, name: \"bar\", content: [\"new\", \"updated\", \"field\"] },\n * // ],\n */\nconst replaceWith = (filter, newValue) =>\n map(item =>\n isMatch(filter)(item)\n ? typeof newValue === \"function\"\n ? newValue(item)\n : newValue\n : item\n )\n\nexport { replace, replaceWith }\n"],"names":["map","isMatch","type","replaceString","oldString","newString","input","String","prototype","replace","call","replaceArray","oldElm","newElm","result","i","length","push","inputType","byType","Array","replaceWith","filter","newValue","item"],"mappings":"AAAA,SAASA,GAAG,QAAQ,gBAAe;AACnC,SAASC,OAAO,QAAQ,0BAAyB;AACjD,SAASC,IAAI,QAAQ,kBAAiB;AAEtC;;;;;;;CAOC,GACD,IAAMC,gBAAgB,SAACC,WAAWC;WAAcC,SAAAA;eAC9CC,OAAOC,SAAS,CAACC,OAAO,CAACC,IAAI,CAACJ,OAAOF,WAAWC;;;AAElD;;;;;;;CAOC,GACD,IAAMM,eAAe,SAACC,QAAQC;WAAWP,SAAAA,OAAS;QAChD,IAAMQ,SAAS,EAAE;QAEjB,IAAK,IAAIC,IAAI,GAAGC,SAASV,MAAMU,MAAM,GAAG,GAAGD,KAAKC,QAAQD,IAAK;YAC3D,IAAIH,WAAWN,KAAK,CAACS,EAAE,EAAE;gBACvBD,OAAOG,IAAI,CAACJ;YACd,OAAO;gBACLC,OAAOG,IAAI,CAACX,KAAK,CAACS,EAAE;YACtB,CAAC;QACH;QAEA,OAAOD;IACT;;AAEA;;;;;;;;;;;;;CAaC,GACD,IAAML,UAAU,SAACG,QAAQC;WAAWP,SAAAA,OAAS;QAC3C,IAAMY,YAAYhB,KAAKI;QACvB,IAAMa,SAAS;YACbZ,QAAQJ;YACRiB,OAAOT;QACT;QAEA,OAAOQ,MAAM,CAACD,UAAU,CAACN,QAAQC,QAAQP;IAC3C;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCC,GACD,IAAMe,cAAc,SAACC,QAAQC;WAC3BvB,IAAIwB,SAAAA;eACFvB,QAAQqB,QAAQE,QACZ,OAAOD,aAAa,aAClBA,SAASC,QACTD,QAAQ,GACVC,IAAI;;;AAGZ,SAASf,OAAO,EAAEY,WAAW,GAAE"}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import _object_spread from "@swc/helpers/src/_object_spread.mjs";
|
|
2
|
-
import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
|
|
3
|
-
import test from "tape";
|
|
4
|
-
import { replace, replaceWith } from "./replace.js";
|
|
5
|
-
test("replace(With)", function(t) {
|
|
6
|
-
t.equals(replace("test", "ipsum")("lorem test"), "lorem ipsum", "Replace substring in string");
|
|
7
|
-
t.equals(replace("testx", "ipsum")("lorem test"), "lorem test", "Replacement string does not exist");
|
|
8
|
-
t.deepEquals(replace("test", "ipsum")([
|
|
9
|
-
"lorem",
|
|
10
|
-
"test"
|
|
11
|
-
]), [
|
|
12
|
-
"lorem",
|
|
13
|
-
"ipsum"
|
|
14
|
-
], "Replace string element in array source");
|
|
15
|
-
t.deepEquals(replace("testx", "ipsum")([
|
|
16
|
-
"lorem",
|
|
17
|
-
"test"
|
|
18
|
-
]), [
|
|
19
|
-
"lorem",
|
|
20
|
-
"test"
|
|
21
|
-
], "Replacement string does not exist in array source");
|
|
22
|
-
var input = [
|
|
23
|
-
"lorem",
|
|
24
|
-
"test"
|
|
25
|
-
];
|
|
26
|
-
t.notEquals(replace("test", "ipsum")(input), input, "Imutable");
|
|
27
|
-
t.deepEquals(replace("test", "ipsum")(replace("test", "ipsum")([
|
|
28
|
-
"lorem",
|
|
29
|
-
"test"
|
|
30
|
-
])), [
|
|
31
|
-
"lorem",
|
|
32
|
-
"ipsum"
|
|
33
|
-
], "Idempotent");
|
|
34
|
-
t.deepEqual(replaceWith({
|
|
35
|
-
id: 2
|
|
36
|
-
}, {
|
|
37
|
-
id: 2,
|
|
38
|
-
title: "boss",
|
|
39
|
-
isBoss: true
|
|
40
|
-
})([
|
|
41
|
-
{
|
|
42
|
-
id: 2,
|
|
43
|
-
title: "minion"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
id: 3,
|
|
47
|
-
title: "minion"
|
|
48
|
-
}
|
|
49
|
-
]), [
|
|
50
|
-
{
|
|
51
|
-
id: 2,
|
|
52
|
-
title: "boss",
|
|
53
|
-
isBoss: true
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
id: 3,
|
|
57
|
-
title: "minion"
|
|
58
|
-
}
|
|
59
|
-
], "Replace existing object");
|
|
60
|
-
t.deepEqual(replaceWith({
|
|
61
|
-
"!name": "alice"
|
|
62
|
-
}, {
|
|
63
|
-
name: "bobby",
|
|
64
|
-
title: "tables"
|
|
65
|
-
})([
|
|
66
|
-
{
|
|
67
|
-
name: "alice",
|
|
68
|
-
title: "first"
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: "bob",
|
|
72
|
-
title: "second"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
name: "george",
|
|
76
|
-
title: "third"
|
|
77
|
-
}
|
|
78
|
-
]), [
|
|
79
|
-
{
|
|
80
|
-
name: "alice",
|
|
81
|
-
title: "first"
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
name: "bobby",
|
|
85
|
-
title: "tables"
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
name: "bobby",
|
|
89
|
-
title: "tables"
|
|
90
|
-
}
|
|
91
|
-
], "Replace multiple objects by using negate in filter object");
|
|
92
|
-
t.deepEquals(replaceWith({
|
|
93
|
-
id: 2
|
|
94
|
-
}, function(item) {
|
|
95
|
-
return _object_spread_props(_object_spread({}, item), {
|
|
96
|
-
content: [
|
|
97
|
-
"new",
|
|
98
|
-
"updated",
|
|
99
|
-
"field"
|
|
100
|
-
]
|
|
101
|
-
});
|
|
102
|
-
})([
|
|
103
|
-
{
|
|
104
|
-
id: 1,
|
|
105
|
-
name: "foo",
|
|
106
|
-
content: []
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
id: 2,
|
|
110
|
-
name: "bar",
|
|
111
|
-
content: []
|
|
112
|
-
}
|
|
113
|
-
]), [
|
|
114
|
-
{
|
|
115
|
-
id: 1,
|
|
116
|
-
name: "foo",
|
|
117
|
-
content: []
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
id: 2,
|
|
121
|
-
name: "bar",
|
|
122
|
-
content: [
|
|
123
|
-
"new",
|
|
124
|
-
"updated",
|
|
125
|
-
"field"
|
|
126
|
-
]
|
|
127
|
-
}
|
|
128
|
-
], "Replace object with custom update function");
|
|
129
|
-
t.end();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
//# sourceMappingURL=replace.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/replace/replace.test.js"],"sourcesContent":["import test from \"tape\"\nimport { replace, replaceWith } from \"./replace.js\"\n\ntest(\"replace(With)\", t => {\n t.equals(\n replace(\"test\", \"ipsum\")(\"lorem test\"),\n \"lorem ipsum\",\n \"Replace substring in string\"\n )\n\n t.equals(\n replace(\"testx\", \"ipsum\")(\"lorem test\"),\n \"lorem test\",\n \"Replacement string does not exist\"\n )\n\n t.deepEquals(\n replace(\"test\", \"ipsum\")([\"lorem\", \"test\"]),\n [\"lorem\", \"ipsum\"],\n \"Replace string element in array source\"\n )\n\n t.deepEquals(\n replace(\"testx\", \"ipsum\")([\"lorem\", \"test\"]),\n [\"lorem\", \"test\"],\n \"Replacement string does not exist in array source\"\n )\n\n const input = [\"lorem\", \"test\"]\n\n t.notEquals(replace(\"test\", \"ipsum\")(input), input, \"Imutable\")\n\n t.deepEquals(\n replace(\"test\", \"ipsum\")(replace(\"test\", \"ipsum\")([\"lorem\", \"test\"])),\n [\"lorem\", \"ipsum\"],\n \"Idempotent\"\n )\n\n t.deepEqual(\n replaceWith(\n { id: 2 },\n { id: 2, title: \"boss\", isBoss: true }\n )([\n { id: 2, title: \"minion\" },\n { id: 3, title: \"minion\" },\n ]),\n [\n { id: 2, title: \"boss\", isBoss: true },\n { id: 3, title: \"minion\" },\n ],\n \"Replace existing object\"\n )\n\n t.deepEqual(\n replaceWith(\n { \"!name\": \"alice\" },\n { name: \"bobby\", title: \"tables\" }\n )([\n { name: \"alice\", title: \"first\" },\n { name: \"bob\", title: \"second\" },\n { name: \"george\", title: \"third\" },\n ]),\n [\n { name: \"alice\", title: \"first\" },\n { name: \"bobby\", title: \"tables\" },\n { name: \"bobby\", title: \"tables\" },\n ],\n \"Replace multiple objects by using negate in filter object\"\n )\n\n t.deepEquals(\n replaceWith({ id: 2 }, item => ({\n ...item,\n content: [\"new\", \"updated\", \"field\"],\n }))([\n { id: 1, name: \"foo\", content: [] },\n { id: 2, name: \"bar\", content: [] },\n ]),\n [\n { id: 1, name: \"foo\", content: [] },\n { id: 2, name: \"bar\", content: [\"new\", \"updated\", \"field\"] },\n ],\n \"Replace object with custom update function\"\n )\n\n t.end()\n})\n"],"names":["test","replace","replaceWith","t","equals","deepEquals","input","notEquals","deepEqual","id","title","isBoss","name","item","content","end"],"mappings":"AAAA;;AAAA,OAAOA,UAAU,OAAM;AACvB,SAASC,OAAO,EAAEC,WAAW,QAAQ,eAAc;AAEnDF,KAAK,iBAAiBG,SAAAA,GAAK;IACzBA,EAAEC,MAAM,CACNH,QAAQ,QAAQ,SAAS,eACzB,eACA;IAGFE,EAAEC,MAAM,CACNH,QAAQ,SAAS,SAAS,eAC1B,cACA;IAGFE,EAAEE,UAAU,CACVJ,QAAQ,QAAQ,SAAS;QAAC;QAAS;KAAO,GAC1C;QAAC;QAAS;KAAQ,EAClB;IAGFE,EAAEE,UAAU,CACVJ,QAAQ,SAAS,SAAS;QAAC;QAAS;KAAO,GAC3C;QAAC;QAAS;KAAO,EACjB;IAGF,IAAMK,QAAQ;QAAC;QAAS;KAAO;IAE/BH,EAAEI,SAAS,CAACN,QAAQ,QAAQ,SAASK,QAAQA,OAAO;IAEpDH,EAAEE,UAAU,CACVJ,QAAQ,QAAQ,SAASA,QAAQ,QAAQ,SAAS;QAAC;QAAS;KAAO,IACnE;QAAC;QAAS;KAAQ,EAClB;IAGFE,EAAEK,SAAS,CACTN,YACE;QAAEO,IAAI;IAAE,GACR;QAAEA,IAAI;QAAGC,OAAO;QAAQC,QAAQ,IAAI;IAAC,GACrC;QACA;YAAEF,IAAI;YAAGC,OAAO;QAAS;QACzB;YAAED,IAAI;YAAGC,OAAO;QAAS;KAC1B,GACD;QACE;YAAED,IAAI;YAAGC,OAAO;YAAQC,QAAQ,IAAI;QAAC;QACrC;YAAEF,IAAI;YAAGC,OAAO;QAAS;KAC1B,EACD;IAGFP,EAAEK,SAAS,CACTN,YACE;QAAE,SAAS;IAAQ,GACnB;QAAEU,MAAM;QAASF,OAAO;IAAS,GACjC;QACA;YAAEE,MAAM;YAASF,OAAO;QAAQ;QAChC;YAAEE,MAAM;YAAOF,OAAO;QAAS;QAC/B;YAAEE,MAAM;YAAUF,OAAO;QAAQ;KAClC,GACD;QACE;YAAEE,MAAM;YAASF,OAAO;QAAQ;QAChC;YAAEE,MAAM;YAASF,OAAO;QAAS;QACjC;YAAEE,MAAM;YAASF,OAAO;QAAS;KAClC,EACD;IAGFP,EAAEE,UAAU,CACVH,YAAY;QAAEO,IAAI;IAAE,GAAGI,SAAAA;eAAS,wCAC3BA;YACHC,SAAS;gBAAC;gBAAO;gBAAW;aAAQ;;OAClC;QACF;YAAEL,IAAI;YAAGG,MAAM;YAAOE,SAAS,EAAE;QAAC;QAClC;YAAEL,IAAI;YAAGG,MAAM;YAAOE,SAAS,EAAE;QAAC;KACnC,GACD;QACE;YAAEL,IAAI;YAAGG,MAAM;YAAOE,SAAS,EAAE;QAAC;QAClC;YAAEL,IAAI;YAAGG,MAAM;YAAOE,SAAS;gBAAC;gBAAO;gBAAW;aAAQ;QAAC;KAC5D,EACD;IAGFX,EAAEY,GAAG;AACP"}
|
package/dist/same/same.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Curried funtion that always returns the input given
|
|
3
|
-
*
|
|
4
|
-
* @param {any} input Something, anything
|
|
5
|
-
*
|
|
6
|
-
* @returns {any}
|
|
7
|
-
*/ export var same = function(input) {
|
|
8
|
-
return function() {
|
|
9
|
-
return input;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=same.js.map
|
package/dist/same/same.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/same/same.js"],"sourcesContent":["/**\n * Curried funtion that always returns the input given\n *\n * @param {any} input Something, anything\n *\n * @returns {any}\n */\nexport const same = input => () => input\n"],"names":["same","input"],"mappings":"AAAA;;;;;;CAMC,GACD,OAAO,IAAMA,OAAOC,SAAAA;WAAS;eAAMA;;EAAK"}
|
package/dist/same/same.test.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/same/same.test.js"],"sourcesContent":["import test from \"tape\"\n\nimport { same } from \"./same.js\"\n\ntest(\"same\", t => {\n const object = {}\n\n t.equals(\n same(object)(),\n object,\n \"Give value as input, get the same value in return\"\n )\n\n t.end()\n})\n"],"names":["test","same","t","object","equals","end"],"mappings":"AAAA,OAAOA,UAAU,OAAM;AAEvB,SAASC,IAAI,QAAQ,YAAW;AAEhCD,KAAK,QAAQE,SAAAA,GAAK;IAChB,IAAMC,SAAS,CAAC;IAEhBD,EAAEE,MAAM,CACNH,KAAKE,WACLA,QACA;IAGFD,EAAEG,GAAG;AACP"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { is } from "../is/is.js";
|
|
2
|
-
var alwaysTrue = function() {
|
|
3
|
-
return true;
|
|
4
|
-
};
|
|
5
|
-
export var sequenceWhile = function(predicateFn, input) {
|
|
6
|
-
if (typeof predicateFn !== "function") {
|
|
7
|
-
throw new TypeError('Invalid predicate control function. Expected function but got "'.concat(JSON.stringify(predicateFn), '"'));
|
|
8
|
-
}
|
|
9
|
-
if (!Array.isArray(input) || Array.isArray(input) && input.length === 0) {
|
|
10
|
-
throw new TypeError('Invalid source array. Expected array of functions but got "'.concat(JSON.stringify(input), '"'));
|
|
11
|
-
}
|
|
12
|
-
var index = 0;
|
|
13
|
-
var resolved = [];
|
|
14
|
-
var queueNext = function(promise) {
|
|
15
|
-
return promise.then(function(result) {
|
|
16
|
-
resolved.push(result);
|
|
17
|
-
if (predicateFn(result) === true) {
|
|
18
|
-
var nextPromiseFn = input[++index];
|
|
19
|
-
if (is(nextPromiseFn)) {
|
|
20
|
-
return queueNext(Promise.resolve(nextPromiseFn(result)));
|
|
21
|
-
}
|
|
22
|
-
// no more functions to process
|
|
23
|
-
return resolved;
|
|
24
|
-
}
|
|
25
|
-
// predicate function failed, return what already resolved and stop
|
|
26
|
-
// processing further
|
|
27
|
-
return resolved;
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
return queueNext(Promise.resolve(input[0]()));
|
|
31
|
-
};
|
|
32
|
-
export var sequence = function(input) {
|
|
33
|
-
return sequenceWhile(alwaysTrue, input);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
//# sourceMappingURL=sequence.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sequence/sequence.js"],"sourcesContent":["import { is } from \"../is/is.js\"\n\nconst alwaysTrue = () => true\n\nexport const sequenceWhile = (predicateFn, input) => {\n if (typeof predicateFn !== \"function\") {\n throw new TypeError(\n `Invalid predicate control function. Expected function but got \"${JSON.stringify(\n predicateFn\n )}\"`\n )\n }\n\n if (!Array.isArray(input) || (Array.isArray(input) && input.length === 0)) {\n throw new TypeError(\n `Invalid source array. Expected array of functions but got \"${JSON.stringify(\n input\n )}\"`\n )\n }\n\n let index = 0\n const resolved = []\n\n const queueNext = promise =>\n promise.then(result => {\n resolved.push(result)\n\n if (predicateFn(result) === true) {\n const nextPromiseFn = input[++index]\n\n if (is(nextPromiseFn)) {\n return queueNext(Promise.resolve(nextPromiseFn(result)))\n }\n\n // no more functions to process\n return resolved\n }\n\n // predicate function failed, return what already resolved and stop\n // processing further\n return resolved\n })\n\n return queueNext(Promise.resolve(input[0]()))\n}\n\nexport const sequence = input => sequenceWhile(alwaysTrue, input)\n"],"names":["is","alwaysTrue","sequenceWhile","predicateFn","input","TypeError","JSON","stringify","Array","isArray","length","index","resolved","queueNext","promise","then","result","push","nextPromiseFn","Promise","resolve","sequence"],"mappings":"AAAA,SAASA,EAAE,QAAQ,cAAa;AAEhC,IAAMC,aAAa;WAAM,IAAI;;AAE7B,OAAO,IAAMC,gBAAgB,SAACC,aAAaC,OAAU;IACnD,IAAI,OAAOD,gBAAgB,YAAY;QACrC,MAAM,IAAIE,UACR,AAAC,kEAEC,OAFgEC,KAAKC,SAAS,CAC9EJ,cACA,MACH;IACH,CAAC;IAED,IAAI,CAACK,MAAMC,OAAO,CAACL,UAAWI,MAAMC,OAAO,CAACL,UAAUA,MAAMM,MAAM,KAAK,GAAI;QACzE,MAAM,IAAIL,UACR,AAAC,8DAEC,OAF4DC,KAAKC,SAAS,CAC1EH,QACA,MACH;IACH,CAAC;IAED,IAAIO,QAAQ;IACZ,IAAMC,WAAW,EAAE;IAEnB,IAAMC,YAAYC,SAAAA;eAChBA,QAAQC,IAAI,CAACC,SAAAA,QAAU;YACrBJ,SAASK,IAAI,CAACD;YAEd,IAAIb,YAAYa,YAAY,IAAI,EAAE;gBAChC,IAAME,gBAAgBd,KAAK,CAAC,EAAEO,MAAM;gBAEpC,IAAIX,GAAGkB,gBAAgB;oBACrB,OAAOL,UAAUM,QAAQC,OAAO,CAACF,cAAcF;gBACjD,CAAC;gBAED,+BAA+B;gBAC/B,OAAOJ;YACT,CAAC;YAED,mEAAmE;YACnE,qBAAqB;YACrB,OAAOA;QACT;;IAEF,OAAOC,UAAUM,QAAQC,OAAO,CAAChB,KAAK,CAAC,EAAE;AAC3C,EAAC;AAED,OAAO,IAAMiB,WAAWjB,SAAAA;WAASF,cAAcD,YAAYG;EAAM"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import test from "tape";
|
|
2
|
-
import { isTrue } from "../is/is.js";
|
|
3
|
-
import { sequence, sequenceWhile } from "./sequence.js";
|
|
4
|
-
var delay = function(ms, value) {
|
|
5
|
-
return new Promise(function(resolve) {
|
|
6
|
-
return setTimeout(function() {
|
|
7
|
-
return resolve(value);
|
|
8
|
-
}, ms);
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
test("sequence", function(t) {
|
|
12
|
-
t.throws(function() {
|
|
13
|
-
return sequence();
|
|
14
|
-
}, /Invalid source array. Expected array of functions but got "undefined"/, "Throw error when source array is not array");
|
|
15
|
-
t.throws(function() {
|
|
16
|
-
return sequence([]);
|
|
17
|
-
}, /Invalid source array. Expected array of functions but got "\[]"/, "Throw error when source array is empty");
|
|
18
|
-
var sum = 0;
|
|
19
|
-
var input = [
|
|
20
|
-
function() {
|
|
21
|
-
sum++;
|
|
22
|
-
return 1;
|
|
23
|
-
},
|
|
24
|
-
function(previous) {
|
|
25
|
-
sum += previous;
|
|
26
|
-
return delay(10, 2);
|
|
27
|
-
},
|
|
28
|
-
function(previous) {
|
|
29
|
-
sum += previous;
|
|
30
|
-
return Promise.resolve("abc");
|
|
31
|
-
},
|
|
32
|
-
function(previous) {
|
|
33
|
-
sum += previous;
|
|
34
|
-
return Promise.all([
|
|
35
|
-
Promise.resolve(3),
|
|
36
|
-
Promise.resolve(4)
|
|
37
|
-
]);
|
|
38
|
-
}
|
|
39
|
-
];
|
|
40
|
-
return sequence(input).then(function(result) {
|
|
41
|
-
t.deepEqual([
|
|
42
|
-
sum,
|
|
43
|
-
result
|
|
44
|
-
], [
|
|
45
|
-
"".concat(1 + 1 + 2, "abc"),
|
|
46
|
-
[
|
|
47
|
-
1,
|
|
48
|
-
2,
|
|
49
|
-
"abc",
|
|
50
|
-
[
|
|
51
|
-
3,
|
|
52
|
-
4
|
|
53
|
-
]
|
|
54
|
-
]
|
|
55
|
-
], "All promise functions run in sequence, each having access to previous result");
|
|
56
|
-
t.end();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
test("sequenceWith", function(t) {
|
|
60
|
-
t.throws(function() {
|
|
61
|
-
return sequenceWhile();
|
|
62
|
-
}, /Invalid predicate control function. Expected function but got "undefined"/, "Throw error when predicate function invalid");
|
|
63
|
-
var sum = 1;
|
|
64
|
-
return sequenceWhile(isTrue, [
|
|
65
|
-
function() {
|
|
66
|
-
return true;
|
|
67
|
-
},
|
|
68
|
-
function() {
|
|
69
|
-
return false;
|
|
70
|
-
},
|
|
71
|
-
function() {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
]).then(function(result) {
|
|
75
|
-
t.deepEqual(result, [
|
|
76
|
-
true,
|
|
77
|
-
false
|
|
78
|
-
], "Two promise fn resolve with array of both resolved values");
|
|
79
|
-
}).then(function() {
|
|
80
|
-
return sequenceWhile(isTrue, [
|
|
81
|
-
function() {
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
]);
|
|
85
|
-
}).then(function(result) {
|
|
86
|
-
t.deepEqual(result, [
|
|
87
|
-
true
|
|
88
|
-
], "One successfull promise fn resolve with array of resolved value");
|
|
89
|
-
}).then(function() {
|
|
90
|
-
return sequenceWhile(isTrue, [
|
|
91
|
-
function() {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
]);
|
|
95
|
-
}).then(function(result) {
|
|
96
|
-
t.deepEqual(result, [
|
|
97
|
-
false
|
|
98
|
-
], "One failing promise fn resolve with array of resolved value");
|
|
99
|
-
}).then(function() {
|
|
100
|
-
return sequenceWhile(function(input) {
|
|
101
|
-
return input <= 5;
|
|
102
|
-
}, [
|
|
103
|
-
function() {
|
|
104
|
-
return 1;
|
|
105
|
-
},
|
|
106
|
-
function(previous) {
|
|
107
|
-
sum += previous;
|
|
108
|
-
return delay(10, 2);
|
|
109
|
-
},
|
|
110
|
-
function(previous) {
|
|
111
|
-
sum += previous;
|
|
112
|
-
return delay(10, 100);
|
|
113
|
-
},
|
|
114
|
-
function(previous) {
|
|
115
|
-
sum += previous;
|
|
116
|
-
return delay(10, 2);
|
|
117
|
-
},
|
|
118
|
-
function(previous) {
|
|
119
|
-
sum += previous;
|
|
120
|
-
return delay(10, 5);
|
|
121
|
-
}
|
|
122
|
-
]);
|
|
123
|
-
}).then(function(result) {
|
|
124
|
-
t.deepEqual([
|
|
125
|
-
sum,
|
|
126
|
-
result
|
|
127
|
-
], [
|
|
128
|
-
1 + 1 + 2,
|
|
129
|
-
[
|
|
130
|
-
1,
|
|
131
|
-
2,
|
|
132
|
-
100
|
|
133
|
-
]
|
|
134
|
-
], "Promise functions run in sequence until control fn fails. No further promises will run");
|
|
135
|
-
t.end();
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
//# sourceMappingURL=sequence.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sequence/sequence.test.js"],"sourcesContent":["import test from \"tape\"\n\nimport { isTrue } from \"../is/is.js\"\nimport { sequence, sequenceWhile } from \"./sequence.js\"\n\nconst delay = (ms, value) =>\n new Promise(resolve => setTimeout(() => resolve(value), ms))\n\ntest(\"sequence\", t => {\n t.throws(\n () => sequence(),\n /Invalid source array. Expected array of functions but got \"undefined\"/,\n \"Throw error when source array is not array\"\n )\n\n t.throws(\n () => sequence([]),\n /Invalid source array. Expected array of functions but got \"\\[]\"/,\n \"Throw error when source array is empty\"\n )\n\n let sum = 0\n\n const input = [\n () => {\n sum++\n\n return 1\n },\n previous => {\n sum += previous\n\n return delay(10, 2)\n },\n previous => {\n sum += previous\n\n return Promise.resolve(\"abc\")\n },\n previous => {\n sum += previous\n\n return Promise.all([Promise.resolve(3), Promise.resolve(4)])\n },\n ]\n\n return sequence(input).then(result => {\n t.deepEqual(\n [sum, result],\n [`${1 + 1 + 2}abc`, [1, 2, \"abc\", [3, 4]]],\n \"All promise functions run in sequence, each having access to previous result\"\n )\n\n t.end()\n })\n})\n\ntest(\"sequenceWith\", t => {\n t.throws(\n () => sequenceWhile(),\n /Invalid predicate control function. Expected function but got \"undefined\"/,\n \"Throw error when predicate function invalid\"\n )\n\n let sum = 1\n\n return sequenceWhile(isTrue, [() => true, () => false, () => true])\n .then(result => {\n t.deepEqual(\n result,\n [true, false],\n \"Two promise fn resolve with array of both resolved values\"\n )\n })\n .then(() => sequenceWhile(isTrue, [() => true]))\n .then(result => {\n t.deepEqual(\n result,\n [true],\n \"One successfull promise fn resolve with array of resolved value\"\n )\n })\n .then(() => sequenceWhile(isTrue, [() => false]))\n .then(result => {\n t.deepEqual(\n result,\n [false],\n \"One failing promise fn resolve with array of resolved value\"\n )\n })\n .then(() =>\n sequenceWhile(\n input => input <= 5,\n [\n () => 1,\n\n previous => {\n sum += previous\n\n return delay(10, 2)\n },\n\n previous => {\n sum += previous\n\n return delay(10, 100)\n },\n\n previous => {\n sum += previous\n\n return delay(10, 2)\n },\n\n previous => {\n sum += previous\n\n return delay(10, 5)\n },\n ]\n )\n )\n .then(result => {\n t.deepEqual(\n [sum, result],\n [1 + 1 + 2, [1, 2, 100]],\n \"Promise functions run in sequence until control fn fails. No further promises will run\"\n )\n\n t.end()\n })\n})\n"],"names":["test","isTrue","sequence","sequenceWhile","delay","ms","value","Promise","resolve","setTimeout","t","throws","sum","input","previous","all","then","result","deepEqual","end"],"mappings":"AAAA,OAAOA,UAAU,OAAM;AAEvB,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,QAAQ,EAAEC,aAAa,QAAQ,gBAAe;AAEvD,IAAMC,QAAQ,SAACC,IAAIC;WACjB,IAAIC,QAAQC,SAAAA;eAAWC,WAAW;mBAAMD,QAAQF;WAAQD;;;AAE1DL,KAAK,YAAYU,SAAAA,GAAK;IACpBA,EAAEC,MAAM,CACN;eAAMT;OACN,yEACA;IAGFQ,EAAEC,MAAM,CACN;eAAMT,SAAS,EAAE;OACjB,mEACA;IAGF,IAAIU,MAAM;IAEV,IAAMC,QAAQ;QACZ,WAAM;YACJD;YAEA,OAAO;QACT;QACAE,SAAAA,UAAY;YACVF,OAAOE;YAEP,OAAOV,MAAM,IAAI;QACnB;QACAU,SAAAA,UAAY;YACVF,OAAOE;YAEP,OAAOP,QAAQC,OAAO,CAAC;QACzB;QACAM,SAAAA,UAAY;YACVF,OAAOE;YAEP,OAAOP,QAAQQ,GAAG,CAAC;gBAACR,QAAQC,OAAO,CAAC;gBAAID,QAAQC,OAAO,CAAC;aAAG;QAC7D;KACD;IAED,OAAON,SAASW,OAAOG,IAAI,CAACC,SAAAA,QAAU;QACpCP,EAAEQ,SAAS,CACT;YAACN;YAAKK;SAAO,EACb;YAAE,GAAY,OAAV,IAAI,IAAI,GAAE;YAAM;gBAAC;gBAAG;gBAAG;gBAAO;oBAAC;oBAAG;iBAAE;aAAC;SAAC,EAC1C;QAGFP,EAAES,GAAG;IACP;AACF;AAEAnB,KAAK,gBAAgBU,SAAAA,GAAK;IACxBA,EAAEC,MAAM,CACN;eAAMR;OACN,6EACA;IAGF,IAAIS,MAAM;IAEV,OAAOT,cAAcF,QAAQ;QAAC;mBAAM,IAAI;;QAAE;mBAAM,KAAK;;QAAE;mBAAM,IAAI;;KAAC,EAC/De,IAAI,CAACC,SAAAA,QAAU;QACdP,EAAEQ,SAAS,CACTD,QACA;YAAC,IAAI;YAAE,KAAK;SAAC,EACb;IAEJ,GACCD,IAAI,CAAC;eAAMb,cAAcF,QAAQ;YAAC;uBAAM,IAAI;;SAAC;OAC7Ce,IAAI,CAACC,SAAAA,QAAU;QACdP,EAAEQ,SAAS,CACTD,QACA;YAAC,IAAI;SAAC,EACN;IAEJ,GACCD,IAAI,CAAC;eAAMb,cAAcF,QAAQ;YAAC;uBAAM,KAAK;;SAAC;OAC9Ce,IAAI,CAACC,SAAAA,QAAU;QACdP,EAAEQ,SAAS,CACTD,QACA;YAAC,KAAK;SAAC,EACP;IAEJ,GACCD,IAAI,CAAC;eACJb,cACEU,SAAAA;mBAASA,SAAS;WAClB;YACE;uBAAM;;YAENC,SAAAA,UAAY;gBACVF,OAAOE;gBAEP,OAAOV,MAAM,IAAI;YACnB;YAEAU,SAAAA,UAAY;gBACVF,OAAOE;gBAEP,OAAOV,MAAM,IAAI;YACnB;YAEAU,SAAAA,UAAY;gBACVF,OAAOE;gBAEP,OAAOV,MAAM,IAAI;YACnB;YAEAU,SAAAA,UAAY;gBACVF,OAAOE;gBAEP,OAAOV,MAAM,IAAI;YACnB;SACD;OAGJY,IAAI,CAACC,SAAAA,QAAU;QACdP,EAAEQ,SAAS,CACT;YAACN;YAAKK;SAAO,EACb;YAAC,IAAI,IAAI;YAAG;gBAAC;gBAAG;gBAAG;aAAI;SAAC,EACxB;QAGFP,EAAES,GAAG;IACP;AACJ"}
|
package/dist/sort/sort-with.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs";
|
|
2
|
-
import _to_consumable_array from "@swc/helpers/src/_to_consumable_array.mjs";
|
|
3
|
-
import { is } from "../is/is.js";
|
|
4
|
-
var _compareTwoValues = function(direction, a, b) {
|
|
5
|
-
var valueIfFieldMissing = direction === "asc" ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
6
|
-
var aValue = is(a) ? a : valueIfFieldMissing;
|
|
7
|
-
var bValue = is(b) ? b : valueIfFieldMissing;
|
|
8
|
-
if (a === null && b === undefined) {
|
|
9
|
-
return direction === "desc" ? -1 : 1;
|
|
10
|
-
}
|
|
11
|
-
if (a === undefined && b === null) {
|
|
12
|
-
return direction === "desc" ? 1 : -1;
|
|
13
|
-
}
|
|
14
|
-
if (aValue === bValue) {
|
|
15
|
-
return 0;
|
|
16
|
-
}
|
|
17
|
-
if (aValue < bValue) {
|
|
18
|
-
return direction === "desc" ? 1 : -1;
|
|
19
|
-
}
|
|
20
|
-
// aValue > bValue
|
|
21
|
-
return direction === "desc" ? -1 : 1;
|
|
22
|
-
};
|
|
23
|
-
var _validateProps = function(subset) {
|
|
24
|
-
var sorters = Object.entries(subset);
|
|
25
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
26
|
-
try {
|
|
27
|
-
for(var _iterator = sorters[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
28
|
-
var _value = _sliced_to_array(_step.value, 2), key = _value[0], sorter = _value[1];
|
|
29
|
-
var ref = _sliced_to_array(Array.isArray(sorter) ? sorter : typeof sorter === "function" ? [
|
|
30
|
-
sorter
|
|
31
|
-
] : [
|
|
32
|
-
undefined,
|
|
33
|
-
sorter
|
|
34
|
-
], 2), sortFn = ref[0], tmp = ref[1], direction = tmp === void 0 ? "asc" : tmp;
|
|
35
|
-
if (direction !== "asc" && direction !== "desc") {
|
|
36
|
-
throw new Error('@asd14/m/sortWith: Unsuported sort direction for key "'.concat(key, '". Accepting "asc" or "desc", received "').concat(direction, '".'));
|
|
37
|
-
}
|
|
38
|
-
if (typeof sortFn === "function" && (sortFn.length === 0 || sortFn.length > 2)) {
|
|
39
|
-
throw new Error('@asd14/m/sortWith: Unsuported sort function signature for key "'.concat(key, '". Accepting function with one or two parameters, received ').concat(sortFn.length, "."));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
} catch (err) {
|
|
43
|
-
_didIteratorError = true;
|
|
44
|
-
_iteratorError = err;
|
|
45
|
-
} finally{
|
|
46
|
-
try {
|
|
47
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
48
|
-
_iterator.return();
|
|
49
|
-
}
|
|
50
|
-
} finally{
|
|
51
|
-
if (_didIteratorError) {
|
|
52
|
-
throw _iteratorError;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
var _sortWith = function(subset, input) {
|
|
58
|
-
_validateProps(subset);
|
|
59
|
-
var sorters = Object.entries(subset);
|
|
60
|
-
return _to_consumable_array(input).sort(function(a, b) {
|
|
61
|
-
for(var i = 0; i < sorters.length; ++i){
|
|
62
|
-
var _i = _sliced_to_array(sorters[i], 2), key = _i[0], sorter = _i[1];
|
|
63
|
-
var ref = _sliced_to_array(Array.isArray(sorter) ? sorter : typeof sorter === "function" ? [
|
|
64
|
-
sorter
|
|
65
|
-
] : [
|
|
66
|
-
undefined,
|
|
67
|
-
sorter
|
|
68
|
-
], 2), sortFn = ref[0], tmp = ref[1], direction = tmp === void 0 ? "asc" : tmp;
|
|
69
|
-
var isLastSorter = i === sorters.length - 1;
|
|
70
|
-
var result = void 0;
|
|
71
|
-
if (typeof sortFn === "function") {
|
|
72
|
-
// one param, treat as lens: (source) => source.field
|
|
73
|
-
// two params, treas as compare func: (a, b) => a - b
|
|
74
|
-
result = sortFn.length === 2 ? sortFn(a[key], b[key]) : _compareTwoValues(direction, sortFn(a[key]), sortFn(b[key]));
|
|
75
|
-
} else {
|
|
76
|
-
// { key: "direction" }
|
|
77
|
-
result = _compareTwoValues(direction, a[key], b[key]);
|
|
78
|
-
}
|
|
79
|
-
if (result !== 0 || isLastSorter) {
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Sort an array of objects by multiple fields
|
|
87
|
-
*
|
|
88
|
-
* @param {Object} subset
|
|
89
|
-
* @param {Array} source
|
|
90
|
-
*
|
|
91
|
-
* @param {...any} params
|
|
92
|
-
* @returns {Array}
|
|
93
|
-
*
|
|
94
|
-
* @name sortWith
|
|
95
|
-
* @tag Array
|
|
96
|
-
* @signature (subset: Object, source: Array): Array
|
|
97
|
-
*
|
|
98
|
-
* @see {@link sort}
|
|
99
|
-
* @see {@link sortBy}
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* sortWith({position: "asc"},
|
|
103
|
-
* { id: 1, position: 3 },
|
|
104
|
-
* { id: 2, position: 2 },
|
|
105
|
-
* { id: 3 },
|
|
106
|
-
* { id: 4, position: 5 },
|
|
107
|
-
* { id: 5, position: null },
|
|
108
|
-
* ])
|
|
109
|
-
* // [
|
|
110
|
-
* // { id: 2, position: 2 },
|
|
111
|
-
* // { id: 1, position: 3 },
|
|
112
|
-
* // { id: 4, position: 5 },
|
|
113
|
-
* // { id: 5, position: null },
|
|
114
|
-
* // { id: 3 },
|
|
115
|
-
* //]
|
|
116
|
-
*/ export var sortWith = function() {
|
|
117
|
-
for(var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++){
|
|
118
|
-
params[_key] = arguments[_key];
|
|
119
|
-
}
|
|
120
|
-
// @signature (subset) => (source)
|
|
121
|
-
if (params.length <= 1) {
|
|
122
|
-
return function(input) {
|
|
123
|
-
return _sortWith(params[0], input);
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
// @signature (subset, source)
|
|
127
|
-
return _sortWith.apply(void 0, _to_consumable_array(params));
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
//# sourceMappingURL=sort-with.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sort/sort-with.js"],"sourcesContent":["import { is } from \"../is/is.js\"\n\nconst _compareTwoValues = (direction, a, b) => {\n const valueIfFieldMissing =\n direction === \"asc\" ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY\n const aValue = is(a) ? a : valueIfFieldMissing\n const bValue = is(b) ? b : valueIfFieldMissing\n\n if (a === null && b === undefined) {\n return direction === \"desc\" ? -1 : 1\n }\n\n if (a === undefined && b === null) {\n return direction === \"desc\" ? 1 : -1\n }\n\n if (aValue === bValue) {\n return 0\n }\n\n if (aValue < bValue) {\n return direction === \"desc\" ? 1 : -1\n }\n\n // aValue > bValue\n return direction === \"desc\" ? -1 : 1\n}\n\nconst _validateProps = subset => {\n const sorters = Object.entries(subset)\n\n for (const [key, sorter] of sorters) {\n const [sortFn, direction = \"asc\"] = Array.isArray(sorter)\n ? sorter\n : typeof sorter === \"function\"\n ? [sorter]\n : [undefined, sorter]\n\n if (direction !== \"asc\" && direction !== \"desc\") {\n throw new Error(\n `@asd14/m/sortWith: Unsuported sort direction for key \"${key}\". Accepting \"asc\" or \"desc\", received \"${direction}\".`\n )\n }\n\n if (\n typeof sortFn === \"function\" &&\n (sortFn.length === 0 || sortFn.length > 2)\n ) {\n throw new Error(\n `@asd14/m/sortWith: Unsuported sort function signature for key \"${key}\". Accepting function with one or two parameters, received ${sortFn.length}.`\n )\n }\n }\n}\n\nconst _sortWith = (subset, input) => {\n _validateProps(subset)\n\n const sorters = Object.entries(subset)\n\n return [...input].sort((a, b) => {\n for (let i = 0; i < sorters.length; ++i) {\n const [key, sorter] = sorters[i]\n const [sortFn, direction = \"asc\"] = Array.isArray(sorter)\n ? sorter\n : typeof sorter === \"function\"\n ? [sorter]\n : [undefined, sorter]\n const isLastSorter = i === sorters.length - 1\n\n let result\n\n if (typeof sortFn === \"function\") {\n // one param, treat as lens: (source) => source.field\n // two params, treas as compare func: (a, b) => a - b\n\n result =\n sortFn.length === 2\n ? sortFn(a[key], b[key])\n : _compareTwoValues(direction, sortFn(a[key]), sortFn(b[key]))\n } else {\n // { key: \"direction\" }\n result = _compareTwoValues(direction, a[key], b[key])\n }\n\n if (result !== 0 || isLastSorter) {\n return result\n }\n }\n })\n}\n\n/**\n * Sort an array of objects by multiple fields\n *\n * @param {Object} subset\n * @param {Array} source\n *\n * @param {...any} params\n * @returns {Array}\n *\n * @name sortWith\n * @tag Array\n * @signature (subset: Object, source: Array): Array\n *\n * @see {@link sort}\n * @see {@link sortBy}\n *\n * @example\n * sortWith({position: \"asc\"},\n * { id: 1, position: 3 },\n * { id: 2, position: 2 },\n * { id: 3 },\n * { id: 4, position: 5 },\n * { id: 5, position: null },\n * ])\n * // [\n * // { id: 2, position: 2 },\n * // { id: 1, position: 3 },\n * // { id: 4, position: 5 },\n * // { id: 5, position: null },\n * // { id: 3 },\n * //]\n */\nexport const sortWith = (...params) => {\n // @signature (subset) => (source)\n if (params.length <= 1) {\n return input => _sortWith(params[0], input)\n }\n\n // @signature (subset, source)\n return _sortWith(...params)\n}\n"],"names":["is","_compareTwoValues","direction","a","b","valueIfFieldMissing","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","aValue","bValue","undefined","_validateProps","subset","sorters","Object","entries","key","sorter","Array","isArray","sortFn","Error","length","_sortWith","input","sort","i","isLastSorter","result","sortWith","params"],"mappings":"AAAA;;AAAA,SAASA,EAAE,QAAQ,cAAa;AAEhC,IAAMC,oBAAoB,SAACC,WAAWC,GAAGC,GAAM;IAC7C,IAAMC,sBACJH,cAAc,QAAQI,OAAOC,iBAAiB,GAAGD,OAAOE,iBAAiB;IAC3E,IAAMC,SAAST,GAAGG,KAAKA,IAAIE,mBAAmB;IAC9C,IAAMK,SAASV,GAAGI,KAAKA,IAAIC,mBAAmB;IAE9C,IAAIF,MAAM,IAAI,IAAIC,MAAMO,WAAW;QACjC,OAAOT,cAAc,SAAS,CAAC,IAAI,CAAC;IACtC,CAAC;IAED,IAAIC,MAAMQ,aAAaP,MAAM,IAAI,EAAE;QACjC,OAAOF,cAAc,SAAS,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,IAAIO,WAAWC,QAAQ;QACrB,OAAO;IACT,CAAC;IAED,IAAID,SAASC,QAAQ;QACnB,OAAOR,cAAc,SAAS,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,kBAAkB;IAClB,OAAOA,cAAc,SAAS,CAAC,IAAI,CAAC;AACtC;AAEA,IAAMU,iBAAiBC,SAAAA,QAAU;IAC/B,IAAMC,UAAUC,OAAOC,OAAO,CAACH;QAE1B,kCAAA,2BAAA;;QAAL,QAAK,YAAuBC,4BAAvB,SAAA,6BAAA,QAAA,yBAAA,iCAAgC;YAAhC,8BAAA,iBAAOG,iBAAKC;YACf,IAAoCC,uBAAAA,MAAMC,OAAO,CAACF,UAC9CA,SACA,OAAOA,WAAW,aAClB;gBAACA;aAAO,GACR;gBAACP;gBAAWO;aAAO,MAJhBG,SAA6BF,QAArBjB,MAAqBiB,QAArBjB,YAAAA,iBAAY,QAAZA;YAMf,IAAIA,cAAc,SAASA,cAAc,QAAQ;gBAC/C,MAAM,IAAIoB,MACR,AAAC,yDAAsGpB,OAA9Ce,KAAI,4CAAoD,OAAVf,WAAU,OAClH;YACH,CAAC;YAED,IACE,OAAOmB,WAAW,cACjBA,CAAAA,OAAOE,MAAM,KAAK,KAAKF,OAAOE,MAAM,GAAG,CAAA,GACxC;gBACA,MAAM,IAAID,MACR,AAAC,kEAAkID,OAAjEJ,KAAI,+DAA2E,OAAdI,OAAOE,MAAM,EAAC,MAClJ;YACH,CAAC;QACH;;QArBK;QAAA;;;iBAAA,6BAAA;gBAAA;;;gBAAA;sBAAA;;;;AAsBP;AAEA,IAAMC,YAAY,SAACX,QAAQY,OAAU;IACnCb,eAAeC;IAEf,IAAMC,UAAUC,OAAOC,OAAO,CAACH;IAE/B,OAAO,AAAC,qBAAGY,OAAOC,IAAI,CAAC,SAACvB,GAAGC,GAAM;QAC/B,IAAK,IAAIuB,IAAI,GAAGA,IAAIb,QAAQS,MAAM,EAAE,EAAEI,EAAG;YACvC,IAAsBb,sBAAAA,OAAO,CAACa,EAAE,MAAzBV,MAAeH,OAAVI,SAAUJ;YACtB,IAAoCK,uBAAAA,MAAMC,OAAO,CAACF,UAC9CA,SACA,OAAOA,WAAW,aAClB;gBAACA;aAAO,GACR;gBAACP;gBAAWO;aAAO,MAJhBG,SAA6BF,QAArBjB,MAAqBiB,QAArBjB,YAAAA,iBAAY,QAAZA;YAKf,IAAM0B,eAAeD,MAAMb,QAAQS,MAAM,GAAG;YAE5C,IAAIM,SAAAA,KAAAA;YAEJ,IAAI,OAAOR,WAAW,YAAY;gBAChC,qDAAqD;gBACrD,qDAAqD;gBAErDQ,SACER,OAAOE,MAAM,KAAK,IACdF,OAAOlB,CAAC,CAACc,IAAI,EAAEb,CAAC,CAACa,IAAI,IACrBhB,kBAAkBC,WAAWmB,OAAOlB,CAAC,CAACc,IAAI,GAAGI,OAAOjB,CAAC,CAACa,IAAI,EAAE;YACpE,OAAO;gBACL,uBAAuB;gBACvBY,SAAS5B,kBAAkBC,WAAWC,CAAC,CAACc,IAAI,EAAEb,CAAC,CAACa,IAAI;YACtD,CAAC;YAED,IAAIY,WAAW,KAAKD,cAAc;gBAChC,OAAOC;YACT,CAAC;QACH;IACF;AACF;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GACD,OAAO,IAAMC,WAAW,WAAe;qCAAXC;QAAAA;;IAC1B,kCAAkC;IAClC,IAAIA,OAAOR,MAAM,IAAI,GAAG;QACtB,OAAOE,SAAAA;mBAASD,UAAUO,MAAM,CAAC,EAAE,EAAEN;;IACvC,CAAC;IAED,8BAA8B;IAC9B,OAAOD,UAAAA,MAAAA,KAAAA,GAAU,qBAAGO;AACtB,EAAC"}
|