@bigbinary/neeto-commons-frontend 2.0.59 → 2.0.61

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/pure.d.ts CHANGED
@@ -2,344 +2,1969 @@ export type Primitives = symbol | string | number | boolean | null | undefined;
2
2
  export type ObjectAndPrimitives = Primitives | object;
3
3
  type KeyType = string | number | symbol;
4
4
  type NilOr<T> = T | null | undefined;
5
-
6
- type Matchable<Obj, Parent, key extends keyof Obj> =
7
- | ((object: Obj[key], parent: Parent) => boolean)
8
- | MatchPattern<Obj[key], Parent>
9
- | Primitives;
10
-
11
- type MatchPattern<Obj = any, Parent = Obj> = Obj extends any[]
12
- ?
13
- | Matchable<Obj, Parent, number>[]
14
- | { [key: number]: Matchable<Obj, Parent, number> }
15
- : Obj extends Primitives
16
- ? Obj
17
- :
18
- | {
19
- [key in keyof Partial<Obj>]: Matchable<Obj, Parent, key>;
20
- } & {
21
- [key: KeyType]: Matchable<any, Parent, KeyType>;
22
- };
23
-
5
+ type Matchable<Obj, Parent, key extends keyof Obj> = ((object: Obj[key], parent: Parent) => boolean) | MatchPattern<Obj[key], Parent> | Primitives;
6
+ type MatchPattern<Obj = any, Parent = Obj> = Obj extends any[] ? Matchable<Obj, Parent, number>[] | {
7
+ [key: number]: Matchable<Obj, Parent, number>;
8
+ } : Obj extends Primitives ? Obj : ({ [key in keyof Partial<Obj>]: Matchable<Obj, Parent, key> } & {
9
+ [key: KeyType]: Matchable<any, Parent, KeyType>;
10
+ });
11
+ /**
12
+ *
13
+ * Curried: false
14
+ *
15
+ * Failsafe status: alternative available
16
+ *
17
+ * Converts camelCase to snake_case.
18
+ *
19
+ * @example
20
+ *
21
+ * camelToSnakeCase("firstName"); // "first_name"
22
+ * @endexample
23
+ */
24
24
  export function camelToSnakeCase(string: string): string;
25
25
  export function _camelToSnakeCase(string: NilOr<string>): NilOr<string>;
26
-
26
+ /**
27
+ *
28
+ * Curried: false
29
+ *
30
+ * Failsafe status: alternative available
31
+ *
32
+ * Convert the first character of string to upper case.
33
+ *
34
+ * @example
35
+ *
36
+ * capitalize("oliver"); // "Oliver"
37
+ * capitalize("OLIVER"); // "OLIVER"
38
+ * capitalize("oLIVER"); // "OLIVER"
39
+ * @endexample
40
+ */
27
41
  export function capitalize(string: string): string;
28
42
  export function _capitalize(string: NilOr<string>): NilOr<string>;
29
-
30
- export function copyKeys<T>(
31
- keyMap: { [key in keyof Partial<T>]: string },
32
- objectArray: T[]
33
- ): (T & { [key: string]: any })[];
43
+ /**
44
+ *
45
+ * Curried: true
46
+ *
47
+ * Failsafe status: alternative available
48
+ *
49
+ * Similar to renameKeys function, but it keeps both the source and destination
50
+ *
51
+ * keys in the resulting array.
52
+ *
53
+ * A function that accepts an input array and returns a new array with elements
54
+ *
55
+ * such that: each element will contain the newly specified keys with its value
56
+ *
57
+ * same as the value of specified source keys.
58
+ *
59
+ * Usage:
60
+ *
61
+ * @example
62
+ *
63
+ * copyKeys({
64
+ * sourceKey1: "destinationKey1",
65
+ * sourceKey2: "destinationKey2",
66
+ * ...
67
+ * }, arrayOfObjects);
68
+ * @endexample
69
+ * Example:
70
+ *
71
+ * @example
72
+ *
73
+ * const data = [
74
+ * { id: 1, name: "Tomato", quantity: 10 },
75
+ * { id: 2, name: "Potato", quantity: 20 },
76
+ * ];
77
+ *
78
+ * // copy name to label and id to value
79
+ * copyKeys({ name: "label", id: "value" }, data);
80
+ *
81
+ *
82
+ * output: [
83
+ * { label: "Tomato", value: 1, id: 1, name: "Tomato", quantity: 10 },
84
+ * { label: "Potato", value: 2, id: 2, name: "Potato", quantity: 20 },
85
+ * ];
86
+ *
87
+ * @endexample
88
+ */
89
+ export function copyKeys<T>(keyMap: { [key in keyof Partial<T>]: string }, objectArray: T[]): (T & {
90
+ [key: string]: any;
91
+ })[];
92
+ /**
93
+ *
94
+ * Curried: true
95
+ *
96
+ * Failsafe status: alternative available
97
+ *
98
+ * Similar to renameKeys function, but it keeps both the source and destination
99
+ *
100
+ * keys in the resulting array.
101
+ *
102
+ * A function that accepts an input array and returns a new array with elements
103
+ *
104
+ * such that: each element will contain the newly specified keys with its value
105
+ *
106
+ * same as the value of specified source keys.
107
+ *
108
+ * Usage:
109
+ *
110
+ * @example
111
+ *
112
+ * copyKeys({
113
+ * sourceKey1: "destinationKey1",
114
+ * sourceKey2: "destinationKey2",
115
+ * ...
116
+ * }, arrayOfObjects);
117
+ * @endexample
118
+ * Example:
119
+ *
120
+ * @example
121
+ *
122
+ * const data = [
123
+ * { id: 1, name: "Tomato", quantity: 10 },
124
+ * { id: 2, name: "Potato", quantity: 20 },
125
+ * ];
126
+ *
127
+ * // copy name to label and id to value
128
+ * copyKeys({ name: "label", id: "value" }, data);
129
+ *
130
+ *
131
+ * output: [
132
+ * { label: "Tomato", value: 1, id: 1, name: "Tomato", quantity: 10 },
133
+ * { label: "Potato", value: 2, id: 2, name: "Potato", quantity: 20 },
134
+ * ];
135
+ *
136
+ * @endexample
137
+ */
34
138
  export function copyKeys(keyMap: {
35
139
  [key: string]: string;
36
- }): <T>(objectArray: T[]) => (T & { [key: string]: any })[];
37
- export function _copyKeys<T>(
38
- keyMap: { [key in keyof Partial<T>]: string },
39
- objectArray: NilOr<T[]>
40
- ): NilOr<(T & { [key: string]: any })[]>;
140
+ }): <T>(objectArray: T[]) => (T & {
141
+ [key: string]: any;
142
+ })[];
143
+ export function _copyKeys<T>(keyMap: { [key in keyof Partial<T>]: string }, objectArray: NilOr<T[]>): NilOr<(T & {
144
+ [key: string]: any;
145
+ })[]>;
41
146
  export function _copyKeys(keyMap: {
42
147
  [key: string]: string;
43
- }): <T>(objectArray: NilOr<T[]>) => NilOr<(T & { [key: string]: any })[]>;
44
-
148
+ }): <T>(objectArray: NilOr<T[]>) => NilOr<(T & {
149
+ [key: string]: any;
150
+ })[]>;
151
+ /**
152
+ *
153
+ * Curried: true
154
+ *
155
+ * Failsafe status: alternative available
156
+ *
157
+ * A more advanced version of copyKeys function. It supports nested objects. It
158
+ *
159
+ * has a different structure for the key mapping to support nesting.
160
+ *
161
+ * They key mapping object is completely different from the one used in copyKeys
162
+ *
163
+ * to support object nesting. It accepts destination as key and source as value.
164
+ *
165
+ * Source can be of three types
166
+ *
167
+ * Usage:
168
+ *
169
+ * @example
170
+ *
171
+ * copyKeysDeep({
172
+ * destinationKey: "sourceKey",
173
+ * {
174
+ * destinationKey: "sourceKeyInNestedObject",
175
+ * },
176
+ * {
177
+ * destinationKey2: ["path", "to", "sourceKeyInNestedObject"],
178
+ * destinationKey3: (value, root) => value + root.id,
179
+ * }
180
+ * }, arrayOfObjects);
181
+ * @endexample
182
+ * Example:
183
+ *
184
+ * @example
185
+ *
186
+ * const data = [
187
+ * {
188
+ * id: 1,
189
+ * name: "Tomato",
190
+ * quantity: 10,
191
+ * user: { id: 1, name: "John", bonusQty: 3 },
192
+ * address: { street: "First street", pin: 101283 },
193
+ * },
194
+ * {
195
+ * id: 2,
196
+ * name: "Potato",
197
+ * quantity: 20,
198
+ * user: { id: 2, name: "Jane", bonusQty: 2 },
199
+ * address: { street: "Second street", pin: 998472 },
200
+ * },
201
+ * ];
202
+ *
203
+ * // reformatting `data` to label-and-value format for neetoui-select.
204
+ * copyKeys(
205
+ * {
206
+ * name: "label",
207
+ * quantity: (qty, root) => qty + root.user.bonusQty,
208
+ * user: { pin: ["address", "pin"] },
209
+ * },
210
+ * data
211
+ * );
212
+ *
213
+ *
214
+ * output: [
215
+ * {
216
+ * label: "Tomato", // label copied
217
+ * id: 1,
218
+ * name: "Tomato",
219
+ * quantity: 13, // quantity updated
220
+ * user: { pin: 101283, id: 1, name: "John", bonusQty: 3 }, // pin copied
221
+ * address: { street: "First street", pin: 101283 },
222
+ * },
223
+ * {
224
+ * label: "Potato",
225
+ * id: 2,
226
+ * name: "Potato",
227
+ * quantity: 22,
228
+ * user: { id: 2, name: "Jane", bonusQty: 2 },
229
+ * address: { pin: 998472, street: "Second street" },
230
+ * },
231
+ * ];
232
+ *
233
+ * @endexample
234
+ */
45
235
  export function copyKeysDeep(keyMap: object, objectArray: object[]): object[];
