@asd14/m 6.6.0 → 7.3.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 +9 -10
- package/dist/all/all.js +14 -27
- package/dist/all/all.js.map +1 -0
- package/dist/all/all.test.js +18 -24
- package/dist/all/all.test.js.map +1 -0
- package/dist/any/any.js +16 -29
- package/dist/any/any.js.map +1 -0
- package/dist/any/any.test.js +16 -21
- package/dist/any/any.test.js.map +1 -0
- package/dist/append/append.js +8 -18
- package/dist/append/append.js.map +1 -0
- package/dist/append/append.test.js +10 -15
- package/dist/append/append.test.js.map +1 -0
- package/dist/bottom/bottom.js +8 -16
- package/dist/bottom/bottom.js.map +1 -0
- package/dist/bottom/bottom.test.js +16 -21
- package/dist/bottom/bottom.test.js.map +1 -0
- package/dist/cases/cases.js +11 -24
- package/dist/cases/cases.js.map +1 -0
- package/dist/cases/cases.test.js +8 -13
- package/dist/cases/cases.test.js.map +1 -0
- package/dist/clone/clone.js +20 -33
- package/dist/clone/clone.js.map +1 -0
- package/dist/clone/clone.test.js +16 -21
- package/dist/clone/clone.test.js.map +1 -0
- package/dist/compact/compact.js +21 -35
- package/dist/compact/compact.js.map +1 -0
- package/dist/compact/compact.test.js +17 -21
- package/dist/compact/compact.test.js.map +1 -0
- package/dist/contains/contains.js +6 -13
- package/dist/contains/contains.js.map +1 -0
- package/dist/contains/contains.test.js +9 -14
- package/dist/contains/contains.test.js.map +1 -0
- package/dist/converge/converge.js +11 -22
- package/dist/converge/converge.js.map +1 -0
- package/dist/converge/converge.test.js +18 -24
- package/dist/converge/converge.test.js.map +1 -0
- package/dist/count/count.js +22 -40
- package/dist/count/count.js.map +1 -0
- package/dist/count/count.test.js +26 -34
- package/dist/count/count.test.js.map +1 -0
- package/dist/curry/curry.js +5 -15
- package/dist/curry/curry.js.map +1 -0
- package/dist/curry/curry.test.js +9 -48
- package/dist/curry/curry.test.js.map +1 -0
- package/dist/debounce/debounce.js +2 -8
- package/dist/debounce/debounce.js.map +1 -0
- package/dist/debounce/debounce.test.js +9 -14
- package/dist/debounce/debounce.test.js.map +1 -0
- package/dist/dec/dec.js +5 -13
- package/dist/dec/dec.js.map +1 -0
- package/dist/dec/dec.test.js +6 -11
- package/dist/dec/dec.test.js.map +1 -0
- package/dist/deep-equal/deep-equal.bench.js +28 -37
- package/dist/deep-equal/deep-equal.bench.js.map +1 -0
- package/dist/deep-equal/deep-equal.js +5 -83
- package/dist/deep-equal/deep-equal.js.map +1 -0
- package/dist/deep-equal/deep-equal.own.js +117 -0
- package/dist/deep-equal/deep-equal.own.js.map +1 -0
- package/dist/deep-equal/deep-equal.test.js +34 -32
- package/dist/deep-equal/deep-equal.test.js.map +1 -0
- package/dist/distinct/distinct.bench.js +13 -19
- package/dist/distinct/distinct.bench.js.map +1 -0
- package/dist/distinct/distinct.js +13 -24
- package/dist/distinct/distinct.js.map +1 -0
- package/dist/distinct/distinct.test.js +20 -82
- package/dist/distinct/distinct.test.js.map +1 -0
- package/dist/drop-last/drop-last.js +9 -17
- package/dist/drop-last/drop-last.js.map +1 -0
- package/dist/drop-last/drop-last.test.js +11 -16
- package/dist/drop-last/drop-last.test.js.map +1 -0
- package/dist/elapsed-time/elapsed-time.js +3 -11
- package/dist/elapsed-time/elapsed-time.js.map +1 -0
- package/dist/elapsed-time/elapsed-time.test.js +6 -11
- package/dist/elapsed-time/elapsed-time.test.js.map +1 -0
- package/dist/ends-with/ends-with.js +7 -14
- package/dist/ends-with/ends-with.js.map +1 -0
- package/dist/ends-with/ends-with.test.js +10 -15
- package/dist/ends-with/ends-with.test.js.map +1 -0
- package/dist/escape/escape.js +5 -12
- package/dist/escape/escape.js.map +1 -0
- package/dist/escape-html/escape-html.js +3 -11
- package/dist/escape-html/escape-html.js.map +1 -0
- package/dist/escape-html/escape-html.test.js +6 -11
- package/dist/escape-html/escape-html.test.js.map +1 -0
- package/dist/escape-reg-exp/escape-reg-exp.js +4 -11
- package/dist/escape-reg-exp/escape-reg-exp.js.map +1 -0
- package/dist/escape-reg-exp/escape-reg-exp.test.js +7 -12
- package/dist/escape-reg-exp/escape-reg-exp.test.js.map +1 -0
- package/dist/filter/filter.js +15 -28
- package/dist/filter/filter.js.map +1 -0
- package/dist/filter/filter.test.js +14 -21
- package/dist/filter/filter.test.js.map +1 -0
- package/dist/find/find.js +18 -32
- package/dist/find/find.js.map +1 -0
- package/dist/find/find.test.js +23 -19
- package/dist/find/find.test.js.map +1 -0
- package/dist/find-index/find-index.js +13 -26
- package/dist/find-index/find-index.js.map +1 -0
- package/dist/find-index/find-index.test.js +12 -17
- package/dist/find-index/find-index.test.js.map +1 -0
- package/dist/first/first.js +4 -12
- package/dist/first/first.js.map +1 -0
- package/dist/first/first.test.js +11 -16
- package/dist/first/first.test.js.map +1 -0
- package/dist/flatten/flatten.js +23 -36
- package/dist/flatten/flatten.js.map +1 -0
- package/dist/flatten/flatten.test.js +11 -16
- package/dist/flatten/flatten.test.js.map +1 -0
- package/dist/for-each/for-each.js +10 -21
- package/dist/for-each/for-each.js.map +1 -0
- package/dist/for-each/for-each.test.js +8 -14
- package/dist/for-each/for-each.test.js.map +1 -0
- package/dist/group-by/group-by.js +8 -15
- package/dist/group-by/group-by.js.map +1 -0
- package/dist/group-by/group-by.test.js +7 -12
- package/dist/group-by/group-by.test.js.map +1 -0
- package/dist/gt/gt.js +3 -10
- package/dist/gt/gt.js.map +1 -0
- package/dist/gt/gt.test.js +9 -14
- package/dist/gt/gt.test.js.map +1 -0
- package/dist/has-key/has-key.js +6 -14
- package/dist/has-key/has-key.js.map +1 -0
- package/dist/has-key/has-key.test.js +8 -13
- package/dist/has-key/has-key.test.js.map +1 -0
- package/dist/hist/hist.js +14 -21
- package/dist/hist/hist.js.map +1 -0
- package/dist/hist/hist.test.js +8 -13
- package/dist/hist/hist.test.js.map +1 -0
- package/dist/i/i.js +4 -12
- package/dist/i/i.js.map +1 -0
- package/dist/i/i.test.js +10 -15
- package/dist/i/i.test.js.map +1 -0
- package/dist/inc/inc.js +4 -12
- package/dist/inc/inc.js.map +1 -0
- package/dist/inc/inc.test.js +6 -11
- package/dist/inc/inc.test.js.map +1 -0
- package/dist/index-by/index-by.js +8 -15
- package/dist/index-by/index-by.js.map +1 -0
- package/dist/index-by/index-by.test.js +7 -12
- package/dist/index-by/index-by.test.js.map +1 -0
- package/dist/index.js +98 -1023
- package/dist/index.js.map +1 -0
- package/dist/index.test.js +6 -9
- package/dist/index.test.js.map +1 -0
- package/dist/intersect/intersect.js +11 -22
- package/dist/intersect/intersect.js.map +1 -0
- package/dist/intersect/intersect.test.js +40 -106
- package/dist/intersect/intersect.test.js.map +1 -0
- package/dist/is/is.js +18 -36
- package/dist/is/is.js.map +1 -0
- package/dist/is/is.test.js +26 -31
- package/dist/is/is.test.js.map +1 -0
- package/dist/is-between/is-between.js +4 -12
- package/dist/is-between/is-between.js.map +1 -0
- package/dist/is-between/is-between.test.js +10 -15
- package/dist/is-between/is-between.test.js.map +1 -0
- package/dist/is-empty/is-empty.js +16 -28
- package/dist/is-empty/is-empty.js.map +1 -0
- package/dist/is-empty/is-empty.test.js +23 -28
- package/dist/is-empty/is-empty.test.js.map +1 -0
- package/dist/is-equal/is-equal.js +3 -10
- package/dist/is-equal/is-equal.js.map +1 -0
- package/dist/is-equal/is-equal.test.js +12 -17
- package/dist/is-equal/is-equal.test.js.map +1 -0
- package/dist/is-match/is-match.js +13 -26
- package/dist/is-match/is-match.js.map +1 -0
- package/dist/is-match/is-match.test.js +26 -24
- package/dist/is-match/is-match.test.js.map +1 -0
- package/dist/is-uri/is-uri.js +6 -17
- package/dist/is-uri/is-uri.js.map +1 -0
- package/dist/is-uri/is-uri.test.js +15 -85
- package/dist/is-uri/is-uri.test.js.map +1 -0
- package/dist/join/join.js +11 -22
- package/dist/join/join.js.map +1 -0
- package/dist/join/join.test.js +42 -108
- package/dist/join/join.test.js.map +1 -0
- package/dist/keys/keys.js +7 -17
- package/dist/keys/keys.js.map +1 -0
- package/dist/keys/keys.test.js +9 -14
- package/dist/keys/keys.test.js.map +1 -0
- package/dist/last/last.js +6 -12
- package/dist/last/last.js.map +1 -0
- package/dist/last/last.test.js +10 -15
- package/dist/last/last.test.js.map +1 -0
- package/dist/lt/lt.js +7 -13
- package/dist/lt/lt.js.map +1 -0
- package/dist/lt/lt.test.js +8 -13
- package/dist/lt/lt.test.js.map +1 -0
- package/dist/map/map.js +13 -24
- package/dist/map/map.js.map +1 -0
- package/dist/map/map.test.js +13 -17
- package/dist/map/map.test.js.map +1 -0
- package/dist/map-matrix/map-matrix.js +14 -25
- package/dist/map-matrix/map-matrix.js.map +1 -0
- package/dist/map-matrix/map-matrix.test.js +9 -13
- package/dist/map-matrix/map-matrix.test.js.map +1 -0
- package/dist/max/max.js +26 -40
- package/dist/max/max.js.map +1 -0
- package/dist/max/max.test.js +14 -20
- package/dist/max/max.test.js.map +1 -0
- package/dist/merge/merge.js +18 -34
- package/dist/merge/merge.js.map +1 -0
- package/dist/merge/merge.test.js +12 -17
- package/dist/merge/merge.test.js.map +1 -0
- package/dist/min/min.js +26 -40
- package/dist/min/min.js.map +1 -0
- package/dist/min/min.test.js +13 -19
- package/dist/min/min.test.js.map +1 -0
- package/dist/move/move.js +15 -25
- package/dist/move/move.js.map +1 -0
- package/dist/move/move.test.js +10 -15
- package/dist/move/move.test.js.map +1 -0
- package/dist/mutate/mutate.js +31 -51
- package/dist/mutate/mutate.js.map +1 -0
- package/dist/mutate/mutate.test.js +19 -23
- package/dist/mutate/mutate.test.js.map +1 -0
- package/dist/page/page.js +6 -14
- package/dist/page/page.js.map +1 -0
- package/dist/page/page.test.js +9 -14
- package/dist/page/page.test.js.map +1 -0
- package/dist/partition/partition.js +17 -31
- package/dist/partition/partition.js.map +1 -0
- package/dist/partition/partition.test.js +14 -20
- package/dist/partition/partition.test.js.map +1 -0
- package/dist/pick/pick.js +12 -20
- package/dist/pick/pick.js.map +1 -0
- package/dist/pick/pick.test.js +8 -13
- package/dist/pick/pick.test.js.map +1 -0
- package/dist/pipe/pipe.js +4 -12
- package/dist/pipe/pipe.js.map +1 -0
- package/dist/pipe/pipe.test.js +9 -13
- package/dist/pipe/pipe.test.js.map +1 -0
- package/dist/pipe-p/pipe-p.js +4 -10
- package/dist/pipe-p/pipe-p.js.map +1 -0
- package/dist/pipe-p/pipe-p.test.js +10 -15
- package/dist/pipe-p/pipe-p.test.js.map +1 -0
- package/dist/pluck/pluck.js +18 -26
- package/dist/pluck/pluck.js.map +1 -0
- package/dist/pluck/pluck.test.js +10 -15
- package/dist/pluck/pluck.test.js.map +1 -0
- package/dist/prepend/prepend.js +11 -21
- package/dist/prepend/prepend.js.map +1 -0
- package/dist/prepend/prepend.test.js +10 -15
- package/dist/prepend/prepend.test.js.map +1 -0
- package/dist/proto-chain/proto-chain.js +9 -17
- package/dist/proto-chain/proto-chain.js.map +1 -0
- package/dist/proto-chain/proto-chain.test.js +8 -13
- package/dist/proto-chain/proto-chain.test.js.map +1 -0
- package/dist/push/push.js +7 -15
- package/dist/push/push.js.map +1 -0
- package/dist/push/push.test.js +9 -14
- package/dist/push/push.test.js.map +1 -0
- package/dist/raise/raise.js +2 -8
- package/dist/raise/raise.js.map +1 -0
- package/dist/raise/raise.test.js +6 -11
- package/dist/raise/raise.test.js.map +1 -0
- package/dist/random/random.js +3 -11
- package/dist/random/random.js.map +1 -0
- package/dist/random/random.test.js +16 -17
- package/dist/random/random.test.js.map +1 -0
- package/dist/read/read.js +23 -40
- package/dist/read/read.js.map +1 -0
- package/dist/read/read.test.js +63 -179
- package/dist/read/read.test.js.map +1 -0
- package/dist/reduce/reduce.js +17 -28
- package/dist/reduce/reduce.js.map +1 -0
- package/dist/reduce/reduce.test.js +14 -19
- package/dist/reduce/reduce.test.js.map +1 -0
- package/dist/remove/remove.js +27 -42
- package/dist/remove/remove.js.map +1 -0
- package/dist/remove/remove.test.js +14 -21
- package/dist/remove/remove.test.js.map +1 -0
- package/dist/rename/rename.js +26 -40
- package/dist/rename/rename.js.map +1 -0
- package/dist/rename/rename.test.js +42 -103
- package/dist/rename/rename.test.js.map +1 -0
- package/dist/rename-file/rename-file.js +14 -28
- package/dist/rename-file/rename-file.js.map +1 -0
- package/dist/rename-file/rename-file.test.js +11 -16
- package/dist/rename-file/rename-file.test.js.map +1 -0
- package/dist/repeat/repeat.js +10 -21
- package/dist/repeat/repeat.js.map +1 -0
- package/dist/repeat/repeat.test.js +10 -14
- package/dist/repeat/repeat.test.js.map +1 -0
- package/dist/replace/replace.js +17 -27
- package/dist/replace/replace.js.map +1 -0
- package/dist/replace/replace.test.js +17 -22
- package/dist/replace/replace.test.js.map +1 -0
- package/dist/same/same.js +4 -12
- package/dist/same/same.js.map +1 -0
- package/dist/same/same.test.js +6 -11
- package/dist/same/same.test.js.map +1 -0
- package/dist/sequence/sequence.js +10 -21
- package/dist/sequence/sequence.js.map +1 -0
- package/dist/sequence/sequence.test.js +17 -22
- package/dist/sequence/sequence.test.js.map +1 -0
- package/dist/sort/sort-with.js +15 -27
- package/dist/sort/sort-with.js.map +1 -0
- package/dist/sort/sort.js +19 -31
- package/dist/sort/sort.js.map +1 -0
- package/dist/sort/sort.test.js +298 -368
- package/dist/sort/sort.test.js.map +1 -0
- package/dist/split/split.js +15 -25
- package/dist/split/split.js.map +1 -0
- package/dist/split/split.test.js +14 -59
- package/dist/split/split.test.js.map +1 -0
- package/dist/split-in-groups-of/split-in-groups-of.js +10 -20
- package/dist/split-in-groups-of/split-in-groups-of.js.map +1 -0
- package/dist/split-in-groups-of/split-in-groups-of.test.js +17 -77
- package/dist/split-in-groups-of/split-in-groups-of.test.js.map +1 -0
- package/dist/spy/spy.js +5 -13
- package/dist/spy/spy.js.map +1 -0
- package/dist/spy/spy.test.js +25 -70
- package/dist/spy/spy.test.js.map +1 -0
- package/dist/starts-with/starts-with.js +5 -12
- package/dist/starts-with/starts-with.js.map +1 -0
- package/dist/starts-with/starts-with.test.js +11 -16
- package/dist/starts-with/starts-with.test.js.map +1 -0
- package/dist/throttle/throttle.js +2 -8
- package/dist/throttle/throttle.js.map +1 -0
- package/dist/throttle/throttle.test.js +11 -16
- package/dist/throttle/throttle.test.js.map +1 -0
- package/dist/to-lower/to-lower.js +4 -12
- package/dist/to-lower/to-lower.js.map +1 -0
- package/dist/to-lower/to-lower.test.js +7 -12
- package/dist/to-lower/to-lower.test.js.map +1 -0
- package/dist/to-upper/to-upper.js +4 -12
- package/dist/to-upper/to-upper.js.map +1 -0
- package/dist/to-upper/to-upper.test.js +7 -12
- package/dist/to-upper/to-upper.test.js.map +1 -0
- package/dist/toggle/toggle.js +12 -22
- package/dist/toggle/toggle.js.map +1 -0
- package/dist/toggle/toggle.test.js +8 -13
- package/dist/toggle/toggle.test.js.map +1 -0
- package/dist/top/top.js +10 -16
- package/dist/top/top.js.map +1 -0
- package/dist/top/top.test.js +16 -21
- package/dist/top/top.test.js.map +1 -0
- package/dist/trim/trim.js +9 -15
- package/dist/trim/trim.js.map +1 -0
- package/dist/trim/trim.test.js +8 -13
- package/dist/trim/trim.test.js.map +1 -0
- package/dist/try-catch/try-catch.js +6 -12
- package/dist/try-catch/try-catch.js.map +1 -0
- package/dist/try-catch/try-catch.test.js +10 -16
- package/dist/try-catch/try-catch.test.js.map +1 -0
- package/dist/type/type.js +5 -11
- package/dist/type/type.js.map +1 -0
- package/dist/type/type.test.js +17 -22
- package/dist/type/type.test.js.map +1 -0
- package/dist/unite/unite.js +5 -12
- package/dist/unite/unite.js.map +1 -0
- package/dist/unite/unite.test.js +7 -37
- package/dist/unite/unite.test.js.map +1 -0
- package/dist/update/update.js +27 -45
- package/dist/update/update.js.map +1 -0
- package/dist/update/update.test.js +17 -21
- package/dist/update/update.test.js.map +1 -0
- package/dist/upsert/upsert.js +11 -20
- package/dist/upsert/upsert.js.map +1 -0
- package/dist/upsert/upsert.test.js +12 -17
- package/dist/upsert/upsert.test.js.map +1 -0
- package/dist/values/values.js +8 -19
- package/dist/values/values.js.map +1 -0
- package/dist/values/values.test.js +9 -14
- package/dist/values/values.test.js.map +1 -0
- package/dist/when/when.js +16 -27
- package/dist/when/when.js.map +1 -0
- package/dist/when/when.test.js +18 -24
- package/dist/when/when.test.js.map +1 -0
- package/dist/write/write.js +8 -16
- package/dist/write/write.js.map +1 -0
- package/dist/write/write.test.js +9 -14
- package/dist/write/write.test.js.map +1 -0
- package/dist/zip-to-object/zip-to-object.js +5 -11
- package/dist/zip-to-object/zip-to-object.js.map +1 -0
- package/dist/zip-to-object/zip-to-object.test.js +8 -13
- package/dist/zip-to-object/zip-to-object.test.js.map +1 -0
- package/package.json +33 -32
package/dist/move/move.test.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _move = require("./move");
|
|
8
|
-
|
|
9
|
-
(0, _tape.default)("move", function (t) {
|
|
10
|
-
t.deepEqual((0, _move.move)(0, 1, [1, 2]), [2, 1], "Move element from and to valid positions (uncurried)");
|
|
11
|
-
t.deepEqual((0, _move.move)(0, 1, [{
|
|
1
|
+
import test from "tape";
|
|
2
|
+
import { move } from "./move.js";
|
|
3
|
+
test("move", function (t) {
|
|
4
|
+
t.deepEqual(move(0, 1, [1, 2]), [2, 1], "Move element from and to valid positions (uncurried)");
|
|
5
|
+
t.deepEqual(move(0, 1, [{
|
|
12
6
|
id: 1
|
|
13
7
|
}, {
|
|
14
8
|
id: 2
|
|
@@ -17,8 +11,9 @@ var _move = require("./move");
|
|
|
17
11
|
}, {
|
|
18
12
|
id: 1
|
|
19
13
|
}], "Move element from and to valid positions (curried)");
|
|
20
|
-
t.deepEqual(
|
|
21
|
-
t.deepEqual(
|
|
22
|
-
t.deepEqual(
|
|
14
|
+
t.deepEqual(move(0, 100, [1, 2, 3, 4]), [2, 3, 4, 1], "Move element from valid position to out-of-bounds should move it at end of array");
|
|
15
|
+
t.deepEqual(move(1, -1, [1, 2, 3, 4]), [1, 3, 4, 2], "Move element from valid position to negative position should move it at position starting from the end");
|
|
16
|
+
t.deepEqual(move(-1, 0, [1, 2, 3, 4]), [4, 1, 2, 3], "Move element from negative position to valid position");
|
|
23
17
|
t.end();
|
|
24
|
-
});
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=move.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/move/move.test.js"],"names":["test","move","t","deepEqual","id","end"],"mappings":"AAAA,OAAOA,IAAP,MAAiB,MAAjB;AAEA,SAASC,IAAT,QAAqB,WAArB;AAEAD,IAAI,CAAC,MAAD,EAAS,UAAAE,CAAC,EAAI;AAChBA,EAAAA,CAAC,CAACC,SAAF,CACEF,IAAI,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAC,CAAD,EAAI,CAAJ,CAAP,CADN,EAEE,CAAC,CAAD,EAAI,CAAJ,CAFF,EAGE,sDAHF;AAMAC,EAAAA,CAAC,CAACC,SAAF,CACEF,IAAI,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAC;AAAEG,IAAAA,EAAE,EAAE;AAAN,GAAD,EAAY;AAAEA,IAAAA,EAAE,EAAE;AAAN,GAAZ,CAAP,CADN,EAEE,CAAC;AAAEA,IAAAA,EAAE,EAAE;AAAN,GAAD,EAAY;AAAEA,IAAAA,EAAE,EAAE;AAAN,GAAZ,CAFF,EAGE,oDAHF;AAMAF,EAAAA,CAAC,CAACC,SAAF,CACEF,IAAI,CAAC,CAAD,EAAI,GAAJ,EAAS,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAAT,CADN,EAEE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAFF,EAGE,kFAHF;AAMAC,EAAAA,CAAC,CAACC,SAAF,CACEF,IAAI,CAAC,CAAD,EAAI,CAAC,CAAL,EAAQ,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAAR,CADN,EAEE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAFF,EAGE,wGAHF;AAMAC,EAAAA,CAAC,CAACC,SAAF,CACEF,IAAI,CAAC,CAAC,CAAF,EAAK,CAAL,EAAQ,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAAR,CADN,EAEE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAFF,EAGE,uDAHF;AAMAC,EAAAA,CAAC,CAACG,GAAF;AACD,CAhCG,CAAJ","sourcesContent":["import test from \"tape\"\n\nimport { move } from \"./move.js\"\n\ntest(\"move\", t => {\n t.deepEqual(\n move(0, 1, [1, 2]),\n [2, 1],\n \"Move element from and to valid positions (uncurried)\"\n )\n\n t.deepEqual(\n move(0, 1, [{ id: 1 }, { id: 2 }]),\n [{ id: 2 }, { id: 1 }],\n \"Move element from and to valid positions (curried)\"\n )\n\n t.deepEqual(\n move(0, 100, [1, 2, 3, 4]),\n [2, 3, 4, 1],\n \"Move element from valid position to out-of-bounds should move it at end of array\"\n )\n\n t.deepEqual(\n move(1, -1, [1, 2, 3, 4]),\n [1, 3, 4, 2],\n \"Move element from valid position to negative position should move it at position starting from the end\"\n )\n\n t.deepEqual(\n move(-1, 0, [1, 2, 3, 4]),\n [4, 1, 2, 3],\n \"Move element from negative position to valid position\"\n )\n\n t.end()\n})\n"],"file":"move.test.js"}
|
package/dist/mutate/mutate.js
CHANGED
|
@@ -1,115 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.mutateWith = exports.mutateMany = exports.mutate = void 0;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
|
-
var _map = require("../map/map");
|
|
17
|
-
|
|
18
|
-
var _pipe = require("../pipe/pipe");
|
|
19
|
-
|
|
20
|
-
var _isMatch = require("../is-match/is-match");
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
21
4
|
|
|
22
5
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
23
6
|
|
|
24
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (
|
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
|
+
|
|
9
|
+
import { map } from "../map/map.js";
|
|
10
|
+
import { pipe } from "../pipe/pipe.js";
|
|
11
|
+
import { isMatch } from "../is-match/is-match.js";
|
|
25
12
|
|
|
26
|
-
var _mutate = function _mutate(transformations,
|
|
13
|
+
var _mutate = function _mutate(transformations, input) {
|
|
27
14
|
var entries = Object.entries(transformations);
|
|
28
15
|
|
|
29
|
-
var result = _objectSpread({},
|
|
16
|
+
var result = _objectSpread({}, input);
|
|
30
17
|
|
|
31
18
|
for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
|
|
32
|
-
var _entries$_i = (
|
|
19
|
+
var _entries$_i = _slicedToArray(_entries[_i], 2),
|
|
33
20
|
key = _entries$_i[0],
|
|
34
21
|
value = _entries$_i[1];
|
|
35
22
|
|
|
36
|
-
if (
|
|
37
|
-
var transform = Array.isArray(value) ?
|
|
38
|
-
result[key] = typeof transform === "function" ? transform(
|
|
23
|
+
if (input.hasOwnProperty(key)) {
|
|
24
|
+
var transform = Array.isArray(value) ? pipe.apply(void 0, _toConsumableArray(value)) : value;
|
|
25
|
+
result[key] = typeof transform === "function" ? transform(input[key], input) : transform;
|
|
39
26
|
}
|
|
40
27
|
}
|
|
41
28
|
|
|
42
29
|
return result;
|
|
43
30
|
};
|
|
44
31
|
|
|
45
|
-
var _mutateWith = function _mutateWith(filter, transformations,
|
|
32
|
+
var _mutateWith = function _mutateWith(filter, transformations, input) {
|
|
46
33
|
var result = [];
|
|
47
34
|
|
|
48
|
-
for (var i = 0, length =
|
|
49
|
-
var item =
|
|
50
|
-
var shouldMutate =
|
|
35
|
+
for (var i = 0, length = input.length; i < length; ++i) {
|
|
36
|
+
var item = input[i];
|
|
37
|
+
var shouldMutate = isMatch(filter, item);
|
|
51
38
|
result.push(shouldMutate ? _mutate(transformations, item) : item);
|
|
52
39
|
}
|
|
53
40
|
|
|
54
41
|
return result;
|
|
55
42
|
};
|
|
56
43
|
|
|
57
|
-
var _mutateMany = function _mutateMany(transformations,
|
|
58
|
-
return
|
|
44
|
+
var _mutateMany = function _mutateMany(transformations, input) {
|
|
45
|
+
return map(function (item) {
|
|
59
46
|
return _mutate(transformations, item);
|
|
60
|
-
},
|
|
47
|
+
}, input);
|
|
61
48
|
};
|
|
62
49
|
|
|
63
|
-
var mutate = function mutate() {
|
|
50
|
+
export var mutate = function mutate() {
|
|
64
51
|
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
65
52
|
params[_key] = arguments[_key];
|
|
66
53
|
}
|
|
67
54
|
|
|
68
55
|
// @signature (transformations) => (source)
|
|
69
56
|
if (params.length <= 1) {
|
|
70
|
-
return function (
|
|
71
|
-
return _mutate(params[0],
|
|
57
|
+
return function (input) {
|
|
58
|
+
return _mutate(params[0], input);
|
|
72
59
|
};
|
|
73
60
|
} // @signature (transformations, source)
|
|
74
61
|
|
|
75
62
|
|
|
76
63
|
return _mutate.apply(void 0, params);
|
|
77
64
|
};
|
|
78
|
-
|
|
79
|
-
exports.mutate = mutate;
|
|
80
|
-
|
|
81
|
-
var mutateMany = function mutateMany() {
|
|
65
|
+
export var mutateMany = function mutateMany() {
|
|
82
66
|
for (var _len2 = arguments.length, params = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
83
67
|
params[_key2] = arguments[_key2];
|
|
84
68
|
}
|
|
85
69
|
|
|
86
70
|
// @signature (transformations) => (source)
|
|
87
71
|
if (params.length <= 1) {
|
|
88
|
-
return function (
|
|
89
|
-
return _mutateMany(params[0],
|
|
72
|
+
return function (input) {
|
|
73
|
+
return _mutateMany(params[0], input);
|
|
90
74
|
};
|
|
91
75
|
} // @signature (transformations, source)
|
|
92
76
|
|
|
93
77
|
|
|
94
78
|
return _mutateMany.apply(void 0, params);
|
|
95
79
|
};
|
|
96
|
-
|
|
97
|
-
exports.mutateMany = mutateMany;
|
|
98
|
-
|
|
99
|
-
var mutateWith = function mutateWith() {
|
|
80
|
+
export var mutateWith = function mutateWith() {
|
|
100
81
|
for (var _len3 = arguments.length, params = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
101
82
|
params[_key3] = arguments[_key3];
|
|
102
83
|
}
|
|
103
84
|
|
|
104
85
|
// @signature (filter, transformations) => (source)
|
|
105
86
|
if (params.length <= 2) {
|
|
106
|
-
return function (
|
|
107
|
-
return _mutateWith(params[0], params[1],
|
|
87
|
+
return function (input) {
|
|
88
|
+
return _mutateWith(params[0], params[1], input);
|
|
108
89
|
};
|
|
109
90
|
} // @signature (filter, transformations, source)
|
|
110
91
|
|
|
111
92
|
|
|
112
93
|
return _mutateWith.apply(void 0, params);
|
|
113
94
|
};
|
|
114
|
-
|
|
115
|
-
exports.mutateWith = mutateWith;
|
|
95
|
+
//# sourceMappingURL=mutate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mutate/mutate.js"],"names":["map","pipe","isMatch","_mutate","transformations","input","entries","Object","result","key","value","hasOwnProperty","transform","Array","isArray","_mutateWith","filter","i","length","item","shouldMutate","push","_mutateMany","mutate","params","mutateMany","mutateWith"],"mappings":";;;;;;;;AAAA,SAASA,GAAT,QAAoB,eAApB;AACA,SAASC,IAAT,QAAqB,iBAArB;AACA,SAASC,OAAT,QAAwB,yBAAxB;;AAEA,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,eAAD,EAAkBC,KAAlB,EAA4B;AAC1C,MAAMC,OAAO,GAAGC,MAAM,CAACD,OAAP,CAAeF,eAAf,CAAhB;;AACA,MAAMI,MAAM,qBAAQH,KAAR,CAAZ;;AAEA,8BAA2BC,OAA3B,8BAAoC;AAA/B;AAAA,QAAOG,GAAP;AAAA,QAAYC,KAAZ;;AACH,QAAIL,KAAK,CAACM,cAAN,CAAqBF,GAArB,CAAJ,EAA+B;AAC7B,UAAMG,SAAS,GAAGC,KAAK,CAACC,OAAN,CAAcJ,KAAd,IAAuBT,IAAI,MAAJ,4BAAQS,KAAR,EAAvB,GAAwCA,KAA1D;AAEAF,MAAAA,MAAM,CAACC,GAAD,CAAN,GACE,OAAOG,SAAP,KAAqB,UAArB,GACIA,SAAS,CAACP,KAAK,CAACI,GAAD,CAAN,EAAaJ,KAAb,CADb,GAEIO,SAHN;AAID;AACF;;AAED,SAAOJ,MAAP;AACD,CAhBD;;AAkBA,IAAMO,WAAW,GAAG,SAAdA,WAAc,CAACC,MAAD,EAASZ,eAAT,EAA0BC,KAA1B,EAAoC;AACtD,MAAMG,MAAM,GAAG,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;;;AACA,SAAOiB,WAAW,MAAX,SAAeE,MAAf,CAAP;AACD,CARM;AAUP,OAAO,IAAME,UAAU,GAAG,SAAbA,UAAa,GAAe;AAAA,qCAAXF,MAAW;AAAXA,IAAAA,MAAW;AAAA;;AACvC;AACA,MAAIA,MAAM,CAACN,MAAP,IAAiB,CAArB,EAAwB;AACtB,WAAO,UAAAb,KAAK;AAAA,aAAIU,WAAW,CAACS,MAAM,CAAC,CAAD,CAAP,EAAYA,MAAM,CAAC,CAAD,CAAlB,EAAuBnB,KAAvB,CAAf;AAAA,KAAZ;AACD,GAJsC,CAMvC;;;AACA,SAAOU,WAAW,MAAX,SAAeS,MAAf,CAAP;AACD,CARM","sourcesContent":["import { map } from \"../map/map.js\"\nimport { pipe } from \"../pipe/pipe.js\"\nimport { isMatch } from \"../is-match/is-match.js\"\n\nconst _mutate = (transformations, input) => {\n const entries = Object.entries(transformations)\n const result = { ...input }\n\n for (const [key, value] of entries) {\n if (input.hasOwnProperty(key)) {\n const transform = Array.isArray(value) ? pipe(...value) : value\n\n result[key] =\n typeof transform === \"function\"\n ? transform(input[key], input)\n : transform\n }\n }\n\n return result\n}\n\nconst _mutateWith = (filter, transformations, input) => {\n const result = []\n\n for (let i = 0, length = input.length; i < length; ++i) {\n const item = input[i]\n const shouldMutate = isMatch(filter, item)\n\n result.push(shouldMutate ? _mutate(transformations, item) : item)\n }\n\n return result\n}\n\nconst _mutateMany = (transformations, input) =>\n map(item => _mutate(transformations, item), input)\n\nexport const mutate = (...params) => {\n // @signature (transformations) => (source)\n if (params.length <= 1) {\n return input => _mutate(params[0], input)\n }\n\n // @signature (transformations, source)\n return _mutate(...params)\n}\n\nexport const mutateMany = (...params) => {\n // @signature (transformations) => (source)\n if (params.length <= 1) {\n return input => _mutateMany(params[0], input)\n }\n\n // @signature (transformations, source)\n return _mutateMany(...params)\n}\n\nexport const mutateWith = (...params) => {\n // @signature (filter, transformations) => (source)\n if (params.length <= 2) {\n return input => _mutateWith(params[0], params[1], input)\n }\n\n // @signature (filter, transformations, source)\n return _mutateWith(...params)\n}\n"],"file":"mutate.js"}
|
|
@@ -1,54 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _tape = _interopRequireDefault(require("tape"));
|
|
6
|
-
|
|
7
|
-
var _mutate = require("./mutate");
|
|
1
|
+
import test from "tape";
|
|
2
|
+
import { mutate, mutateMany, mutateWith } from "./mutate.js";
|
|
8
3
|
|
|
9
4
|
var inc = function inc(x) {
|
|
10
5
|
return x + 1;
|
|
11
6
|
};
|
|
12
7
|
|
|
13
|
-
(
|
|
14
|
-
t.deepEqual(
|
|
8
|
+
test("mutate", function (t) {
|
|
9
|
+
t.deepEqual(mutate({
|
|
15
10
|
test: "changed"
|
|
16
11
|
}, {
|
|
17
12
|
test: "Lorem Ipsum"
|
|
18
13
|
}), {
|
|
19
14
|
test: "changed"
|
|
20
15
|
}, "Mutating existing property should return changed object");
|
|
21
|
-
t.deepEqual(
|
|
16
|
+
t.deepEqual(mutate({
|
|
22
17
|
test: inc
|
|
23
18
|
})({
|
|
24
19
|
test: 2
|
|
25
20
|
}), {
|
|
26
21
|
test: 3
|
|
27
22
|
}, "Mutating existing property with function should return changed object");
|
|
28
|
-
t.deepEqual(
|
|
23
|
+
t.deepEqual(mutate({
|
|
29
24
|
test: [inc, inc]
|
|
30
25
|
})({
|
|
31
26
|
test: 2
|
|
32
27
|
}), {
|
|
33
28
|
test: 4
|
|
34
29
|
}, "Mutating existing property with array if piped functions should return changed object");
|
|
35
|
-
t.deepEqual(
|
|
30
|
+
t.deepEqual(mutate({
|
|
36
31
|
notExist: 2
|
|
37
32
|
}, {
|
|
38
33
|
test: "Lorem Ipsum"
|
|
39
34
|
}), {
|
|
40
35
|
test: "Lorem Ipsum"
|
|
41
36
|
}, "Mutating non-existing property should return unchanged object");
|
|
42
|
-
t.deepEqual(
|
|
37
|
+
t.deepEqual(mutate({
|
|
43
38
|
test: "changed"
|
|
44
39
|
}, {
|
|
45
40
|
test: undefined
|
|
46
41
|
}), {
|
|
47
42
|
test: "changed"
|
|
48
43
|
}, "Mutating existing but undefined property should return changed object");
|
|
49
|
-
t.deepEqual(
|
|
50
|
-
test: function test(
|
|
51
|
-
return "".concat(
|
|
44
|
+
t.deepEqual(mutate({
|
|
45
|
+
test: function test(input, item) {
|
|
46
|
+
return "".concat(input, " ").concat(item.foo);
|
|
52
47
|
}
|
|
53
48
|
}, {
|
|
54
49
|
foo: "bar",
|
|
@@ -59,10 +54,10 @@ var inc = function inc(x) {
|
|
|
59
54
|
}, "Mutating existing property based on other field should return changed object");
|
|
60
55
|
t.end();
|
|
61
56
|
});
|
|
62
|
-
(
|
|
63
|
-
t.deepEqual(
|
|
64
|
-
id: function id(
|
|
65
|
-
return
|
|
57
|
+
test("mutateMany", function (t) {
|
|
58
|
+
t.deepEqual(mutateMany({
|
|
59
|
+
id: function id(input) {
|
|
60
|
+
return input + 1;
|
|
66
61
|
}
|
|
67
62
|
}, [{
|
|
68
63
|
id: 1
|
|
@@ -79,8 +74,8 @@ var inc = function inc(x) {
|
|
|
79
74
|
}], "Mutating existing but undefined property should return changed object");
|
|
80
75
|
t.end();
|
|
81
76
|
});
|
|
82
|
-
(
|
|
83
|
-
t.deepEqual(
|
|
77
|
+
test("mutateWith", function (t) {
|
|
78
|
+
t.deepEqual(mutateWith({
|
|
84
79
|
id: 2
|
|
85
80
|
}, {
|
|
86
81
|
count: [inc],
|
|
@@ -97,4 +92,5 @@ var inc = function inc(x) {
|
|
|
97
92
|
count: 2
|
|
98
93
|
}], "Mutating item inside array should return new array with changed object");
|
|
99
94
|
t.end();
|
|
100
|
-
});
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=mutate.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mutate/mutate.test.js"],"names":["test","mutate","mutateMany","mutateWith","inc","x","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gBY,IAAAA,KAAK,EAAE;AAAvB,GAAZ,EAAwC,CAChD;AAAEF,IAAAA,EAAE,EAAE;AAAN,GADgD,EAEhD;AAAEA,IAAAA,EAAE,EAAE,CAAN;AAASC,IAAAA,KAAK,EAAE;AAAhB,GAFgD,CAAxC,CADZ,EAKE,CAAC;AAAED,IAAAA,EAAE,EAAE;AAAN,GAAD,EAAY;AAAEA,IAAAA,EAAE,EAAE,CAAN;AAASC,IAAAA,KAAK,EAAE;AAAhB,GAAZ,CALF,EAME,wEANF;AASAT,EAAAA,CAAC,CAACO,GAAF;AACD,CAXG,CAAJ","sourcesContent":["import test from \"tape\"\n\nimport { mutate, mutateMany, mutateWith } from \"./mutate.js\"\n\nconst inc = x => x + 1\n\ntest(\"mutate\", t => {\n t.deepEqual(\n mutate({ test: \"changed\" }, { test: \"Lorem Ipsum\" }),\n { test: \"changed\" },\n \"Mutating existing property should return changed object\"\n )\n\n t.deepEqual(\n mutate({ test: inc })({ test: 2 }),\n { test: 3 },\n \"Mutating existing property with function should return changed object\"\n )\n\n t.deepEqual(\n mutate({ test: [inc, inc] })({ test: 2 }),\n { test: 4 },\n \"Mutating existing property with array if piped functions should return changed object\"\n )\n\n t.deepEqual(\n mutate({ notExist: 2 }, { test: \"Lorem Ipsum\" }),\n { test: \"Lorem Ipsum\" },\n \"Mutating non-existing property should return unchanged object\"\n )\n\n t.deepEqual(\n mutate({ test: \"changed\" }, { test: undefined }),\n { test: \"changed\" },\n \"Mutating existing but undefined property should return changed object\"\n )\n\n t.deepEqual(\n mutate(\n {\n test: (input, item) => `${input} ${item.foo}`,\n },\n {\n foo: \"bar\",\n test: \"Lorem Ipsum\",\n }\n ),\n {\n foo: \"bar\",\n test: \"Lorem Ipsum bar\",\n },\n \"Mutating existing property based on other field should return changed object\"\n )\n\n t.end()\n})\n\ntest(\"mutateMany\", t => {\n t.deepEqual(\n mutateMany({ id: input => input + 1 }, [\n { id: 1 },\n { id: 2 },\n { test: \"dolor\" },\n ]),\n [{ id: 2 }, { id: 3 }, { test: \"dolor\" }],\n \"Mutating existing but undefined property should return changed object\"\n )\n\n t.end()\n})\n\ntest(\"mutateWith\", t => {\n t.deepEqual(\n mutateWith({ id: 2 }, { count: [inc], other: 2 }, [\n { id: 1 },\n { id: 2, count: 1 },\n ]),\n [{ id: 1 }, { id: 2, count: 2 }],\n \"Mutating item inside array should return new array with changed object\"\n )\n\n t.end()\n})\n"],"file":"mutate.test.js"}
|
package/dist/page/page.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.page = void 0;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
11
2
|
|
|
12
3
|
/**
|
|
13
4
|
* Get a subset array using offset and limit
|
|
@@ -15,7 +6,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
15
6
|
* @param {Object} props
|
|
16
7
|
* @param {number} props.offset
|
|
17
8
|
* @param {number} props.limit
|
|
18
|
-
* @param {Array}
|
|
9
|
+
* @param {Array} input
|
|
19
10
|
*
|
|
20
11
|
* @returns {Array}
|
|
21
12
|
*
|
|
@@ -33,9 +24,10 @@ var page = function page() {
|
|
|
33
24
|
_ref$limit = _ref.limit,
|
|
34
25
|
limit = _ref$limit === void 0 ? 10 : _ref$limit;
|
|
35
26
|
|
|
36
|
-
return function (
|
|
37
|
-
return (
|
|
27
|
+
return function (input) {
|
|
28
|
+
return _toConsumableArray(input.splice(offset, limit));
|
|
38
29
|
};
|
|
39
30
|
};
|
|
40
31
|
|
|
41
|
-
|
|
32
|
+
export { page };
|
|
33
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/page/page.js"],"names":["page","offset","limit","input","splice"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMA,IAAI,GACR,SADIA,IACJ;AAAA,iFAA8B,EAA9B;AAAA,yBAAGC,MAAH;AAAA,MAAGA,MAAH,4BAAY,CAAZ;AAAA,wBAAeC,KAAf;AAAA,MAAeA,KAAf,2BAAuB,EAAvB;;AAAA,SACA,UAAAC,KAAK;AAAA,8BACCA,KAAK,CAACC,MAAN,CAAaH,MAAb,EAAqBC,KAArB,CADD;AAAA,GADL;AAAA,CADF;;AAKA,SAASF,IAAT","sourcesContent":["/**\n * Get a subset array using offset and limit\n *\n * @param {Object} props\n * @param {number} props.offset\n * @param {number} props.limit\n * @param {Array} input\n *\n * @returns {Array}\n *\n * @example\n * page({\n * offset: 1,\n * limit: 5\n * })([1, 2, 3, 4, 5, 6, 7, 8])\n * // => [2, 3, 4, 5, 6]\n */\nconst page =\n ({ offset = 0, limit = 10 } = {}) =>\n input =>\n [...input.splice(offset, limit)]\n\nexport { page }\n"],"file":"page.js"}
|
package/dist/page/page.test.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _ = require("..");
|
|
8
|
-
|
|
9
|
-
(0, _tape.default)("page", function (t) {
|
|
10
|
-
t.deepEqual((0, _.page)()([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "Page with default");
|
|
11
|
-
t.deepEqual((0, _.page)({
|
|
1
|
+
import test from "tape";
|
|
2
|
+
import { page } from "./page.js";
|
|
3
|
+
test("page", function (t) {
|
|
4
|
+
t.deepEqual(page()([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "Page with default");
|
|
5
|
+
t.deepEqual(page({
|
|
12
6
|
offset: 1,
|
|
13
7
|
limit: 5
|
|
14
8
|
})([1, 2, 3, 4, 5, 6, 7, 8]), [2, 3, 4, 5, 6], "5 length page starting from position 1");
|
|
15
|
-
t.deepEqual(
|
|
9
|
+
t.deepEqual(page({
|
|
16
10
|
offset: 0,
|
|
17
11
|
limit: 5
|
|
18
12
|
})([1, 2, 3]), [1, 2, 3], "limit over source lenght");
|
|
19
|
-
t.deepEqual(
|
|
13
|
+
t.deepEqual(page({
|
|
20
14
|
offset: 11,
|
|
21
15
|
limit: 5
|
|
22
16
|
})([1, 2, 3]), [], "offset over source lenght");
|
|
23
17
|
t.end();
|
|
24
|
-
});
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=page.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/page/page.test.js"],"names":["test","page","t","deepEqual","offset","limit","end"],"mappings":"AAAA,OAAOA,IAAP,MAAiB,MAAjB;AAEA,SAASC,IAAT,QAAqB,WAArB;AAEAD,IAAI,CAAC,MAAD,EAAS,UAAAE,CAAC,EAAI;AAChBA,EAAAA,CAAC,CAACC,SAAF,CACEF,IAAI,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,EAA5B,EAAgC,EAAhC,CAAH,CADN,EAEE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,EAA5B,CAFF,EAGE,mBAHF;AAMAC,EAAAA,CAAC,CAACC,SAAF,CACEF,IAAI,CAAC;AAAEG,IAAAA,MAAM,EAAE,CAAV;AAAaC,IAAAA,KAAK,EAAE;AAApB,GAAD,CAAJ,CAA8B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,CAA9B,CADF,EAEE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,CAFF,EAGE,wCAHF;AAMAH,EAAAA,CAAC,CAACC,SAAF,CACEF,IAAI,CAAC;AAAEG,IAAAA,MAAM,EAAE,CAAV;AAAaC,IAAAA,KAAK,EAAE;AAApB,GAAD,CAAJ,CAA8B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAA9B,CADF,EAEE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAFF,EAGE,0BAHF;AAMAH,EAAAA,CAAC,CAACC,SAAF,CACEF,IAAI,CAAC;AAAEG,IAAAA,MAAM,EAAE,EAAV;AAAcC,IAAAA,KAAK,EAAE;AAArB,GAAD,CAAJ,CAA+B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAA/B,CADF,EAEE,EAFF,EAGE,2BAHF;AAMAH,EAAAA,CAAC,CAACI,GAAF;AACD,CA1BG,CAAJ","sourcesContent":["import test from \"tape\"\n\nimport { page } from \"./page.js\"\n\ntest(\"page\", t => {\n t.deepEqual(\n page()([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]),\n [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n \"Page with default\"\n )\n\n t.deepEqual(\n page({ offset: 1, limit: 5 })([1, 2, 3, 4, 5, 6, 7, 8]),\n [2, 3, 4, 5, 6],\n \"5 length page starting from position 1\"\n )\n\n t.deepEqual(\n page({ offset: 0, limit: 5 })([1, 2, 3]),\n [1, 2, 3],\n \"limit over source lenght\"\n )\n\n t.deepEqual(\n page({ offset: 11, limit: 5 })([1, 2, 3]),\n [],\n \"offset over source lenght\"\n )\n\n t.end()\n})\n"],"file":"page.test.js"}
|
|
@@ -1,33 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.partitionWith = exports.partition = void 0;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
|
-
var _pipe = require("../pipe/pipe");
|
|
13
|
-
|
|
14
|
-
var _reduce = require("../reduce/reduce");
|
|
15
|
-
|
|
16
|
-
var _curry = require("../curry/curry");
|
|
17
|
-
|
|
18
|
-
var _isMatch = require("../is-match/is-match");
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
19
2
|
|
|
20
3
|
/* eslint-disable no-unused-vars*/
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
import { pipe } from "../pipe/pipe.js";
|
|
5
|
+
import { curry } from "../curry/curry.js";
|
|
6
|
+
import { isMatch } from "../is-match/is-match.js";
|
|
7
|
+
|
|
8
|
+
var _partition = function _partition(_fn, input) {
|
|
9
|
+
var fn = Array.isArray(_fn) ? pipe.apply(void 0, _toConsumableArray(_fn)) : _fn;
|
|
23
10
|
var pass = [];
|
|
24
11
|
var fail = [];
|
|
25
12
|
|
|
26
|
-
for (var i = 0; i <
|
|
27
|
-
if (fn(
|
|
28
|
-
pass.push(
|
|
13
|
+
for (var i = 0; i < input.length; ++i) {
|
|
14
|
+
if (fn(input[i], i, input)) {
|
|
15
|
+
pass.push(input[i]);
|
|
29
16
|
} else {
|
|
30
|
-
fail.push(
|
|
17
|
+
fail.push(input[i]);
|
|
31
18
|
}
|
|
32
19
|
}
|
|
33
20
|
|
|
@@ -45,7 +32,7 @@ var _partition = function _partition(_fn, source) {
|
|
|
45
32
|
*
|
|
46
33
|
* @name partition
|
|
47
34
|
* @tag Array
|
|
48
|
-
* @signature (fn: Function|Function[],
|
|
35
|
+
* @signature (fn: Function|Function[], input: Array) => Array<Array, Array>
|
|
49
36
|
*
|
|
50
37
|
* @example
|
|
51
38
|
* partition(x => x % 2 === 0)([1, 2, 3, 4, 5])
|
|
@@ -53,7 +40,7 @@ var _partition = function _partition(_fn, source) {
|
|
|
53
40
|
*/
|
|
54
41
|
|
|
55
42
|
|
|
56
|
-
var partition =
|
|
43
|
+
export var partition = curry(_partition);
|
|
57
44
|
/**
|
|
58
45
|
* Split an array based on object matching
|
|
59
46
|
* Take `A[]` and return a two-tuple of `A[]`s. The first element of the tuple
|
|
@@ -66,15 +53,14 @@ var partition = (0, _curry.curry)(_partition);
|
|
|
66
53
|
*
|
|
67
54
|
* @name partitionWith
|
|
68
55
|
* @tag Array
|
|
69
|
-
* @signature (subset: Object,
|
|
56
|
+
* @signature (subset: Object, input: Array) => Array<Array, Array>
|
|
70
57
|
*
|
|
71
58
|
* @example
|
|
72
59
|
* partitionWith({comments: is}, [{id: 1}, {id: 2, comments: []}])
|
|
73
60
|
* // => [[{id: 1}], [{id: 2, comments: []}]]
|
|
74
61
|
*/
|
|
75
62
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return _partition((0, _isMatch.isMatch)(subset), source);
|
|
63
|
+
export var partitionWith = curry(function (subset, input) {
|
|
64
|
+
return _partition(isMatch(subset), input);
|
|
79
65
|
});
|
|
80
|
-
|
|
66
|
+
//# sourceMappingURL=partition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/partition/partition.js"],"names":["pipe","curry","isMatch","_partition","_fn","input","fn","Array","isArray","pass","fail","i","length","push","partition","partitionWith","subset"],"mappings":";;AAAA;AAEA,SAASA,IAAT,QAAqB,iBAArB;AACA,SAASC,KAAT,QAAsB,mBAAtB;AACA,SAASC,OAAT,QAAwB,yBAAxB;;AAEA,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,GAAD,EAAMC,KAAN,EAAgB;AACjC,MAAMC,EAAE,GAAGC,KAAK,CAACC,OAAN,CAAcJ,GAAd,IAAqBJ,IAAI,MAAJ,4BAAQI,GAAR,EAArB,GAAoCA,GAA/C;AACA,MAAMK,IAAI,GAAG,EAAb;AACA,MAAMC,IAAI,GAAG,EAAb;;AAEA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGN,KAAK,CAACO,MAA1B,EAAkC,EAAED,CAApC,EAAuC;AACrC,QAAIL,EAAE,CAACD,KAAK,CAACM,CAAD,CAAN,EAAWA,CAAX,EAAcN,KAAd,CAAN,EAA4B;AAC1BI,MAAAA,IAAI,CAACI,IAAL,CAAUR,KAAK,CAACM,CAAD,CAAf;AACD,KAFD,MAEO;AACLD,MAAAA,IAAI,CAACG,IAAL,CAAUR,KAAK,CAACM,CAAD,CAAf;AACD;AACF;;AAED,SAAO,CAACF,IAAD,EAAOC,IAAP,CAAP;AACD,CAdD;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,IAAMI,SAAS,GAAGb,KAAK,CAACE,UAAD,CAAvB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMY,aAAa,GAAGd,KAAK,CAAC,UAACe,MAAD,EAASX,KAAT;AAAA,SACjCF,UAAU,CAACD,OAAO,CAACc,MAAD,CAAR,EAAkBX,KAAlB,CADuB;AAAA,CAAD,CAA3B","sourcesContent":["/* eslint-disable no-unused-vars*/\n\nimport { pipe } from \"../pipe/pipe.js\"\nimport { curry } from \"../curry/curry.js\"\nimport { isMatch } from \"../is-match/is-match.js\"\n\nconst _partition = (_fn, input) => {\n const fn = Array.isArray(_fn) ? pipe(..._fn) : _fn\n const pass = []\n const fail = []\n\n for (let i = 0; i < input.length; ++i) {\n if (fn(input[i], i, input)) {\n pass.push(input[i])\n } else {\n fail.push(input[i])\n }\n }\n\n return [pass, fail]\n}\n\n/**\n * Split an array based on a predicate function.\n * Take `A[]` and return a two-tuple of `A[]`s. The first element of the tuple\n * consists of elements for which the predicate returned `true`, the second of\n * elements for which it returned `false`.\n *\n * @param {Function} fn A predicate function.\n *\n * @returns {Array<Array, Array>}\n *\n * @name partition\n * @tag Array\n * @signature (fn: Function|Function[], input: Array) => Array<Array, Array>\n *\n * @example\n * partition(x => x % 2 === 0)([1, 2, 3, 4, 5])\n * // => [[2, 4], [1, 3, 5]]\n */\nexport const partition = curry(_partition)\n\n/**\n * Split an array based on object matching\n * Take `A[]` and return a two-tuple of `A[]`s. The first element of the tuple\n * consists of elements for which the predicate returned `true`, the second of\n * elements for which it returned `false`.\n *\n * @param {object} subset A predicate function.\n *\n * @returns {Array<Array, Array>}\n *\n * @name partitionWith\n * @tag Array\n * @signature (subset: Object, input: Array) => Array<Array, Array>\n *\n * @example\n * partitionWith({comments: is}, [{id: 1}, {id: 2, comments: []}])\n * // => [[{id: 1}], [{id: 2, comments: []}]]\n */\nexport const partitionWith = curry((subset, input) =>\n _partition(isMatch(subset), input)\n)\n"],"file":"partition.js"}
|
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var _tape = _interopRequireDefault(require("tape"));
|
|
6
|
-
|
|
7
|
-
var _is = require("../is/is");
|
|
8
|
-
|
|
9
|
-
var _read = require("../read/read");
|
|
10
|
-
|
|
11
|
-
var _partition = require("./partition");
|
|
1
|
+
import test from "tape";
|
|
2
|
+
import { is } from "../is/is.js";
|
|
3
|
+
import { read } from "../read/read.js";
|
|
4
|
+
import { partition, partitionWith } from "./partition.js";
|
|
12
5
|
|
|
13
6
|
var equalsTwo = function equalsTwo(x) {
|
|
14
7
|
return x === 2;
|
|
15
8
|
};
|
|
16
9
|
|
|
17
|
-
(
|
|
18
|
-
t.deepEqual(
|
|
19
|
-
t.deepEqual(
|
|
20
|
-
t.deepEqual(
|
|
10
|
+
test("partition", function (t) {
|
|
11
|
+
t.deepEqual(partition(equalsTwo)([2, 2, 1, 1, 2]), [[2, 2, 2], [1, 1]], "(equalsTwo)([2,2,1,1,2]) // => [[2,2,2],[1,1]]");
|
|
12
|
+
t.deepEqual(partition(equalsTwo, [2, 2, 1, 1, 2]), [[2, 2, 2], [1, 1]], "(equalsTwo, [2,2,1,1,2]) // => [[2,2,2],[1,1]]");
|
|
13
|
+
t.deepEqual(partition([read("comments"), is], [{
|
|
21
14
|
id: 1,
|
|
22
15
|
comments: []
|
|
23
16
|
}, {
|
|
@@ -28,12 +21,12 @@ var equalsTwo = function equalsTwo(x) {
|
|
|
28
21
|
}], [{
|
|
29
22
|
id: 2
|
|
30
23
|
}]], "(equalsTwo, [2,2,1,1,2]) // => [[2,2,2],[1,1]]");
|
|
31
|
-
t.deepEqual(
|
|
24
|
+
t.deepEqual(partition(equalsTwo)([1]), [[], [1]], "(equalsTwo)([1]) // => [[], [1]]");
|
|
32
25
|
t.end();
|
|
33
26
|
});
|
|
34
|
-
(
|
|
35
|
-
t.deepEqual(
|
|
36
|
-
parentId:
|
|
27
|
+
test("partitionWith", function (t) {
|
|
28
|
+
t.deepEqual(partitionWith({
|
|
29
|
+
parentId: is
|
|
37
30
|
})([{
|
|
38
31
|
id: 1
|
|
39
32
|
}, {
|
|
@@ -46,4 +39,5 @@ var equalsTwo = function equalsTwo(x) {
|
|
|
46
39
|
id: 1
|
|
47
40
|
}]], "partitionWith({parentId: is}) // => [[{parentId: 1}], [{id: 1}]]");
|
|
48
41
|
t.end();
|
|
49
|
-
});
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=partition.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/partition/partition.test.js"],"names":["test","is","read","partition","partitionWith","equalsTwo","x","t","deepEqual","id","comments","end","parentId"],"mappings":"AAAA,OAAOA,IAAP,MAAiB,MAAjB;AAEA,SA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AAC,CAAD,CAArB,CADF,EAEE,CAAC,EAAD,EAAK,CAAC,CAAD,CAAL,CAFF,EAGE,kCAHF;AAMAE,EAAAA,CAAC,CAACI,GAAF;AACD,CAhCG,CAAJ;AAkCAX,IAAI,CAAC,eAAD,EAAkB,UAAAO,CAAC,EAAI;AACzBA,EAAAA,CAAC,CAACC,SAAF,CACEJ,aAAa,CAAC;AACZQ,IAAAA,QAAQ,EAAEX;AADE,GAAD,CAAb,CAEG,CAAC;AAAEQ,IAAAA,EAAE,EAAE;AAAN,GAAD,EAAY;AAAEA,IAAAA,EAAE,EAAE,CAAN;AAASG,IAAAA,QAAQ,EAAE;AAAnB,GAAZ,CAFH,CADF,EAIE,CAAC,CAAC;AAAEH,IAAAA,EAAE,EAAE,CAAN;AAASG,IAAAA,QAAQ,EAAE;AAAnB,GAAD,CAAD,EAA2B,CAAC;AAAEH,IAAAA,EAAE,EAAE;AAAN,GAAD,CAA3B,CAJF,EAKE,kEALF;AAQAF,EAAAA,CAAC,CAACI,GAAF;AACD,CAVG,CAAJ","sourcesContent":["import test from \"tape\"\n\nimport { is } from \"../is/is.js\"\nimport { read } from \"../read/read.js\"\nimport { partition, partitionWith } from \"./partition.js\"\n\nconst equalsTwo = x => x === 2\n\ntest(\"partition\", t => {\n t.deepEqual(\n partition(equalsTwo)([2, 2, 1, 1, 2]),\n [\n [2, 2, 2],\n [1, 1],\n ],\n \"(equalsTwo)([2,2,1,1,2]) // => [[2,2,2],[1,1]]\"\n )\n\n t.deepEqual(\n partition(equalsTwo, [2, 2, 1, 1, 2]),\n [\n [2, 2, 2],\n [1, 1],\n ],\n \"(equalsTwo, [2,2,1,1,2]) // => [[2,2,2],[1,1]]\"\n )\n\n t.deepEqual(\n partition([read(\"comments\"), is], [{ id: 1, comments: [] }, { id: 2 }]),\n [[{ id: 1, comments: [] }], [{ id: 2 }]],\n \"(equalsTwo, [2,2,1,1,2]) // => [[2,2,2],[1,1]]\"\n )\n\n t.deepEqual(\n partition(equalsTwo)([1]),\n [[], [1]],\n \"(equalsTwo)([1]) // => [[], [1]]\"\n )\n\n t.end()\n})\n\ntest(\"partitionWith\", t => {\n t.deepEqual(\n partitionWith({\n parentId: is,\n })([{ id: 1 }, { id: 2, parentId: 1 }]),\n [[{ id: 2, parentId: 1 }], [{ id: 1 }]],\n \"partitionWith({parentId: is}) // => [[{parentId: 1}], [{id: 1}]]\"\n )\n\n t.end()\n})\n"],"file":"partition.test.js"}
|
package/dist/pick/pick.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.pick = void 0;
|
|
7
|
-
|
|
8
1
|
/**
|
|
9
|
-
* @param {string} key
|
|
10
|
-
* @param {Object[]}
|
|
2
|
+
* @param {string} key Field name to extract values from
|
|
3
|
+
* @param {Object[]} input Array of objects
|
|
11
4
|
*
|
|
12
5
|
* @returns {Array}
|
|
13
6
|
*/
|
|
14
|
-
var _pick = function _pick(key,
|
|
7
|
+
var _pick = function _pick(key, input) {
|
|
15
8
|
var result = [];
|
|
16
9
|
|
|
17
|
-
for (var i = 0, length =
|
|
18
|
-
result.push(
|
|
10
|
+
for (var i = 0, length = input.length; i < length; i++) {
|
|
11
|
+
result.push(input[i][key]);
|
|
19
12
|
}
|
|
20
13
|
|
|
21
14
|
return result;
|
|
@@ -29,7 +22,7 @@ var _pick = function _pick(key, source) {
|
|
|
29
22
|
* @returns {Array}
|
|
30
23
|
*
|
|
31
24
|
* @tag Array
|
|
32
|
-
* @signature (key: string) => (
|
|
25
|
+
* @signature (key: string) => (input: object[]): mixed[]
|
|
33
26
|
*
|
|
34
27
|
* @example
|
|
35
28
|
* pick("position")([{id: 1, position: 3}, {id:2, position: -1}])
|
|
@@ -37,20 +30,19 @@ var _pick = function _pick(key, source) {
|
|
|
37
30
|
*/
|
|
38
31
|
|
|
39
32
|
|
|
40
|
-
var pick = function pick() {
|
|
33
|
+
export var pick = function pick() {
|
|
41
34
|
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
42
35
|
params[_key] = arguments[_key];
|
|
43
36
|
}
|
|
44
37
|
|
|
45
|
-
// @signature (key) => (
|
|
38
|
+
// @signature (key) => (input)
|
|
46
39
|
if (params.length <= 1) {
|
|
47
|
-
return function (
|
|
48
|
-
return _pick(params[0],
|
|
40
|
+
return function (input) {
|
|
41
|
+
return _pick(params[0], input);
|
|
49
42
|
};
|
|
50
|
-
} // @signature (key,
|
|
43
|
+
} // @signature (key, input)
|
|
51
44
|
|
|
52
45
|
|
|
53
46
|
return _pick.apply(void 0, params);
|
|
54
47
|
};
|
|
55
|
-
|
|
56
|
-
exports.pick = pick;
|
|
48
|
+
//# sourceMappingURL=pick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/pick/pick.js"],"names":["_pick","key","input","result","i","length","push","pick","params"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMA,KAAK,GAAG,SAARA,KAAQ,CAACC,GAAD,EAAMC,KAAN,EAAgB;AAC5B,MAAMC,MAAM,GAAG,EAAf;;AAEA,OAAK,IAAIC,CAAC,GAAG,CAAR,EAAWC,MAAM,GAAGH,KAAK,CAACG,MAA/B,EAAuCD,CAAC,GAAGC,MAA3C,EAAmDD,CAAC,EAApD,EAAwD;AACtDD,IAAAA,MAAM,CAACG,IAAP,CAAYJ,KAAK,CAACE,CAAD,CAAL,CAASH,GAAT,CAAZ;AACD;;AAED,SAAOE,MAAP;AACD,CARD;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,IAAMI,IAAI,GAAG,SAAPA,IAAO,GAAe;AAAA,oCAAXC,MAAW;AAAXA,IAAAA,MAAW;AAAA;;AACjC;AACA,MAAIA,MAAM,CAACH,MAAP,IAAiB,CAArB,EAAwB;AACtB,WAAO,UAAAH,KAAK;AAAA,aAAIF,KAAK,CAACQ,MAAM,CAAC,CAAD,CAAP,EAAYN,KAAZ,CAAT;AAAA,KAAZ;AACD,GAJgC,CAMjC;;;AACA,SAAOF,KAAK,MAAL,SAASQ,MAAT,CAAP;AACD,CARM","sourcesContent":["/**\n * @param {string} key Field name to extract values from\n * @param {Object[]} input Array of objects\n *\n * @returns {Array}\n */\nconst _pick = (key, input) => {\n const result = []\n\n for (let i = 0, length = input.length; i < length; i++) {\n result.push(input[i][key])\n }\n\n return result\n}\n\n/**\n * Returns a new list by extracting the same named property off all objects in\n * the source list\n *\n * @param {...any} params\n *\n * @returns {Array}\n *\n * @tag Array\n * @signature (key: string) => (input: object[]): mixed[]\n *\n * @example\n * pick(\"position\")([{id: 1, position: 3}, {id:2, position: -1}])\n * // => [3, -1]\n */\nexport const pick = (...params) => {\n // @signature (key) => (input)\n if (params.length <= 1) {\n return input => _pick(params[0], input)\n }\n\n // @signature (key, input)\n return _pick(...params)\n}\n"],"file":"pick.js"}
|