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/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
  */
@@ -586,6 +597,123 @@ export function minBy<T>(compareFn: (input: T) => Ord, x: T): (y: T) => T;
586
597
  */
587
598
  export function modifyItemAtIndex<T>(index: number, replaceFn: (x: T) => T): (list: T[]) => T[];
588
599
 
600
+ /**
601
+ * It changes a property of object on the base of provided path and transformer function.
602
+ */
603
+ export function modifyPath<U, T>(path: [], fn: (value: U) => T): (obj: U) => T;
604
+ export function modifyPath<
605
+ K0 extends keyof U,
606
+ U,
607
+ T
608
+ >(path: [K0], fn: (value: U[K0]) => T): (obj: U) => DeepModify<[K0], U, T>;
609
+ export function modifyPath<
610
+ K0 extends string & keyof U,
611
+ U,
612
+ T
613
+ >(path: `${K0}`, fn: (value: U[K0]) => T): (obj: U) => DeepModify<[K0], U, T>;
614
+ export function modifyPath<
615
+ K0 extends keyof U,
616
+ K1 extends keyof U[K0],
617
+ U,
618
+ T
619
+ >(path: [K0, K1], fn: (value: U[K0][K1]) => T): (obj: U) => DeepModify<[K0, K1], U, T>;
620
+ export function modifyPath<
621
+ K0 extends string & keyof U,
622
+ K1 extends string & keyof U[K0],
623
+ U,
624
+ T
625
+ >(path: `${K0}.${K1}`, fn: (value: U[K0][K1]) => T): (obj: U) => DeepModify<[K0, K1], U, T>;
626
+ export function modifyPath<
627
+ K0 extends keyof U,
628
+ K1 extends keyof U[K0],
629
+ K2 extends keyof U[K0][K1],
630
+ U,
631
+ T
632
+ >(path: [K0, K1, K2], fn: (value: U[K0][K1][K2]) => T): (obj: U) => DeepModify<[K0, K1, K2], U, T>;
633
+ export function modifyPath<
634
+ K0 extends string & keyof U,
635
+ K1 extends string & keyof U[K0],
636
+ K2 extends string & keyof U[K0][K1],
637
+ U,
638
+ T
639
+ >(path: `${K0}.${K1}.${K2}`, fn: (value: U[K0][K1][K2]) => T): (obj: U) => DeepModify<[K0, K1, K2], U, T>;
640
+ export function modifyPath<
641
+ K0 extends keyof U,
642
+ K1 extends keyof U[K0],
643
+ K2 extends keyof U[K0][K1],
644
+ K3 extends keyof U[K0][K1][K2],
645
+ U,
646
+ T
647
+ >(path: [K0, K1, K2, K3], fn: (value: U[K0][K1][K2][K3]) => T): (obj: U) => DeepModify<[K0, K1, K2, K3], U, T>;
648
+ export function modifyPath<
649
+ K0 extends string & keyof U,
650
+ K1 extends string & keyof U[K0],
651
+ K2 extends string & keyof U[K0][K1],
652
+ K3 extends string & keyof U[K0][K1][K2],
653
+ U,
654
+ T
655
+ >(path: `${K0}.${K1}.${K2}.${K3}`, fn: (value: U[K0][K1][K2][K3]) => T): (obj: U) => DeepModify<[K0, K1, K2, K3], U, T>;
656
+ export function modifyPath<
657
+ K0 extends keyof U,
658
+ K1 extends keyof U[K0],
659
+ K2 extends keyof U[K0][K1],
660
+ K3 extends keyof U[K0][K1][K2],
661
+ K4 extends keyof U[K0][K1][K2][K3],
662
+ U,
663
+ T
664
+ >(path: [K0, K1, K2, K3, K4], fn: (value: U[K0][K1][K2][K3][K4]) => T): (obj: U) => DeepModify<[K0, K1, K2, K3, K4], U, T>;
665
+ export function modifyPath<
666
+ K0 extends string & keyof U,
667
+ K1 extends string & keyof U[K0],
668
+ K2 extends string & keyof U[K0][K1],
669
+ K3 extends string & keyof U[K0][K1][K2],
670
+ K4 extends string & keyof U[K0][K1][K2][K3],
671
+ U,
672
+ T
673
+ >(path: `${K0}.${K1}.${K2}.${K3}.${K4}`, fn: (value: U[K0][K1][K2][K3][K4]) => T): (obj: U) => DeepModify<[K0, K1, K2, K3, K4], U, T>;
674
+ export function modifyPath<
675
+ K0 extends keyof U,
676
+ K1 extends keyof U[K0],
677
+ K2 extends keyof U[K0][K1],
678
+ K3 extends keyof U[K0][K1][K2],
679
+ K4 extends keyof U[K0][K1][K2][K3],
680
+ K5 extends keyof U[K0][K1][K2][K3][K4],
681
+ U,
682
+ T
683
+ >(path: [K0, K1, K2, K3, K4, K5], fn: (value: U[K0][K1][K2][K3][K4][K5]) => T): (obj: U) => DeepModify<[K0, K1, K2, K3, K4, K5], U, T>;
684
+ export function modifyPath<
685
+ K0 extends string & keyof U,
686
+ K1 extends string & keyof U[K0],
687
+ K2 extends string & keyof U[K0][K1],
688
+ K3 extends string & keyof U[K0][K1][K2],
689
+ K4 extends string & keyof U[K0][K1][K2][K3],
690
+ K5 extends string & keyof U[K0][K1][K2][K3][K4],
691
+ U,
692
+ T
693
+ >(path: `${K0}.${K1}.${K2}.${K3}.${K4}.${K5}`, fn: (value: U[K0][K1][K2][K3][K4][K5]) => T): (obj: U) => DeepModify<[K0, K1, K2, K3, K4, K5], U, T>;
694
+ export function modifyPath<
695
+ K0 extends keyof U,
696
+ K1 extends keyof U[K0],
697
+ K2 extends keyof U[K0][K1],
698
+ K3 extends keyof U[K0][K1][K2],
699
+ K4 extends keyof U[K0][K1][K2][K3],
700
+ K5 extends keyof U[K0][K1][K2][K3][K4],
701
+ K6 extends keyof U[K0][K1][K2][K3][K4][K5],
702
+ U,
703
+ T
704
+ >(path: [K0, K1, K2, K3, K4, K5, K6], fn: (value: U[K0][K1][K2][K3][K4][K5][K6]) => T): (obj: U) => DeepModify<[K0, K1, K2, K3, K4, K5, K6], U, T>;
705
+ export function modifyPath<
706
+ K0 extends string & keyof U,
707
+ K1 extends string & keyof U[K0],
708
+ K2 extends string & keyof U[K0][K1],
709
+ K3 extends string & keyof U[K0][K1][K2],
710
+ K4 extends string & keyof U[K0][K1][K2][K3],
711
+ K5 extends string & keyof U[K0][K1][K2][K3][K4],
712
+ K6 extends string & keyof U[K0][K1][K2][K3][K4][K5],
713
+ U,
714
+ T
715
+ >(path: `${K0}.${K1}.${K2}.${K3}.${K4}.${K5}.${K6}`, fn: (value: U[K0][K1][K2][K3][K4][K5][K6]) => T): (obj: U) => DeepModify<[K0, K1, K2, K3, K4, K5, K6], U, T>;
716
+
589
717
  /**
590
718
  * It changes a property with the result of transformer function.
591
719
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rambda",
3
- "version": "10.0.1",
3
+ "version": "10.2.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'
@@ -59,6 +61,7 @@ export * from './src/merge.js'
59
61
  export * from './src/mergeTypes.js'
60
62
  export * from './src/minBy.js'
61
63
  export * from './src/modifyItemAtIndex.js'
64
+ export * from './src/modifyPath.js'
62
65
  export * from './src/modifyProp.js'
63
66
  export * from './src/none.js'
64
67
  export * from './src/objOf.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
+ }
@@ -0,0 +1,30 @@
1
+ import { createPath } from './_internals/createPath.js'
2
+ import { path as pathModule } from './path.js'
3
+
4
+ function assoc(prop, newValue) {
5
+ return obj => Object.assign({}, obj, { [prop]: newValue })
6
+ }
7
+
8
+ function modifyPathFn(pathInput, fn, obj) {
9
+ const path = createPath(pathInput)
10
+ if (path.length === 1) {
11
+ return {
12
+ ...obj,
13
+ [path[0]]: fn(obj[path[0]]),
14
+ }
15
+ }
16
+ if (pathModule(path)(obj) === undefined) {
17
+ return obj
18
+ }
19
+
20
+ const val = modifyPathFn(Array.prototype.slice.call(path, 1), fn, obj[path[0]])
21
+ if (val === obj[path[0]]) {
22
+ return obj
23
+ }
24
+
25
+ return assoc(path[0], val)(obj)
26
+ }
27
+
28
+ export function modifyPath(pathInput, fn) {
29
+ return obj => modifyPathFn(pathInput, fn, obj)
30
+ }