rambda 10.0.1 → 10.2.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/CHANGELOG.md +8 -0
- package/README.md +292 -1
- package/dist/rambda.cjs +76 -32
- package/dist/rambda.js +74 -33
- package/dist/rambda.umd.js +76 -32
- package/index.d.cts +2313 -0
- package/index.d.ts +128 -0
- package/package.json +4 -3
- package/rambda.js +3 -0
- package/src/assertType.js +8 -0
- package/src/convertToType.js +3 -0
- package/src/modifyPath.js +30 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
10.1.0
|
|
2
|
+
|
|
3
|
+
- Add `R.assertType` and `R.convertToType` methods
|
|
4
|
+
|
|
5
|
+
- Fix issue with exports in old Node.js versions - [Discussion #768](https://github.com/selfrefactor/rambda/discussions/768)
|
|
6
|
+
|
|
7
|
+
- Fix `deno` release as it was not possible for users to import version `10.0.0`
|
|
8
|
+
|
|
1
9
|
10.0.1
|
|
2
10
|
|
|
3
11
|
- Fix issue with `R.unwind`/`R.pick` typings - [Issue #766](https://github.com/selfrefactor/rambda/issues/766)
|
package/README.md
CHANGED
|
@@ -1021,6 +1021,103 @@ it('R.ascend', () => {
|
|
|
1021
1021
|
|
|
1022
1022
|
[](#ascend)
|
|
1023
1023
|
|
|
1024
|
+
### assertType
|
|
1025
|
+
|
|
1026
|
+
```typescript
|
|
1027
|
+
|
|
1028
|
+
assertType<T, U extends T>(fn: (x: T) => x is U) : (x: T) => U
|
|
1029
|
+
```
|
|
1030
|
+
|
|
1031
|
+
It helps to make sure that input is from specific type. Similar to `R.convertToType`, but it actually checks the type of the input value. If `fn` input returns falsy value, then the function will throw an error.
|
|
1032
|
+
|
|
1033
|
+
<details>
|
|
1034
|
+
|
|
1035
|
+
<summary>All TypeScript definitions</summary>
|
|
1036
|
+
|
|
1037
|
+
```typescript
|
|
1038
|
+
assertType<T, U extends T>(fn: (x: T) => x is U) : (x: T) => U;
|
|
1039
|
+
```
|
|
1040
|
+
|
|
1041
|
+
</details>
|
|
1042
|
+
|
|
1043
|
+
<details>
|
|
1044
|
+
|
|
1045
|
+
<summary><strong>R.assertType</strong> source</summary>
|
|
1046
|
+
|
|
1047
|
+
```javascript
|
|
1048
|
+
export function assertType(fn) {
|
|
1049
|
+
return (x) => {
|
|
1050
|
+
if (fn(x)) {
|
|
1051
|
+
return x
|
|
1052
|
+
}
|
|
1053
|
+
throw new Error('type assertion failed in R.assertType')
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
```
|
|
1057
|
+
|
|
1058
|
+
</details>
|
|
1059
|
+
|
|
1060
|
+
<details>
|
|
1061
|
+
|
|
1062
|
+
<summary><strong>Tests</strong></summary>
|
|
1063
|
+
|
|
1064
|
+
```javascript
|
|
1065
|
+
import { assertType } from './assertType.js'
|
|
1066
|
+
import { pipe } from './pipe.js'
|
|
1067
|
+
|
|
1068
|
+
test('happy', () => {
|
|
1069
|
+
const result = pipe(
|
|
1070
|
+
[1, 2, 3],
|
|
1071
|
+
assertType((x) => x.length === 3),
|
|
1072
|
+
)
|
|
1073
|
+
expect(result).toEqual([1, 2, 3])
|
|
1074
|
+
})
|
|
1075
|
+
|
|
1076
|
+
test('throw', () => {
|
|
1077
|
+
expect(() => {
|
|
1078
|
+
pipe(
|
|
1079
|
+
[1, 2, 3],
|
|
1080
|
+
assertType((x) => x.length === 4),
|
|
1081
|
+
)
|
|
1082
|
+
}).toThrow('type assertion failed in R.assertType')
|
|
1083
|
+
})
|
|
1084
|
+
```
|
|
1085
|
+
|
|
1086
|
+
</details>
|
|
1087
|
+
|
|
1088
|
+
<details>
|
|
1089
|
+
|
|
1090
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
1091
|
+
|
|
1092
|
+
```typescript
|
|
1093
|
+
import { pipe, assertType } from 'rambda'
|
|
1094
|
+
|
|
1095
|
+
type Book = {
|
|
1096
|
+
title: string
|
|
1097
|
+
year: number
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
type BookToRead = Book & {
|
|
1101
|
+
bookmarkFlag: boolean
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
function isBookToRead(book: Book): book is BookToRead {
|
|
1105
|
+
return (book as BookToRead).bookmarkFlag !== undefined
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
it('R.assertType', () => {
|
|
1109
|
+
const result = pipe(
|
|
1110
|
+
{ title: 'Book1', year: 2020, bookmarkFlag: true },
|
|
1111
|
+
assertType(isBookToRead),
|
|
1112
|
+
)
|
|
1113
|
+
result // $ExpectType BookToRead
|
|
1114
|
+
})
|
|
1115
|
+
```
|
|
1116
|
+
|
|
1117
|
+
</details>
|
|
1118
|
+
|
|
1119
|
+
[](#assertType)
|
|
1120
|
+
|
|
1024
1121
|
### checkObjectWithSpec
|
|
1025
1122
|
|
|
1026
1123
|
```typescript
|
|
@@ -1429,6 +1526,63 @@ it('R.concat', () => {
|
|
|
1429
1526
|
|
|
1430
1527
|
[](#concat)
|
|
1431
1528
|
|
|
1529
|
+
### convertToType
|
|
1530
|
+
|
|
1531
|
+
```typescript
|
|
1532
|
+
|
|
1533
|
+
convertToType<T>(x: unknown) : T
|
|
1534
|
+
```
|
|
1535
|
+
|
|
1536
|
+
It helps to convert a value to a specific type.
|
|
1537
|
+
It is useful when you have to overcome TypeScript's type inference.
|
|
1538
|
+
|
|
1539
|
+
<details>
|
|
1540
|
+
|
|
1541
|
+
<summary>All TypeScript definitions</summary>
|
|
1542
|
+
|
|
1543
|
+
```typescript
|
|
1544
|
+
convertToType<T>(x: unknown) : T;
|
|
1545
|
+
```
|
|
1546
|
+
|
|
1547
|
+
</details>
|
|
1548
|
+
|
|
1549
|
+
<details>
|
|
1550
|
+
|
|
1551
|
+
<summary><strong>R.convertToType</strong> source</summary>
|
|
1552
|
+
|
|
1553
|
+
```javascript
|
|
1554
|
+
export function convertToType(x) {
|
|
1555
|
+
return x
|
|
1556
|
+
}
|
|
1557
|
+
```
|
|
1558
|
+
|
|
1559
|
+
</details>
|
|
1560
|
+
|
|
1561
|
+
<details>
|
|
1562
|
+
|
|
1563
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
1564
|
+
|
|
1565
|
+
```typescript
|
|
1566
|
+
import { convertToType, pipe } from 'rambda'
|
|
1567
|
+
|
|
1568
|
+
const list = [1, 2, 3]
|
|
1569
|
+
|
|
1570
|
+
it('R.convertToType', () => {
|
|
1571
|
+
const result = pipe(list,
|
|
1572
|
+
convertToType<string[]>,
|
|
1573
|
+
x => {
|
|
1574
|
+
x // $ExpectType string[]
|
|
1575
|
+
return x
|
|
1576
|
+
}
|
|
1577
|
+
)
|
|
1578
|
+
result // $ExpectType string[]
|
|
1579
|
+
})
|
|
1580
|
+
```
|
|
1581
|
+
|
|
1582
|
+
</details>
|
|
1583
|
+
|
|
1584
|
+
[](#convertToType)
|
|
1585
|
+
|
|
1432
1586
|
### count
|
|
1433
1587
|
|
|
1434
1588
|
```typescript
|
|
@@ -6560,6 +6714,135 @@ test('when index is out of bounds', () => {
|
|
|
6560
6714
|
|
|
6561
6715
|
[](#modifyItemAtIndex)
|
|
6562
6716
|
|
|
6717
|
+
### modifyPath
|
|
6718
|
+
|
|
6719
|
+
```typescript
|
|
6720
|
+
|
|
6721
|
+
modifyPath<U, T>(path: [], fn: (value: U) => T): (obj: U) => T
|
|
6722
|
+
```
|
|
6723
|
+
|
|
6724
|
+
It changes a property of object on the base of provided path and transformer function.
|
|
6725
|
+
|
|
6726
|
+
```javascript
|
|
6727
|
+
const result = R.modifyPath('a.b.c', x=> x+1, {a:{b: {c:1}}})
|
|
6728
|
+
// => {a:{b: {c:2}}}
|
|
6729
|
+
```
|
|
6730
|
+
|
|
6731
|
+
<a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.modifyPath('a.b.c'%2C%20x%3D%3E%20x%2B1%2C%20%7Ba%3A%7Bb%3A%20%7Bc%3A1%7D%7D%7D)%0A%2F%2F%20%3D%3E%20%7Ba%3A%7Bb%3A%20%7Bc%3A2%7D%7D%7D">Try this <strong>R.modifyPath</strong> example in Rambda REPL</a>
|
|
6732
|
+
|
|
6733
|
+
<details>
|
|
6734
|
+
|
|
6735
|
+
<summary>All TypeScript definitions</summary>
|
|
6736
|
+
|
|
6737
|
+
```typescript
|
|
6738
|
+
modifyPath<U, T>(path: [], fn: (value: U) => T): (obj: U) => T;
|
|
6739
|
+
modifyPath<
|
|
6740
|
+
K0 extends keyof U,
|
|
6741
|
+
U,
|
|
6742
|
+
T
|
|
6743
|
+
>(path: [K0], fn: (value: U[K0]) => T): (obj: U) => DeepModify<[K0], U, T>;
|
|
6744
|
+
modifyPath<
|
|
6745
|
+
K0 extends string & keyof U,
|
|
6746
|
+
U,
|
|
6747
|
+
T
|
|
6748
|
+
>(path: `${K0}`, fn: (value: U[K0]) => T): (obj: U) => DeepModify<[K0], U, T>;
|
|
6749
|
+
modifyPath<
|
|
6750
|
+
K0 extends keyof U,
|
|
6751
|
+
K1 extends keyof U[K0],
|
|
6752
|
+
U,
|
|
6753
|
+
T
|
|
6754
|
+
>(path: [K0, K1], fn: (value: U[K0][K1]) => T): (obj: U) => DeepModify<[K0, K1], U, T>;
|
|
6755
|
+
...
|
|
6756
|
+
...
|
|
6757
|
+
```
|
|
6758
|
+
|
|
6759
|
+
</details>
|
|
6760
|
+
|
|
6761
|
+
<details>
|
|
6762
|
+
|
|
6763
|
+
<summary><strong>R.modifyPath</strong> source</summary>
|
|
6764
|
+
|
|
6765
|
+
```javascript
|
|
6766
|
+
import { createPath } from './_internals/createPath.js'
|
|
6767
|
+
import { path as pathModule } from './path.js'
|
|
6768
|
+
|
|
6769
|
+
function assoc(prop, newValue) {
|
|
6770
|
+
return obj => Object.assign({}, obj, { [prop]: newValue })
|
|
6771
|
+
}
|
|
6772
|
+
|
|
6773
|
+
function modifyPathFn(pathInput, fn, obj) {
|
|
6774
|
+
const path = createPath(pathInput)
|
|
6775
|
+
if (path.length === 1) {
|
|
6776
|
+
return {
|
|
6777
|
+
...obj,
|
|
6778
|
+
[path[0]]: fn(obj[path[0]]),
|
|
6779
|
+
}
|
|
6780
|
+
}
|
|
6781
|
+
if (pathModule(path)(obj) === undefined) {
|
|
6782
|
+
return obj
|
|
6783
|
+
}
|
|
6784
|
+
|
|
6785
|
+
const val = modifyPathFn(Array.prototype.slice.call(path, 1), fn, obj[path[0]])
|
|
6786
|
+
if (val === obj[path[0]]) {
|
|
6787
|
+
return obj
|
|
6788
|
+
}
|
|
6789
|
+
|
|
6790
|
+
return assoc(path[0], val)(obj)
|
|
6791
|
+
}
|
|
6792
|
+
|
|
6793
|
+
export function modifyPath(pathInput, fn) {
|
|
6794
|
+
return obj => modifyPathFn(pathInput, fn, obj)
|
|
6795
|
+
}
|
|
6796
|
+
```
|
|
6797
|
+
|
|
6798
|
+
</details>
|
|
6799
|
+
|
|
6800
|
+
<details>
|
|
6801
|
+
|
|
6802
|
+
<summary><strong>Tests</strong></summary>
|
|
6803
|
+
|
|
6804
|
+
```javascript
|
|
6805
|
+
import { modifyPath } from './modifyPath.js'
|
|
6806
|
+
|
|
6807
|
+
test('happy', () => {
|
|
6808
|
+
const result = modifyPath('a.b.c', x => x + 1)({ a: { b: { c: 1 } } })
|
|
6809
|
+
expect(result).toEqual({ a: { b: { c: 2 } } })
|
|
6810
|
+
})
|
|
6811
|
+
```
|
|
6812
|
+
|
|
6813
|
+
</details>
|
|
6814
|
+
|
|
6815
|
+
<details>
|
|
6816
|
+
|
|
6817
|
+
<summary><strong>TypeScript</strong> test</summary>
|
|
6818
|
+
|
|
6819
|
+
```typescript
|
|
6820
|
+
import { modifyPath, pipe } from 'rambda'
|
|
6821
|
+
|
|
6822
|
+
const obj = { a: { b: { c: 1 } } }
|
|
6823
|
+
|
|
6824
|
+
describe('R.modifyPath', () => {
|
|
6825
|
+
it('array path', () => {
|
|
6826
|
+
const result = pipe(
|
|
6827
|
+
obj,
|
|
6828
|
+
modifyPath(['a', 'b', 'c'], (x: number) => String(x)),
|
|
6829
|
+
)
|
|
6830
|
+
result.a.b.c // $ExpectType string
|
|
6831
|
+
})
|
|
6832
|
+
it('string path', () => {
|
|
6833
|
+
const result = pipe(
|
|
6834
|
+
obj,
|
|
6835
|
+
modifyPath('a.b.c', (x: number) => String(x)),
|
|
6836
|
+
)
|
|
6837
|
+
result.a.b.c // $ExpectType string
|
|
6838
|
+
})
|
|
6839
|
+
})
|
|
6840
|
+
```
|
|
6841
|
+
|
|
6842
|
+
</details>
|
|
6843
|
+
|
|
6844
|
+
[](#modifyPath)
|
|
6845
|
+
|
|
6563
6846
|
### modifyProp
|
|
6564
6847
|
|
|
6565
6848
|
```typescript
|
|
@@ -8219,7 +8502,7 @@ function assertType<T, U extends T>(fn: (x: T) => x is U) {
|
|
|
8219
8502
|
function convertToType<T>() {
|
|
8220
8503
|
return <U>(x: U) => x as unknown as T
|
|
8221
8504
|
}
|
|
8222
|
-
const convertToType = <T>(x: unknown)=> x as unknown as T
|
|
8505
|
+
// const convertToType = <T>(x: unknown)=> x as unknown as T
|
|
8223
8506
|
|
|
8224
8507
|
function tapFn<T, U>(
|
|
8225
8508
|
transformFn: (x: T) => U,
|
|
@@ -12706,6 +12989,14 @@ describe('R.zipWith', () => {
|
|
|
12706
12989
|
|
|
12707
12990
|
## ❯ CHANGELOG
|
|
12708
12991
|
|
|
12992
|
+
10.1.0
|
|
12993
|
+
|
|
12994
|
+
- Add `R.assertType` and `R.convertToType` methods
|
|
12995
|
+
|
|
12996
|
+
- Fix issue with exports in old Node.js versions - [Discussion #768](https://github.com/selfrefactor/rambda/discussions/768)
|
|
12997
|
+
|
|
12998
|
+
- Fix `deno` release as it was not possible for users to import version `10.0.0`
|
|
12999
|
+
|
|
12709
13000
|
10.0.1
|
|
12710
13001
|
|
|
12711
13002
|
- Fix issue with `R.unwind`/`R.pick` typings - [Issue #766](https://github.com/selfrefactor/rambda/issues/766)
|
package/dist/rambda.cjs
CHANGED
|
@@ -115,6 +115,15 @@ function ascend(getFunction) {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
function assertType(fn) {
|
|
119
|
+
return (x) => {
|
|
120
|
+
if (fn(x)) {
|
|
121
|
+
return x
|
|
122
|
+
}
|
|
123
|
+
throw new Error('type assertion failed in R.assertType')
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
118
127
|
function checkObjectWithSpec(conditions) {
|
|
119
128
|
return input => {
|
|
120
129
|
let shouldProceed = true;
|
|
@@ -190,6 +199,10 @@ function concat(x) {
|
|
|
190
199
|
return y => (typeof x === 'string' ? `${x}${y}` : [...x, ...y])
|
|
191
200
|
}
|
|
192
201
|
|
|
202
|
+
function convertToType(x) {
|
|
203
|
+
return x
|
|
204
|
+
}
|
|
205
|
+
|
|
193
206
|
function count(predicate) {
|
|
194
207
|
return list => {
|
|
195
208
|
if (!isArray(list)) {
|
|
@@ -997,6 +1010,66 @@ function modifyItemAtIndex(index, replaceFn) {
|
|
|
997
1010
|
}
|
|
998
1011
|
}
|
|
999
1012
|
|
|
1013
|
+
function createPath(path, delimiter = '.') {
|
|
1014
|
+
return typeof path === 'string'
|
|
1015
|
+
? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
|
|
1016
|
+
: path
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
function path(pathInput) {
|
|
1020
|
+
return (obj) => {
|
|
1021
|
+
if (!obj) {
|
|
1022
|
+
return undefined
|
|
1023
|
+
}
|
|
1024
|
+
let willReturn = obj;
|
|
1025
|
+
let counter = 0;
|
|
1026
|
+
|
|
1027
|
+
const pathArrValue = createPath(pathInput);
|
|
1028
|
+
|
|
1029
|
+
while (counter < pathArrValue.length) {
|
|
1030
|
+
if (willReturn === null || willReturn === undefined) {
|
|
1031
|
+
return undefined
|
|
1032
|
+
}
|
|
1033
|
+
if (willReturn[pathArrValue[counter]] === null) {
|
|
1034
|
+
return undefined
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
willReturn = willReturn[pathArrValue[counter]];
|
|
1038
|
+
counter++;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
return willReturn
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
function assoc(prop, newValue) {
|
|
1046
|
+
return obj => Object.assign({}, obj, { [prop]: newValue })
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
function modifyPathFn(pathInput, fn, obj) {
|
|
1050
|
+
const path$1 = createPath(pathInput);
|
|
1051
|
+
if (path$1.length === 1) {
|
|
1052
|
+
return {
|
|
1053
|
+
...obj,
|
|
1054
|
+
[path$1[0]]: fn(obj[path$1[0]]),
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
if (path(path$1)(obj) === undefined) {
|
|
1058
|
+
return obj
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
const val = modifyPathFn(Array.prototype.slice.call(path$1, 1), fn, obj[path$1[0]]);
|
|
1062
|
+
if (val === obj[path$1[0]]) {
|
|
1063
|
+
return obj
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
return assoc(path$1[0], val)(obj)
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
function modifyPath(pathInput, fn) {
|
|
1070
|
+
return obj => modifyPathFn(pathInput, fn, obj)
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1000
1073
|
function update(index, newValue) {
|
|
1001
1074
|
return list => {
|
|
1002
1075
|
const clone = cloneList(list);
|
|
@@ -1052,12 +1125,6 @@ function objectIncludes(condition) {
|
|
|
1052
1125
|
}
|
|
1053
1126
|
}
|
|
1054
1127
|
|
|
1055
|
-
function createPath(path, delimiter = '.') {
|
|
1056
|
-
return typeof path === 'string'
|
|
1057
|
-
? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
|
|
1058
|
-
: path
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
1128
|
function _includes(x, list) {
|
|
1062
1129
|
let index = -1;
|
|
1063
1130
|
const { length } = list;
|
|
@@ -1124,32 +1191,6 @@ function partitionObject(predicate) {
|
|
|
1124
1191
|
}
|
|
1125
1192
|
}
|
|
1126
1193
|
|
|
1127
|
-
function path(pathInput) {
|
|
1128
|
-
return (obj) => {
|
|
1129
|
-
if (!obj) {
|
|
1130
|
-
return undefined
|
|
1131
|
-
}
|
|
1132
|
-
let willReturn = obj;
|
|
1133
|
-
let counter = 0;
|
|
1134
|
-
|
|
1135
|
-
const pathArrValue = createPath(pathInput);
|
|
1136
|
-
|
|
1137
|
-
while (counter < pathArrValue.length) {
|
|
1138
|
-
if (willReturn === null || willReturn === undefined) {
|
|
1139
|
-
return undefined
|
|
1140
|
-
}
|
|
1141
|
-
if (willReturn[pathArrValue[counter]] === null) {
|
|
1142
|
-
return undefined
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
willReturn = willReturn[pathArrValue[counter]];
|
|
1146
|
-
counter++;
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
return willReturn
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
1194
|
function pathSatisfies(fn, pathInput) {
|
|
1154
1195
|
return obj => Boolean(fn(path(pathInput)(obj)))
|
|
1155
1196
|
}
|
|
@@ -1787,10 +1828,12 @@ exports.any = any;
|
|
|
1787
1828
|
exports.anyPass = anyPass;
|
|
1788
1829
|
exports.append = append;
|
|
1789
1830
|
exports.ascend = ascend;
|
|
1831
|
+
exports.assertType = assertType;
|
|
1790
1832
|
exports.checkObjectWithSpec = checkObjectWithSpec;
|
|
1791
1833
|
exports.compact = compact;
|
|
1792
1834
|
exports.complement = complement;
|
|
1793
1835
|
exports.concat = concat;
|
|
1836
|
+
exports.convertToType = convertToType;
|
|
1794
1837
|
exports.count = count;
|
|
1795
1838
|
exports.countBy = countBy;
|
|
1796
1839
|
exports.createCompareFunction = createCompareFunction;
|
|
@@ -1844,6 +1887,7 @@ exports.merge = merge;
|
|
|
1844
1887
|
exports.mergeTypes = mergeTypes;
|
|
1845
1888
|
exports.minBy = minBy;
|
|
1846
1889
|
exports.modifyItemAtIndex = modifyItemAtIndex;
|
|
1890
|
+
exports.modifyPath = modifyPath;
|
|
1847
1891
|
exports.modifyProp = modifyProp;
|
|
1848
1892
|
exports.none = none;
|
|
1849
1893
|
exports.objOf = objOf;
|
package/dist/rambda.js
CHANGED
|
@@ -113,6 +113,15 @@ function ascend(getFunction) {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
function assertType(fn) {
|
|
117
|
+
return (x) => {
|
|
118
|
+
if (fn(x)) {
|
|
119
|
+
return x
|
|
120
|
+
}
|
|
121
|
+
throw new Error('type assertion failed in R.assertType')
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
116
125
|
function checkObjectWithSpec(conditions) {
|
|
117
126
|
return input => {
|
|
118
127
|
let shouldProceed = true;
|
|
@@ -188,6 +197,10 @@ function concat(x) {
|
|
|
188
197
|
return y => (typeof x === 'string' ? `${x}${y}` : [...x, ...y])
|
|
189
198
|
}
|
|
190
199
|
|
|
200
|
+
function convertToType(x) {
|
|
201
|
+
return x
|
|
202
|
+
}
|
|
203
|
+
|
|
191
204
|
function count(predicate) {
|
|
192
205
|
return list => {
|
|
193
206
|
if (!isArray(list)) {
|
|
@@ -995,6 +1008,66 @@ function modifyItemAtIndex(index, replaceFn) {
|
|
|
995
1008
|
}
|
|
996
1009
|
}
|
|
997
1010
|
|
|
1011
|
+
function createPath(path, delimiter = '.') {
|
|
1012
|
+
return typeof path === 'string'
|
|
1013
|
+
? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
|
|
1014
|
+
: path
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
function path(pathInput) {
|
|
1018
|
+
return (obj) => {
|
|
1019
|
+
if (!obj) {
|
|
1020
|
+
return undefined
|
|
1021
|
+
}
|
|
1022
|
+
let willReturn = obj;
|
|
1023
|
+
let counter = 0;
|
|
1024
|
+
|
|
1025
|
+
const pathArrValue = createPath(pathInput);
|
|
1026
|
+
|
|
1027
|
+
while (counter < pathArrValue.length) {
|
|
1028
|
+
if (willReturn === null || willReturn === undefined) {
|
|
1029
|
+
return undefined
|
|
1030
|
+
}
|
|
1031
|
+
if (willReturn[pathArrValue[counter]] === null) {
|
|
1032
|
+
return undefined
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
willReturn = willReturn[pathArrValue[counter]];
|
|
1036
|
+
counter++;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
return willReturn
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
function assoc(prop, newValue) {
|
|
1044
|
+
return obj => Object.assign({}, obj, { [prop]: newValue })
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
function modifyPathFn(pathInput, fn, obj) {
|
|
1048
|
+
const path$1 = createPath(pathInput);
|
|
1049
|
+
if (path$1.length === 1) {
|
|
1050
|
+
return {
|
|
1051
|
+
...obj,
|
|
1052
|
+
[path$1[0]]: fn(obj[path$1[0]]),
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
if (path(path$1)(obj) === undefined) {
|
|
1056
|
+
return obj
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
const val = modifyPathFn(Array.prototype.slice.call(path$1, 1), fn, obj[path$1[0]]);
|
|
1060
|
+
if (val === obj[path$1[0]]) {
|
|
1061
|
+
return obj
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
return assoc(path$1[0], val)(obj)
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
function modifyPath(pathInput, fn) {
|
|
1068
|
+
return obj => modifyPathFn(pathInput, fn, obj)
|
|
1069
|
+
}
|
|
1070
|
+
|
|
998
1071
|
function update(index, newValue) {
|
|
999
1072
|
return list => {
|
|
1000
1073
|
const clone = cloneList(list);
|
|
@@ -1050,12 +1123,6 @@ function objectIncludes(condition) {
|
|
|
1050
1123
|
}
|
|
1051
1124
|
}
|
|
1052
1125
|
|
|
1053
|
-
function createPath(path, delimiter = '.') {
|
|
1054
|
-
return typeof path === 'string'
|
|
1055
|
-
? path.split(delimiter).map(x => (Number.isInteger(Number(x)) ? Number(x) : x))
|
|
1056
|
-
: path
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
1126
|
function _includes(x, list) {
|
|
1060
1127
|
let index = -1;
|
|
1061
1128
|
const { length } = list;
|
|
@@ -1122,32 +1189,6 @@ function partitionObject(predicate) {
|
|
|
1122
1189
|
}
|
|
1123
1190
|
}
|
|
1124
1191
|
|
|
1125
|
-
function path(pathInput) {
|
|
1126
|
-
return (obj) => {
|
|
1127
|
-
if (!obj) {
|
|
1128
|
-
return undefined
|
|
1129
|
-
}
|
|
1130
|
-
let willReturn = obj;
|
|
1131
|
-
let counter = 0;
|
|
1132
|
-
|
|
1133
|
-
const pathArrValue = createPath(pathInput);
|
|
1134
|
-
|
|
1135
|
-
while (counter < pathArrValue.length) {
|
|
1136
|
-
if (willReturn === null || willReturn === undefined) {
|
|
1137
|
-
return undefined
|
|
1138
|
-
}
|
|
1139
|
-
if (willReturn[pathArrValue[counter]] === null) {
|
|
1140
|
-
return undefined
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
willReturn = willReturn[pathArrValue[counter]];
|
|
1144
|
-
counter++;
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
return willReturn
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
1192
|
function pathSatisfies(fn, pathInput) {
|
|
1152
1193
|
return obj => Boolean(fn(path(pathInput)(obj)))
|
|
1153
1194
|
}
|
|
@@ -1773,4 +1814,4 @@ function zipWith(fn, x) {
|
|
|
1773
1814
|
)
|
|
1774
1815
|
}
|
|
1775
1816
|
|
|
1776
|
-
export { _arity, _includes, _indexOf, _lastIndexOf, addProp, addPropToObjects, all, allPass, any, anyPass, append, ascend, checkObjectWithSpec, compact, complement, concat, count, countBy, createCompareFunction, createObjectFromKeys, defaultTo, descend, drop, dropLast, dropLastWhile, dropWhile, eqBy, eqProps, equals, equalsFn, evolve, excludes, filter, filterObject, find, findIndex, findLast, findLastIndex, findNth, flatMap, flatten, flattenObject, flattenObjectHelper, groupBy, groupByFallback, head, includes, indexOf, init, innerJoin, interpolate, intersection, intersperse, join, last, lastIndexOf, map, mapAsync, mapFn, mapKeys, mapObject, mapObjectAsync, mapParallelAsync, match, maxBy, merge, mergeTypes, minBy, modifyItemAtIndex, modifyProp, none, objOf, objectIncludes, omit, partition, partitionObject, path, pathSatisfies, permutations, pick, pipe, pipeAsync, pluck, prepend, prop, propEq, propOr, propSatisfies, range, reduce, reject, rejectObject, replace, shuffle, sort, sortBy, sortByDescending, sortByFn, sortByPath, sortByPathDescending, sortObject, sortWith, split, splitEvery, symmetricDifference, tail, take, takeLast, takeLastWhile, takeWhile, tap, test, transformFlatObject, tryCatch, type, union, uniq, uniqBy, uniqWith, unless, unwind, update, when, zip, zipWith };
|
|
1817
|
+
export { _arity, _includes, _indexOf, _lastIndexOf, addProp, addPropToObjects, all, allPass, any, anyPass, append, ascend, assertType, checkObjectWithSpec, compact, complement, concat, convertToType, count, countBy, createCompareFunction, createObjectFromKeys, defaultTo, descend, drop, dropLast, dropLastWhile, dropWhile, eqBy, eqProps, equals, equalsFn, evolve, excludes, filter, filterObject, find, findIndex, findLast, findLastIndex, findNth, flatMap, flatten, flattenObject, flattenObjectHelper, groupBy, groupByFallback, head, includes, indexOf, init, innerJoin, interpolate, intersection, intersperse, join, last, lastIndexOf, map, mapAsync, mapFn, mapKeys, mapObject, mapObjectAsync, mapParallelAsync, match, maxBy, merge, mergeTypes, minBy, modifyItemAtIndex, modifyPath, modifyProp, none, objOf, objectIncludes, omit, partition, partitionObject, path, pathSatisfies, permutations, pick, pipe, pipeAsync, pluck, prepend, prop, propEq, propOr, propSatisfies, range, reduce, reject, rejectObject, replace, shuffle, sort, sortBy, sortByDescending, sortByFn, sortByPath, sortByPathDescending, sortObject, sortWith, split, splitEvery, symmetricDifference, tail, take, takeLast, takeLastWhile, takeWhile, tap, test, transformFlatObject, tryCatch, type, union, uniq, uniqBy, uniqWith, unless, unwind, update, when, zip, zipWith };
|