@valkyriestudios/utils 12.10.0 → 12.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +82 -68
  2. package/array/dedupe.js +6 -6
  3. package/array/groupBy.js +2 -3
  4. package/array/is.js +2 -3
  5. package/array/isNotEmpty.js +2 -3
  6. package/array/join.d.ts +6 -0
  7. package/array/join.js +13 -9
  8. package/array/mapFn.js +5 -5
  9. package/array/mapKey.js +5 -6
  10. package/array/mapPrimitive.js +4 -4
  11. package/array/shuffle.js +2 -3
  12. package/array/sort.d.ts +4 -5
  13. package/array/sort.js +17 -22
  14. package/boolean/is.js +2 -3
  15. package/caching/memoize.js +2 -3
  16. package/date/addUTC.js +2 -3
  17. package/date/diff.js +2 -3
  18. package/date/endOfUTC.js +2 -3
  19. package/date/format.js +18 -15
  20. package/date/index.d.ts +2 -1
  21. package/date/index.js +3 -1
  22. package/date/is.js +2 -3
  23. package/date/nowUnix.js +2 -3
  24. package/date/nowUnixMs.js +2 -3
  25. package/date/setTimeUTC.d.ts +15 -0
  26. package/date/setTimeUTC.js +11 -0
  27. package/date/startOfUTC.js +2 -3
  28. package/date/toUTC.js +2 -3
  29. package/date/toUnix.js +2 -3
  30. package/deep/freeze.js +3 -4
  31. package/deep/get.js +3 -4
  32. package/deep/seal.js +3 -4
  33. package/deep/set.js +2 -3
  34. package/equal.js +2 -3
  35. package/formdata/is.js +2 -3
  36. package/function/is.js +2 -3
  37. package/function/isAsync.js +2 -3
  38. package/function/noop.js +2 -3
  39. package/function/noopresolve.js +2 -3
  40. package/function/noopreturn.js +2 -3
  41. package/function/sleep.js +2 -3
  42. package/hash/fnv1A.js +2 -3
  43. package/hash/guid.js +2 -3
  44. package/index.d.ts +20 -9
  45. package/number/is.js +2 -3
  46. package/number/isAbove.js +2 -3
  47. package/number/isAboveOrEqual.js +2 -3
  48. package/number/isBelow.js +2 -3
  49. package/number/isBelowOrEqual.js +2 -3
  50. package/number/isBetween.js +2 -3
  51. package/number/isInteger.js +2 -3
  52. package/number/isIntegerAbove.js +2 -3
  53. package/number/isIntegerAboveOrEqual.js +2 -3
  54. package/number/isIntegerBelow.js +2 -3
  55. package/number/isIntegerBelowOrEqual.js +2 -3
  56. package/number/isIntegerBetween.js +2 -3
  57. package/number/isNumericalNaN.js +2 -3
  58. package/number/randomBetween.js +2 -3
  59. package/number/randomIntBetween.js +2 -3
  60. package/number/round.js +2 -3
  61. package/number/toPercentage.js +2 -3
  62. package/object/define.js +2 -3
  63. package/object/is.js +2 -3
  64. package/object/isNotEmpty.js +2 -3
  65. package/object/merge.js +3 -6
  66. package/object/pick.js +4 -4
  67. package/package.json +1 -1
  68. package/regexp/is.js +2 -3
  69. package/regexp/sanitize.js +2 -3
  70. package/string/humanizeBytes.js +2 -3
  71. package/string/humanizeNumber.js +2 -3
  72. package/string/is.js +2 -3
  73. package/string/isBetween.js +2 -3
  74. package/string/isNotEmpty.js +2 -3
  75. package/string/shorten.js +2 -3
package/README.md CHANGED
@@ -17,14 +17,14 @@ Zero-dependency collection of single-function utilities for common tasks
17
17
  ### array
18
18
  - **isArray(val:any)**
19
19
  Check if a variable is of type Array
20
- ```js
20
+ ```typescript
21
21
  isArray({a:1}); // FALSE
22
22
  isArray([]); // TRUE
23
23
  ```
24
24
 
25
25
  - **isNotEmptyArray(val:any)**
26
26
  Check if a variable a non-empty array
27
- ```js
27
+ ```typescript
28
28
  isNotEmptyArray({a:1}); // FALSE
29
29
  isNotEmptyArray([]); // FALSE
30
30
  isNotEmptyArray([0, 1, 2]); // TRUE
@@ -32,7 +32,7 @@ isNotEmptyArray([0, 1, 2]); // TRUE
32
32
 
33
33
  - **mapKey(val:Record[], key:string, opts:object={})**
34
34
  Map a non-primitive object array into an object map by key
35
- ```js
35
+ ```typescript
36
36
  mapKey([
37
37
  {uid: 12, name: 'Peter'},
38
38
  {uid: 15, name: 'Jonas'},
@@ -49,7 +49,7 @@ output:
49
49
  ```