46
- export function copyKeysDeep(
47
- keyMap: object
48
- ): (objectArray: object[]) => object[];
49
- export function _copyKeysDeep(
50
- keyMap: object,
51
- objectArray: NilOr<object[]>
52
- ): NilOr<object[]>;
53
- export function _copyKeysDeep(
54
- keyMap: object
55
- ): (objectArray: NilOr<object[]>) => NilOr<object[]>;
56
-
236
+ /**
237
+ *
238
+ * Curried: true
239
+ *
240
+ * Failsafe status: alternative available
241
+ *
242
+ * A more advanced version of copyKeys function. It supports nested objects. It
243
+ *
244
+ * has a different structure for the key mapping to support nesting.
245
+ *
246
+ * They key mapping object is completely different from the one used in copyKeys
247
+ *
248
+ * to support object nesting. It accepts destination as key and source as value.
249
+ *
250
+ * Source can be of three types
251
+ *
252
+ * Usage:
253
+ *
254
+ * @example
255
+ *
256
+ * copyKeysDeep({
257
+ * destinationKey: "sourceKey",
258
+ * {
259
+ * destinationKey: "sourceKeyInNestedObject",
260
+ * },
261
+ * {
262
+ * destinationKey2: ["path", "to", "sourceKeyInNestedObject"],
263
+ * destinationKey3: (value, root) => value + root.id,
264
+ * }
265
+ * }, arrayOfObjects);
266
+ * @endexample
267
+ * Example:
268
+ *
269
+ * @example
270
+ *
271
+ * const data = [
272
+ * {
273
+ * id: 1,
274
+ * name: "Tomato",
275
+ * quantity: 10,
276
+ * user: { id: 1, name: "John", bonusQty: 3 },
277
+ * address: { street: "First street", pin: 101283 },
278
+ * },
279
+ * {
280
+ * id: 2,
281
+ * name: "Potato",
282
+ * quantity: 20,
283
+ * user: { id: 2, name: "Jane", bonusQty: 2 },
284
+ * address: { street: "Second street", pin: 998472 },
285
+ * },
286
+ * ];
287
+ *
288
+ * // reformatting `data` to label-and-value format for neetoui-select.
289
+ * copyKeys(
290
+ * {
291
+ * name: "label",
292
+ * quantity: (qty, root) => qty + root.user.bonusQty,
293
+ * user: { pin: ["address", "pin"] },
294
+ * },
295
+ * data
296
+ * );
297
+ *
298
+ *
299
+ * output: [
300
+ * {
301
+ * label: "Tomato", // label copied
302
+ * id: 1,
303
+ * name: "Tomato",
304
+ * quantity: 13, // quantity updated
305
+ * user: { pin: 101283, id: 1, name: "John", bonusQty: 3 }, // pin copied
306
+ * address: { street: "First street", pin: 101283 },
307
+ * },
308
+ * {
309
+ * label: "Potato",
310
+ * id: 2,
311
+ * name: "Potato",
312
+ * quantity: 22,
313
+ * user: { id: 2, name: "Jane", bonusQty: 2 },
314
+ * address: { pin: 998472, street: "Second street" },
315
+ * },
316
+ * ];
317
+ *
318
+ * @endexample
319
+ */
320
+ export function copyKeysDeep(keyMap: object): (objectArray: object[]) => object[];
321
+ export function _copyKeysDeep(keyMap: object, objectArray: NilOr<object[]>): NilOr<object[]>;
322
+ export function _copyKeysDeep(keyMap: object): (objectArray: NilOr<object[]>) => NilOr<object[]>;
323
+ /**
324
+ *
325
+ * Curried: true
326
+ *
327
+ * Failsafe status: alternative available
328
+ *
329
+ * Counts an array of items for items that matches the given pattern.
330
+ *
331
+ * Usage:
332
+ *
333
+ * @example
334
+ *
335
+ * const array = [
336
+ * { name: "Oliver", age: 20 },
337
+ * { name: "Sam", age: 40 },
338
+ * { name: "George", age: 41 },
339
+ * { name: "Smith", age: 20 },
340
+ * ];
341
+ *
342
+ * countBy({ age: 20 }, array); // returns 2
343
+ * countBy({ age: gt(__, 40) }, array); // returns 1
344
+ * countBy({ age: 50 }, array); // returns 0
345
+ * @endexample
346
+ */
57
347
  export function countBy<T>(pattern: MatchPattern<T>, entityArray: T[]): number;
58
- export function countBy(
59
- pattern: MatchPattern
60
- ): (entityArray: object[]) => number;
61
- export function _countBy<T>(
62
- pattern: MatchPattern<T>,
63
- entityArray: NilOr<T[]>
64
- ): NilOr<number>;
65
- export function _countBy(
66
- pattern: MatchPattern
67
- ): (entityArray: NilOr<object[]>) => NilOr<number>;
68
-
348
+ /**
349
+ *
350
+ * Curried: true
351
+ *
352
+ * Failsafe status: alternative available
353
+ *
354
+ * Counts an array of items for items that matches the given pattern.
355
+ *
356
+ * Usage:
357
+ *
358
+ * @example
359
+ *
360
+ * const array = [
361
+ * { name: "Oliver", age: 20 },
362
+ * { name: "Sam", age: 40 },
363
+ * { name: "George", age: 41 },
364
+ * { name: "Smith", age: 20 },
365
+ * ];
366
+ *
367
+ * countBy({ age: 20 }, array); // returns 2
368
+ * countBy({ age: gt(__, 40) }, array); // returns 1
369
+ * countBy({ age: 50 }, array); // returns 0
370
+ * @endexample
371
+ */
372
+ export function countBy(pattern: MatchPattern): (entityArray: object[]) => number;
373
+ export function _countBy<T>(pattern: MatchPattern<T>, entityArray: NilOr<T[]>): NilOr<number>;
374
+ export function _countBy(pattern: MatchPattern): (entityArray: NilOr<object[]>) => NilOr<number>;
375
+ /**
376
+ *
377
+ * Curried: false
378
+ *
379
+ * Failsafe status: failsafe by default
380
+ *
381
+ * To make an object immutable, recursively freeze each property which is of type
382
+ *
383
+ * object.
384
+ *
385
+ * Usage:
386
+ *
387
+ * @example
388
+ *
389
+ * const user = {
390
+ * address: { city: "Miami", phoneNumber: "389791382" },
391
+ * firstName: "Oliver",
392
+ * };
393
+ * deepFreezeObject(user);
394
+ *
395
+ * user.address.phoneNumber = "123456789"; // fails silently in non-strict mode
396
+ * user.lastName = "Smith"; // fails silently in non-strict mode
397
+ *
398
+ * console.log(user);
399
+ *
400
+ *
401
+ * {
402
+ * address: { city: "Miami", phoneNumber: "389791382" },
403
+ * firstName: "Oliver",
404
+ * };
405
+ *
406
+ * @endexample
407
+ * The assignment operation will throw the error only when we execute it in strict
408
+ *
409
+ * mode, in non-strict mode it will fail silently.
410
+ *
411
+ * @example
412
+ *
413
+ * "use strict"; user.address.phoneNumber = "123456789";
414
+ *
415
+ * Cannot assign to read only property 'phoneNumber' of object '#<Object>
416
+ *
417
+ *
418
+ * "use strict"; user.lastName = "Smith";
419
+ *
420
+ * Cannot add property lastName, object is not extensible
421
+ *
422
+ * @endexample
423
+ */
69
424
  export function deepFreezeObject<T>(object: T): Readonly<T>;
70
-
71
- export function dynamicArray<T>(
72
- count: number,
73
- elementGenerator: (index: number) => T
74
- ): T[];
75
-
76
- export function existsBy<T>(
77
- pattern: MatchPattern<T>,
78
- entityArray: T[]
79
- ): boolean;
80
- export function existsBy(
81
- pattern: MatchPattern
82
- ): (entityArray: object[]) => boolean;
83
-
84
- export function _existsBy<T>(
85
- pattern: MatchPattern<T>,
86
- entityArray: NilOr<T[]>
87
- ): NilOr<boolean>;
88
- export function _existsBy(
89
- pattern: MatchPattern
90
- ): (entityArray: NilOr<object[]>) => NilOr<boolean>;
91
-
425
+ /**
426
+ *
427
+ * Curried: false
428
+ *
429
+ * Failsafe status: not failsafe
430
+ *
431
+ * Builds an array of given length using a given function to generate each element.
432
+ *
433
+ * The function will get index as parameter and is expected to return the element
434
+ *
435
+ * corresponding to that index.
436
+ *
437
+ * Usage:
438
+ *
439
+ * @example
440
+ *
441
+ * dynamicArray(3, index => `option ${index + 1}`);
442
+ *
443
+ * // output: ["option 1", "option 2", "option 3"]
444
+ * @endexample
445
+ */
446
+ export function dynamicArray<T>(count: number, elementGenerator: (index: number) => T): T[];
447
+ /**
448
+ *
449
+ * Curried: true
450
+ *
451
+ * Failsafe status: alternative available
452
+ *
453
+ * Search for an item that matches the given pattern in an array. Returns true if
454
+ *
455
+ * found, false otherwise.
456
+ *
457
+ * Usage:
458
+ *
459
+ * @example
460
+ *
461
+ * const array = [
462
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 101283 } },
463
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 998472 } },
464
+ * ];
465
+ *
466
+ * existsBy({ name: "Sam" }, array); // true
467
+ * existsBy({ name: "Harry" }, array); // false
468
+ * @endexample
469
+ */
470
+ export function existsBy<T>(pattern: MatchPattern<T>, entityArray: T[]): boolean;
471
+ /**
472
+ *
473
+ * Curried: true
474
+ *
475
+ * Failsafe status: alternative available
476
+ *
477
+ * Search for an item that matches the given pattern in an array. Returns true if
478
+ *
479
+ * found, false otherwise.
480
+ *
481
+ * Usage:
482
+ *
483
+ * @example
484
+ *
485
+ * const array = [
486
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 101283 } },
487
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 998472 } },
488
+ * ];
489
+ *
490
+ * existsBy({ name: "Sam" }, array); // true
491
+ * existsBy({ name: "Harry" }, array); // false
492
+ * @endexample
493
+ */
494
+ export function existsBy(pattern: MatchPattern): (entityArray: object[]) => boolean;
495
+ export function _existsBy<T>(pattern: MatchPattern<T>, entityArray: NilOr<T[]>): NilOr<boolean>;
496
+ export function _existsBy(pattern: MatchPattern): (entityArray: NilOr<object[]>) => NilOr<boolean>;
497
+ /**
498
+ *
499
+ * Curried: true
500
+ *
501
+ * Failsafe status: alternative available
502
+ *
503
+ * Search for an item in the given array using the given id.
504
+ *
505
+ * Usage:
506
+ *
507
+ * @example
508
+ *
509
+ * const array = [
510
+ * { id: 1, name: "Sam" },
511
+ * { id: 2, name: "Oliver" },
512
+ * ];
513
+ *
514
+ * existsById(2, array); // true Oliver's id is 2
515
+ * existsById(5, array); // false no one has an id of 5
516
+ * @endexample
517
+ */
92
518
  export function existsById(id: any, entityArray: object[]): boolean;
