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/index.d.ts CHANGED
@@ -206,6 +206,11 @@ export function append<T>(el: T): (list: readonly T[]) => T[];
206
206
  */
207
207
  export function ascend<T>(fn: (obj: T) => Ord): (a: T, b: T)=> Ordering;
208
208
 
209
+ /**
210
+ * 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.
211
+ */
212
+ export function assertType<T, U extends T>(fn: (x: T) => x is U) : (x: T) => U;
213
+
209
214
  /**
210
215
  * It returns `true` if all each property in `conditions` returns `true` when applied to corresponding property in `input` object.
211
216
  */
@@ -235,6 +240,12 @@ export function complement<T extends any[]>(predicate: (...args: T) => unknown):
235
240
  export function concat<T>(x: T[]): (y: T[]) => T[];
236
241
  export function concat(x: string): (y: string) => string;
237
242
 
243
+ /**
244
+ * It helps to convert a value to a specific type.
245
+ * It is useful when you have to overcome TypeScript's type inference.
246
+ */
247
+ export function convertToType<T>(x: unknown) : T;
248
+
238
249
  /**
239
250
  * It counts how many times `predicate` function returns `true`, when supplied with iteration of `list`.
240
251
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rambda",
3
- "version": "10.0.1",
3
+ "version": "10.1.0",
4
4
  "scripts": {
5
5
  "out": "yarn populatedocs && yarn populatereadme && yarn build && yarn create-docsify",
6
6
  "build": "yarn build:main && yarn build:web && yarn build:esm",
@@ -28,7 +28,7 @@
28
28
  "type": "module",
29
29
  "exports": {
30
30
  "require": {
31
- "types": "./index.d.ts",
31
+ "types": "./index.d.cts",
32
32
  "default": "./dist/rambda.cjs"
33
33
  },
34
34
  "types": "./index.d.ts",
@@ -95,9 +95,10 @@
95
95
  "src",
96
96
  "CHANGELOG.md",
97
97
  "index.d.ts",
98
+ "index.d.cts",
98
99
  "rambda.js"
99
100
  ],
100
101
  "sideEffects": false,
101
102
  "umd": "./dist/rambda.umd.js",
102
- "types": "./index.d.ts"
103
+ "types": "./index.d.cts"
103
104
  }
package/rambda.js CHANGED
@@ -7,10 +7,12 @@ export * from './src/any.js'
7
7
  export * from './src/anyPass.js'
8
8
  export * from './src/append.js'
9
9
  export * from './src/ascend.js'
10
+ export * from './src/assertType.js'
10
11
  export * from './src/checkObjectWithSpec.js'
11
12
  export * from './src/compact.js'
12
13
  export * from './src/complement.js'
13
14
  export * from './src/concat.js'
15
+ export * from './src/convertToType.js'
14
16
  export * from './src/count.js'
15
17
  export * from './src/countBy.js'
16
18
  export * from './src/createObjectFromKeys.js'
@@ -0,0 +1,8 @@
1
+ export function assertType(fn) {
2
+ return (x) => {
3
+ if (fn(x)) {
4
+ return x
5
+ }
6
+ throw new Error('type assertion failed in R.assertType')
7
+ }
8
+ }
@@ -0,0 +1,3 @@
1
+ export function convertToType(x) {
2
+ return x
3
+ }