50
50
 
51
51
  Autofilters anything not meeting the spec:
52
- ```js
52
+ ```typescript
53
53
  mapKey([
54
54
  0,
55
55
  {uid: 12, name: 'Peter'},
@@ -73,7 +73,7 @@ output:
73
73
  ```
74
74
 
75
75
  allows merging objects onto existing keys:
76
- ```js
76
+ ```typescript
77
77
  mapKey([
78
78
  0,
79
79
  {uid: 12, name: 'Peter'},
@@ -102,7 +102,7 @@ output:
102
102
  - **mapFn(val:Record[], key:Function, opts:object={})**
103
103
  Same behavior as mapKey but instead of a key, a function is passed to generate your own key. Eg:
104
104
 
105
- ```js
105
+ ```typescript
106
106
  mapFn([
107
107
  {uid: 12, name: 'Peter'},
108
108
  {uid: 15, name: 'Jonas'},
@@ -122,7 +122,7 @@ options are the same as the mapKey function
122
122
 
123
123
  - **mapPrimitive(val:any[], opts:object={valtrim:false,keyround:false,valround:false})**
124
124
  Map an array of primitives (number/string)
125
- ```js
125
+ ```typescript
126
126
  mapPrimitive([1,2,3]); // {1: 1, 2: 2, 3: 3}
127
127
  mapPrimitive(['hello', 'hello', 'foo', 'bar']); // {hello: 'hello', foo: 'foo', bar: 'bar'}
128
128
  mapPrimitive(['hello', ' hello', 'foo', ' foo'], {valtrim: true}); // {hello: 'hello', foo: 'foo'}
@@ -186,7 +186,7 @@ const group = groupBy([
186
186
 
187
187
  - **dedupe(val:Array)**
188
188
  Remove all duplicates from an array, behind the scenes it uses the fnv 1A hash algorithm to performantly do comparisons.
189
- ```js
189
+ ```typescript
190
190
  dedupe(['a','a','b','c','c']); // ['a', 'b', 'c']
191
191
  dedupe(['1',1,'2',2]); // ['1','2']
192
192
  dedupe([new RegExp(/ab+c/, 'i'), new RegExp(/ab+c/, 'i')]); // [new RegExp(/ab+c/, 'i')]
@@ -194,21 +194,22 @@ dedupe([new Date('2012-02-02'), new Date('2012-02-02')]); // [new Date('2012-02-
194
194
  dedupe(['hello', 'hello', 'world']); // ['hello', 'world']
195
195
  ```
196
196
 
197
- - **join(val:Array, opts:object={delim:' ',trim:true,valtrim:true,valround:false})**
197
+ - **join(val:Array, opts:object={delim:' ',trim:true,valtrim:true,innertrim:true,valround:false})**
198
198
  Concatenate the values within an array into a string, behind the scenes this will automatically filter out any value that is not a string or numerical value. For strings it will automatically trim (and remove if empty after trimming) before joining.
199
199
 
200
- ```js
200
+ ```typescript
201
201
  join(['Valkyrie', 'Studios']); // 'Valkyrie Studios'
202
202
  join([5.1, ' years ', 'ago'], {valround: 0}); // '5 years ago'
203
203
  join(['peter ', ' valkyrie '], {delim: '@'}); // 'peter@valkyrie'
204
204
  join([user.first_name, user.last_name]); // 'John' (where user is {first_name: 'John', last_name: false})
205
205
  join([' a', 1], {delim: '', valtrim: false, trim: false}); // ' a1'
206
+ join([' hello world ', 'this is peter '], {valtrim:true, innertrim: true, delim: ' '}); // 'hello world this is peter'
206
207
  ```
207
208
 
208
209
  - **shuffle(val:Array)**
209
210
  Shuffle an array (Fisher-Yates) in O(n), take note this changes the passed value
210
211
 
211
- ```js
212
+ ```typescript
212
213
  const arr = [1, 2, 3, 4, 5, 6];
213
214
  shuffle(arr);
214
215
  // [4, 6, 3, 2, 5, 1]
@@ -217,7 +218,7 @@ shuffle(arr);
217
218
  - **sort(val:Array[object], by:string|Function, dir:Enum(asc,desc), options:Object)**
218
219
  Sort an array of objects, uses an implementation of [Tony Hoare's quicksort](https://cs.stanford.edu/people/eroberts/courses/soco/projects/2008-09/tony-hoare/quicksort.html)
219
220
 
220
- ```js
221
+ ```typescript
221
222
  const out = sort([
222
223
  {test: 'Peter'},
223
224
  {test: 'Jack'},
@@ -230,7 +231,7 @@ const out = sort([
230
231
  // [{test: 'Pony'}, {test: 'Peter'}, {test: 'John'}, {test: 'Joe'}, {test: 'Jack'}, {test: 'Bob'}, {test: 'Alice'}]
231
232
  ```
232
233
 
233
- ```js
234
+ ```typescript
234
235
  const out = sort([
235
236
  {test: 'Peter'},
236
237
  {test: 'Jack'},
@@ -245,7 +246,7 @@ const out = sort([
245
246
 
246
247
  allows passing a function to determine the key to sort by
247
248
 
248
- ```js
249
+ ```typescript
249
250
  const out = sort([
250
251
  {test: 'Peter'},
251
252
  {test: 'Jack'},
@@ -260,7 +261,7 @@ const out = sort([
260
261
 
261
262
  auto-cleans input to only contains non-empty objects
262
263
 
263
- ```js
264
+ ```typescript
264
265
  const out = sort([
265
266
  {test: 'Peter'},
266
267
  {},
@@ -279,7 +280,7 @@ const out = sort([
279
280
  allows passing custom filter function to clean input
280
281
  Take note: Sort will still verify that the object is not an empty object, even when passing a custom filter function.
281
282
 
282
- ```js
283
+ ```typescript
283
284
  const out = sort([
284
285
  {test: 'Peter'},
285
286
  {},
@@ -299,7 +300,7 @@ const out = sort([
299
300
 
300
301
  allows passing custom options to position elements without a proper key (nokey_atend, defaults to true), or hide them (nokey_hide, defaults to false)
301
302
 
302
- ```js
303
+ ```typescript
303
304
  const arr = [{test: 'Peter'}, {test: undefined}, {test: 'Jack'}, {test: 'Pony'}, {uid: 100}, {test: 'JOHn'}];
304
305
  const out = sort(arr, el => el.test.toLowerCase(), 'desc', {nokey_atend: false});
305
306
  // [{test: undefined}, {uid: 100}, {test: 'Pony'}, {test: 'Peter'}, {test: 'JOHn'}, {test: 'Jack'}]
@@ -314,7 +315,7 @@ const out = sort(arr, el => el.test.toLowerCase(), 'desc', {nokey_hide: true});
314
315
  ### boolean
315
316
  - **isBoolean(val:any)**
316
317
  Check if a variable is of type Boolean
317
- ```js
318
+ ```typescript
318
319
  isBoolean(null); // FALSE
319
320
  isBoolean(false); // TRUE
320
321
  isBoolean(true); // TRUE
@@ -324,14 +325,14 @@ isBoolean(true); // TRUE
324
325
  - **memoize(fn:Function, resolver:Function=false, memoize_for:number|false)**
325
326
  memoize the output of a function. An optional resolver function can be passed which allows custom cache key generation.
326
327
 
327
- ```js
328
+ ```typescript
328
329
  const memoized_function = memoize((a) => {
329
330
  return fnv1A(a);
330
331
  });
331
332
  ```
332
333
 
333
334
  Take Note: Also supports async functions and cache busting, eg:
334
- ```js
335
+ ```typescript
335
336
  async function retrieveUser (userId:string) {
336
337
  ...
337
338
  }
@@ -354,7 +355,7 @@ await memoized('123456'); /* Original function will be called and re-cached */
354
355
  ### date
355
356
  - **isDate(val:any)**
356
357
  Check if a variable is of type Date
357
- ```js
358
+ ```typescript
358
359
  isDate(new Date('December 17, 1995 03:24:00')); // TRUE
359
360
  isDate('December 17, 1995 03:24:00'); // FALSE
360
361
  ```
@@ -363,7 +364,7 @@ isDate('December 17, 1995 03:24:00'); // FALSE
363
364
  Take two incoming dates and return the difference between them in a certain unit. Possible key options(week,day,hour,minute,second,millisecond).
364
365
 
365
366
  Note: Does not touch the passed date objects, if no key is passed will default to millisecond
366
- ```js
367
+ ```typescript
367
368
  diff(new Date("2022-10-05T13:12:11+02:00"), new Date("2022-11-05T13:12:11+06:00"), 'week'); // -4.404761904761905
368
369
  diff(new Date("2022-11-05T13:12:11+06:00"), new Date("2022-10-05T13:12:11+02:00"), 'day'); // 30.83333333333333332
369
370
  diff(new Date("2022-11-05T13:12:11+06:00"), new Date("2022-10-05T13:12:11+02:00"), 'hour'); // 740
@@ -404,7 +405,7 @@ Available tokens for usage in spec:
404
405
  | `A` | Uppercase AM/PM | AM ... PM |
405
406
  | `a` | Lowercase AM/PM | am ... pm |
406
407
 
407
- ```js
408
+ ```typescript
408
409
  format(new Date('2023-01-10T14:30:00Z'), '[Today is] dddd, MMMM D, YYYY [at] h:mm A', 'en', 'Europe/Brussels');
409
410
  // 'Today is Tuesday, January 10, 2023 at 2:30 PM'
410
411
 
@@ -430,11 +431,24 @@ Returns the current unix timestamp in seconds
430
431
  - **nowUnixMs()**
431
432
  Returns the current unix timestamp in milliseconds
432
433
 
434
+ - **setTimeUTC(val:Date, props:{hour?:number;minute?:number;second?:number;millisecond?:number})**
435
+ Take the incoming date and return a date where the time portion is set to the values in the provided props
436
+
437
+ Note: Does not touch the date object passed
438
+ ```typescript
439
+ setTimeUTC(new Date("2023-05-04T12:04:27.432Z"), {hour: 5}); // new Date("2023-05-04T05:04:27.432Z")
440
+ setTimeUTC(new Date("2023-05-04T12:04:27.432Z"), {hour: 5, minute: 30}); // new Date("2023-05-04T05:30:27.432Z")
441
+ setTimeUTC(new Date("2023-05-04T12:04:27.432Z"), {hour: 5, minute: 30, second: 0}); // new Date("2023-05-04T05:30:00.432Z")
442
+ setTimeUTC(new Date("2023-05-04T12:04:27.432Z"), {hour: 5, minute: 30, second: 0, millisecond: 0}); // new Date("2023-05-04T05:30:00.000Z")
443
+ setTimeUTC(new Date("2023-05-04T12:04:27.432Z"), {minute: 30, second: 0, millisecond: 0}); // new Date("2023-05-04T12:30:00.000Z")
444
+ setTimeUTC(new Date("2023-05-04T12:04:27.432Z"), {second: 9, millisecond: 0}); // new Date("2023-05-04T12:04:09.000Z")
445
+ ```
446
+
433
447
  - **startOfUTC(val:Date, key:string)**
434
448
  Take the incoming date and return a date set to the start of passed key. Possible key options(year,quarter,month,week,week_sun,week_mon,week_tue,week_wed,week_thu,week_fri,week_sat,day,hour,minute,second).
435
449
 
436
450
  Note: Does not touch the date object passed
437
- ```js
451
+ ```typescript
438
452
  startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'year'); // new Date("2023-01-01T00:00:00.000Z")
439
453
  startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'quarter'); // new Date("2023-04-01T00:00:00.000Z")
440
454
  startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'month'); // new Date("2023-05-01T00:00:00.000Z")
@@ -454,7 +468,7 @@ startOfUTC(new Date("2023-05-04T12:04:27.043+02:00"), 'second'); // new Date("20
454
468
  Take the incoming date and return a date set to the end of passed key. Possible key options(year,quarter,month,week,week_sun,week_mon,week_tue,week_wed,week_thu,week_fri,week_sat,day,hour,minute,second).
455
469
 
456
470
  Note: Does not touch the date object passed
457
- ```js
471
+ ```typescript
458
472
  endOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'year'); // new Date("2023-12-31T23:59:59.999Z")
459
473
  endOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'quarter'); // new Date("2023-06-30T23:59:59.999Z")
460
474
  endOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'month'); // new Date("2023-05-31T23:59:59.999Z")
@@ -478,7 +492,7 @@ endOfUTC(new Date("2023-05-04T12:04:27.043+02:00"), 'second'); // new Date("2023
478
492
  Take the incoming date and add a certain amount of the passed key. Possible key options(year,years,month,months,day,days,hour,hours,minute,minutes,second,seconds,millisecond,milliseconds).
479
493
 
480
494
  Note: Does not touch the date object passed
481
- ```js
495
+ ```typescript
482
496
  addUTC(new Date("2022-10-05T13:12:11+02:00"), 10, 'year'); // new Date("2032-10-05T11:12:11.000Z")
483
497
  addUTC(new Date("2022-10-05T13:12:11+02:00"), -10, 'year'); // new Date("2012-10-05T11:12:11.000Z")
484
498
  addUTC(new Date("2022-10-05T13:12:11+02:00"), 10, 'month'); // new Date("2023-08-05T11:12:11.000Z")
@@ -500,7 +514,7 @@ addUTC(new Date("2022-10-05T13:12:11+02:00"), -10, 'second'); // new Date("2022-
500
514
  ### deep
501
515
  - **deepFreeze(val:Object)**
502
516
  Recursively freezes all properties of an object
503
- ```js
517
+ ```typescript
504
518
  const myObj = deepFreeze({
505
519
  a: 2,
506
520
  b: {
@@ -517,7 +531,7 @@ Object.isFrozen(myObj.b.d); // TRUE
517
531
 
518
532
  - **deepSeal(val:Object)**
519
533
  Recursively freezes all properties of an object
520
- ```js
534
+ ```typescript
521
535
  const myObj = deepSeal({
522
536
  a: 2,
523
537
  b: {
@@ -535,7 +549,7 @@ Object.isFrozen(myObj.b.d); // FALSE
535
549
 
536
550
  - **deepSet(obj:Object, path:string, value:any=null, define:boolean=false)**
537
551
  Sets a property and its value deep in the structure of an object
538
- ```js
552
+ ```typescript
539
553
  const myObj = {
540
554
  a: 2,
541
555
  };
@@ -543,7 +557,7 @@ deepSet(myObj, 'b.c.d.e', 4);
543
557
  myObj.b.c.d.e; // 4
544
558
  ```
545
559
 
546
- ```js
560
+ ```typescript
547
561
  const myObj = {
548
562
  a: 2,
549
563
  b: [
@@ -557,7 +571,7 @@ myObj.b[0].price; // 100
557
571
  myObj.b[1].price; // 500
558
572
  ```
559
573
 
560
- ```js
574
+ ```typescript
561
575
  const myObj = {
562
576
  a: 2,
563
577
  };
@@ -567,7 +581,7 @@ myObj.b.c; // Function
567
581
 
568
582
  - **deepGet(obj:Object, path:string, get_parent:boolean=false)**
569
583
  Retrieves a value based on a path in a deeply nested object
570
- ```js
584
+ ```typescript
571
585
  const myObj = {
572
586
  a: 2,
573
587
  b: [
@@ -578,7 +592,7 @@ const myObj = {
578
592
  deepGet(myObj, 'b[0].price', true); // [{price: 2}, {price: 4}]
579
593
  ```
580
594
 
581
- ```js
595
+ ```typescript
582
596
  const myObj = {
583
597
  a: 2,
584
598
  b: [
@@ -592,7 +606,7 @@ deepGet(myObj, 'b[0].price'); // 2
592
606
  ### equal
593
607
  - **equal(a:any, b:any)**
594
608
  Check if a variable is equal to another one
595
- ```js
609
+ ```typescript
596
610
  equal(5, 6); // FALSE
597
611
  equal(1, 1); // TRUE
598
612
  equal([0, 1, 2], [1, 2]); // FALSE
@@ -625,7 +639,7 @@ An empty function that returns a promise that will resolve after X milliseconds,
625
639
  ### formdata
626
640
  - **isFormData(val:any)**
627
641
  Check if a variable is of type FormData
628
- ```js
642
+ ```typescript
629
643
  isFormData(new FormData()); // TRUE
630
644
  isFormData({hi: 'there'}); // FALSE
631
645
  ```
@@ -633,13 +647,13 @@ isFormData({hi: 'there'}); // FALSE
633
647
  ### hash
634
648
  - **guid()**
635
649
  Generate a unique identifier (guid) according to RFC4122
636
- ```js
650
+ ```typescript
637
651
  guid(); // 245caf1a-86af-11e7-bb31-be2e44b06b34
638
652
  ```
639
653
 
640
654
  - **fnv1A(val:any)**
641
655
  Generate a fnv1A hash from an object, using a 32-bit prime/offset
642
- ```js
656
+ ```typescript
643
657
  fnv1A('hello world'); // -2023343616
644
658
  fnv1A({a:1,b:2}); // 361168128
645
659
  fnv1A(4); // 1630425728
@@ -650,7 +664,7 @@ fnv1A(new Date('2012-02-02')); // 1655579136
650
664
  ### number
651
665
  - **isNumber(val:any)**
652
666
  Check if a variable is a number
653
- ```js
667
+ ```typescript
654
668
  isNumber('foo'); // FALSE
655
669
  isNumber(4); // TRUE
656
670
  isNumber(0.5); // TRUE
@@ -658,7 +672,7 @@ isNumber(0.5); // TRUE
658
672
 
659
673
  - **isNumberAbove(val:number, comp:number)**
660
674
  Check if a variable is a number above a certain bound
661
- ```js
675
+ ```typescript
662
676
  isNumberAbove(5, 0); // TRUE
663
677
  isNumberAbove(.1, 0); // TRUE
664
678
  isNumberAbove(-1, -1); // FALSE
@@ -667,7 +681,7 @@ isNumberAbove(-10, -9); // FALSE
667
681
 
668
682
  - **isNumberAboveOrEqual(val:number, comp:number)**
669
683
  Check if a variable is a number above or equal to a certain bound
670
- ```js
684
+ ```typescript
671
685
  isNumberAboveOrEqual(5, 0); // TRUE
672
686
  isNumberAboveOrEqual(.1, 0); // TRUE
673
687
  isNumberAboveOrEqual(-1, -1); // TRUE
@@ -676,7 +690,7 @@ isNumberAboveOrEqual(-10, -9); // FALSE
676
690
 
677
691
  - **isNumberBelow(val:number, comp:number)**
678
692
  Check if a variable is a number below a certain bound
679
- ```js
693
+ ```typescript
680
694
  isNumberBelow(0, 5); // TRUE
681
695
  isNumberBelow(0, .1); // TRUE
682
696
  isNumberBelow(-1, -1); // FALSE
@@ -685,7 +699,7 @@ isNumberBelow(-9, -10); // FALSE
685
699
 
686
700
  - **isNumberBelowOrEqual(val:number, comp:number)**
687
701
  Check if a variable is a number below or equal a certain bound
688
- ```js
702
+ ```typescript
689
703
  isNumberBelowOrEqual(0, 5); // TRUE
690
704
  isNumberBelowOrEqual(0, .1); // TRUE
691
705
  isNumberBelowOrEqual(-1, -1); // TRUE
@@ -694,7 +708,7 @@ isNumberBelowOrEqual(-9, -10); // FALSE
694
708
 
695
709
  - **isNumberBetween(val:number, min:number, max:number)**
696
710
  Check if a variable is a number between a range of numbers
697
- ```js
711
+ ```typescript
698
712
  isNumberBetween(5, 0, 10); // TRUE
699
713
  isNumberBetween(.1, 0, 1); // TRUE
700
714
  isNumberBetween(-.1, -1, 0); // TRUE
@@ -704,7 +718,7 @@ isNumberBetween(-1, 0, 1); // FALSE
704
718
 
705
719
  - **isInteger(val:any)**
706
720
  Check if a variable is an integer
707
- ```js
721
+ ```typescript
708
722
  isInteger('foo'); // FALSE
709
723
  isInteger(4); // TRUE
710
724
  isInteger(0.5); // FALSE
@@ -712,7 +726,7 @@ isInteger(0.5); // FALSE
712
726
 
713
727
  - **isIntegerAbove(val:number, comp:number)**
714
728
  Check if a variable is an integer above a certain bound
715
- ```js
729
+ ```typescript
716
730
  isIntegerAbove(5, 0); // TRUE
717
731
  isIntegerAbove(.1, 0); // FALSE
718
732
  isIntegerAbove(-1, -1); // FALSE
@@ -721,7 +735,7 @@ isIntegerAbove(-10, -9); // FALSE
721
735
 
722
736
  - **isIntegerAboveOrEqual(val:number, comp:number)**
723
737
  Check if a variable is an integer above or equal to a certain bound
724
- ```js
738
+ ```typescript
725
739
  isIntegerAboveOrEqual(5, 0); // TRUE
726
740
  isIntegerAboveOrEqual(.1, 0); // FALSE
727
741
  isIntegerAboveOrEqual(-1, -1); // TRUE
@@ -730,7 +744,7 @@ isIntegerAboveOrEqual(-10, -9); // FALSE
730
744
 
731
745
  - **isIntegerBelow(val:number, comp:number)**
732
746
  Check if a variable is an integer below a certain bound
733
- ```js
747
+ ```typescript
734
748
  isIntegerBelow(0, 5); // TRUE
735
749
  isIntegerBelow(0, .1); // TRUE
736
750
  isIntegerBelow(.4, 5); // FALSE
@@ -740,7 +754,7 @@ isIntegerBelow(-9, -10); // FALSE
740
754
 
741
755
  - **isIntegerBelowOrEqual(val:number, comp:number)**
742
756
  Check if a variable is an integer below or equal to a certain bound
743
- ```js
757
+ ```typescript
744
758
  isIntegerBelowOrEqual(0, 5); // TRUE
745
759
  isIntegerBelowOrEqual(0, .1); // TRUE
746
760
  isIntegerBelowOrEqual(.4, 5); // FALSE
@@ -750,7 +764,7 @@ isIntegerBelowOrEqual(-9, -10); // FALSE
750
764
 
751
765
  - **isIntegerBetween(val:number, min:number, max:number)**
752
766
  Check if a variable is an integer between a range of numbers
753
- ```js
767
+ ```typescript
754
768
  isIntegerBetween(5, 0, 10); // TRUE
755
769
  isIntegerBetween(.1, 0, 1); // FALSE
756
770
  isIntegerBetween(-.1, -1, 0); // FALSE
@@ -760,14 +774,14 @@ isIntegerBetween(-1, 0, 1); // FALSE
760
774
 
761
775
  - **isNumericalNaN(val:any)**
762
776
  Check if a variable is a numerical nan ( a number that is a NaN, this distinguishment is made since both a string or a number can be NaN)
763
- ```js
777
+ ```typescript
764
778
  isNumericalNaN('foo'); // FALSE
765
779
  isNumericalNaN(NaN); // TRUE
766
780
  ```
767
781
 
768
782
  - **toPercentage(val:Number,precision:Number=0,min:Number=0,max:Number=1)**
769
783
  Calculate the percentage of a specific value in a range
770
- ```js
784
+ ```typescript
771
785
  toPercentage(0.50106579, 5); // 50.11658
772
786
  toPercentage(-356, 0, -1000, 1000); // 32
773
787
  toPercentage(0.5); // 50
@@ -775,7 +789,7 @@ toPercentage(0.5); // 50
775
789
 
776
790
  - **round(val:Number,precision:Number=0)**
777
791
  Round a numeric value to a specific amount of decimals
778
- ```js
792
+ ```typescript
779
793
  round(5.123456789, 0); // 5
780
794
  round(5.123456789, 2); // 5.12
781
795
  round(5.123456789, 5); // 5.12346
@@ -783,14 +797,14 @@ round(5.123456789, 5); // 5.12346
783
797
 
784
798
  - **randomBetween(min:Number=0,max:Number=10)**
785
799
  Generate a random numeric value between a min and max range
786
- ```js
800
+ ```typescript
787
801
  randomBetween(); // Will generate a random between 0 and 10
788
802
  randomBetween(25, 100); // Will generate a random between 25 and 100
789
803
  ```
790
804
 
791
805
  - **randomIntBetween(min:Number=0,max:Number=10)**
792
806
  Generate a random numeric value between a min and max range (max not inclusive)
793
- ```js
807
+ ```typescript
794
808
  randomIntBetween(); // Will generate a random between 0 and 10 (10 not inclusive)
795
809
  randomIntBetween(25, 100); // Will generate a random between 25 and 100 (100 not inclusive)
796
810
  ```
@@ -798,14 +812,14 @@ randomIntBetween(25, 100); // Will generate a random between 25 and 100 (100 not
798
812
  ### object
799
813
  - **isObject(val:any)**
800
814
  Check if a variable is of type Object
801
- ```js
815
+ ```typescript
802
816
  isObject({a: 1}); // TRUE
803
817
  isObject(1); // FALSE
804
818
  ```
805
819
 
806
820
  - **isNotEmptyObject(val:any)**
807
821
  Check if a variable a non-empty object
808
- ```js
822
+ ```typescript
809
823
  isNotEmptyObject({a:1}); // TRUE
810
824
  isNotEmptyObject({}); // FALSE
811
825
  isNotEmptyObject('Hi'); // FALSE
@@ -814,19 +828,19 @@ isNotEmptyObject('Hi'); // FALSE
814
828
  - **pick(obj:Object={}, keys:Array[string]=[])**
815
829
  Copies the keys passed in the 'keys' array from the passed object to a new object and returns that object.**
816
830
  <small>If a key wasn't found it will be set as undefined</small>
817
- ```js
831
+ ```typescript
818
832
  pick({a: 1, b: 2, c: 3}, ['a','b']); // {a: 1, b: 2}
819
833
  ```
820
834
 
821
835
  - **merge(target:Object={},obj:Object={})**
822
836
  Merges two objects together, with the preference over the second object.
823
- ```js
837
+ ```typescript
824
838
  merge({a: 1, b: false}, {a: 900, c: 50}); // {a: 900, b: false, c: 50}
825
839
  ```
826
840
 
827
841
  - **define(props:Object, obj:Object={})**
828
842
  Creates an object with the passed accessors set on it
829
- ```js
843
+ ```typescript
830
844
  define(
831
845
  {
832
846
  a: {
@@ -839,7 +853,7 @@ define(
839
853
  // { a : () => ..., b: 2 }
840
854
  ```
841
855
 
842
- ```js
856
+ ```typescript
843
857
  define({
844
858
  a : {
845
859
  enumerable: false,
@@ -851,7 +865,7 @@ define({
851
865
  ### regexp
852
866
  - **isRegExp(val:any)**
853
867
  Check if a variable is an instance of RegExp
854
- ```js
868
+ ```typescript
855
869
  isRegExp('foo'); // FALSE
856
870
  isRegExp(new RegExp('ab+c', 'i')); // TRUE
857
871
  isRegExp(new RegExp(/ab+c/, 'i')); // TRUE
@@ -860,21 +874,21 @@ isRegExp(/ab+c/i); // FALSE
860
874
 
861
875
  - **sanitize(val:string)**
862
876
  Escapes special characters in a string and returns a sanitized version safe for usage in RegExp instances
863
- ```js
877
+ ```typescript
864
878
  sanitizeRegExp('contact@valkyriestudios.be'); // contact@valkyriestudios\\.be
865
879
  ```
866
880
 
867
881
  ### string
868
882
  - **isString(val:any)**
869
883
  Check if a variable is a string
870
- ```js
884
+ ```typescript
871
885
  isString('foo'); // TRUE
872
886
  isString(4); // FALSE
873
887
  ```
874
888
 
875
889
  - **isStringBetween(val:string, min:number, max:number, trimmed:boolean=true)**
876
890
  Check if a variable is between a range of numbers
877
- ```js
891
+ ```typescript
878
892
  isStringBetween('Peter', 4, 10); // TRUE
879
893
  isStringBetween('Jeff', 4, 10); // TRUE
880
894
  isStringBetween('Moe', 4, 10); // FALSE
@@ -885,7 +899,7 @@ isStringBetween(' Joe', 1, 3, false); // FALSE
885
899
 
886
900
  - **isNotEmptyString(val:any, trimmed:boolean=true)**
887
901
  Check if a variable a non-empty string
888
- ```js
902
+ ```typescript
889
903
  isNotEmptyString({a:1}); // FALSE
890
904
  isNotEmptyString(''); // FALSE
891
905
  isNotEmptyString(' '); // FALSE
@@ -895,7 +909,7 @@ isNotEmptyString('Hi'); // TRUE
895
909
 
896
910
  - **shorten(val:any, length:integer, postfix:string=...)**
897
911
  Shorten a string and add a postfix if string went over length
898
- ```js
912
+ ```typescript
899
913
  shorten('To the moon and beyond', 11, '..'); // 'To the moon..'
900
914
  shorten('Hi', 250); // 'Hi'
901
915
  shorten('To the moon and beyond'); // 'To the moon...'
@@ -908,7 +922,7 @@ Humanize an amount of bytes
908
922
  -- option:separator (default:'.'): Override the separator used for floats, eg: '20.034' -> '20,034'
909
923
  -- option:precision (default:2): Override decimal precision for floats: eg: '20.0344233' with precision 2 -> '20.03'
910
924
  -- option:units (default:[' byes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB']): Override units used, eg: `4893290423489 with units [' Jedi', ' Darth', ' Vader', ' Force'] and precision of 0` -> `'4,893 Force'`
911
- ```js
925
+ ```typescript
912
926
  humanizeBytes(1504230); // '1.4 MB'
913
927
  humanizeBytes(23); // '23 bytes'
914
928
  humanizeBytes(-374237489237); // '-348.5 GB'
@@ -924,7 +938,7 @@ Humanize a number
924
938
  -- option:real (default:false): Set to true to automatically round input numbers
925
939
  -- option:divider (default:1000): Override default divider used for units (used internally for humanizeBytes with 1024 as divider)
926
940
 
927
- ```js
941
+ ```typescript
928
942
  humanizeNumber(4327963279469432); // '4.33q'
929
943
  humanizeNumber(1504230); // '1.5m'
930
944
  humanizeNumber(-432443); // '-432.44k'
package/array/dedupe.js CHANGED
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = exports.dedupe = void 0;
3
+ exports.dedupe = dedupe;
4
+ exports.default = dedupe;
4
5
  const fnv1A_1 = require("../hash/fnv1A");
5
6
  function dedupe(val) {
6
7
  if (!Array.isArray(val))
7
8
  return [];
8
9
  const set = new Set();
9
10
  const acc = [];
10
- for (const item of val) {
11
- const hash = (0, fnv1A_1.fnv1A)(item);
11
+ for (let i = 0; i < val.length; i++) {
12
+ const el = val[i];
13
+ const hash = (0, fnv1A_1.fnv1A)(el);
12
14
  if (set.has(hash))
13
15
  continue;
14
16
  set.add(hash);
15
- acc.push(item);
17
+ acc.push(el);
16
18
  }
17
19
  return acc;
18
20
  }
19
- exports.dedupe = dedupe;
20
- exports.default = dedupe;
package/array/groupBy.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = exports.groupBy = void 0;
3
+ exports.groupBy = groupBy;
4
+ exports.default = groupBy;
4
5
  const isNotEmpty_1 = require("../object/isNotEmpty");
5
6
  const FALLBACK = '_';
6
7
  const defaultHandler = () => FALLBACK;
@@ -30,5 +31,3 @@ function groupBy(arr, handler) {
30
31
  }
31
32
  return acc;
32
33
  }
33
- exports.groupBy = groupBy;
34
- exports.default = groupBy;
package/array/is.js CHANGED
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = exports.isArray = void 0;
3
+ exports.isArray = isArray;
4
+ exports.default = isArray;
4
5
  function isArray(val) {
5
6
  return Array.isArray(val);
6
7
  }
7
- exports.isArray = isArray;
8
- exports.default = isArray;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = exports.isNotEmptyArray = void 0;
3
+ exports.isNotEmptyArray = isNotEmptyArray;
4
+ exports.default = isNotEmptyArray;
4
5
  function isNotEmptyArray(val) {
5
6
  return Array.isArray(val) && val.length !== 0;
6
7
  }
7
- exports.isNotEmptyArray = isNotEmptyArray;
8
- exports.default = isNotEmptyArray;
package/array/join.d.ts CHANGED
@@ -11,6 +11,12 @@ interface joinOptions {
11
11
  * eg: join([' hello', 'world '], {trim: true}) -> 'hello world'
12
12
  */
13
13
  trim?: boolean;
14
+ /**
15
+ * Trim internals of values or not
16
+ * (default=false)
17
+ * eg: join([' hello world', 'this is ', 'Peter'], {trimBetween: true, trim: true}) -> 'hello world this is peter'
18
+ */
19
+ innertrim?: boolean;
14
20
  /**
15
21
  * Automatically trim all string values
16
22
  * (default=true)