519
+ /**
520
+ *
521
+ * Curried: true
522
+ *
523
+ * Failsafe status: alternative available
524
+ *
525
+ * Search for an item in the given array using the given id.
526
+ *
527
+ * Usage:
528
+ *
529
+ * @example
530
+ *
531
+ * const array = [
532
+ * { id: 1, name: "Sam" },
533
+ * { id: 2, name: "Oliver" },
534
+ * ];
535
+ *
536
+ * existsById(2, array); // true Oliver's id is 2
537
+ * existsById(5, array); // false no one has an id of 5
538
+ * @endexample
539
+ */
93
540
  export function existsById(id: any): (entityArray: object[]) => boolean;
94
- export function _existsById(
95
- id: any,
96
- entityArray: NilOr<object[]>
97
- ): NilOr<boolean>;
98
- export function _existsById(
99
- id: any
100
- ): (entityArray: NilOr<object[]>) => NilOr<boolean>;
101
-
541
+ export function _existsById(id: any, entityArray: NilOr<object[]>): NilOr<boolean>;
542
+ export function _existsById(id: any): (entityArray: NilOr<object[]>) => NilOr<boolean>;
543
+ /**
544
+ *
545
+ * Curried: true
546
+ *
547
+ * Failsafe status: alternative available
548
+ *
549
+ * Filter an array of items based on pattern matching.
550
+ *
551
+ * Usage:
552
+ *
553
+ * @example
554
+ *
555
+ * const array = [
556
+ * { name: "Oliver", age: 20 },
557
+ * { name: "Sam", age: 40 },
558
+ * { name: "George", age: 41 },
559
+ * { name: "Smith", age: 20 },
560
+ * ];
561
+ *
562
+ * filterBy({ age: 20 }, array); // [{ name: "Oliver", age: 20 }, { name: "Smith", age: 20 }]
563
+ * filterBy({ age: gt(__, 40) }, array); // [{ name: "George", age: 41 }]
564
+ * filterBy({ age: 50 }, array); // []
565
+ * @endexample
566
+ */
102
567
  export function filterBy<T>(pattern: MatchPattern<T>, entityArray: T[]): T[];
568
+ /**
569
+ *
570
+ * Curried: true
571
+ *
572
+ * Failsafe status: alternative available
573
+ *
574
+ * Filter an array of items based on pattern matching.
575
+ *
576
+ * Usage:
577
+ *
578
+ * @example
579
+ *
580
+ * const array = [
581
+ * { name: "Oliver", age: 20 },
582
+ * { name: "Sam", age: 40 },
583
+ * { name: "George", age: 41 },
584
+ * { name: "Smith", age: 20 },
585
+ * ];
586
+ *
587
+ * filterBy({ age: 20 }, array); // [{ name: "Oliver", age: 20 }, { name: "Smith", age: 20 }]
588
+ * filterBy({ age: gt(__, 40) }, array); // [{ name: "George", age: 41 }]
589
+ * filterBy({ age: 50 }, array); // []
590
+ * @endexample
591
+ */
103
592
  export function filterBy(pattern: MatchPattern): <T>(entityArray: T[]) => T[];
104
- export function _filterBy<T>(
105
- pattern: MatchPattern<T>,
106
- entityArray: NilOr<T[]>
107
- ): NilOr<T[]>;
108
- export function _filterBy(
109
- pattern: MatchPattern
110
- ): <T>(entityArray: NilOr<T[]>) => NilOr<T[]>;
111
-
593
+ export function _filterBy<T>(pattern: MatchPattern<T>, entityArray: NilOr<T[]>): NilOr<T[]>;
594
+ export function _filterBy(pattern: MatchPattern): <T>(entityArray: NilOr<T[]>) => NilOr<T[]>;
595
+ /**
596
+ *
597
+ * Curried: false
598
+ *
599
+ * Failsafe status: alternative available
600
+ *
601
+ * A function that accepts an object and returns a new object with only the
602
+ *
603
+ * properties that are not null or undefined. This won't work well for arrays.
604
+ *
605
+ * @example
606
+ *
607
+ * filterNonNull({
608
+ * firstName: "Oliver",
609
+ * lastName: null,
610
+ * phoneNumbers: { home: undefined, office: "1234567890" },
611
+ * });
612
+ *
613
+ *
614
+ * {
615
+ * firstName: "Oliver",
616
+ * phoneNumbers: { office: "1234567890" },
617
+ * }
618
+ *
619
+ * @endexample
620
+ */
112
621
  export function filterNonNull(object: object): object;
113
622
  export function _filterNonNull(object: NilOr<object>): NilOr<object>;
114
-
623
+ /**
624
+ *
625
+ * Curried: true
626
+ *
627
+ * Failsafe status: alternative available
628
+ *
629
+ * Find the first item that matches the given pattern from an array.
630
+ *
631
+ * Usage:
632
+ *
633
+ * @example
634
+ *
635
+ * const array = [
636
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 123456 } },
637
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 654321 } },
638
+ * ];
639
+ *
640
+ * findBy({ name: "Sam" }, array); // returns object corresponding to Sam
641
+ * findBy({ id: 2, address: { pin: 654321 } }, array); // returns object corresponding to Oliver
642
+ * findBy({ id: 3 }, array); // returns undefined
643
+ * @endexample
644
+ */
115
645
  export function findBy<T>(pattern: MatchPattern<T>, entityArray: T[]): T;
646
+ /**
647
+ *
648
+ * Curried: true
649
+ *
650
+ * Failsafe status: alternative available
651
+ *
652
+ * Find the first item that matches the given pattern from an array.
653
+ *
654
+ * Usage:
655
+ *
656
+ * @example
657
+ *
658
+ * const array = [
659
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 123456 } },
660
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 654321 } },
661
+ * ];
662
+ *
663
+ * findBy({ name: "Sam" }, array); // returns object corresponding to Sam
664
+ * findBy({ id: 2, address: { pin: 654321 } }, array); // returns object corresponding to Oliver
665
+ * findBy({ id: 3 }, array); // returns undefined
666
+ * @endexample
667
+ */
116
668
  export function findBy(pattern: MatchPattern): <T>(entityArray: T[]) => T;
117
- export function _findBy<T>(
118
- pattern: MatchPattern<T>,
119
- entityArray: NilOr<T[]>
120
- ): NilOr<T>;
121
- export function _findBy(
122
- pattern: MatchPattern
123
- ): <T>(entityArray: NilOr<T[]>) => NilOr<T>;
124
-
669
+ export function _findBy<T>(pattern: MatchPattern<T>, entityArray: NilOr<T[]>): NilOr<T>;
670
+ export function _findBy(pattern: MatchPattern): <T>(entityArray: NilOr<T[]>) => NilOr<T>;
671
+ /**
672
+ *
673
+ * Curried: true
674
+ *
675
+ * Failsafe status: alternative available
676
+ *
677
+ * Find an object having the given id from an array.
678
+ *
679
+ * Usage:
680
+ *
681
+ * @example
682
+ *
683
+ * const array = [
684
+ * { id: 1, name: "Sam" },
685
+ * { id: 2, name: "Oliver" },
686
+ * ];
687
+ * const idOfItemToBeFind = 2;
688
+ *
689
+ * findById(idOfItemToBeFind, array);
690
+ * // { id: 2, name: "Oliver" }
691
+ * @endexample
692
+ */
125
693
  export function findById<T>(id: any, entityArray: T[]): T;
694
+ /**
695
+ *
696
+ * Curried: true
697
+ *
698
+ * Failsafe status: alternative available
699
+ *
700
+ * Find an object having the given id from an array.
701
+ *
702
+ * Usage:
703
+ *
704
+ * @example
705
+ *
706
+ * const array = [
707
+ * { id: 1, name: "Sam" },
708
+ * { id: 2, name: "Oliver" },
709
+ * ];
710
+ * const idOfItemToBeFind = 2;
711
+ *
712
+ * findById(idOfItemToBeFind, array);
713
+ * // { id: 2, name: "Oliver" }
714
+ * @endexample
715
+ */
126
716
  export function findById(id: any): <T>(entityArray: T[]) => T;
127
717
  export function _findById<T>(id: any, entityArray: NilOr<T[]>): NilOr<T>;
128
718
  export function _findById(id: any): <T>(entityArray: NilOr<T[]>) => NilOr<T>;
129
-
130
- export function findIndexBy<T>(
131
- pattern: MatchPattern<T>,
132
- entityArray: T[]
133
- ): number;
134
- export function findIndexBy(
135
- pattern: MatchPattern
136
- ): (entityArray: object[]) => number;
137
- export function _findIndexBy<T>(
138
- pattern: MatchPattern<T>,
139
- entityArray: NilOr<T[]>
140
- ): NilOr<number>;
141
- export function _findIndexBy(
142
- pattern: MatchPattern
143
- ): (entityArray: NilOr<object[]>) => NilOr<number>;
144
-
719
+ /**
720
+ *
721
+ * Curried: true
722
+ *
723
+ * Failsafe status: alternative available
724
+ *
725
+ * Find the index of an item that matches the pattern from the given array.
726
+ *
727
+ * Usage:
728
+ *
729
+ * @example
730
+ *
731
+ * const array = [
732
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 123456 } },
733
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 654321 } },
734
+ * ];
735
+ *
736
+ * findIndexBy({ name: "Sam" }, array); // returns 0
737
+ * findIndexBy({ id: 2, address: { pin: 654321 } }, array); // returns 1
738
+ * findIndexBy({ id: 3 }, array); // returns -1
739
+ * @endexample
740
+ */
741
+ export function findIndexBy<T>(pattern: MatchPattern<T>, entityArray: T[]): number;
742
+ /**
743
+ *
744
+ * Curried: true
745
+ *
746
+ * Failsafe status: alternative available
747
+ *
748
+ * Find the index of an item that matches the pattern from the given array.
749
+ *
750
+ * Usage:
751
+ *
752
+ * @example
753
+ *
754
+ * const array = [
755
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 123456 } },
756
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 654321 } },
757
+ * ];
758
+ *
759
+ * findIndexBy({ name: "Sam" }, array); // returns 0
760
+ * findIndexBy({ id: 2, address: { pin: 654321 } }, array); // returns 1
761
+ * findIndexBy({ id: 3 }, array); // returns -1
762
+ * @endexample
763
+ */
764
+ export function findIndexBy(pattern: MatchPattern): (entityArray: object[]) => number;
765
+ export function _findIndexBy<T>(pattern: MatchPattern<T>, entityArray: NilOr<T[]>): NilOr<number>;
766
+ export function _findIndexBy(pattern: MatchPattern): (entityArray: NilOr<object[]>) => NilOr<number>;
767
+ /**
768
+ *
769
+ * Curried: true
770
+ *
771
+ * Failsafe status: alternative available
772
+ *
773
+ * Find an index of an item from an array of items based on the id property of
774
+ *
775
+ * entities inside it.
776
+ *
777
+ * Usage:
778
+ *
779
+ * @example
780
+ *
781
+ * const array = [
782
+ * { id: "1001", name: "Sam" },
783
+ * { id: "2001", name: "Oliver" },
784
+ * ];
785
+ *
786
+ * findIndexById("2001", array); // returns 1
787
+ * findIndexById("1001", array); // returns 0
788
+ * findIndexById("3001", array); // returns -1
789
+ * @endexample
790
+ */
145
791
  export function findIndexById(id: any, entityArray: object[]): number;
