rambda 10.0.1 → 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 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
  [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#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
+ [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#assertType)
1120
+
1024
1121
  ### checkObjectWithSpec
1025
1122
 
1026
1123
  ```typescript
@@ -1429,6 +1526,63 @@ it('R.concat', () => {
1429
1526
 
1430
1527
  [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#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
+ [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#convertToType)
1585
+
1432
1586
  ### count
1433
1587
 
1434
1588
  ```typescript
@@ -8219,7 +8373,7 @@ function assertType<T, U extends T>(fn: (x: T) => x is U) {
8219
8373
  function convertToType<T>() {
8220
8374
  return <U>(x: U) => x as unknown as T
8221
8375
  }
8222
- const convertToType = <T>(x: unknown)=> x as unknown as T
8376
+ // const convertToType = <T>(x: unknown)=> x as unknown as T
8223
8377
 
8224
8378
  function tapFn<T, U>(
8225
8379
  transformFn: (x: T) => U,
@@ -12706,6 +12860,14 @@ describe('R.zipWith', () => {
12706
12860
 
12707
12861
  ## ❯ CHANGELOG
12708
12862
 
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`
12870
+
12709
12871
  10.0.1
12710
12872
 
12711
12873
  - 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)) {
@@ -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 };
@@ -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;