rambda 10.0.0-alpha.0 → 10.0.0-beta.3
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 +125 -16
- package/README.md +8035 -3592
- package/dist/{rambda.esm.js → rambda.cjs} +800 -385
- package/dist/rambda.js +673 -486
- package/dist/rambda.umd.js +701 -388
- package/immutable.d.ts +896 -345
- package/index.d.ts +896 -345
- package/package.json +22 -15
- package/rambda.js +23 -2
- package/src/addProp.js +3 -0
- package/src/addPropToObjects.js +14 -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/defaultTo.js +2 -6
- package/src/descend.js +10 -0
- package/src/drop.js +2 -6
- 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/flattenObject.js +76 -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/map.js +13 -9
- 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/{replaceItemAtIndex.js → modifyItemAtIndex.js} +1 -1
- 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/path.js +24 -26
- package/src/pathSatisfies.js +5 -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/propOr.js +1 -1
- package/src/propSatisfies.js +1 -3
- package/src/range.js +29 -13
- 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 +20 -9
- package/src/sortByDescending.js +5 -0
- package/src/sortByPath.js +6 -0
- package/src/sortByPathDescending.js +6 -0
- 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/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/map.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
export function mapFn(
|
|
2
|
+
fn, list
|
|
3
|
+
){
|
|
4
|
+
let index = 0
|
|
5
|
+
const willReturn = Array(list.length)
|
|
6
|
+
while (index < list.length) {
|
|
7
|
+
willReturn[index] = fn(list[index], index)
|
|
8
|
+
index++
|
|
9
|
+
}
|
|
10
|
+
return willReturn
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
export function map(fn) {
|
|
2
|
-
return list =>
|
|
3
|
-
let index = 0
|
|
4
|
-
const willReturn = Array(list.length)
|
|
5
|
-
while (index < list.length) {
|
|
6
|
-
willReturn[index] = fn(list[index], index)
|
|
7
|
-
index++
|
|
8
|
-
}
|
|
9
|
-
return willReturn
|
|
10
|
-
}
|
|
14
|
+
return list => mapFn(fn, list)
|
|
11
15
|
}
|
package/src/mapAsync.js
CHANGED
package/src/mapKeys.js
ADDED
package/src/mapObjectAsync.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export function mapObjectAsync(fn) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
2
|
+
return async obj => {
|
|
3
|
+
const willReturn = {}
|
|
4
|
+
for (const prop in obj) {
|
|
5
|
+
willReturn[prop] = await fn(obj[prop], prop)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return willReturn
|
|
9
|
+
}
|
|
10
|
+
}
|
package/src/match.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function match(pattern) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
return input => {
|
|
3
|
+
const willReturn = input.match(pattern)
|
|
4
|
+
|
|
5
|
+
return willReturn === null ? [] : willReturn
|
|
6
|
+
}
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cloneList } from './_internals/cloneList.js'
|
|
2
2
|
|
|
3
|
-
export function
|
|
3
|
+
export function modifyItemAtIndex(index, replaceFn) {
|
|
4
4
|
return list => {
|
|
5
5
|
const actualIndex = index < 0 ? list.length + index : index
|
|
6
6
|
if (index >= list.length || actualIndex < 0) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isArray } from './_internals/isArray.js'
|
|
2
|
+
import { update } from './update.js'
|
|
3
|
+
|
|
4
|
+
function modifyFn(property, fn, list) {
|
|
5
|
+
if (list[property] === undefined) {
|
|
6
|
+
return list
|
|
7
|
+
}
|
|
8
|
+
if (isArray(list)) {
|
|
9
|
+
return update(property, fn(list[property]))(list)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
...list,
|
|
14
|
+
[property]: fn(list[property]),
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function modifyProp(property, fn) {
|
|
19
|
+
return obj => modifyFn(property, fn, obj)
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { equals } from './equals.js'
|
|
2
|
+
import { filterObject } from './filterObject.js'
|
|
3
|
+
|
|
4
|
+
export function objectIncludes(condition) {
|
|
5
|
+
return obj => {
|
|
6
|
+
const result = filterObject((conditionValue, conditionProp) =>
|
|
7
|
+
equals(conditionValue)(obj[conditionProp]),
|
|
8
|
+
)(condition)
|
|
9
|
+
|
|
10
|
+
return Object.keys(result).length === Object.keys(condition).length
|
|
11
|
+
}
|
|
12
|
+
}
|
package/src/partition.js
CHANGED
|
@@ -1,41 +1,17 @@
|
|
|
1
|
-
import { isArray } from './_internals/isArray.js'
|
|
2
|
-
|
|
3
|
-
export function partitionObject(predicate, iterable) {
|
|
4
|
-
const yes = {}
|
|
5
|
-
const no = {}
|
|
6
|
-
Object.entries(iterable).forEach(([prop, value]) => {
|
|
7
|
-
if (predicate(value, prop)) {
|
|
8
|
-
yes[prop] = value
|
|
9
|
-
} else {
|
|
10
|
-
no[prop] = value
|
|
11
|
-
}
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
return [yes, no]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function partitionArray(predicate, list, indexed = false) {
|
|
18
|
-
const yes = []
|
|
19
|
-
const no = []
|
|
20
|
-
let counter = -1
|
|
21
|
-
|
|
22
|
-
while (counter++ < list.length - 1) {
|
|
23
|
-
if (indexed ? predicate(list[counter], counter) : predicate(list[counter])) {
|
|
24
|
-
yes.push(list[counter])
|
|
25
|
-
} else {
|
|
26
|
-
no.push(list[counter])
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return [yes, no]
|
|
31
|
-
}
|
|
32
|
-
|
|
33
1
|
export function partition(predicate) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
const yes = []
|
|
4
|
+
const no = []
|
|
5
|
+
let counter = -1
|
|
6
|
+
|
|
7
|
+
while (counter++ < list.length - 1) {
|
|
8
|
+
if (predicate(list[counter], counter)) {
|
|
9
|
+
yes.push(list[counter])
|
|
10
|
+
} else {
|
|
11
|
+
no.push(list[counter])
|
|
12
|
+
}
|
|
37
13
|
}
|
|
38
14
|
|
|
39
|
-
return
|
|
40
|
-
|
|
15
|
+
return [yes, no]
|
|
16
|
+
}
|
|
41
17
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function partitionObject(predicate) {
|
|
2
|
+
return obj => {
|
|
3
|
+
const yes = {}
|
|
4
|
+
const no = {}
|
|
5
|
+
Object.entries(obj).forEach(([prop, value]) => {
|
|
6
|
+
if (predicate(value, prop)) {
|
|
7
|
+
yes[prop] = value
|
|
8
|
+
} else {
|
|
9
|
+
no[prop] = value
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return [yes, no]
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/path.js
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import { createPath } from './_internals/createPath.js'
|
|
2
2
|
|
|
3
|
-
export function path(pathInput
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return willReturn
|
|
3
|
+
export function path(pathInput) {
|
|
4
|
+
return (obj) => {
|
|
5
|
+
if (!obj) {
|
|
6
|
+
return undefined
|
|
7
|
+
}
|
|
8
|
+
let willReturn = obj
|
|
9
|
+
let counter = 0
|
|
10
|
+
|
|
11
|
+
const pathArrValue = createPath(pathInput)
|
|
12
|
+
|
|
13
|
+
while (counter < pathArrValue.length) {
|
|
14
|
+
if (willReturn === null || willReturn === undefined) {
|
|
15
|
+
return undefined
|
|
16
|
+
}
|
|
17
|
+
if (willReturn[pathArrValue[counter]] === null) {
|
|
18
|
+
return undefined
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
willReturn = willReturn[pathArrValue[counter]]
|
|
22
|
+
counter++
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return willReturn
|
|
26
|
+
}
|
|
29
27
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { cloneList } from './_internals/cloneList.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Source:
|
|
5
|
+
* https://github.com/denoland/std/blob/main/collections/permutations.ts
|
|
6
|
+
*/
|
|
7
|
+
export function permutations(inputArray) {
|
|
8
|
+
const result = [];
|
|
9
|
+
const array = cloneList(inputArray);
|
|
10
|
+
const k = array.length;
|
|
11
|
+
if (k === 0) {
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const c = new Array(k).fill(0);
|
|
16
|
+
|
|
17
|
+
result.push([...array]);
|
|
18
|
+
|
|
19
|
+
let i = 1;
|
|
20
|
+
|
|
21
|
+
while (i < k) {
|
|
22
|
+
if (c[i] < i) {
|
|
23
|
+
if (i % 2 === 0) {
|
|
24
|
+
[array[0], array[i]] = [array[i], array[0]]
|
|
25
|
+
} else {
|
|
26
|
+
[array[c[i]], array[i]] = [array[i], array[c[i]]]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
result.push([...array]);
|
|
30
|
+
|
|
31
|
+
c[i] += 1;
|
|
32
|
+
i = 1;
|
|
33
|
+
} else {
|
|
34
|
+
c[i] = 0;
|
|
35
|
+
i += 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return result;
|
|
40
|
+
}
|
package/src/pipeAsync.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type } from './type.js'
|
|
2
2
|
|
|
3
3
|
export async function pipeAsync(input, ...fnList) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
let willReturn = input
|
|
5
|
+
for (const fn of fnList) {
|
|
6
|
+
const initialResult = fn(willReturn)
|
|
7
|
+
willReturn =
|
|
8
|
+
type(initialResult) === 'Promise' ? await initialResult : initialResult
|
|
9
|
+
}
|
|
10
|
+
return willReturn
|
|
10
11
|
}
|
package/src/pluck.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export function pluck(property) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
return list => {
|
|
3
|
+
const willReturn = []
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
list.forEach(x => {
|
|
6
|
+
if (x[property] !== undefined) {
|
|
7
|
+
willReturn.push(x[property])
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
}
|
|
11
|
+
return willReturn
|
|
12
|
+
}
|
|
13
13
|
}
|
package/src/prepend.js
CHANGED
package/src/propOr.js
CHANGED
package/src/propSatisfies.js
CHANGED
package/src/range.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
throw new TypeError('Both arguments to range must be numbers')
|
|
5
|
-
}
|
|
1
|
+
function rangeDescending(start, end) {
|
|
2
|
+
const len = start - end
|
|
3
|
+
const willReturn = Array(len)
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
for (let i = 0; i < len; i++) {
|
|
6
|
+
willReturn[i] = start - i
|
|
7
|
+
}
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
return willReturn
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export function range(start) {
|
|
13
|
+
return end => {
|
|
14
|
+
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
15
|
+
throw new TypeError('Both arguments to range must be numbers')
|
|
16
|
+
}
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
if (end === start) {
|
|
19
|
+
return []
|
|
20
|
+
}
|
|
21
|
+
if (end < start) return rangeDescending(start,end)
|
|
22
|
+
|
|
23
|
+
const len = end - start
|
|
24
|
+
const willReturn = Array(len)
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < len; i++) {
|
|
27
|
+
willReturn[i] = start + i
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return willReturn
|
|
31
|
+
}
|
|
18
32
|
}
|
|
33
|
+
|
|
34
|
+
|
package/src/reject.js
CHANGED
package/src/shuffle.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function shuffle(listInput) {
|
|
2
|
+
const list = cloneList(listInput)
|
|
3
|
+
let counter = list.length
|
|
4
|
+
while (counter > 0) {
|
|
5
|
+
const index = Math.floor(Math.random() * counter)
|
|
6
|
+
counter--
|
|
7
|
+
const temp = list[counter]
|
|
8
|
+
list[counter] = list[index]
|
|
9
|
+
list[index] = temp
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return list
|
|
13
|
+
}
|
package/src/sort.js
CHANGED
package/src/sortBy.js
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import { cloneList } from './_internals/cloneList.js'
|
|
2
2
|
|
|
3
|
-
export function
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export function sortByFn (
|
|
4
|
+
sortFn,
|
|
5
|
+
list,
|
|
6
|
+
descending
|
|
7
|
+
){
|
|
8
|
+
const clone = cloneList(list)
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
return clone.sort((a, b) => {
|
|
11
|
+
const aSortResult = sortFn(a)
|
|
12
|
+
const bSortResult = sortFn(b)
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
if (aSortResult === bSortResult) {
|
|
15
|
+
return 0
|
|
16
|
+
}
|
|
17
|
+
if(
|
|
18
|
+
descending
|
|
19
|
+
) return aSortResult > bSortResult ? -1 : 1
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
return aSortResult < bSortResult ? -1 : 1
|
|
22
|
+
})
|
|
15
23
|
}
|
|
24
|
+
|
|
25
|
+
export function sortBy(sortFn) {
|
|
26
|
+
return list => sortByFn(sortFn, list, false)
|
|
16
27
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { sort } from './sort.js'
|
|
2
|
+
|
|
3
|
+
export function sortObject(predicate) {
|
|
4
|
+
return obj => {
|
|
5
|
+
const keys = Object.keys(obj)
|
|
6
|
+
const sortedKeys = sort((a, b) => predicate(a, b, obj[a], obj[b]))(keys)
|
|
7
|
+
|
|
8
|
+
const toReturn = {}
|
|
9
|
+
sortedKeys.forEach(singleKey => {
|
|
10
|
+
toReturn[singleKey] = obj[singleKey]
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return toReturn
|
|
14
|
+
}
|
|
15
|
+
}
|