792
+ /**
793
+ *
794
+ * Curried: true
795
+ *
796
+ * Failsafe status: alternative available
797
+ *
798
+ * Find an index of an item from an array of items based on the id property of
799
+ *
800
+ * entities inside it.
801
+ *
802
+ * Usage:
803
+ *
804
+ * @example
805
+ *
806
+ * const array = [
807
+ * { id: "1001", name: "Sam" },
808
+ * { id: "2001", name: "Oliver" },
809
+ * ];
810
+ *
811
+ * findIndexById("2001", array); // returns 1
812
+ * findIndexById("1001", array); // returns 0
813
+ * findIndexById("3001", array); // returns -1
814
+ * @endexample
815
+ */
146
816
  export function findIndexById(id: any): (entityArray: object[]) => number;
147
- export function _findIndexById(
148
- id: any,
149
- entityArray: NilOr<object[]>
150
- ): NilOr<number>;
151
- export function _findIndexById(
152
- id: any
153
- ): (entityArray: NilOr<object[]>) => NilOr<number>;
154
-
817
+ export function _findIndexById(id: any, entityArray: NilOr<object[]>): NilOr<number>;
818
+ export function _findIndexById(id: any): (entityArray: NilOr<object[]>) => NilOr<number>;
819
+ /**
820
+ *
821
+ * Curried: true
822
+ *
823
+ * Failsafe status: alternative available
824
+ *
825
+ * Find the last item that matches the given pattern.
826
+ *
827
+ * Usage:
828
+ *
829
+ * @example
830
+ *
831
+ * const array = [
832
+ * { name: "Oliver", age: 20 },
833
+ * { name: "Sam", age: 40 },
834
+ * { name: "George", age: 41 },
835
+ * { name: "Smith", age: 20 },
836
+ * ];
837
+ *
838
+ * findLastBy({ age: 20 }, array); // { name: "Smith", age: 20 }
839
+ * findLastBy({ name: includes("e") }, array); // { name: "George", age: 41 }
840
+ * @endexample
841
+ */
155
842
  export function findLastBy<T>(pattern: MatchPattern<T>, entityArray: T[]): T;
843
+ /**
844
+ *
845
+ * Curried: true
846
+ *
847
+ * Failsafe status: alternative available
848
+ *
849
+ * Find the last item that matches the given pattern.
850
+ *
851
+ * Usage:
852
+ *
853
+ * @example
854
+ *
855
+ * const array = [
856
+ * { name: "Oliver", age: 20 },
857
+ * { name: "Sam", age: 40 },
858
+ * { name: "George", age: 41 },
859
+ * { name: "Smith", age: 20 },
860
+ * ];
861
+ *
862
+ * findLastBy({ age: 20 }, array); // { name: "Smith", age: 20 }
863
+ * findLastBy({ name: includes("e") }, array); // { name: "George", age: 41 }
864
+ * @endexample
865
+ */
156
866
  export function findLastBy(pattern: MatchPattern): <T>(entityArray: T[]) => T;
157
- export function _findLastBy<T>(
158
- pattern: MatchPattern<T>,
159
- entityArray: NilOr<T[]>
160
- ): NilOr<T>;
161
- export function _findLastBy(
162
- pattern: MatchPattern
163
- ): <T>(entityArray: NilOr<T[]>) => NilOr<T>;
164
-
867
+ export function _findLastBy<T>(pattern: MatchPattern<T>, entityArray: NilOr<T[]>): NilOr<T>;
868
+ export function _findLastBy(pattern: MatchPattern): <T>(entityArray: NilOr<T[]>) => NilOr<T>;
869
+ /**
870
+ *
871
+ * Curried: true
872
+ *
873
+ * Failsafe status: alternative available
874
+ *
875
+ * Find the last index of item that matches the given pattern.
876
+ *
877
+ * Usage:
878
+ *
879
+ * @example
880
+ *
881
+ * const array = [
882
+ * { name: "Oliver", age: 20 },
883
+ * { name: "Sam", age: 40 },
884
+ * { name: "George", age: 41 },
885
+ * { name: "Smith", age: 20 },
886
+ * ];
887
+ *
888
+ * findLastIndexBy({ age: 20 }, array); // returns 3
889
+ * findLastIndexBy({ name: includes("e") }, array); // returns 2
890
+ * @endexample
891
+ */
165
892
  export function findLastIndexBy(id: any, entityArray: object[]): number;
893
+ /**
894
+ *
895
+ * Curried: true
896
+ *
897
+ * Failsafe status: alternative available
898
+ *
899
+ * Find the last index of item that matches the given pattern.
900
+ *
901
+ * Usage:
902
+ *
903
+ * @example
904
+ *
905
+ * const array = [
906
+ * { name: "Oliver", age: 20 },
907
+ * { name: "Sam", age: 40 },
908
+ * { name: "George", age: 41 },
909
+ * { name: "Smith", age: 20 },
910
+ * ];
911
+ *
912
+ * findLastIndexBy({ age: 20 }, array); // returns 3
913
+ * findLastIndexBy({ name: includes("e") }, array); // returns 2
914
+ * @endexample
915
+ */
166
916
  export function findLastIndexBy(id: any): (entityArray: object[]) => number;
167
- export function _findLastIndexBy(
168
- id: any,
169
- entityArray: NilOr<object[]>
170
- ): NilOr<number>;
171
- export function _findLastIndexBy(
172
- id: any
173
- ): (entityArray: NilOr<object[]>) => NilOr<number>;
174
-
917
+ export function _findLastIndexBy(id: any, entityArray: NilOr<object[]>): NilOr<number>;
918
+ export function _findLastIndexBy(id: any): (entityArray: NilOr<object[]>) => NilOr<number>;
919
+ /**
920
+ *
921
+ * Curried: false
922
+ *
923
+ * Failsafe status: not failsafe
924
+ *
925
+ * This function is used to generate a random integer.
926
+ *
927
+ * Here are some sample usages:
928
+ *
929
+ * @example
930
+ *
931
+ * getRandomInt(); // returns a random integer between 0 and 9007199254740991 (MAX_SAFE_INTEGER)
932
+ * getRandomInt(10); // returns a random integer between 0 and 10
933
+ * getRandomInt(1, 5); // returns a random integer between 1 and 5
934
+ * @endexample
935
+ */
175
936
  export function getRandomInt(a?: number, b?: number): number;
937
+ /**
938
+ *
939
+ * Curried: false
940
+ *
941
+ * Failsafe status: alternative available
942
+ *
943
+ * Converts common developer friendly string formats (camelCase, snake_case,
944
+ *
945
+ * dash-case etc) to human readable string.
946
+ *
947
+ * @example
948
+ *
949
+ * humanize("helloWorld"); // "Hello world"
950
+ * humanize("hello-world"); // "Hello world"
951
+ * humanize("__hello_world"); // "Hello world"
952
+ * humanize("HelloUSA"); // "Hello usa"
953
+ * @endexample
954
+ */
176
955
  export function humanize(string: string): string;
177
956
  export function _humanize(string: NilOr<string>): NilOr<string>;
178
-
179
957
  export function isNot(a: any, b: any): boolean;
180
958
  export function isNot(a: any): (b: any) => boolean;
181
-
959
+ /**
960
+ *
961
+ * Curried: false
962
+ *
963
+ * Failsafe status: failsafe by default
964
+ *
965
+ * Returns true if the given value is not empty (includes strings, arrays,
966
+ *
967
+ * objects). False otherwise. (the opposite of isEmpty in ramda)
968
+ *
969
+ */
182
970
  export const isNotEmpty: (a: any) => boolean;
183
-
184
971
  export function isNotEqualDeep(a: any, b: any): boolean;
185
972
  export function isNotEqualDeep(a: any): (b: any) => boolean;
186
-
973
+ /**
974
+ *
975
+ * Curried: false
976
+ *
977
+ * Failsafe status: failsafe by default
978
+ *
979
+ * Returns true if the given value is not null or undefined. False otherwise.
980
+ *
981
+ * (the opposite of isNil in ramda)
982
+ *
983
+ */
187
984
  export const isNotNil: (a: any) => boolean;
188
-
985
+ /**
986
+ *
987
+ * Curried: false
988
+ *
989
+ * Failsafe status: failsafe by default
990
+ *
991
+ * Recursively converts the snake cased object keys to camel case
992
+ *
993
+ * Usage:
994
+ *
995
+ * @example
996
+ *
997
+ * keysToCamelCase({
998
+ * first_name: "Oliver",
999
+ * last_name: "Smith",
1000
+ * address: { city: "Miami", phone_number: "389791382" },
1001
+ * });
1002
+ *
1003
+ * {
1004
+ * address: {city: 'Miami', phoneNumber: '389791382'},
1005
+ * firstName: "Oliver",
1006
+ * lastName: "Smith",
1007
+ * }
1008
+ *
1009
+ * @endexample
1010
+ */
189
1011
  export function keysToCamelCase(object: any): any;
