rambda 10.0.0-beta.1 → 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 +9 -8
- package/README.md +947 -300
- package/dist/rambda.cjs +206 -99
- package/dist/rambda.js +196 -98
- package/dist/rambda.umd.js +206 -99
- package/immutable.d.ts +586 -13
- package/index.d.ts +586 -13
- package/package.json +7 -7
- package/rambda.js +7 -1
- package/src/addPropToObjects.js +14 -0
- package/src/defaultTo.js +2 -6
- package/src/drop.js +2 -6
- package/src/flattenObject.js +76 -0
- package/src/map.js +13 -9
- package/src/{replaceItemAtIndex.js → modifyItemAtIndex.js} +1 -1
- package/src/path.js +24 -26
- package/src/pathSatisfies.js +5 -0
- package/src/propOr.js +1 -1
- package/src/range.js +14 -21
- package/src/sortBy.js +21 -12
- package/src/sortByDescending.js +5 -0
- package/src/sortByPath.js +6 -0
- package/src/sortByPathDescending.js +6 -0
package/rambda.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="./index.d.ts" />
|
|
2
2
|
export * from './src/addProp.js'
|
|
3
|
+
export * from './src/addPropToObjects.js'
|
|
3
4
|
export * from './src/all.js'
|
|
4
5
|
export * from './src/allPass.js'
|
|
5
6
|
export * from './src/any.js'
|
|
@@ -33,6 +34,7 @@ export * from './src/findLastIndex.js'
|
|
|
33
34
|
export * from './src/findNth.js'
|
|
34
35
|
export * from './src/flatMap.js'
|
|
35
36
|
export * from './src/flatten.js'
|
|
37
|
+
export * from './src/flattenObject.js'
|
|
36
38
|
export * from './src/groupBy.js'
|
|
37
39
|
export * from './src/head.js'
|
|
38
40
|
export * from './src/includes.js'
|
|
@@ -56,6 +58,7 @@ export * from './src/maxBy.js'
|
|
|
56
58
|
export * from './src/merge.js'
|
|
57
59
|
export * from './src/mergeTypes.js'
|
|
58
60
|
export * from './src/minBy.js'
|
|
61
|
+
export * from './src/modifyItemAtIndex.js'
|
|
59
62
|
export * from './src/modifyProp.js'
|
|
60
63
|
export * from './src/none.js'
|
|
61
64
|
export * from './src/objOf.js'
|
|
@@ -64,6 +67,7 @@ export * from './src/omit.js'
|
|
|
64
67
|
export * from './src/partition.js'
|
|
65
68
|
export * from './src/partitionObject.js'
|
|
66
69
|
export * from './src/path.js'
|
|
70
|
+
export * from './src/pathSatisfies.js'
|
|
67
71
|
export * from './src/permutations.js'
|
|
68
72
|
export * from './src/pick.js'
|
|
69
73
|
export * from './src/pipe.js'
|
|
@@ -79,10 +83,12 @@ export * from './src/reduce.js'
|
|
|
79
83
|
export * from './src/reject.js'
|
|
80
84
|
export * from './src/rejectObject.js'
|
|
81
85
|
export * from './src/replace.js'
|
|
82
|
-
export * from './src/replaceItemAtIndex.js'
|
|
83
86
|
export * from './src/shuffle.js'
|
|
84
87
|
export * from './src/sort.js'
|
|
85
88
|
export * from './src/sortBy.js'
|
|
89
|
+
export * from './src/sortByDescending.js'
|
|
90
|
+
export * from './src/sortByPath.js'
|
|
91
|
+
export * from './src/sortByPathDescending.js'
|
|
86
92
|
export * from './src/sortObject.js'
|
|
87
93
|
export * from './src/sortWith.js'
|
|
88
94
|
export * from './src/split.js'
|
package/src/defaultTo.js
CHANGED
|
@@ -2,10 +2,6 @@ function isFalsy(input) {
|
|
|
2
2
|
return input === undefined || input === null || Number.isNaN(input) === true
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export function defaultTo(defaultArgument
|
|
6
|
-
|
|
7
|
-
return _input => defaultTo(defaultArgument, _input)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return isFalsy(input) ? defaultArgument : input
|
|
5
|
+
export function defaultTo(defaultArgument) {
|
|
6
|
+
return input => isFalsy(input) ? defaultArgument : input
|
|
11
7
|
}
|
package/src/drop.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export function drop(howManyToDrop,
|
|
2
|
-
|
|
3
|
-
return _list => drop(howManyToDrop, _list)
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
return listOrString.slice(howManyToDrop > 0 ? howManyToDrop : 0)
|
|
1
|
+
export function drop(howManyToDrop, ) {
|
|
2
|
+
return list => list.slice(howManyToDrop > 0 ? howManyToDrop : 0)
|
|
7
3
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type } from './type.js'
|
|
2
|
+
|
|
3
|
+
export function flattenObjectHelper(obj, accumulator = []){
|
|
4
|
+
const willReturn = {}
|
|
5
|
+
Object.keys(obj).forEach(key => {
|
|
6
|
+
const typeIs = type(obj[ key ])
|
|
7
|
+
if (typeIs === 'Object'){
|
|
8
|
+
const [ flatResultValue, flatResultPath ] = flattenObjectHelper(obj[ key ],
|
|
9
|
+
[ ...accumulator, key ])
|
|
10
|
+
willReturn[ flatResultPath.join('.') ] = flatResultValue
|
|
11
|
+
|
|
12
|
+
return
|
|
13
|
+
} else if (accumulator.length > 0){
|
|
14
|
+
const finalKey = [ ...accumulator, key ].join('.')
|
|
15
|
+
willReturn[ finalKey ] = obj[ key ]
|
|
16
|
+
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
willReturn[ key ] = obj[ key ]
|
|
20
|
+
})
|
|
21
|
+
if (accumulator.length > 0) return [ willReturn, accumulator ]
|
|
22
|
+
|
|
23
|
+
return willReturn
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function transformFlatObject(obj){
|
|
27
|
+
const willReturn = {}
|
|
28
|
+
|
|
29
|
+
const transformFlatObjectFn = objLocal => {
|
|
30
|
+
const willReturnLocal = {}
|
|
31
|
+
Object.keys(objLocal).forEach(key => {
|
|
32
|
+
const typeIs = type(objLocal[ key ])
|
|
33
|
+
if (typeIs === 'Object'){
|
|
34
|
+
transformFlatObjectFn(objLocal[ key ])
|
|
35
|
+
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
willReturnLocal[ key ] = objLocal[ key ]
|
|
39
|
+
willReturn[ key ] = objLocal[ key ]
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
return willReturnLocal
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Object.keys(obj).forEach(key => {
|
|
46
|
+
const typeIs = type(obj[ key ])
|
|
47
|
+
if (typeIs === 'Object'){
|
|
48
|
+
transformFlatObjectFn(obj[ key ], key)
|
|
49
|
+
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
willReturn[ key ] = obj[ key ]
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
return willReturn
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function flattenObject(obj){
|
|
59
|
+
const willReturn = {}
|
|
60
|
+
|
|
61
|
+
Object.keys(obj).forEach(key => {
|
|
62
|
+
const typeIs = type(obj[ key ])
|
|
63
|
+
if (typeIs === 'Object'){
|
|
64
|
+
const flatObject = flattenObjectHelper(obj[ key ])
|
|
65
|
+
const transformed = transformFlatObject(flatObject)
|
|
66
|
+
|
|
67
|
+
Object.keys(transformed).forEach(keyTransformed => {
|
|
68
|
+
willReturn[ `${ key }.${ keyTransformed }` ] = transformed[ keyTransformed ]
|
|
69
|
+
})
|
|
70
|
+
} else {
|
|
71
|
+
willReturn[ key ] = obj[ key ]
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
return willReturn
|
|
76
|
+
}
|
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
|
}
|
|
@@ -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) {
|
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
|
}
|
package/src/propOr.js
CHANGED
package/src/range.js
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
|
+
function rangeDescending(start, end) {
|
|
2
|
+
const len = start - end
|
|
3
|
+
const willReturn = Array(len)
|
|
4
|
+
|
|
5
|
+
for (let i = 0; i < len; i++) {
|
|
6
|
+
willReturn[i] = start - i
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return willReturn
|
|
10
|
+
}
|
|
11
|
+
|
|
1
12
|
export function range(start) {
|
|
2
13
|
return end => {
|
|
3
14
|
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
4
15
|
throw new TypeError('Both arguments to range must be numbers')
|
|
5
16
|
}
|
|
6
17
|
|
|
7
|
-
if (end
|
|
18
|
+
if (end === start) {
|
|
8
19
|
return []
|
|
9
20
|
}
|
|
21
|
+
if (end < start) return rangeDescending(start,end)
|
|
10
22
|
|
|
11
23
|
const len = end - start
|
|
12
24
|
const willReturn = Array(len)
|
|
13
25
|
|
|
14
|
-
for (let i = 0; i < len
|
|
26
|
+
for (let i = 0; i < len; i++) {
|
|
15
27
|
willReturn[i] = start + i
|
|
16
28
|
}
|
|
17
29
|
|
|
@@ -19,23 +31,4 @@ export function range(start) {
|
|
|
19
31
|
}
|
|
20
32
|
}
|
|
21
33
|
|
|
22
|
-
export function rangeDescending(start) {
|
|
23
|
-
return end => {
|
|
24
|
-
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
25
|
-
throw new TypeError('Both arguments to range must be numbers')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (end >= start) {
|
|
29
|
-
return []
|
|
30
|
-
}
|
|
31
34
|
|
|
32
|
-
const len = start - end
|
|
33
|
-
const willReturn = Array(len)
|
|
34
|
-
|
|
35
|
-
for (let i = 0; i < len + 1; i++) {
|
|
36
|
-
willReturn[i] = start - i
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return willReturn
|
|
40
|
-
}
|
|
41
|
-
}
|
package/src/sortBy.js
CHANGED
|
@@ -1,18 +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)
|
|
9
|
+
|
|
10
|
+
return clone.sort((a, b) => {
|
|
11
|
+
const aSortResult = sortFn(a)
|
|
12
|
+
const bSortResult = sortFn(b)
|
|
6
13
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
if (aSortResult === bSortResult) {
|
|
15
|
+
return 0
|
|
16
|
+
}
|
|
17
|
+
if(
|
|
18
|
+
descending
|
|
19
|
+
) return aSortResult > bSortResult ? -1 : 1
|
|
10
20
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
21
|
+
return aSortResult < bSortResult ? -1 : 1
|
|
22
|
+
})
|
|
23
|
+
}
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
25
|
+
export function sortBy(sortFn) {
|
|
26
|
+
return list => sortByFn(sortFn, list, false)
|
|
18
27
|
}
|