rambda 10.0.0-alpha.0 → 10.0.0-beta.1
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/CHANGELOG.md +124 -16
- package/README.md +5526 -1730
- package/dist/{rambda.esm.js → rambda.cjs} +663 -355
- package/dist/rambda.js +545 -456
- package/dist/rambda.umd.js +563 -357
- package/immutable.d.ts +321 -343
- package/index.d.ts +321 -343
- package/package.json +20 -13
- package/rambda.js +16 -1
- package/src/addProp.js +3 -0
- package/src/append.js +5 -5
- package/src/ascend.js +16 -0
- package/src/compact.js +12 -0
- package/src/concat.js +1 -1
- package/src/count.js +7 -7
- package/src/countBy.js +12 -12
- package/src/createObjectFromKeys.js +10 -0
- package/src/descend.js +10 -0
- package/src/dropLast.js +1 -3
- package/src/eqProps.js +1 -2
- package/src/equals.js +2 -2
- package/src/evolve.js +2 -23
- package/src/filter.js +14 -14
- package/src/find.js +10 -10
- package/src/findIndex.js +9 -9
- package/src/findLast.js +8 -8
- package/src/findLastIndex.js +8 -8
- package/src/findNth.js +16 -0
- package/src/groupBy.js +14 -13
- package/src/includes.js +12 -13
- package/src/interpolate.js +29 -0
- package/src/intersection.js +1 -1
- package/src/intersperse.js +12 -12
- package/src/join.js +1 -1
- package/src/mapAsync.js +3 -3
- package/src/mapKeys.js +11 -0
- package/src/mapObjectAsync.js +9 -9
- package/src/mapParallelAsync.js +3 -0
- package/src/match.js +5 -5
- package/src/modifyProp.js +20 -0
- package/src/objectIncludes.js +12 -0
- package/src/partition.js +13 -37
- package/src/partitionObject.js +15 -0
- package/src/permutations.js +40 -0
- package/src/pipeAsync.js +7 -6
- package/src/pluck.js +9 -9
- package/src/prepend.js +1 -1
- package/src/propSatisfies.js +1 -3
- package/src/range.js +35 -12
- package/src/reject.js +1 -1
- package/src/rejectObject.js +13 -0
- package/src/shuffle.js +13 -0
- package/src/sort.js +1 -1
- package/src/sortBy.js +12 -10
- package/src/sortObject.js +15 -0
- package/src/sortWith.js +8 -8
- package/src/split.js +2 -2
- package/src/splitEvery.js +11 -11
- package/src/takeLastWhile.js +18 -18
- package/src/tap.js +4 -4
- package/src/test.js +1 -1
- package/src/uniqBy.js +4 -4
- package/src/uniqWith.js +10 -10
- package/src/modifyPath.js +0 -30
package/package.json
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rambda",
|
|
3
|
-
"version": "10.0.0-
|
|
3
|
+
"version": "10.0.0-beta.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"out": "yarn populatedocs && yarn populatereadme && yarn immutable && yarn build && yarn create-docsify",
|
|
6
6
|
"build": "yarn build:main && yarn build:web && yarn build:esm",
|
|
7
|
-
"build:main": "rollup rambda.js --file dist/rambda.
|
|
8
|
-
"build:esm": "rollup rambda.js --file dist/rambda.
|
|
7
|
+
"build:main": "rollup rambda.js --file dist/rambda.cjs --format cjs",
|
|
8
|
+
"build:esm": "rollup rambda.js --file dist/rambda.js --format es",
|
|
9
9
|
"build:web": "rollup rambda.js --file dist/rambda.umd.js --format umd --name \"R\"",
|
|
10
|
-
"immutable": "cd ../rambda-scripts && yarn immutable
|
|
10
|
+
"immutable": "cd ../rambda-scripts && yarn immutable",
|
|
11
11
|
"populatedocs": "cd ../rambda-scripts && yarn populate:docs",
|
|
12
12
|
"populatereadme": "cd ../rambda-scripts && yarn populate:readme",
|
|
13
13
|
"lint": "cd source && run lint:folder > lint-output.txt",
|
|
14
14
|
"test:file": "node scripts/tasks/run/run-test.js",
|
|
15
15
|
"test:ci": "vitest run",
|
|
16
16
|
"test": "vitest run --watch -u",
|
|
17
|
-
"x": "vitest run --watch source/and.spec.js",
|
|
18
|
-
"test:cover": "vitest run --coverage",
|
|
19
17
|
"test:typings": "dtslint --localTs ./node_modules/typescript/lib --expectOnly ./source",
|
|
20
18
|
"create-docsify": "cd ../rambda-scripts && yarn create-docsify",
|
|
21
19
|
"deps": "run dep:next",
|
|
@@ -27,20 +25,30 @@
|
|
|
27
25
|
"depFn": [
|
|
28
26
|
"@definitelytyped/dtslint"
|
|
29
27
|
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"import": "./dist/rambda.js",
|
|
32
|
+
"require": "./dist/rambda.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"main": "dist/rambda.cjs",
|
|
36
|
+
"module": "dist/rambda.js",
|
|
30
37
|
"dependencies": {},
|
|
31
38
|
"devDependencies": {
|
|
32
39
|
"@definitelytyped/dtslint": "0.0.182",
|
|
33
40
|
"@types/mocha": "10.0.10",
|
|
34
|
-
"@vitest/coverage-v8": "
|
|
41
|
+
"@vitest/coverage-v8": "3.1.0-beta.2",
|
|
35
42
|
"helpers-fn": "2.0.0",
|
|
36
43
|
"lodash": "4.17.21",
|
|
44
|
+
"radashi": "^12.4.0",
|
|
37
45
|
"rambdax": "11.3.1",
|
|
38
46
|
"ramda": "0.30.1",
|
|
39
|
-
"remeda": "
|
|
40
|
-
"rollup": "4.
|
|
47
|
+
"remeda": "2.21.2",
|
|
48
|
+
"rollup": "4.36.0",
|
|
41
49
|
"types-ramda": "0.30.1",
|
|
42
|
-
"typescript": "5.
|
|
43
|
-
"vitest": "3.0.
|
|
50
|
+
"typescript": "5.9.0-dev.20250321",
|
|
51
|
+
"vitest": "3.1.0-beta.2"
|
|
44
52
|
},
|
|
45
53
|
"jest": {
|
|
46
54
|
"testEnvironment": "node",
|
|
@@ -68,6 +76,7 @@
|
|
|
68
76
|
"generics",
|
|
69
77
|
"lodash",
|
|
70
78
|
"ramda",
|
|
79
|
+
"remeda",
|
|
71
80
|
"stdlib",
|
|
72
81
|
"toolkit",
|
|
73
82
|
"ts",
|
|
@@ -90,8 +99,6 @@
|
|
|
90
99
|
"immutable.js"
|
|
91
100
|
],
|
|
92
101
|
"sideEffects": false,
|
|
93
|
-
"main": "./dist/rambda.js",
|
|
94
102
|
"umd": "./dist/rambda.umd.js",
|
|
95
|
-
"module": "./rambda.js",
|
|
96
103
|
"types": "./index.d.ts"
|
|
97
104
|
}
|
package/rambda.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
/// <reference types="./index.d.ts" />
|
|
2
|
+
export * from './src/addProp.js'
|
|
2
3
|
export * from './src/all.js'
|
|
3
4
|
export * from './src/allPass.js'
|
|
4
5
|
export * from './src/any.js'
|
|
5
6
|
export * from './src/anyPass.js'
|
|
6
7
|
export * from './src/append.js'
|
|
8
|
+
export * from './src/ascend.js'
|
|
7
9
|
export * from './src/checkObjectWithSpec.js'
|
|
10
|
+
export * from './src/compact.js'
|
|
8
11
|
export * from './src/complement.js'
|
|
9
12
|
export * from './src/concat.js'
|
|
10
13
|
export * from './src/count.js'
|
|
11
14
|
export * from './src/countBy.js'
|
|
15
|
+
export * from './src/createObjectFromKeys.js'
|
|
12
16
|
export * from './src/defaultTo.js'
|
|
17
|
+
export * from './src/descend.js'
|
|
13
18
|
export * from './src/drop.js'
|
|
14
19
|
export * from './src/dropLast.js'
|
|
15
20
|
export * from './src/dropLastWhile.js'
|
|
@@ -25,6 +30,7 @@ export * from './src/find.js'
|
|
|
25
30
|
export * from './src/findIndex.js'
|
|
26
31
|
export * from './src/findLast.js'
|
|
27
32
|
export * from './src/findLastIndex.js'
|
|
33
|
+
export * from './src/findNth.js'
|
|
28
34
|
export * from './src/flatMap.js'
|
|
29
35
|
export * from './src/flatten.js'
|
|
30
36
|
export * from './src/groupBy.js'
|
|
@@ -33,6 +39,7 @@ export * from './src/includes.js'
|
|
|
33
39
|
export * from './src/indexOf.js'
|
|
34
40
|
export * from './src/init.js'
|
|
35
41
|
export * from './src/innerJoin.js'
|
|
42
|
+
export * from './src/interpolate.js'
|
|
36
43
|
export * from './src/intersection.js'
|
|
37
44
|
export * from './src/intersperse.js'
|
|
38
45
|
export * from './src/join.js'
|
|
@@ -40,19 +47,24 @@ export * from './src/last.js'
|
|
|
40
47
|
export * from './src/lastIndexOf.js'
|
|
41
48
|
export * from './src/map.js'
|
|
42
49
|
export * from './src/mapAsync.js'
|
|
50
|
+
export * from './src/mapKeys.js'
|
|
43
51
|
export * from './src/mapObject.js'
|
|
44
52
|
export * from './src/mapObjectAsync.js'
|
|
53
|
+
export * from './src/mapParallelAsync.js'
|
|
45
54
|
export * from './src/match.js'
|
|
46
55
|
export * from './src/maxBy.js'
|
|
47
56
|
export * from './src/merge.js'
|
|
48
57
|
export * from './src/mergeTypes.js'
|
|
49
58
|
export * from './src/minBy.js'
|
|
50
|
-
export * from './src/
|
|
59
|
+
export * from './src/modifyProp.js'
|
|
51
60
|
export * from './src/none.js'
|
|
52
61
|
export * from './src/objOf.js'
|
|
62
|
+
export * from './src/objectIncludes.js'
|
|
53
63
|
export * from './src/omit.js'
|
|
54
64
|
export * from './src/partition.js'
|
|
65
|
+
export * from './src/partitionObject.js'
|
|
55
66
|
export * from './src/path.js'
|
|
67
|
+
export * from './src/permutations.js'
|
|
56
68
|
export * from './src/pick.js'
|
|
57
69
|
export * from './src/pipe.js'
|
|
58
70
|
export * from './src/pipeAsync.js'
|
|
@@ -65,10 +77,13 @@ export * from './src/propSatisfies.js'
|
|
|
65
77
|
export * from './src/range.js'
|
|
66
78
|
export * from './src/reduce.js'
|
|
67
79
|
export * from './src/reject.js'
|
|
80
|
+
export * from './src/rejectObject.js'
|
|
68
81
|
export * from './src/replace.js'
|
|
69
82
|
export * from './src/replaceItemAtIndex.js'
|
|
83
|
+
export * from './src/shuffle.js'
|
|
70
84
|
export * from './src/sort.js'
|
|
71
85
|
export * from './src/sortBy.js'
|
|
86
|
+
export * from './src/sortObject.js'
|
|
72
87
|
export * from './src/sortWith.js'
|
|
73
88
|
export * from './src/split.js'
|
|
74
89
|
export * from './src/splitEvery.js'
|
package/src/addProp.js
ADDED
package/src/append.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { cloneList } from './_internals/cloneList.js'
|
|
2
2
|
|
|
3
3
|
export function append(x) {
|
|
4
|
-
return list=> {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
return list => {
|
|
5
|
+
const clone = cloneList(list)
|
|
6
|
+
clone.push(x)
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
return clone
|
|
9
|
+
}
|
|
10
10
|
}
|
package/src/ascend.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function createCompareFunction(a, b, winner, loser) {
|
|
2
|
+
if (a === b) {
|
|
3
|
+
return 0
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return a < b ? winner : loser
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function ascend(getFunction) {
|
|
10
|
+
return (a, b) => {
|
|
11
|
+
const aValue = getFunction(a)
|
|
12
|
+
const bValue = getFunction(b)
|
|
13
|
+
|
|
14
|
+
return createCompareFunction(aValue, bValue, -1, 1)
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/compact.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isArray } from './_internals/isArray.js'
|
|
2
|
+
import { reject } from './reject.js'
|
|
3
|
+
import { rejectObject } from './rejectObject.js'
|
|
4
|
+
|
|
5
|
+
const isNullOrUndefined = x => x === null || x === undefined
|
|
6
|
+
|
|
7
|
+
export function compact(input){
|
|
8
|
+
if(isArray(input)){
|
|
9
|
+
return reject(isNullOrUndefined)(input)
|
|
10
|
+
}
|
|
11
|
+
return rejectObject(isNullOrUndefined)(input)
|
|
12
|
+
}
|
package/src/concat.js
CHANGED
package/src/count.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { isArray } from './_internals/isArray.js'
|
|
2
2
|
|
|
3
|
-
export function count(predicate
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export function count(predicate) {
|
|
4
|
+
return list => {
|
|
5
|
+
if (!isArray(list)) {
|
|
6
|
+
return 0
|
|
7
|
+
}
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
}
|
|
9
|
+
return list.filter(x => predicate(x)).length
|
|
10
|
+
}
|
|
11
11
|
}
|
package/src/countBy.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export function countBy(fn) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
const willReturn = {}
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
list.forEach(item => {
|
|
6
|
+
const key = fn(item)
|
|
7
|
+
if (!willReturn[key]) {
|
|
8
|
+
willReturn[key] = 1
|
|
9
|
+
} else {
|
|
10
|
+
willReturn[key]++
|
|
11
|
+
}
|
|
12
|
+
})
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
}
|
|
14
|
+
return willReturn
|
|
15
|
+
}
|
|
16
16
|
}
|
package/src/descend.js
ADDED
package/src/dropLast.js
CHANGED
package/src/eqProps.js
CHANGED
package/src/equals.js
CHANGED
|
@@ -98,7 +98,7 @@ function parseRegex(maybeRegex) {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
export function equalsFn(a, b) {
|
|
101
|
-
|
|
101
|
+
if (Object.is(a, b)) {
|
|
102
102
|
return true
|
|
103
103
|
}
|
|
104
104
|
|
|
@@ -207,5 +207,5 @@ export function equalsFn(a, b) {
|
|
|
207
207
|
return false
|
|
208
208
|
}
|
|
209
209
|
export function equals(a) {
|
|
210
|
-
|
|
210
|
+
return b => equalsFn(a, b)
|
|
211
211
|
}
|
package/src/evolve.js
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
1
|
import { mapObject } from './mapObject.js'
|
|
2
2
|
import { type } from './type.js'
|
|
3
3
|
|
|
4
|
-
export function evolveFn(rules, obj) {
|
|
5
|
-
return mapObject((x, prop) => {
|
|
6
|
-
if (type(x) === 'Object') {
|
|
7
|
-
const typeRule = type(rules[prop])
|
|
8
|
-
if (typeRule === 'Function') {
|
|
9
|
-
return rules[prop](x)
|
|
10
|
-
}
|
|
11
|
-
if (typeRule === 'Object') {
|
|
12
|
-
return evolveFn(rules[prop], x)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return x
|
|
16
|
-
}
|
|
17
|
-
if (type(rules[prop]) === 'Function') {
|
|
18
|
-
return rules[prop](x)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return x
|
|
22
|
-
})(obj)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
4
|
export function evolve(rules) {
|
|
26
|
-
return
|
|
27
|
-
|
|
5
|
+
return mapObject((x, prop) => type(rules[prop]) === 'Function' ? rules[prop](x): x)
|
|
6
|
+
}
|
package/src/filter.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
export function filter(predicate) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
if (!list) {
|
|
4
|
+
throw new Error('Incorrect iterable input')
|
|
5
|
+
}
|
|
6
|
+
let index = 0
|
|
7
|
+
const len = list.length
|
|
8
|
+
const willReturn = []
|
|
9
|
+
|
|
10
|
+
while (index < len) {
|
|
11
|
+
if (predicate(list[index], index)) {
|
|
12
|
+
willReturn.push(list[index])
|
|
13
|
+
}
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
if (predicate(list[index], index)) {
|
|
12
|
-
willReturn.push(list[index])
|
|
15
|
+
index++
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
return willReturn
|
|
16
19
|
}
|
|
17
|
-
|
|
18
|
-
return willReturn
|
|
19
|
-
}
|
|
20
20
|
}
|
package/src/find.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export function find(predicate) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
let index = 0
|
|
4
|
+
const len = list.length
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
while (index < len) {
|
|
7
|
+
const x = list[index]
|
|
8
|
+
if (predicate(x)) {
|
|
9
|
+
return x
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
index++
|
|
13
|
+
}
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
|
-
}
|
package/src/findIndex.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export function findIndex(predicate) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
const len = list.length
|
|
4
|
+
let index = -1
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
while (++index < len) {
|
|
7
|
+
if (predicate(list[index])) {
|
|
8
|
+
return index
|
|
9
|
+
}
|
|
9
10
|
}
|
|
10
|
-
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
}
|
|
12
|
+
return -1
|
|
13
|
+
}
|
|
14
14
|
}
|
package/src/findLast.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export function findLast(predicate) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
let index = list.length
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
while (--index >= 0) {
|
|
6
|
+
if (predicate(list[index])) {
|
|
7
|
+
return list[index]
|
|
8
|
+
}
|
|
8
9
|
}
|
|
9
|
-
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
}
|
|
11
|
+
return undefined
|
|
12
|
+
}
|
|
13
13
|
}
|
package/src/findLastIndex.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export function findLastIndex(fn) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
let index = list.length
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
while (--index >= 0) {
|
|
6
|
+
if (fn(list[index])) {
|
|
7
|
+
return index
|
|
8
|
+
}
|
|
8
9
|
}
|
|
9
|
-
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
}
|
|
11
|
+
return -1
|
|
12
|
+
}
|
|
13
13
|
}
|
package/src/findNth.js
ADDED
package/src/groupBy.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
export function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export function groupByFallback(groupFn, list) {
|
|
2
|
+
const result = {}
|
|
3
|
+
for (let i = 0; i < list.length; i++) {
|
|
4
|
+
const item = list[i]
|
|
5
|
+
const key = groupFn(item)
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const key = groupFn(item)
|
|
7
|
+
if (!result[key]) {
|
|
8
|
+
result[key] = []
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
result[key] = []
|
|
11
|
+
result[key].push(item)
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
result
|
|
16
|
-
|
|
14
|
+
return result
|
|
15
|
+
}
|
|
16
|
+
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
export function groupBy(groupFn) {
|
|
19
|
+
return iterable => Object.groupBy ? Object.groupBy(iterable,groupFn) : groupByFallback(groupFn, iterable)
|
|
19
20
|
}
|
package/src/includes.js
CHANGED
|
@@ -2,18 +2,17 @@ import { isArray } from './_internals/isArray.js'
|
|
|
2
2
|
import { _indexOf } from './equals.js'
|
|
3
3
|
|
|
4
4
|
export function includes(valueToFind) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
5
|
+
return iterable => {
|
|
6
|
+
if (typeof iterable === 'string') {
|
|
7
|
+
return iterable.includes(valueToFind)
|
|
8
|
+
}
|
|
9
|
+
if (!iterable) {
|
|
10
|
+
throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`)
|
|
11
|
+
}
|
|
12
|
+
if (!isArray(iterable)) {
|
|
13
|
+
return false
|
|
14
|
+
}
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
}
|
|
16
|
+
return _indexOf(valueToFind, iterable) > -1
|
|
17
|
+
}
|
|
19
18
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const getOccurrences = input => input.match(/{{\s*.+?\s*}}/g)
|
|
2
|
+
const getOccurrenceProp = occurrence => occurrence.replace(/{{\s*|\s*}}/g, '')
|
|
3
|
+
|
|
4
|
+
const replace = ({ inputHolder, prop, replacer }) => {
|
|
5
|
+
const regexBase = `{{${prop}}}`
|
|
6
|
+
const regex = new RegExp(regexBase, 'g')
|
|
7
|
+
return inputHolder.replace(regex, replacer)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function interpolate(input) {
|
|
11
|
+
return templateInput => {
|
|
12
|
+
const occurrences = getOccurrences(input)
|
|
13
|
+
if (occurrences === null) {
|
|
14
|
+
return input
|
|
15
|
+
}
|
|
16
|
+
let inputHolder = input
|
|
17
|
+
|
|
18
|
+
for (const occurrence of occurrences) {
|
|
19
|
+
const prop = getOccurrenceProp(occurrence)
|
|
20
|
+
inputHolder = replace({
|
|
21
|
+
inputHolder,
|
|
22
|
+
prop,
|
|
23
|
+
replacer: templateInput[prop],
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return inputHolder
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/intersection.js
CHANGED
package/src/intersperse.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export function intersperse(separator) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
let index = -1
|
|
4
|
+
const len = list.length
|
|
5
|
+
const willReturn = []
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
while (++index < len) {
|
|
8
|
+
if (index === len - 1) {
|
|
9
|
+
willReturn.push(list[index])
|
|
10
|
+
} else {
|
|
11
|
+
willReturn.push(list[index], separator)
|
|
12
|
+
}
|
|
12
13
|
}
|
|
13
|
-
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
}
|
|
15
|
+
return willReturn
|
|
16
|
+
}
|
|
17
17
|
}
|
package/src/join.js
CHANGED
package/src/mapAsync.js
CHANGED