1012
+ /**
1013
+ *
1014
+ * Curried: false
1015
+ *
1016
+ * Failsafe status: failsafe by default
1017
+ *
1018
+ * Recursively converts the camel cased object keys to snake case.
1019
+ *
1020
+ * Usage:
1021
+ *
1022
+ * @example
1023
+ *
1024
+ * keysToSnakeCase({
1025
+ * address: { city: "Miami", phoneNumber: "389791382" },
1026
+ * firstName: "Oliver",
1027
+ * lastName: "Smith",
1028
+ * });
1029
+ *
1030
+ * {
1031
+ * first_name: "Oliver",
1032
+ * last_name: "Smith",
1033
+ * address: { city: "Miami", phone_number: "389791382" },
1034
+ * }
1035
+ *
1036
+ * @endexample
1037
+ */
190
1038
  export function keysToSnakeCase(object: any): any;
191
-
1039
+ /**
1040
+ *
1041
+ * Curried: true
1042
+ *
1043
+ * Failsafe status: failsafe by default
1044
+ *
1045
+ * Checks whether the given object matches the given pattern. Each primitive value
1046
+ *
1047
+ * (int, boolean, string, etc.) in the pattern should be same as the corresponding
1048
+ *
1049
+ * value in the object (deeply) for a match.
1050
+ *
1051
+ * This function accepts two objects (pattern and data) as parameters and returns
1052
+ *
1053
+ * true if all the keys in pattern exist in data and the primitive values of those
1054
+ *
1055
+ * keys are identical to the data. Object values are compared recursively for inner
1056
+ *
1057
+ * primitives.
1058
+ *
1059
+ * If a function is passed as pattern's property, and equality test is performed
1060
+ *
1061
+ * with corresponding object property. If equality fails, the function will be
1062
+ *
1063
+ * evaluated with the value of the corresponding property of the data. If function
1064
+ *
1065
+ * returns true, it will be considered as a match.
1066
+ *
1067
+ * In short, this function checks whether all the primitive keys in the pattern is
1068
+ *
1069
+ * equal to corresponding keys in the data and all conditions (functions) are
1070
+ *
1071
+ * satisfied.
1072
+ *
1073
+ * @example
1074
+ *
1075
+ * const user = {
1076
+ * firstName: "Oliver",
1077
+ * address: { city: "Miami", phoneNumber: "389791382" },
1078
+ * cars: [{ brand: "Ford" }, { brand: "Honda" }],
1079
+ * };
1080
+ *
1081
+ * matches({ firstName: "Oliver" }, user); // true
1082
+ * matches({ address: { city: "Miami" } }, user); // true
1083
+ * matches({ cars: [{ brand: "Ford" }] }, user); // true
1084
+ * matches({ firstName: "Sam" }, user); // false
1085
+ * matches({ address: { country: "US" } }, user); // false
1086
+ * matches({ cars: [{ brand: "Honda" }] }, user); // false
1087
+ * // array index as object key
1088
+ * matches({ cars: { 1: { brand: "Honda" } } }, user); // true
1089
+ * // conditional functions
1090
+ * matches({ cars: arr => arr.length === 2 }, user); // true
1091
+ * // point-free functions with ramda
1092
+ * matches({ firstName: startsWith("O") }, user); // true
1093
+ * @endexample
1094
+ */
192
1095
  export function matches<T>(pattern: MatchPattern<T>, data: T): boolean;
1096
+ /**
1097
+ *
1098
+ * Curried: true
1099
+ *
1100
+ * Failsafe status: failsafe by default
1101
+ *
1102
+ * Checks whether the given object matches the given pattern. Each primitive value
1103
+ *
1104
+ * (int, boolean, string, etc.) in the pattern should be same as the corresponding
1105
+ *
1106
+ * value in the object (deeply) for a match.
1107
+ *
1108
+ * This function accepts two objects (pattern and data) as parameters and returns
1109
+ *
1110
+ * true if all the keys in pattern exist in data and the primitive values of those
1111
+ *
1112
+ * keys are identical to the data. Object values are compared recursively for inner
1113
+ *
1114
+ * primitives.
1115
+ *
1116
+ * If a function is passed as pattern's property, and equality test is performed
1117
+ *
1118
+ * with corresponding object property. If equality fails, the function will be
1119
+ *
1120
+ * evaluated with the value of the corresponding property of the data. If function
1121
+ *
1122
+ * returns true, it will be considered as a match.
1123
+ *
1124
+ * In short, this function checks whether all the primitive keys in the pattern is
1125
+ *
1126
+ * equal to corresponding keys in the data and all conditions (functions) are
1127
+ *
1128
+ * satisfied.
1129
+ *
1130
+ * @example
1131
+ *
1132
+ * const user = {
1133
+ * firstName: "Oliver",
1134
+ * address: { city: "Miami", phoneNumber: "389791382" },
1135
+ * cars: [{ brand: "Ford" }, { brand: "Honda" }],
1136
+ * };
1137
+ *
1138
+ * matches({ firstName: "Oliver" }, user); // true
1139
+ * matches({ address: { city: "Miami" } }, user); // true
1140
+ * matches({ cars: [{ brand: "Ford" }] }, user); // true
1141
+ * matches({ firstName: "Sam" }, user); // false
1142
+ * matches({ address: { country: "US" } }, user); // false
1143
+ * matches({ cars: [{ brand: "Honda" }] }, user); // false
1144
+ * // array index as object key
1145
+ * matches({ cars: { 1: { brand: "Honda" } } }, user); // true
1146
+ * // conditional functions
1147
+ * matches({ cars: arr => arr.length === 2 }, user); // true
1148
+ * // point-free functions with ramda
1149
+ * matches({ firstName: startsWith("O") }, user); // true
1150
+ * @endexample
1151
+ */
193
1152
  export function matches(pattern: MatchPattern): (data: any) => boolean;
