rambda 10.2.0 → 10.3.1
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 +134 -773
- package/README.md +941 -511
- package/dist/rambda.cjs +107 -42
- package/dist/rambda.js +103 -43
- package/dist/rambda.umd.js +107 -42
- package/index.d.cts +65 -47
- package/index.d.ts +65 -47
- package/package.json +8 -8
- package/rambda.js +5 -0
- package/src/duplicateBy.js +9 -0
- package/src/filterAsync.js +14 -0
- package/src/indexBy.js +14 -0
- package/src/mapAsync.js +2 -2
- package/src/mapPropObject.js +10 -0
- package/src/propOr.js +1 -1
- package/src/replaceAll.js +10 -0
package/index.d.cts
CHANGED
|
@@ -95,10 +95,10 @@ type Flatten<T> = T extends object
|
|
|
95
95
|
[K in keyof T]-?: NonNullable<T[K]> extends infer V
|
|
96
96
|
? V extends object
|
|
97
97
|
? V extends readonly any[]
|
|
98
|
-
? never
|
|
98
|
+
? never
|
|
99
99
|
: Flatten<V>
|
|
100
100
|
: V
|
|
101
|
-
: never
|
|
101
|
+
: never
|
|
102
102
|
}
|
|
103
103
|
: T;
|
|
104
104
|
|
|
@@ -109,17 +109,17 @@ export type FlattenObject<T extends object> = object extends T
|
|
|
109
109
|
x: NonNullable<T[K]> extends infer V
|
|
110
110
|
? V extends object
|
|
111
111
|
? V extends readonly any[]
|
|
112
|
-
? never
|
|
112
|
+
? never
|
|
113
113
|
: Flatten<V> extends infer FV
|
|
114
114
|
? {
|
|
115
115
|
[P in keyof FV as `${Extract<K, string>}.${Extract<P, string>}`]: FV[P]
|
|
116
116
|
}
|
|
117
|
-
: never
|
|
117
|
+
: never
|
|
118
118
|
: Pick<T, K>
|
|
119
|
-
: never
|
|
119
|
+
: never
|
|
120
120
|
) => void
|
|
121
121
|
} extends Record<keyof T, (y: infer O) => void>
|
|
122
|
-
? O
|
|
122
|
+
? O
|
|
123
123
|
: never;
|
|
124
124
|
|
|
125
125
|
/**
|
|
@@ -295,6 +295,8 @@ export function dropRepeatsWith<T>(predicate: (x: T, y: T) => boolean): (list: T
|
|
|
295
295
|
export function dropWhile<T>(predicate: (x: T, index: number) => boolean): (list: T[]) => T[];
|
|
296
296
|
export function dropWhile<T>(predicate: (x: T) => boolean): (list: T[]) => T[];
|
|
297
297
|
|
|
298
|
+
export function duplicateBy<T, U>(fn: (x: T) => U): (list: T[]) => T[];
|
|
299
|
+
|
|
298
300
|
export function eqBy<T>(fn: (x: T) => unknown, a: T): (b: T) => boolean;
|
|
299
301
|
|
|
300
302
|
/**
|
|
@@ -340,6 +342,10 @@ export function filter<T>(
|
|
|
340
342
|
predicate: (value: T) => boolean,
|
|
341
343
|
): (list: T[]) => T[];
|
|
342
344
|
|
|
345
|
+
export function filterAsync<T>(
|
|
346
|
+
predicate: (value: T) => Promise<boolean>,
|
|
347
|
+
): (list: T[]) => Promise<T[]>;
|
|
348
|
+
|
|
343
349
|
/**
|
|
344
350
|
* It loops over each property of `obj` and returns a new object with only those properties that satisfy the `predicate`.
|
|
345
351
|
*/
|
|
@@ -408,13 +414,13 @@ export function groupBy<T, K extends string = string>(fn: (x: T) => K): (list: T
|
|
|
408
414
|
/**
|
|
409
415
|
* It returns the first element of list or string `input`. It returns `undefined` if array has length of 0.
|
|
410
416
|
*/
|
|
411
|
-
export function head<T>(listOrString: T): T extends string ? string :
|
|
412
|
-
T extends [] ? undefined:
|
|
413
|
-
T extends readonly [infer F, ...infer R] ? F :
|
|
417
|
+
export function head<T>(listOrString: T): T extends string ? string :
|
|
418
|
+
T extends [] ? undefined:
|
|
419
|
+
T extends readonly [infer F, ...infer R] ? F :
|
|
414
420
|
T extends readonly [infer F] ? F :
|
|
415
421
|
T extends [infer F] ? F :
|
|
416
|
-
T extends [infer F, ...infer R] ? F :
|
|
417
|
-
T extends unknown[] ? T[number] :
|
|
422
|
+
T extends [infer F, ...infer R] ? F :
|
|
423
|
+
T extends unknown[] ? T[number] :
|
|
418
424
|
undefined;
|
|
419
425
|
|
|
420
426
|
/**
|
|
@@ -422,8 +428,21 @@ export function head<T>(listOrString: T): T extends string ? string :
|
|
|
422
428
|
*
|
|
423
429
|
* If `input` is array, then `R.equals` is used to define if `valueToFind` belongs to the list.
|
|
424
430
|
*/
|
|
425
|
-
export function includes
|
|
426
|
-
export function includes<T>(
|
|
431
|
+
export function includes(s: string): (list: readonly string[] | string) => boolean;
|
|
432
|
+
export function includes<T>(target: T): (list: readonly T[]) => boolean;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* It transforms list of objects to object using specified property as the base for the returned object.
|
|
436
|
+
*/
|
|
437
|
+
export function indexBy<T, K extends keyof T>(
|
|
438
|
+
property: K
|
|
439
|
+
): (list: readonly T[]) => Record<string, T>;
|
|
440
|
+
export function indexBy<T, K extends keyof T>(
|
|
441
|
+
property: K
|
|
442
|
+
): (list: T[]) => Record<string, T>;
|
|
443
|
+
|
|
444
|
+
// API_MARKER_END
|
|
445
|
+
// ============================================
|
|
427
446
|
|
|
428
447
|
/**
|
|
429
448
|
* It uses `R.equals` for list of objects/arrays or native `indexOf` for any other case.
|
|
@@ -449,10 +468,6 @@ export function innerJoin<T1, T2>(
|
|
|
449
468
|
*/
|
|
450
469
|
export function interpolate(inputWithTags: string): (templateArguments: object) => string;
|
|
451
470
|
|
|
452
|
-
|
|
453
|
-
// API_MARKER_END
|
|
454
|
-
// ===========================================
|
|
455
|
-
|
|
456
471
|
/**
|
|
457
472
|
* It loops through `listA` and `listB` and returns the intersection of the two according to `R.equals`.
|
|
458
473
|
*/
|
|
@@ -471,13 +486,13 @@ export function join<T>(glue: string): (list: T[]) => string;
|
|
|
471
486
|
/**
|
|
472
487
|
* It returns the last element of `input`, as the `input` can be either a string or an array. It returns `undefined` if array has length of 0.
|
|
473
488
|
*/
|
|
474
|
-
export function last<T>(listOrString: T): T extends string ? string :
|
|
475
|
-
T extends [] ? undefined :
|
|
476
|
-
T extends readonly [...infer R, infer L] ? L :
|
|
489
|
+
export function last<T>(listOrString: T): T extends string ? string :
|
|
490
|
+
T extends [] ? undefined :
|
|
491
|
+
T extends readonly [...infer R, infer L] ? L :
|
|
477
492
|
T extends readonly [infer L] ? L :
|
|
478
493
|
T extends [infer L] ? L :
|
|
479
|
-
T extends [...infer R, infer L] ? L :
|
|
480
|
-
T extends unknown[] ? T[number] :
|
|
494
|
+
T extends [...infer R, infer L] ? L :
|
|
495
|
+
T extends unknown[] ? T[number] :
|
|
481
496
|
undefined;
|
|
482
497
|
|
|
483
498
|
/**
|
|
@@ -518,14 +533,6 @@ export function mapAsync<T extends IterableContainer, U>(
|
|
|
518
533
|
export function mapAsync<T extends IterableContainer, U>(
|
|
519
534
|
fn: (value: T[number]) => Promise<U>,
|
|
520
535
|
): (data: T) => Promise<Mapped<T, U>>;
|
|
521
|
-
export function mapAsync<T extends IterableContainer, U>(
|
|
522
|
-
fn: (value: T[number], index: number) => Promise<U>,
|
|
523
|
-
data: T
|
|
524
|
-
): Promise<Mapped<T, U>>;
|
|
525
|
-
export function mapAsync<T extends IterableContainer, U>(
|
|
526
|
-
fn: (value: T[number]) => Promise<U>,
|
|
527
|
-
data: T
|
|
528
|
-
): Promise<Mapped<T, U>>;
|
|
529
536
|
|
|
530
537
|
/**
|
|
531
538
|
* It returns a copy of `obj` with keys transformed by `fn`.
|
|
@@ -557,14 +564,19 @@ export function mapParallelAsync<T extends IterableContainer, U>(
|
|
|
557
564
|
export function mapParallelAsync<T extends IterableContainer, U>(
|
|
558
565
|
fn: (value: T[number]) => Promise<U>,
|
|
559
566
|
): (data: T) => Promise<Mapped<T, U>>;
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
export function
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* It maps over a property of object that is a list.
|
|
570
|
+
*/
|
|
571
|
+
export function mapPropObject<T extends object, K extends keyof T, Value>(
|
|
572
|
+
valueMapper: (
|
|
573
|
+
value: T[K] extends ReadonlyArray<infer ElementType> ? ElementType : never,
|
|
574
|
+
data: T[K],
|
|
575
|
+
) => Value,
|
|
576
|
+
prop: K,
|
|
577
|
+
): (data: T) => T[K] extends ReadonlyArray<any>
|
|
578
|
+
? MergeTypes<Omit<T, K> & { [P in K]: Value[] }>
|
|
579
|
+
: never;
|
|
568
580
|
|
|
569
581
|
/**
|
|
570
582
|
* Curried version of `String.prototype.match` which returns empty array, when there is no match.
|
|
@@ -1567,7 +1579,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M>(
|
|
|
1567
1579
|
fn10: (x: Awaited<K>) => L,
|
|
1568
1580
|
fn11: (x: Awaited<L>) => M,
|
|
1569
1581
|
): M;
|
|
1570
|
-
|
|
1571
1582
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(
|
|
1572
1583
|
input: A,
|
|
1573
1584
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1584,7 +1595,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(
|
|
|
1584
1595
|
fn11: (x: Awaited<L>) => M,
|
|
1585
1596
|
fn12: (x: Awaited<M>) => N,
|
|
1586
1597
|
): N;
|
|
1587
|
-
|
|
1588
1598
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(
|
|
1589
1599
|
input: A,
|
|
1590
1600
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1602,7 +1612,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(
|
|
|
1602
1612
|
fn12: (x: Awaited<M>) => N,
|
|
1603
1613
|
fn13: (x: Awaited<N>) => O,
|
|
1604
1614
|
): O;
|
|
1605
|
-
|
|
1606
1615
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(
|
|
1607
1616
|
input: A,
|
|
1608
1617
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1621,7 +1630,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(
|
|
|
1621
1630
|
fn13: (x: Awaited<N>) => O,
|
|
1622
1631
|
fn14: (x: Awaited<O>) => P,
|
|
1623
1632
|
): P;
|
|
1624
|
-
|
|
1625
1633
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(
|
|
1626
1634
|
input: A,
|
|
1627
1635
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1641,7 +1649,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(
|
|
|
1641
1649
|
fn14: (x: Awaited<O>) => P,
|
|
1642
1650
|
fn15: (x: Awaited<P>) => Q,
|
|
1643
1651
|
): Q;
|
|
1644
|
-
|
|
1645
1652
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(
|
|
1646
1653
|
input: A,
|
|
1647
1654
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1662,7 +1669,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(
|
|
|
1662
1669
|
fn15: (x: Awaited<P>) => Q,
|
|
1663
1670
|
fn16: (x: Awaited<Q>) => R,
|
|
1664
1671
|
): R;
|
|
1665
|
-
|
|
1666
1672
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(
|
|
1667
1673
|
input: A,
|
|
1668
1674
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1684,7 +1690,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R,
|
|
|
1684
1690
|
fn16: (x: Awaited<Q>) => R,
|
|
1685
1691
|
fn17: (x: Awaited<R>) => S,
|
|
1686
1692
|
): S;
|
|
1687
|
-
|
|
1688
1693
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(
|
|
1689
1694
|
input: A,
|
|
1690
1695
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1707,7 +1712,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R,
|
|
|
1707
1712
|
fn17: (x: Awaited<R>) => S,
|
|
1708
1713
|
fn18: (x: Awaited<S>) => T,
|
|
1709
1714
|
): T;
|
|
1710
|
-
|
|
1711
1715
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U>(
|
|
1712
1716
|
input: A,
|
|
1713
1717
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1737,6 +1741,10 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R,
|
|
|
1737
1741
|
* Basically, this is `R.map(R.prop(property))`.
|
|
1738
1742
|
*/
|
|
1739
1743
|
export function pluck<T, K extends keyof T>(property: K): (list: T[]) => T[K][];
|
|
1744
|
+
export function pluck<K extends PropertyKey>(prop: K): {
|
|
1745
|
+
<U extends O[keyof O], UK extends keyof U, O extends Record<string, any>>(obj: K extends UK ? O : never): { [OK in keyof O]: O[OK][K] };
|
|
1746
|
+
<U extends readonly unknown[] | Record<K, any>>(list: readonly U[]): U extends readonly (infer T)[] ? T[] : U extends Record<K, infer T> ? T[] : never;
|
|
1747
|
+
};
|
|
1740
1748
|
|
|
1741
1749
|
/**
|
|
1742
1750
|
* It adds element `x` at the beginning of `list`.
|
|
@@ -1765,7 +1773,7 @@ export function propEq<K extends keyof U, U>(val: U[K], name: K, obj: U): boolea
|
|
|
1765
1773
|
/**
|
|
1766
1774
|
* It returns either `defaultValue` or the value of `property` in `obj`.
|
|
1767
1775
|
*/
|
|
1768
|
-
export function propOr<T, P extends string>(
|
|
1776
|
+
export function propOr<T, P extends string>(property: P, defaultValue: T): (obj: Partial<Record<P, T>>) => T;
|
|
1769
1777
|
|
|
1770
1778
|
/**
|
|
1771
1779
|
* It returns `true` if the object property satisfies a given predicate.
|
|
@@ -1813,6 +1821,11 @@ export function rejectObject<T extends object>(
|
|
|
1813
1821
|
*/
|
|
1814
1822
|
export function replace(strOrRegex: RegExp | string, replacer: RegExp | string): (str: string) => string;
|
|
1815
1823
|
|
|
1824
|
+
/**
|
|
1825
|
+
* Same as `R.replace` but it accepts array of string and regular expressions instead of a single value.
|
|
1826
|
+
*/
|
|
1827
|
+
export function replaceAll(patterns: (RegExp | string)[], replacer: string): (input: string) => string;
|
|
1828
|
+
|
|
1816
1829
|
/**
|
|
1817
1830
|
* It returns a randomized copy of array.
|
|
1818
1831
|
*/
|
|
@@ -2231,6 +2244,11 @@ export function tap<T>(fn: (x: T) => void): (input: T) => T;
|
|
|
2231
2244
|
*/
|
|
2232
2245
|
export function test(regExpression: RegExp): (str: string) => boolean;
|
|
2233
2246
|
|
|
2247
|
+
export function transformPropObject<T extends object, K extends keyof T, Value>(
|
|
2248
|
+
valueMapper: (value: T[K]) => Value,
|
|
2249
|
+
prop: K,
|
|
2250
|
+
): (data: T) => MergeTypes<Omit<T, K> & { [P in K]: Value }>;
|
|
2251
|
+
|
|
2234
2252
|
/**
|
|
2235
2253
|
* It returns function that runs `fn` in `try/catch` block. If there was an error, then `fallback` is used to return the result.
|
|
2236
2254
|
*/
|
package/index.d.ts
CHANGED
|
@@ -95,10 +95,10 @@ type Flatten<T> = T extends object
|
|
|
95
95
|
[K in keyof T]-?: NonNullable<T[K]> extends infer V
|
|
96
96
|
? V extends object
|
|
97
97
|
? V extends readonly any[]
|
|
98
|
-
? never
|
|
98
|
+
? never
|
|
99
99
|
: Flatten<V>
|
|
100
100
|
: V
|
|
101
|
-
: never
|
|
101
|
+
: never
|
|
102
102
|
}
|
|
103
103
|
: T;
|
|
104
104
|
|
|
@@ -109,17 +109,17 @@ export type FlattenObject<T extends object> = object extends T
|
|
|
109
109
|
x: NonNullable<T[K]> extends infer V
|
|
110
110
|
? V extends object
|
|
111
111
|
? V extends readonly any[]
|
|
112
|
-
? never
|
|
112
|
+
? never
|
|
113
113
|
: Flatten<V> extends infer FV
|
|
114
114
|
? {
|
|
115
115
|
[P in keyof FV as `${Extract<K, string>}.${Extract<P, string>}`]: FV[P]
|
|
116
116
|
}
|
|
117
|
-
: never
|
|
117
|
+
: never
|
|
118
118
|
: Pick<T, K>
|
|
119
|
-
: never
|
|
119
|
+
: never
|
|
120
120
|
) => void
|
|
121
121
|
} extends Record<keyof T, (y: infer O) => void>
|
|
122
|
-
? O
|
|
122
|
+
? O
|
|
123
123
|
: never;
|
|
124
124
|
|
|
125
125
|
/**
|
|
@@ -295,6 +295,8 @@ export function dropRepeatsWith<T>(predicate: (x: T, y: T) => boolean): (list: T
|
|
|
295
295
|
export function dropWhile<T>(predicate: (x: T, index: number) => boolean): (list: T[]) => T[];
|
|
296
296
|
export function dropWhile<T>(predicate: (x: T) => boolean): (list: T[]) => T[];
|
|
297
297
|
|
|
298
|
+
export function duplicateBy<T, U>(fn: (x: T) => U): (list: T[]) => T[];
|
|
299
|
+
|
|
298
300
|
export function eqBy<T>(fn: (x: T) => unknown, a: T): (b: T) => boolean;
|
|
299
301
|
|
|
300
302
|
/**
|
|
@@ -340,6 +342,10 @@ export function filter<T>(
|
|
|
340
342
|
predicate: (value: T) => boolean,
|
|
341
343
|
): (list: T[]) => T[];
|
|
342
344
|
|
|
345
|
+
export function filterAsync<T>(
|
|
346
|
+
predicate: (value: T) => Promise<boolean>,
|
|
347
|
+
): (list: T[]) => Promise<T[]>;
|
|
348
|
+
|
|
343
349
|
/**
|
|
344
350
|
* It loops over each property of `obj` and returns a new object with only those properties that satisfy the `predicate`.
|
|
345
351
|
*/
|
|
@@ -408,13 +414,13 @@ export function groupBy<T, K extends string = string>(fn: (x: T) => K): (list: T
|
|
|
408
414
|
/**
|
|
409
415
|
* It returns the first element of list or string `input`. It returns `undefined` if array has length of 0.
|
|
410
416
|
*/
|
|
411
|
-
export function head<T>(listOrString: T): T extends string ? string :
|
|
412
|
-
T extends [] ? undefined:
|
|
413
|
-
T extends readonly [infer F, ...infer R] ? F :
|
|
417
|
+
export function head<T>(listOrString: T): T extends string ? string :
|
|
418
|
+
T extends [] ? undefined:
|
|
419
|
+
T extends readonly [infer F, ...infer R] ? F :
|
|
414
420
|
T extends readonly [infer F] ? F :
|
|
415
421
|
T extends [infer F] ? F :
|
|
416
|
-
T extends [infer F, ...infer R] ? F :
|
|
417
|
-
T extends unknown[] ? T[number] :
|
|
422
|
+
T extends [infer F, ...infer R] ? F :
|
|
423
|
+
T extends unknown[] ? T[number] :
|
|
418
424
|
undefined;
|
|
419
425
|
|
|
420
426
|
/**
|
|
@@ -422,8 +428,21 @@ export function head<T>(listOrString: T): T extends string ? string :
|
|
|
422
428
|
*
|
|
423
429
|
* If `input` is array, then `R.equals` is used to define if `valueToFind` belongs to the list.
|
|
424
430
|
*/
|
|
425
|
-
export function includes
|
|
426
|
-
export function includes<T>(
|
|
431
|
+
export function includes(s: string): (list: readonly string[] | string) => boolean;
|
|
432
|
+
export function includes<T>(target: T): (list: readonly T[]) => boolean;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* It transforms list of objects to object using specified property as the base for the returned object.
|
|
436
|
+
*/
|
|
437
|
+
export function indexBy<T, K extends keyof T>(
|
|
438
|
+
property: K
|
|
439
|
+
): (list: readonly T[]) => Record<string, T>;
|
|
440
|
+
export function indexBy<T, K extends keyof T>(
|
|
441
|
+
property: K
|
|
442
|
+
): (list: T[]) => Record<string, T>;
|
|
443
|
+
|
|
444
|
+
// API_MARKER_END
|
|
445
|
+
// ============================================
|
|
427
446
|
|
|
428
447
|
/**
|
|
429
448
|
* It uses `R.equals` for list of objects/arrays or native `indexOf` for any other case.
|
|
@@ -449,10 +468,6 @@ export function innerJoin<T1, T2>(
|
|
|
449
468
|
*/
|
|
450
469
|
export function interpolate(inputWithTags: string): (templateArguments: object) => string;
|
|
451
470
|
|
|
452
|
-
|
|
453
|
-
// API_MARKER_END
|
|
454
|
-
// ===========================================
|
|
455
|
-
|
|
456
471
|
/**
|
|
457
472
|
* It loops through `listA` and `listB` and returns the intersection of the two according to `R.equals`.
|
|
458
473
|
*/
|
|
@@ -471,13 +486,13 @@ export function join<T>(glue: string): (list: T[]) => string;
|
|
|
471
486
|
/**
|
|
472
487
|
* It returns the last element of `input`, as the `input` can be either a string or an array. It returns `undefined` if array has length of 0.
|
|
473
488
|
*/
|
|
474
|
-
export function last<T>(listOrString: T): T extends string ? string :
|
|
475
|
-
T extends [] ? undefined :
|
|
476
|
-
T extends readonly [...infer R, infer L] ? L :
|
|
489
|
+
export function last<T>(listOrString: T): T extends string ? string :
|
|
490
|
+
T extends [] ? undefined :
|
|
491
|
+
T extends readonly [...infer R, infer L] ? L :
|
|
477
492
|
T extends readonly [infer L] ? L :
|
|
478
493
|
T extends [infer L] ? L :
|
|
479
|
-
T extends [...infer R, infer L] ? L :
|
|
480
|
-
T extends unknown[] ? T[number] :
|
|
494
|
+
T extends [...infer R, infer L] ? L :
|
|
495
|
+
T extends unknown[] ? T[number] :
|
|
481
496
|
undefined;
|
|
482
497
|
|
|
483
498
|
/**
|
|
@@ -518,14 +533,6 @@ export function mapAsync<T extends IterableContainer, U>(
|
|
|
518
533
|
export function mapAsync<T extends IterableContainer, U>(
|
|
519
534
|
fn: (value: T[number]) => Promise<U>,
|
|
520
535
|
): (data: T) => Promise<Mapped<T, U>>;
|
|
521
|
-
export function mapAsync<T extends IterableContainer, U>(
|
|
522
|
-
fn: (value: T[number], index: number) => Promise<U>,
|
|
523
|
-
data: T
|
|
524
|
-
): Promise<Mapped<T, U>>;
|
|
525
|
-
export function mapAsync<T extends IterableContainer, U>(
|
|
526
|
-
fn: (value: T[number]) => Promise<U>,
|
|
527
|
-
data: T
|
|
528
|
-
): Promise<Mapped<T, U>>;
|
|
529
536
|
|
|
530
537
|
/**
|
|
531
538
|
* It returns a copy of `obj` with keys transformed by `fn`.
|
|
@@ -557,14 +564,19 @@ export function mapParallelAsync<T extends IterableContainer, U>(
|
|
|
557
564
|
export function mapParallelAsync<T extends IterableContainer, U>(
|
|
558
565
|
fn: (value: T[number]) => Promise<U>,
|
|
559
566
|
): (data: T) => Promise<Mapped<T, U>>;
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
export function
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* It maps over a property of object that is a list.
|
|
570
|
+
*/
|
|
571
|
+
export function mapPropObject<T extends object, K extends keyof T, Value>(
|
|
572
|
+
valueMapper: (
|
|
573
|
+
value: T[K] extends ReadonlyArray<infer ElementType> ? ElementType : never,
|
|
574
|
+
data: T[K],
|
|
575
|
+
) => Value,
|
|
576
|
+
prop: K,
|
|
577
|
+
): (data: T) => T[K] extends ReadonlyArray<any>
|
|
578
|
+
? MergeTypes<Omit<T, K> & { [P in K]: Value[] }>
|
|
579
|
+
: never;
|
|
568
580
|
|
|
569
581
|
/**
|
|
570
582
|
* Curried version of `String.prototype.match` which returns empty array, when there is no match.
|
|
@@ -1567,7 +1579,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M>(
|
|
|
1567
1579
|
fn10: (x: Awaited<K>) => L,
|
|
1568
1580
|
fn11: (x: Awaited<L>) => M,
|
|
1569
1581
|
): M;
|
|
1570
|
-
|
|
1571
1582
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(
|
|
1572
1583
|
input: A,
|
|
1573
1584
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1584,7 +1595,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(
|
|
|
1584
1595
|
fn11: (x: Awaited<L>) => M,
|
|
1585
1596
|
fn12: (x: Awaited<M>) => N,
|
|
1586
1597
|
): N;
|
|
1587
|
-
|
|
1588
1598
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(
|
|
1589
1599
|
input: A,
|
|
1590
1600
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1602,7 +1612,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(
|
|
|
1602
1612
|
fn12: (x: Awaited<M>) => N,
|
|
1603
1613
|
fn13: (x: Awaited<N>) => O,
|
|
1604
1614
|
): O;
|
|
1605
|
-
|
|
1606
1615
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(
|
|
1607
1616
|
input: A,
|
|
1608
1617
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1621,7 +1630,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(
|
|
|
1621
1630
|
fn13: (x: Awaited<N>) => O,
|
|
1622
1631
|
fn14: (x: Awaited<O>) => P,
|
|
1623
1632
|
): P;
|
|
1624
|
-
|
|
1625
1633
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(
|
|
1626
1634
|
input: A,
|
|
1627
1635
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1641,7 +1649,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(
|
|
|
1641
1649
|
fn14: (x: Awaited<O>) => P,
|
|
1642
1650
|
fn15: (x: Awaited<P>) => Q,
|
|
1643
1651
|
): Q;
|
|
1644
|
-
|
|
1645
1652
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(
|
|
1646
1653
|
input: A,
|
|
1647
1654
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1662,7 +1669,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(
|
|
|
1662
1669
|
fn15: (x: Awaited<P>) => Q,
|
|
1663
1670
|
fn16: (x: Awaited<Q>) => R,
|
|
1664
1671
|
): R;
|
|
1665
|
-
|
|
1666
1672
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(
|
|
1667
1673
|
input: A,
|
|
1668
1674
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1684,7 +1690,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R,
|
|
|
1684
1690
|
fn16: (x: Awaited<Q>) => R,
|
|
1685
1691
|
fn17: (x: Awaited<R>) => S,
|
|
1686
1692
|
): S;
|
|
1687
|
-
|
|
1688
1693
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(
|
|
1689
1694
|
input: A,
|
|
1690
1695
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1707,7 +1712,6 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R,
|
|
|
1707
1712
|
fn17: (x: Awaited<R>) => S,
|
|
1708
1713
|
fn18: (x: Awaited<S>) => T,
|
|
1709
1714
|
): T;
|
|
1710
|
-
|
|
1711
1715
|
export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U>(
|
|
1712
1716
|
input: A,
|
|
1713
1717
|
fn0: (x: Awaited<A>) => B,
|
|
@@ -1737,6 +1741,10 @@ export function pipeAsync<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R,
|
|
|
1737
1741
|
* Basically, this is `R.map(R.prop(property))`.
|
|
1738
1742
|
*/
|
|
1739
1743
|
export function pluck<T, K extends keyof T>(property: K): (list: T[]) => T[K][];
|
|
1744
|
+
export function pluck<K extends PropertyKey>(prop: K): {
|
|
1745
|
+
<U extends O[keyof O], UK extends keyof U, O extends Record<string, any>>(obj: K extends UK ? O : never): { [OK in keyof O]: O[OK][K] };
|
|
1746
|
+
<U extends readonly unknown[] | Record<K, any>>(list: readonly U[]): U extends readonly (infer T)[] ? T[] : U extends Record<K, infer T> ? T[] : never;
|
|
1747
|
+
};
|
|
1740
1748
|
|
|
1741
1749
|
/**
|
|
1742
1750
|
* It adds element `x` at the beginning of `list`.
|
|
@@ -1765,7 +1773,7 @@ export function propEq<K extends keyof U, U>(val: U[K], name: K, obj: U): boolea
|
|
|
1765
1773
|
/**
|
|
1766
1774
|
* It returns either `defaultValue` or the value of `property` in `obj`.
|
|
1767
1775
|
*/
|
|
1768
|
-
export function propOr<T, P extends string>(
|
|
1776
|
+
export function propOr<T, P extends string>(property: P, defaultValue: T): (obj: Partial<Record<P, T>>) => T;
|
|
1769
1777
|
|
|
1770
1778
|
/**
|
|
1771
1779
|
* It returns `true` if the object property satisfies a given predicate.
|
|
@@ -1813,6 +1821,11 @@ export function rejectObject<T extends object>(
|
|
|
1813
1821
|
*/
|
|
1814
1822
|
export function replace(strOrRegex: RegExp | string, replacer: RegExp | string): (str: string) => string;
|
|
1815
1823
|
|
|
1824
|
+
/**
|
|
1825
|
+
* Same as `R.replace` but it accepts array of string and regular expressions instead of a single value.
|
|
1826
|
+
*/
|
|
1827
|
+
export function replaceAll(patterns: (RegExp | string)[], replacer: string): (input: string) => string;
|
|
1828
|
+
|
|
1816
1829
|
/**
|
|
1817
1830
|
* It returns a randomized copy of array.
|
|
1818
1831
|
*/
|
|
@@ -2231,6 +2244,11 @@ export function tap<T>(fn: (x: T) => void): (input: T) => T;
|
|
|
2231
2244
|
*/
|
|
2232
2245
|
export function test(regExpression: RegExp): (str: string) => boolean;
|
|
2233
2246
|
|
|
2247
|
+
export function transformPropObject<T extends object, K extends keyof T, Value>(
|
|
2248
|
+
valueMapper: (value: T[K]) => Value,
|
|
2249
|
+
prop: K,
|
|
2250
|
+
): (data: T) => MergeTypes<Omit<T, K> & { [P in K]: Value }>;
|
|
2251
|
+
|
|
2234
2252
|
/**
|
|
2235
2253
|
* It returns function that runs `fn` in `try/catch` block. If there was an error, then `fallback` is used to return the result.
|
|
2236
2254
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rambda",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.3.1",
|
|
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",
|
|
@@ -40,18 +40,18 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@definitelytyped/dtslint": "0.0.182",
|
|
42
42
|
"@types/mocha": "10.0.10",
|
|
43
|
-
"@types/node": "
|
|
44
|
-
"@vitest/coverage-v8": "
|
|
43
|
+
"@types/node": "24.0.8",
|
|
44
|
+
"@vitest/coverage-v8": "4.0.0-beta.2",
|
|
45
45
|
"helpers-fn": "2.0.0",
|
|
46
46
|
"lodash": "4.17.21",
|
|
47
47
|
"radashi": "13.0.0-beta.ffa4778",
|
|
48
48
|
"rambdax": "11.3.1",
|
|
49
|
-
"ramda": "0.
|
|
50
|
-
"remeda": "2.
|
|
51
|
-
"rollup": "4.
|
|
49
|
+
"ramda": "0.31.3",
|
|
50
|
+
"remeda": "2.23.2",
|
|
51
|
+
"rollup": "4.44.1",
|
|
52
52
|
"types-ramda": "0.30.1",
|
|
53
|
-
"typescript": "5.9.0-dev.
|
|
54
|
-
"vitest": "
|
|
53
|
+
"typescript": "5.9.0-dev.20250630",
|
|
54
|
+
"vitest": "4.0.0-beta.2"
|
|
55
55
|
},
|
|
56
56
|
"jest": {
|
|
57
57
|
"testEnvironment": "node",
|
package/rambda.js
CHANGED
|
@@ -22,12 +22,14 @@ export * from './src/drop.js'
|
|
|
22
22
|
export * from './src/dropLast.js'
|
|
23
23
|
export * from './src/dropLastWhile.js'
|
|
24
24
|
export * from './src/dropWhile.js'
|
|
25
|
+
export * from './src/duplicateBy.js'
|
|
25
26
|
export * from './src/eqBy.js'
|
|
26
27
|
export * from './src/eqProps.js'
|
|
27
28
|
export * from './src/equals.js'
|
|
28
29
|
export * from './src/evolve.js'
|
|
29
30
|
export * from './src/excludes.js'
|
|
30
31
|
export * from './src/filter.js'
|
|
32
|
+
export * from './src/filterAsync.js'
|
|
31
33
|
export * from './src/filterObject.js'
|
|
32
34
|
export * from './src/find.js'
|
|
33
35
|
export * from './src/findIndex.js'
|
|
@@ -40,6 +42,7 @@ export * from './src/flattenObject.js'
|
|
|
40
42
|
export * from './src/groupBy.js'
|
|
41
43
|
export * from './src/head.js'
|
|
42
44
|
export * from './src/includes.js'
|
|
45
|
+
export * from './src/indexBy.js'
|
|
43
46
|
export * from './src/indexOf.js'
|
|
44
47
|
export * from './src/init.js'
|
|
45
48
|
export * from './src/innerJoin.js'
|
|
@@ -55,6 +58,7 @@ export * from './src/mapKeys.js'
|
|
|
55
58
|
export * from './src/mapObject.js'
|
|
56
59
|
export * from './src/mapObjectAsync.js'
|
|
57
60
|
export * from './src/mapParallelAsync.js'
|
|
61
|
+
export * from './src/mapPropObject.js'
|
|
58
62
|
export * from './src/match.js'
|
|
59
63
|
export * from './src/maxBy.js'
|
|
60
64
|
export * from './src/merge.js'
|
|
@@ -86,6 +90,7 @@ export * from './src/reduce.js'
|
|
|
86
90
|
export * from './src/reject.js'
|
|
87
91
|
export * from './src/rejectObject.js'
|
|
88
92
|
export * from './src/replace.js'
|
|
93
|
+
export * from './src/replaceAll.js'
|
|
89
94
|
export * from './src/shuffle.js'
|
|
90
95
|
export * from './src/sort.js'
|
|
91
96
|
export * from './src/sortBy.js'
|
package/src/indexBy.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function indexBy(property){
|
|
2
|
+
return list => {
|
|
3
|
+
const toReturn = {}
|
|
4
|
+
for (let i = 0; i < list.length; i++){
|
|
5
|
+
const item = list[ i ]
|
|
6
|
+
const key = item[property]
|
|
7
|
+
if(key !== undefined){
|
|
8
|
+
toReturn[ key ] = item
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return toReturn
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/mapAsync.js
CHANGED