rambda 10.0.0 → 10.1.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 +13 -3
- package/README.md +173 -11
- package/dist/rambda.cjs +15 -0
- package/dist/rambda.js +14 -1
- package/dist/rambda.umd.js +15 -0
- package/index.d.cts +2196 -0
- package/index.d.ts +13 -5
- package/package.json +12 -9
- package/rambda.js +2 -0
- package/src/assertType.js +8 -0
- package/src/convertToType.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
10.
|
|
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`
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
10.0.1
|
|
10
|
+
|
|
11
|
+
- Fix issue with `R.unwind`/`R.pick` typings - [Issue #766](https://github.com/selfrefactor/rambda/issues/766)
|
|
12
|
+
|
|
13
|
+
10.0.0
|
|
4
14
|
|
|
5
15
|
This is major revamp of `Rambda` library:
|
|
6
16
|
|
|
@@ -196,7 +206,7 @@ const result = piped(
|
|
|
196
206
|
|
|
197
207
|
9.4.1
|
|
198
208
|
|
|
199
|
-
- Fix bug with `R.differenceWith` when two arrays has same length - [Issue #
|
|
209
|
+
- Fix bug with `R.differenceWith` when two arrays has same length - [Issue #757](https://github.com/selfrefactor/rambda/issues/757)
|
|
200
210
|
|
|
201
211
|
- Allow path input to not be transformed when string numbers are there - [Issue #750](https://github.com/selfrefactor/rambda/issues/750)
|
|
202
212
|
|
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
|
|
@@ -7808,10 +7962,7 @@ const expected = [
|
|
|
7808
7962
|
|
|
7809
7963
|
```typescript
|
|
7810
7964
|
pick<K extends PropertyKey>(propsToPick: K[]): <T>(input: T) => MergeTypes<Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>>;
|
|
7811
|
-
pick<
|
|
7812
|
-
S extends string,
|
|
7813
|
-
K extends PickStringToPickPath<K>
|
|
7814
|
-
>(propsToPick: S): <T>(input: T) => MergeTypes<Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>>;
|
|
7965
|
+
pick<S extends string>(propsToPick: S): <T>(input: T) => MergeTypes<Pick<T, Exclude<keyof T, Exclude<keyof T, ElementOf<PickStringToPickPath<S>>>>>>;
|
|
7815
7966
|
```
|
|
7816
7967
|
|
|
7817
7968
|
</details>
|
|
@@ -8222,6 +8373,7 @@ function assertType<T, U extends T>(fn: (x: T) => x is U) {
|
|
|
8222
8373
|
function convertToType<T>() {
|
|
8223
8374
|
return <U>(x: U) => x as unknown as T
|
|
8224
8375
|
}
|
|
8376
|
+
// const convertToType = <T>(x: unknown)=> x as unknown as T
|
|
8225
8377
|
|
|
8226
8378
|
function tapFn<T, U>(
|
|
8227
8379
|
transformFn: (x: T) => U,
|
|
@@ -12156,7 +12308,7 @@ describe('R.unless', () => {
|
|
|
12156
12308
|
|
|
12157
12309
|
```typescript
|
|
12158
12310
|
|
|
12159
|
-
unwind<S extends string>(prop: S): <T
|
|
12311
|
+
unwind<S extends string>(prop: S): <T extends Record<S, readonly any[]>>(obj: T) => Array<MergeTypes<Omit<T, S> & { [K in S]: T[S][number] }>>
|
|
12160
12312
|
```
|
|
12161
12313
|
|
|
12162
12314
|
It takes an object and a property name. The method will return a list of objects, where each object is a shallow copy of the input object, but with the property array unwound.
|
|
@@ -12178,7 +12330,7 @@ const expected = [{a:1, b:2}, {a:1, b:3}]
|
|
|
12178
12330
|
<summary>All TypeScript definitions</summary>
|
|
12179
12331
|
|
|
12180
12332
|
```typescript
|
|
12181
|
-
unwind<S extends string>(prop: S): <T
|
|
12333
|
+
unwind<S extends string>(prop: S): <T extends Record<S, readonly any[]>>(obj: T) => Array<MergeTypes<Omit<T, S> & { [K in S]: T[S][number] }>>;
|
|
12182
12334
|
```
|
|
12183
12335
|
|
|
12184
12336
|
</details>
|
|
@@ -12246,12 +12398,12 @@ const obj = {
|
|
|
12246
12398
|
|
|
12247
12399
|
describe('R.unwind', () => {
|
|
12248
12400
|
it('happy', () => {
|
|
12249
|
-
const result = unwind('b')(obj)
|
|
12401
|
+
const [result] = unwind('b')(obj)
|
|
12250
12402
|
result.a // $ExpectType number
|
|
12251
12403
|
result.b // $ExpectType number
|
|
12252
12404
|
})
|
|
12253
12405
|
it('inside pipe', () => {
|
|
12254
|
-
const result = pipe(obj, unwind('b'))
|
|
12406
|
+
const [result] = pipe(obj, unwind('b'))
|
|
12255
12407
|
result.a // $ExpectType number
|
|
12256
12408
|
result.b // $ExpectType number
|
|
12257
12409
|
})
|
|
@@ -12708,9 +12860,19 @@ describe('R.zipWith', () => {
|
|
|
12708
12860
|
|
|
12709
12861
|
## ❯ CHANGELOG
|
|
12710
12862
|
|
|
12711
|
-
10.
|
|
12863
|
+
10.1.0
|
|
12864
|
+
|
|
12865
|
+
- Add `R.assertType` and `R.convertToType` methods
|
|
12866
|
+
|
|
12867
|
+
- Fix issue with exports in old Node.js versions - [Discussion #768](https://github.com/selfrefactor/rambda/discussions/768)
|
|
12868
|
+
|
|
12869
|
+
- Fix `deno` release as it was not possible for users to import version `10.0.0`
|
|
12712
12870
|
|
|
12713
|
-
|
|
12871
|
+
10.0.1
|
|
12872
|
+
|
|
12873
|
+
- Fix issue with `R.unwind`/`R.pick` typings - [Issue #766](https://github.com/selfrefactor/rambda/issues/766)
|
|
12874
|
+
|
|
12875
|
+
10.0.0
|
|
12714
12876
|
|
|
12715
12877
|
This is major revamp of `Rambda` library:
|
|
12716
12878
|
|
|
@@ -12906,7 +13068,7 @@ const result = piped(
|
|
|
12906
13068
|
|
|
12907
13069
|
9.4.1
|
|
12908
13070
|
|
|
12909
|
-
- Fix bug with `R.differenceWith` when two arrays has same length - [Issue #
|
|
13071
|
+
- Fix bug with `R.differenceWith` when two arrays has same length - [Issue #757](https://github.com/selfrefactor/rambda/issues/757)
|
|
12910
13072
|
|
|
12911
13073
|
- Allow path input to not be transformed when string numbers are there - [Issue #750](https://github.com/selfrefactor/rambda/issues/750)
|
|
12912
13074
|
|
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)) {
|
|
@@ -1787,10 +1800,12 @@ exports.any = any;
|
|
|
1787
1800
|
exports.anyPass = anyPass;
|
|
1788
1801
|
exports.append = append;
|
|
1789
1802
|
exports.ascend = ascend;
|
|
1803
|
+
exports.assertType = assertType;
|
|
1790
1804
|
exports.checkObjectWithSpec = checkObjectWithSpec;
|
|
1791
1805
|
exports.compact = compact;
|
|
1792
1806
|
exports.complement = complement;
|
|
1793
1807
|
exports.concat = concat;
|
|
1808
|
+
exports.convertToType = convertToType;
|
|
1794
1809
|
exports.count = count;
|
|
1795
1810
|
exports.countBy = countBy;
|
|
1796
1811
|
exports.createCompareFunction = createCompareFunction;
|
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)) {
|
|
@@ -1773,4 +1786,4 @@ function zipWith(fn, x) {
|
|
|
1773
1786
|
)
|
|
1774
1787
|
}
|
|
1775
1788
|
|
|
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 };
|
|
1789
|
+
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, 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 };
|
package/dist/rambda.umd.js
CHANGED
|
@@ -119,6 +119,15 @@
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
function assertType(fn) {
|
|
123
|
+
return (x) => {
|
|
124
|
+
if (fn(x)) {
|
|
125
|
+
return x
|
|
126
|
+
}
|
|
127
|
+
throw new Error('type assertion failed in R.assertType')
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
122
131
|
function checkObjectWithSpec(conditions) {
|
|
123
132
|
return input => {
|
|
124
133
|
let shouldProceed = true;
|
|
@@ -194,6 +203,10 @@
|
|
|
194
203
|
return y => (typeof x === 'string' ? `${x}${y}` : [...x, ...y])
|
|
195
204
|
}
|
|
196
205
|
|
|
206
|
+
function convertToType(x) {
|
|
207
|
+
return x
|
|
208
|
+
}
|
|
209
|
+
|
|
197
210
|
function count(predicate) {
|
|
198
211
|
return list => {
|
|
199
212
|
if (!isArray(list)) {
|
|
@@ -1791,10 +1804,12 @@
|
|
|
1791
1804
|
exports.anyPass = anyPass;
|
|
1792
1805
|
exports.append = append;
|
|
1793
1806
|
exports.ascend = ascend;
|
|
1807
|
+
exports.assertType = assertType;
|
|
1794
1808
|
exports.checkObjectWithSpec = checkObjectWithSpec;
|
|
1795
1809
|
exports.compact = compact;
|
|
1796
1810
|
exports.complement = complement;
|
|
1797
1811
|
exports.concat = concat;
|
|
1812
|
+
exports.convertToType = convertToType;
|
|
1798
1813
|
exports.count = count;
|
|
1799
1814
|
exports.countBy = countBy;
|
|
1800
1815
|
exports.createCompareFunction = createCompareFunction;
|