194
-
195
- export function modifyBy<T>(
196
- pattern: MatchPattern<T>,
197
- modifier: (previous: T) => T,
198
- entityArray: T[]
199
- ): T[];
200
- export function modifyBy<T>(
201
- pattern: MatchPattern<T>,
202
- modifier: (previous: T) => T
203
- ): (entityArray: T[]) => T[];
204
- export function modifyBy(
205
- pattern: MatchPattern
206
- ): <T>(modifier: (previous: T) => T, entityArray: T[]) => T[];
207
- export function modifyBy(
208
- pattern: MatchPattern
209
- ): <T>(modifier: (previous: T) => T) => (entityArray: T[]) => T[];
210
- export function _modifyBy<T>(
211
- pattern: MatchPattern<T>,
212
- modifier: (previous: T) => T,
213
- entityArray: NilOr<T[]>
214
- ): NilOr<T[]>;
215
- export function _modifyBy<T>(
216
- pattern: MatchPattern<T>,
217
- modifier: (previous: T) => T
218
- ): (entityArray: NilOr<T[]>) => NilOr<T[]>;
219
- export function _modifyBy(
220
- pattern: MatchPattern
221
- ): <T>(modifier: (previous: T) => T, entityArray: NilOr<T[]>) => NilOr<T[]>;
222
- export function _modifyBy(
223
- pattern: MatchPattern
224
- ): <T>(modifier: (previous: T) => T) => (entityArray: NilOr<T[]>) => NilOr<T[]>;
225
-
226
- export function modifyById<T>(
227
- id: any,
228
- modifier: (previous: T) => T,
229
- entityArray: T[]
230
- ): T[];
231
- export function modifyById<T>(
232
- id: any,
233
- modifier: (previous: T) => T
234
- ): (entityArray: T[]) => T[];
235
- export function modifyById(
236
- id: any
237
- ): <T>(modifier: (previous: T) => T, entityArray: T[]) => T[];
238
- export function modifyById(
239
- id: any
240
- ): <T>(modifier: (previous: T) => T) => (entityArray: T[]) => T[];
241
- export function _modifyById<T>(
242
- id: any,
243
- modifier: (previous: T) => T,
244
- entityArray: NilOr<T[]>
245
- ): NilOr<T[]>;
246
- export function _modifyById<T>(
247
- id: any,
248
- modifier: (previous: T) => T
249
- ): (entityArray: NilOr<T[]>) => NilOr<T[]>;
250
- export function _modifyById(
251
- id: any
252
- ): <T>(modifier: (previous: T) => T, entityArray: NilOr<T[]>) => NilOr<T[]>;
253
- export function _modifyById(
254
- id: any
255
- ): <T>(modifier: (previous: T) => T) => (entityArray: NilOr<T[]>) => NilOr<T[]>;
256
-
1153
+ /**
1154
+ *
1155
+ * Curried: true
1156
+ *
1157
+ * Failsafe status: alternative available
1158
+ *
1159
+ * Modify all items using modifier function based on a pattern passed as an
1160
+ *
1161
+ * argument to the function.
1162
+ *
1163
+ * Usage:
1164
+ *
1165
+ * @example
1166
+ *
1167
+ * const array = [
1168
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 101283 } },
1169
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 998472 } },
1170
+ * ];
1171
+ * const modifier = item => assoc("name", item.name.toUpperCase(), item);
1172
+ *
1173
+ * modifyBy({ name: "Oliver" }, modifier, array);
1174
+ *
1175
+ * [{id: 1, name: "Sam"}, {id: 2, name: "OLIVER"}]
1176
+ *
1177
+ * @endexample
1178
+ */
1179
+ export function modifyBy<T>(pattern: MatchPattern<T>, modifier: (previous: T) => T, entityArray: T[]): T[];
1180
+ /**
1181
+ *
1182
+ * Curried: true
1183
+ *
1184
+ * Failsafe status: alternative available
1185
+ *
1186
+ * Modify all items using modifier function based on a pattern passed as an
1187
+ *
1188
+ * argument to the function.
1189
+ *
1190
+ * Usage:
1191
+ *
1192
+ * @example
1193
+ *
1194
+ * const array = [
1195
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 101283 } },
1196
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 998472 } },
1197
+ * ];
1198
+ * const modifier = item => assoc("name", item.name.toUpperCase(), item);
1199
+ *
1200
+ * modifyBy({ name: "Oliver" }, modifier, array);
1201
+ *
1202
+ * [{id: 1, name: "Sam"}, {id: 2, name: "OLIVER"}]
1203
+ *
1204
+ * @endexample
1205
+ */
1206
+ export function modifyBy<T>(pattern: MatchPattern<T>, modifier: (previous: T) => T): (entityArray: T[]) => T[];
1207
+ /**
1208
+ *
1209
+ * Curried: true
1210
+ *
1211
+ * Failsafe status: alternative available
1212
+ *
1213
+ * Modify all items using modifier function based on a pattern passed as an
1214
+ *
1215
+ * argument to the function.
1216
+ *
1217
+ * Usage:
1218
+ *
1219
+ * @example
1220
+ *
1221
+ * const array = [
1222
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 101283 } },
1223
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 998472 } },
1224
+ * ];
1225
+ * const modifier = item => assoc("name", item.name.toUpperCase(), item);
1226
+ *
1227
+ * modifyBy({ name: "Oliver" }, modifier, array);
1228
+ *
1229
+ * [{id: 1, name: "Sam"}, {id: 2, name: "OLIVER"}]
1230
+ *
1231
+ * @endexample
1232
+ */
1233
+ export function modifyBy(pattern: MatchPattern): <T>(modifier: (previous: T) => T, entityArray: T[]) => T[];
1234
+ /**
1235
+ *
1236
+ * Curried: true
1237
+ *
1238
+ * Failsafe status: alternative available
1239
+ *
1240
+ * Modify all items using modifier function based on a pattern passed as an
1241
+ *
1242
+ * argument to the function.
1243
+ *
1244
+ * Usage:
1245
+ *
1246
+ * @example
1247
+ *
1248
+ * const array = [
1249
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 101283 } },
1250
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 998472 } },
1251
+ * ];
1252
+ * const modifier = item => assoc("name", item.name.toUpperCase(), item);
1253
+ *
1254
+ * modifyBy({ name: "Oliver" }, modifier, array);
1255
+ *
1256
+ * [{id: 1, name: "Sam"}, {id: 2, name: "OLIVER"}]
1257
+ *
1258
+ * @endexample
1259
+ */
1260
+ export function modifyBy(pattern: MatchPattern): <T>(modifier: (previous: T) => T) => (entityArray: T[]) => T[];
1261
+ export function _modifyBy<T>(pattern: MatchPattern<T>, modifier: (previous: T) => T, entityArray: NilOr<T[]>): NilOr<T[]>;
1262
+ export function _modifyBy<T>(pattern: MatchPattern<T>, modifier: (previous: T) => T): (entityArray: NilOr<T[]>) => NilOr<T[]>;
1263
+ export function _modifyBy(pattern: MatchPattern): <T>(modifier: (previous: T) => T, entityArray: NilOr<T[]>) => NilOr<T[]>;
1264
+ export function _modifyBy(pattern: MatchPattern): <T>(modifier: (previous: T) => T) => (entityArray: NilOr<T[]>) => NilOr<T[]>;
1265
+ /**
1266
+ *
1267
+ * Curried: true
1268
+ *
1269
+ * Failsafe status: alternative available
1270
+ *
1271
+ * Applies the modifier function on the item having the given id in an array and
1272
+ *
1273
+ * returns a new array with the return value of the modifier function in the index
1274
+ *
1275
+ * of the match.
1276
+ *
1277
+ * Usage:
1278
+ *
1279
+ * @example
1280
+ *
1281
+ * const array = [
1282
+ * { id: 1, name: "Sam" },
1283
+ * { id: 2, name: "Oliver" },
1284
+ * ];
1285
+ * const idOfItemToBeModified = 2;
1286
+ * const modifier = item => assoc("name", item.name.toUpperCase(), item);
1287
+ *
1288
+ * modifyById(idOfItemToBeModified, modifier, array);
1289
+ *
1290
+ * [{ id: 1, name: "Sam" }, { id: 2, name: "OLIVER" }]
1291
+ *
1292
+ * @endexample
1293
+ */
1294
+ export function modifyById<T>(id: any, modifier: (previous: T) => T, entityArray: T[]): T[];
1295
+ /**
1296
+ *
1297
+ * Curried: true
1298
+ *
1299
+ * Failsafe status: alternative available
1300
+ *
1301
+ * Applies the modifier function on the item having the given id in an array and
1302
+ *
1303
+ * returns a new array with the return value of the modifier function in the index
1304
+ *
1305
+ * of the match.
1306
+ *
1307
+ * Usage:
1308
+ *
1309
+ * @example
1310
+ *
1311
+ * const array = [
1312
+ * { id: 1, name: "Sam" },
1313
+ * { id: 2, name: "Oliver" },
1314
+ * ];
1315
+ * const idOfItemToBeModified = 2;
1316
+ * const modifier = item => assoc("name", item.name.toUpperCase(), item);
1317
+ *
1318
+ * modifyById(idOfItemToBeModified, modifier, array);
1319
+ *
1320
+ * [{ id: 1, name: "Sam" }, { id: 2, name: "OLIVER" }]
1321
+ *
1322
+ * @endexample
1323
+ */
1324
+ export function modifyById<T>(id: any, modifier: (previous: T) => T): (entityArray: T[]) => T[];
1325
+ /**
1326
+ *
1327
+ * Curried: true
1328
+ *
1329
+ * Failsafe status: alternative available
1330
+ *
1331
+ * Applies the modifier function on the item having the given id in an array and
1332
+ *
1333
+ * returns a new array with the return value of the modifier function in the index
1334
+ *
1335
+ * of the match.
1336
+ *
1337
+ * Usage:
1338
+ *
1339
+ * @example
1340
+ *
1341
+ * const array = [
1342
+ * { id: 1, name: "Sam" },
1343
+ * { id: 2, name: "Oliver" },
1344
+ * ];
1345
+ * const idOfItemToBeModified = 2;
1346
+ * const modifier = item => assoc("name", item.name.toUpperCase(), item);
1347
+ *
1348
+ * modifyById(idOfItemToBeModified, modifier, array);
1349
+ *
1350
+ * [{ id: 1, name: "Sam" }, { id: 2, name: "OLIVER" }]
1351
+ *
1352
+ * @endexample
1353
+ */
1354
+ export function modifyById(id: any): <T>(modifier: (previous: T) => T, entityArray: T[]) => T[];
1355
+ /**
1356
+ *
1357
+ * Curried: true
1358
+ *
1359
+ * Failsafe status: alternative available
1360
+ *
1361
+ * Applies the modifier function on the item having the given id in an array and
1362
+ *
1363
+ * returns a new array with the return value of the modifier function in the index
1364
+ *
1365
+ * of the match.
1366
+ *
1367
+ * Usage:
1368
+ *
1369
+ * @example
1370
+ *
1371
+ * const array = [
1372
+ * { id: 1, name: "Sam" },
1373
+ * { id: 2, name: "Oliver" },
1374
+ * ];
1375
+ * const idOfItemToBeModified = 2;
1376
+ * const modifier = item => assoc("name", item.name.toUpperCase(), item);
1377
+ *
1378
+ * modifyById(idOfItemToBeModified, modifier, array);
1379
+ *
1380
+ * [{ id: 1, name: "Sam" }, { id: 2, name: "OLIVER" }]
1381
+ *
1382
+ * @endexample
1383
+ */
1384
+ export function modifyById(id: any): <T>(modifier: (previous: T) => T) => (entityArray: T[]) => T[];
1385
+ export function _modifyById<T>(id: any, modifier: (previous: T) => T, entityArray: NilOr<T[]>): NilOr<T[]>;
1386
+ export function _modifyById<T>(id: any, modifier: (previous: T) => T): (entityArray: NilOr<T[]>) => NilOr<T[]>;
1387
+ export function _modifyById(id: any): <T>(modifier: (previous: T) => T, entityArray: NilOr<T[]>) => NilOr<T[]>;
1388
+ export function _modifyById(id: any): <T>(modifier: (previous: T) => T) => (entityArray: NilOr<T[]>) => NilOr<T[]>;
1389
+ /**
1390
+ *
1391
+ * Curried: false
1392
+ *
1393
+ * Failsafe status: failsafe by default
1394
+ *
1395
+ * A "no-operation" function, which does nothing and returns nothing (undefined).
1396
+ *
1397
+ */
257
1398
  export function noop(...args: any[]): void;
258
-
259
1399
  export function notEquals(a: any, b: any): boolean;
260
1400
  export function notEquals(a: any): (b: any) => boolean;
261
-
262
1401
  export function notEqualsDeep(a: any, b: any): boolean;
263
1402
  export function notEqualsDeep(a: any): (b: any) => boolean;
264
-
1403
+ /**
1404
+ *
1405
+ * Curried: false
1406
+ *
1407
+ * Failsafe status: not failsafe
1408
+ *
1409
+ * This function accepts a variable number of arguments and returns a random
1410
+ *
1411
+ * element from the list of arguments.
1412
+ *
1413
+ * Usage:
1414
+ *
1415
+ * @example
1416
+ *
1417
+ * randomPick("arg1", "arg2", "arg3", "arg4", "arg5");
1418
+ *
1419
+ * // output: a random element from the list "arg1", "arg2", "arg3", "arg4" and "arg5"
1420
+ * @endexample
1421
+ */
265
1422
  export function randomPick<T>(...args: T[]): T;
266
-
1423
+ /**
1424
+ *
1425
+ * Curried: true
1426
+ *
1427
+ * Failsafe status: alternative available
1428
+ *
1429
+ * Remove all items that matches the given pattern from an array of items.
1430
+ *
1431
+ * Usage:
1432
+ *
1433
+ * @example
1434
+ *
1435
+ * const array = [
1436
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 101283 } },
1437
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 998472 } },
1438
+ * ];
1439
+ *
1440
+ * removeBy({ name: "Sam" }, array); // removes Sam
1441
+ * removeBy({ id: 2, address: { pin: 654321 } }, array); // removes Oliver
1442
+ * removeBy({ id: 3 }, array); // does nothing
1443
+ * @endexample
1444
+ */
267
1445
  export function removeBy<T>(pattern: MatchPattern<T>, entityArray: T[]): T[];
1446
+ /**
1447
+ *
1448
+ * Curried: true
1449
+ *
1450
+ * Failsafe status: alternative available
1451
+ *
1452
+ * Remove all items that matches the given pattern from an array of items.
1453
+ *
1454
+ * Usage:
1455
+ *
1456
+ * @example
1457
+ *
1458
+ * const array = [
1459
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 101283 } },
1460
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 998472 } },
1461
+ * ];
1462
+ *
1463
+ * removeBy({ name: "Sam" }, array); // removes Sam
1464
+ * removeBy({ id: 2, address: { pin: 654321 } }, array); // removes Oliver
1465
+ * removeBy({ id: 3 }, array); // does nothing
1466
+ * @endexample
1467
+ */
268
1468
  export function removeBy(pattern: MatchPattern): <T>(entityArray: T[]) => T[];
269
- export function _removeBy<T>(
270
- pattern: MatchPattern<T>,
271
- entityArray: NilOr<T[]>
272
- ): NilOr<T[]>;
273
- export function _removeBy(
274
- pattern: MatchPattern
275
- ): <T>(entityArray: NilOr<T[]>) => NilOr<T[]>;
276
-
1469
+ export function _removeBy<T>(pattern: MatchPattern<T>, entityArray: NilOr<T[]>): NilOr<T[]>;
1470
+ export function _removeBy(pattern: MatchPattern): <T>(entityArray: NilOr<T[]>) => NilOr<T[]>;
1471
+ /**
1472
+ *
1473
+ * Curried: true
1474
+ *
1475
+ * Failsafe status: alternative available
1476
+ *
1477
+ * Return a new array with the item with the given id removed.
1478
+ *
1479
+ * Usage:
1480
+ *
1481
+ * @example
1482
+ *
1483
+ * const array = [
1484
+ * { id: 1, name: "Sam" },
1485
+ * { id: 2, name: "Oliver" },
1486
+ * ];
1487
+ * const idOfItemToBeRemoved = 2;
1488
+ *
1489
+ * removeById(idOfItemToBeRemoved, array);
1490
+ * // [{ id: 1, name: "Sam" }]
1491
+ * @endexample
1492
+ */
277
1493
  export function removeById<T>(id: any, entityArray: T[]): T[];
1494
+ /**
1495
+ *
1496
+ * Curried: true
1497
+ *
1498
+ * Failsafe status: alternative available
1499
+ *
1500
+ * Return a new array with the item with the given id removed.
1501
+ *
1502
+ * Usage:
1503
+ *
1504
+ * @example
1505
+ *
1506
+ * const array = [
1507
+ * { id: 1, name: "Sam" },
1508
+ * { id: 2, name: "Oliver" },
1509
+ * ];
1510
+ * const idOfItemToBeRemoved = 2;
1511
+ *
1512
+ * removeById(idOfItemToBeRemoved, array);
1513
+ * // [{ id: 1, name: "Sam" }]
1514
+ * @endexample
1515
+ */
278
1516
  export function removeById(id: any): <T>(entityArray: T[]) => T[];
279
1517
  export function _removeById<T>(id: any, entityArray: NilOr<T[]>): NilOr<T[]>;
280
- export function _removeById(
281
- id: any
282
- ): <T>(entityArray: NilOr<T[]>) => NilOr<T[]>;
283
-
284
- export function renameKeys<T, M extends { [key in keyof Partial<T>]: string }>(
285
- keyMap: M,
286
- entityArray: T[]
287
- ): (Omit<T, keyof M> & { [key: string]: any })[];
288
- export function renameKeys<M extends { [key: string]: string }>(
289
- keyMap: M
290
- ): <T>(entityArray: T[]) => (Omit<T, keyof M> & { [key: string]: any })[];
291
- export function _renameKeys<T, M extends { [key in keyof Partial<T>]: string }>(
292
- keyMap: M,
293
- entityArray: NilOr<T[]>
294
- ): NilOr<(Omit<T, keyof M> & { [key: string]: any })[]>;
295
- export function _renameKeys<M extends { [key: string]: string }>(
296
- keyMap: M
297
- ): <T>(
298
- entityArray: NilOr<T[]>
299
- ) => NilOr<(Omit<T, keyof M> & { [key: string]: any })[]>;
300
-
1518
+ export function _removeById(id: any): <T>(entityArray: NilOr<T[]>) => NilOr<T[]>;
1519
+ /**
1520
+ *
1521
+ * Curried: true
1522
+ *
1523
+ * Failsafe status: alternative available
1524
+ *
1525
+ * Renames the specified keys keeping its value the same for all elements of an
1526
+ *
1527
+ * array. This creates a new instance and doesn't mutate the array.
1528
+ *
1529
+ * A function that accepts an input array and returns a new array with elements
1530
+ *
1531
+ * such that: each element will contain the newly specified keys with its value
1532
+ *
1533
+ * pointing to the value of specified source keys. The source keys will not be
1534
+ *
1535
+ * copied.
1536
+ *
1537
+ * Usage:
1538
+ *
1539
+ * @example
1540
+ *
1541
+ * renameKeys({
1542
+ * sourceKey1: "destinationKey1",
1543
+ * sourceKey2: "destinationKey2",
1544
+ * ...
1545
+ * }, arrayOfObjects);
1546
+ * @endexample
1547
+ * Example:
1548
+ *
1549
+ * @example
1550
+ *
1551
+ * const data = [
1552
+ * { id: 1, name: "Tomato", quantity: 10 },
1553
+ * { id: 2, name: "Potato", quantity: 20 },
1554
+ * ];
1555
+ *
1556
+ * // rename name to label and id to value
1557
+ * renameKeys({ name: "label", id: "value" }, data);
1558
+ *
1559
+ *
1560
+ * output: [
1561
+ * { label: "Tomato", value: 1, quantity: 10 },
1562
+ * { label: "Potato", value: 2, quantity: 20 },
1563
+ * ];
1564
+ *
1565
+ * @endexample
1566
+ */
1567
+ export function renameKeys<T, M extends { [key in keyof Partial<T>]: string }>(keyMap: M, entityArray: T[]): (Omit<T, keyof M> & {
1568
+ [key: string]: any;
1569
+ })[];
1570
+ /**
1571
+ *
1572
+ * Curried: true
1573
+ *
1574
+ * Failsafe status: alternative available
1575
+ *
1576
+ * Renames the specified keys keeping its value the same for all elements of an
1577
+ *
1578
+ * array. This creates a new instance and doesn't mutate the array.
1579
+ *
1580
+ * A function that accepts an input array and returns a new array with elements
1581
+ *
1582
+ * such that: each element will contain the newly specified keys with its value
1583
+ *
1584
+ * pointing to the value of specified source keys. The source keys will not be
1585
+ *
1586
+ * copied.
1587
+ *
1588
+ * Usage:
1589
+ *
1590
+ * @example
1591
+ *
1592
+ * renameKeys({
1593
+ * sourceKey1: "destinationKey1",
1594
+ * sourceKey2: "destinationKey2",
1595
+ * ...
1596
+ * }, arrayOfObjects);
1597
+ * @endexample
1598
+ * Example:
1599
+ *
1600
+ * @example
1601
+ *
1602
+ * const data = [
1603
+ * { id: 1, name: "Tomato", quantity: 10 },
1604
+ * { id: 2, name: "Potato", quantity: 20 },
1605
+ * ];
1606
+ *
1607
+ * // rename name to label and id to value
1608
+ * renameKeys({ name: "label", id: "value" }, data);
1609
+ *
1610
+ *
1611
+ * output: [
1612
+ * { label: "Tomato", value: 1, quantity: 10 },
1613
+ * { label: "Potato", value: 2, quantity: 20 },
1614
+ * ];
1615
+ *
1616
+ * @endexample
1617
+ */
1618
+ export function renameKeys<M extends {
1619
+ [key: string]: string;
1620
+ }>(keyMap: M): <T>(entityArray: T[]) => (Omit<T, keyof M> & {
1621
+ [key: string]: any;
1622
+ })[];
1623
+ export function _renameKeys<T, M extends { [key in keyof Partial<T>]: string }>(keyMap: M, entityArray: NilOr<T[]>): NilOr<(Omit<T, keyof M> & {
1624
+ [key: string]: any;
1625
+ })[]>;
1626
+ export function _renameKeys<M extends {
1627
+ [key: string]: string;
1628
+ }>(keyMap: M): <T>(entityArray: NilOr<T[]>) => NilOr<(Omit<T, keyof M> & {
1629
+ [key: string]: any;
1630
+ })[]>;
1631
+ /**
1632
+ *
1633
+ * Curried: true
1634
+ *
1635
+ * Failsafe status: alternative available
1636
+ *
1637
+ * Replace all items that matches the given pattern with the given item.
1638
+ *
1639
+ * Usage:
1640
+ *
1641
+ * @example
1642
+ *
1643
+ * const array = [
1644
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 101283 } },
1645
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 998472 } },
1646
+ * ];
1647
+ * const newItem = { id: 2, name: "John" };
1648
+ *
1649
+ * replaceBy({ name: "Oliver" }, newItem, array);
1650
+ *
1651
+ * [{id: 1, name: "Sam"}, {id: 2, name: "John"}]
1652
+ *
1653
+ * @endexample
1654
+ */
301
1655
  export function replaceBy<T>(pattern: MatchPattern<T>, entityArray: T[]): T[];
1656
+ /**
1657
+ *
1658
+ * Curried: true
1659
+ *
1660
+ * Failsafe status: alternative available
1661
+ *
1662
+ * Replace all items that matches the given pattern with the given item.
1663
+ *
1664
+ * Usage:
1665
+ *
1666
+ * @example
1667
+ *
1668
+ * const array = [
1669
+ * { id: 1, name: "Sam", address: { street: "First street", pin: 101283 } },
1670
+ * { id: 2, name: "Oliver", address: { street: "Second street", pin: 998472 } },
1671
+ * ];
1672
+ * const newItem = { id: 2, name: "John" };
1673
+ *
1674
+ * replaceBy({ name: "Oliver" }, newItem, array);
1675
+ *
1676
+ * [{id: 1, name: "Sam"}, {id: 2, name: "John"}]
1677
+ *
1678
+ * @endexample
1679
+ */
302
1680
  export function replaceBy(pattern: MatchPattern): <T>(entityArray: T[]) => T[];
303
- export function _replaceBy<T>(
304
- pattern: MatchPattern<T>,
305
- entityArray: NilOr<T[]>
306
- ): NilOr<T[]>;
307
- export function _replaceBy(
308
- pattern: MatchPattern
309
- ): <T>(entityArray: NilOr<T[]>) => NilOr<T[]>;
310
-
1681
+ export function _replaceBy<T>(pattern: MatchPattern<T>, entityArray: NilOr<T[]>): NilOr<T[]>;
1682
+ export function _replaceBy(pattern: MatchPattern): <T>(entityArray: NilOr<T[]>) => NilOr<T[]>;
1683
+ /**
1684
+ *
1685
+ * Curried: true
1686
+ *
1687
+ * Failsafe status: alternative available
1688
+ *
1689
+ * Returns a new array with the item having the given id is replaced with the given
1690
+ *
1691
+ * object.
1692
+ *
1693
+ * Usage:
1694
+ *
1695
+ * @example
1696
+ *
1697
+ * const array = [
1698
+ * { id: 1, name: "Sam" },
1699
+ * { id: 2, name: "Oliver" },
1700
+ * ];
1701
+ * const idOfItemToBeReplaced = 2;
1702
+ * const newItem = { id: 3, name: "John" };
1703
+ *
1704
+ * replaceById(idOfItemToBeReplaced, newItem, array);
1705
+ *
1706
+ * [{ id: 1, name: "Sam" }, { id: 3, name: "John" }]
1707
+ *
1708
+ * @endexample
1709
+ */
311
1710
  export function replaceById<T>(id: any, entityArray: T[]): T[];
1711
+ /**
1712
+ *
1713
+ * Curried: true
1714
+ *
1715
+ * Failsafe status: alternative available
1716
+ *
1717
+ * Returns a new array with the item having the given id is replaced with the given
1718
+ *
1719
+ * object.
1720
+ *
1721
+ * Usage:
1722
+ *
1723
+ * @example
1724
+ *
1725
+ * const array = [
1726
+ * { id: 1, name: "Sam" },
1727
+ * { id: 2, name: "Oliver" },
1728
+ * ];
1729
+ * const idOfItemToBeReplaced = 2;
1730
+ * const newItem = { id: 3, name: "John" };
1731
+ *
1732
+ * replaceById(idOfItemToBeReplaced, newItem, array);
1733
+ *
1734
+ * [{ id: 1, name: "Sam" }, { id: 3, name: "John" }]
1735
+ *
1736
+ * @endexample
1737
+ */
312
1738
  export function replaceById(id: any): <T>(entityArray: T[]) => T[];
313
1739
  export function _replaceById<T>(id: any, entityArray: NilOr<T[]>): NilOr<T[]>;
314
- export function _replaceById(
315
- id: any
316
- ): <T>(entityArray: NilOr<T[]>) => NilOr<T[]>;
317
-
1740
+ export function _replaceById(id: any): <T>(entityArray: NilOr<T[]>) => NilOr<T[]>;
1741
+ /**
1742
+ *
1743
+ * Curried: false
1744
+ *
1745
+ * Failsafe status: failsafe by default
1746
+ *
1747
+ * Recursively converts the camel cased object keys to snake case. It will
1748
+ *
1749
+ * gracefully handle special objects like Date, dayjs instance etc.
1750
+ *
1751
+ * While converting, this function checks if the function named toJSON is present
1752
+ *
1753
+ * in the value (if the value is an object) and if found, it calls the function and
1754
+ *
1755
+ * uses the return value for further processing.
1756
+ *
1757
+ * Example 1:
1758
+ *
1759
+ * @example
1760
+ *
1761
+ * serializeKeysToSnakeCase({
1762
+ * name: { toJSON: () => ({ firstName: "Oliver", lastName: "Smith" }) },
1763
+ * phoneNumber: "389791382",
1764
+ * });
1765
+ *
1766
+ *
1767
+ * {
1768
+ * name: { first_name: "Oliver", last_name: "Smith" },
1769
+ * phone_number: "389791382",
1770
+ * }
1771
+ *
1772
+ * @endexample
1773
+ * Example 2: (Real world example)
1774
+ *
1775
+ * @example
1776
+ *
1777
+ * serializeKeysToSnakeCase({
1778
+ * address: { city: "Miami", phoneNumber: "389791382" },
1779
+ * firstName: "Oliver",
1780
+ * lastName: "Smith",
1781
+ * dob: new Date("1980-01-01"),
1782
+ * });
1783
+ *
1784
+ *
1785
+ * {
1786
+ * first_name: "Oliver",
1787
+ * last_name: "Smith",
1788
+ * address: { city: "Miami", phone_number: "389791382" },
1789
+ * dob: "1980-01-01T00:00:00.000Z",
1790
+ * }
1791
+ *
1792
+ * @endexample
1793
+ * In the above example, the value of dob is an date object and has toJSON
1794
+ *
1795
+ * method present in it. The toJSON method returns the date in ISO format which
1796
+ *
1797
+ * will be used for further processing instead of recursively converting the
1798
+ *
1799
+ * original date object.
1800
+ *
1801
+ */
318
1802
  export function serializeKeysToSnakeCase(object: object): object;
1803
+ /**
1804
+ *
1805
+ * Curried: false
1806
+ *
1807
+ * Failsafe status: failsafe by default
1808
+ *
1809
+ * Creates a ready-to-be-serialized version of the given object by recursively
1810
+ *
1811
+ * going to all the object properties and replacing it with its JSON serializable
1812
+ *
1813
+ * version.
1814
+ *
1815
+ * This is helpful when serializing Date objects, dayjs objects etc.
1816
+ *
1817
+ * Usage:
1818
+ *
1819
+ * @example
1820
+ *
1821
+ * preprocessForSerialization(dayjs("1980-01-01")); // returns "1980-01-01T00:00:00.000Z"
1822
+ * preprocessForSerialization({
1823
+ * toJSON: () => ({ firstName: "Oliver", lastName: "Smith" }),
1824
+ * }); // returns { firstName: "Oliver", lastName: "Smith" }
1825
+ * @endexample
1826
+ */
319
1827
  export function preprocessForSerialization(object: object): object;
320
-
1828
+ /**
1829
+ *
1830
+ * Curried: false
1831
+ *
1832
+ * Failsafe status: alternative available
1833
+ *
1834
+ * Converts a given string to slug.
1835
+ *
1836
+ * @example
1837
+ *
1838
+ * slugify("My quiz"); // "my-quiz"
1839
+ * slugify("my-quiz"); // "my-quiz"
1840
+ * slugify("-----my----quiz"); // "my-quiz"
1841
+ * slugify("Me & my quiz"); // "me-and-my-quiz"
1842
+ * slugify("my!@#$%^*(quiz"); // "myquiz"
1843
+ * @endexample
1844
+ */
321
1845
  export function slugify(string: string): string;
322
1846
  export function _slugify(string: NilOr<string>): NilOr<string>;
323
-
1847
+ /**
1848
+ *
1849
+ * Curried: false
1850
+ *
1851
+ * Failsafe status: alternative available
1852
+ *
1853
+ * Converts snake_case to camelCase.
1854
+ *
1855
+ * @example
1856
+ *
1857
+ * snakeToCamelCase("first_name"); // "firstName"
1858
+ * @endexample
1859
+ */
324
1860
  export function snakeToCamelCase(string: string): string;
325
1861
  export function _snakeToCamelCase(string: NilOr<string>): NilOr<string>;
326
-
1862
+ /**
1863
+ *
1864
+ * Curried: false
1865
+ *
1866
+ * Failsafe status: failsafe by default
1867
+ *
1868
+ * This function takes a string as an argument and returns an object with keys
1869
+ *
1870
+ * "label" and "value".
1871
+ *
1872
+ * Usage:
1873
+ *
1874
+ * @example
1875
+ *
1876
+ * toLabelAndValue("test");
1877
+ *
1878
+ * // output: {label: "test", value: "test"}
1879
+ * @endexample
1880
+ */
327
1881
  export function toLabelAndValue(string: string): {
328
1882
  label: string;
329
1883
  value: string;
330
1884
  };
331
- export function transformObjectDeep(
332
- object: object,
333
- keyValueTransformer: (key: string | number | symbol, object: any) => any[],
334
- objectPreProcessor?: (object: any) => any
335
- ): object;
336
-
1885
+ /**
1886
+ *
1887
+ * Curried: false
1888
+ *
1889
+ * Failsafe status: failsafe by default
1890
+ *
1891
+ * Passes each key and value of a the given object (recursively) to the given
1892
+ *
1893
+ * transformer function. Reconstructs an object of the same hierarchy with the key
1894
+ *
1895
+ * value pair the transformer function returns.
1896
+ *
1897
+ * You can optionally pass an object transformer which will be executed on every
1898
+ *
1899
+ * value (including the supplied object itself) before any processing is done to
1900
+ *
1901
+ * it.
1902
+ *
1903
+ * Usage:
1904
+ *
1905
+ * @example
1906
+ *
1907
+ * transformObjectDeep(
1908
+ * {
1909
+ * name: "Oliver",
1910
+ * email: "oliver@example.com",
1911
+ * address: { street: "First street", pin: 123456 },
1912
+ * },
1913
+ * (key, value) => [key.toUpperCase(), value]
1914
+ * );
1915
+ *
1916
+ * output: {
1917
+ * NAME: "Oliver",
1918
+ * EMAIL: "oliver@example.com",
1919
+ * ADDRESS: { STREET: "First street", PIN: 123456 },
1920
+ * }
1921
+ *
1922
+ *
1923
+ * transformObjectDeep(
1924
+ * [
1925
+ * [1, 2, 3],
1926
+ * [4, 5, 6],
1927
+ * [7, 8, 9],
1928
+ * ],
1929
+ * (key, value) => [key, value],
1930
+ * item => (Array.isArray(item) ? item.slice(1) : item)
1931
+ * );
1932
+ *
1933
+ * output: [[5, 6], [8, 9]]
1934
+ *
1935
+ * @endexample
1936
+ */
1937
+ export function transformObjectDeep(object: object, keyValueTransformer: (key: string | number | symbol, object: any) => any[], objectPreProcessor?: (object: any) => any): object;
1938
+ /**
1939
+ *
1940
+ * Curried: false
1941
+ *
1942
+ * Failsafe status: alternative available
1943
+ *
1944
+ * Truncate the string with ... if it is longer than specified string length.
1945
+ *
1946
+ * @example
1947
+ *
1948
+ * truncate("Hello World", 5); // "Hello..."
1949
+ * truncate("Hello World", 15); // "Hello World"
1950
+ * @endexample
1951
+ */
337
1952
  export function truncate(string: string, length: number): string;
1953
+ /**
1954
+ *
1955
+ * Curried: false
1956
+ *
1957
+ * Failsafe status: alternative available
1958
+ *
1959
+ * Truncate the string with ... if it is longer than specified string length.
1960
+ *
1961
+ * @example
1962
+ *
1963
+ * truncate("Hello World", 5); // "Hello..."
1964
+ * truncate("Hello World", 15); // "Hello World"
1965
+ * @endexample
1966
+ */
338
1967
  export function truncate(string: NilOr<string>, length: number): NilOr<string>;
339
-
340
- export function nullSafe<T extends Function>(
341
- func: T
342
- ): (...args: any) => ReturnType<T>;
343
-
1968
+ export function nullSafe<T extends Function>(func: T): (...args: any) => ReturnType<T>;
344
1969
  export function isNotPresent(object: any): boolean;
345
- export function isPresent(object: any): boolean;
1970
+ export function isPresent(object: any): boolean;