@valkyriestudios/utils 12.10.0 → 12.11.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 (71) hide show
  1. package/README.md +69 -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 +6 -5
  20. package/date/is.js +2 -3
  21. package/date/nowUnix.js +2 -3
  22. package/date/nowUnixMs.js +2 -3
  23. package/date/startOfUTC.js +2 -3
  24. package/date/toUTC.js +2 -3
  25. package/date/toUnix.js +2 -3
  26. package/deep/freeze.js +3 -4
  27. package/deep/get.js +3 -4
  28. package/deep/seal.js +3 -4
  29. package/deep/set.js +2 -3
  30. package/equal.js +2 -3
  31. package/formdata/is.js +2 -3
  32. package/function/is.js +2 -3
  33. package/function/isAsync.js +2 -3
  34. package/function/noop.js +2 -3
  35. package/function/noopresolve.js +2 -3
  36. package/function/noopreturn.js +2 -3
  37. package/function/sleep.js +2 -3
  38. package/hash/fnv1A.js +2 -3
  39. package/hash/guid.js +2 -3
  40. package/index.d.ts +4 -4
  41. package/number/is.js +2 -3
  42. package/number/isAbove.js +2 -3
  43. package/number/isAboveOrEqual.js +2 -3
  44. package/number/isBelow.js +2 -3
  45. package/number/isBelowOrEqual.js +2 -3
  46. package/number/isBetween.js +2 -3
  47. package/number/isInteger.js +2 -3
  48. package/number/isIntegerAbove.js +2 -3
  49. package/number/isIntegerAboveOrEqual.js +2 -3
  50. package/number/isIntegerBelow.js +2 -3
  51. package/number/isIntegerBelowOrEqual.js +2 -3
  52. package/number/isIntegerBetween.js +2 -3
  53. package/number/isNumericalNaN.js +2 -3
  54. package/number/randomBetween.js +2 -3
  55. package/number/randomIntBetween.js +2 -3
  56. package/number/round.js +2 -3
  57. package/number/toPercentage.js +2 -3
  58. package/object/define.js +2 -3
  59. package/object/is.js +2 -3
  60. package/object/isNotEmpty.js +2 -3
  61. package/object/merge.js +3 -6
  62. package/object/pick.js +4 -4
  63. package/package.json +1 -1
  64. package/regexp/is.js +2 -3
  65. package/regexp/sanitize.js +2 -3
  66. package/string/humanizeBytes.js +2 -3
  67. package/string/humanizeNumber.js +2 -3
  68. package/string/is.js +2 -3
  69. package/string/isBetween.js +2 -3
  70. package/string/isNotEmpty.js +2 -3
  71. 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
 
@@ -434,7 +435,7 @@ Returns the current unix timestamp in milliseconds
434
435
  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
436
 
436
437
  Note: Does not touch the date object passed
437
- ```js
438
+ ```typescript
438
439
  startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'year'); // new Date("2023-01-01T00:00:00.000Z")
439
440
  startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'quarter'); // new Date("2023-04-01T00:00:00.000Z")
440
441
  startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'month'); // new Date("2023-05-01T00:00:00.000Z")
@@ -454,7 +455,7 @@ startOfUTC(new Date("2023-05-04T12:04:27.043+02:00"), 'second'); // new Date("20
454
455
  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
456
 
456
457
  Note: Does not touch the date object passed
457
- ```js
458
+ ```typescript
458
459
  endOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'year'); // new Date("2023-12-31T23:59:59.999Z")
459
460
  endOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'quarter'); // new Date("2023-06-30T23:59:59.999Z")
460
461
  endOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'month'); // new Date("2023-05-31T23:59:59.999Z")
@@ -478,7 +479,7 @@ endOfUTC(new Date("2023-05-04T12:04:27.043+02:00"), 'second'); // new Date("2023
478
479
  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
480
 
480
481
  Note: Does not touch the date object passed
481
- ```js
482
+ ```typescript
482
483
  addUTC(new Date("2022-10-05T13:12:11+02:00"), 10, 'year'); // new Date("2032-10-05T11:12:11.000Z")
483
484
  addUTC(new Date("2022-10-05T13:12:11+02:00"), -10, 'year'); // new Date("2012-10-05T11:12:11.000Z")
484
485
  addUTC(new Date("2022-10-05T13:12:11+02:00"), 10, 'month'); // new Date("2023-08-05T11:12:11.000Z")
@@ -500,7 +501,7 @@ addUTC(new Date("2022-10-05T13:12:11+02:00"), -10, 'second'); // new Date("2022-
500
501
  ### deep
501
502
  - **deepFreeze(val:Object)**
502
503
  Recursively freezes all properties of an object
503
- ```js
504
+ ```typescript
504
505
  const myObj = deepFreeze({
505
506
  a: 2,
506
507
  b: {
@@ -517,7 +518,7 @@ Object.isFrozen(myObj.b.d); // TRUE
517
518
 
518
519
  - **deepSeal(val:Object)**
519
520
  Recursively freezes all properties of an object
520
- ```js
521
+ ```typescript
521
522
  const myObj = deepSeal({
522
523
  a: 2,
523
524
  b: {
@@ -535,7 +536,7 @@ Object.isFrozen(myObj.b.d); // FALSE
535
536
 
536
537
  - **deepSet(obj:Object, path:string, value:any=null, define:boolean=false)**
537
538
  Sets a property and its value deep in the structure of an object
538
- ```js
539
+ ```typescript
539
540
  const myObj = {
540
541
  a: 2,
541
542
  };
@@ -543,7 +544,7 @@ deepSet(myObj, 'b.c.d.e', 4);
543
544
  myObj.b.c.d.e; // 4
544
545
  ```
545
546
 
546
- ```js
547
+ ```typescript
547
548
  const myObj = {
548
549
  a: 2,
549
550
  b: [
@@ -557,7 +558,7 @@ myObj.b[0].price; // 100
557
558
  myObj.b[1].price; // 500
558
559
  ```
559
560
 
560
- ```js
561
+ ```typescript
561
562
  const myObj = {
562
563
  a: 2,
563
564
  };
@@ -567,7 +568,7 @@ myObj.b.c; // Function
567
568
 
568
569
  - **deepGet(obj:Object, path:string, get_parent:boolean=false)**
569
570
  Retrieves a value based on a path in a deeply nested object
570
- ```js
571
+ ```typescript
571
572
  const myObj = {
572
573
  a: 2,
573
574
  b: [
@@ -578,7 +579,7 @@ const myObj = {
578
579
  deepGet(myObj, 'b[0].price', true); // [{price: 2}, {price: 4}]
579
580
  ```
580
581
 
581
- ```js
582
+ ```typescript
582
583
  const myObj = {
583
584
  a: 2,
584
585
  b: [
@@ -592,7 +593,7 @@ deepGet(myObj, 'b[0].price'); // 2
592
593
  ### equal
593
594
  - **equal(a:any, b:any)**
594
595
  Check if a variable is equal to another one
595
- ```js
596
+ ```typescript
596
597
  equal(5, 6); // FALSE
597
598
  equal(1, 1); // TRUE
598
599
  equal([0, 1, 2], [1, 2]); // FALSE
@@ -625,7 +626,7 @@ An empty function that returns a promise that will resolve after X milliseconds,
625
626
  ### formdata
626
627
  - **isFormData(val:any)**
627
628
  Check if a variable is of type FormData
628
- ```js
629
+ ```typescript
629
630
  isFormData(new FormData()); // TRUE
630
631
  isFormData({hi: 'there'}); // FALSE
631
632
  ```
@@ -633,13 +634,13 @@ isFormData({hi: 'there'}); // FALSE
633
634
  ### hash
634
635
  - **guid()**
635
636
  Generate a unique identifier (guid) according to RFC4122
636
- ```js
637
+ ```typescript
637
638
  guid(); // 245caf1a-86af-11e7-bb31-be2e44b06b34
638
639
  ```
639
640
 
640
641
  - **fnv1A(val:any)**
641
642
  Generate a fnv1A hash from an object, using a 32-bit prime/offset
642
- ```js
643
+ ```typescript
643
644
  fnv1A('hello world'); // -2023343616
644
645
  fnv1A({a:1,b:2}); // 361168128
645
646
  fnv1A(4); // 1630425728
@@ -650,7 +651,7 @@ fnv1A(new Date('2012-02-02')); // 1655579136
650
651
  ### number
651
652
  - **isNumber(val:any)**
652
653
  Check if a variable is a number
653
- ```js
654
+ ```typescript
654
655
  isNumber('foo'); // FALSE
655
656
  isNumber(4); // TRUE
656
657
  isNumber(0.5); // TRUE
@@ -658,7 +659,7 @@ isNumber(0.5); // TRUE
658
659
 
659
660
  - **isNumberAbove(val:number, comp:number)**
660
661
  Check if a variable is a number above a certain bound
661
- ```js
662
+ ```typescript
662
663
  isNumberAbove(5, 0); // TRUE
663
664
  isNumberAbove(.1, 0); // TRUE
664
665
  isNumberAbove(-1, -1); // FALSE
@@ -667,7 +668,7 @@ isNumberAbove(-10, -9); // FALSE
667
668
 
668
669
  - **isNumberAboveOrEqual(val:number, comp:number)**
669
670
  Check if a variable is a number above or equal to a certain bound
670
- ```js
671
+ ```typescript
671
672
  isNumberAboveOrEqual(5, 0); // TRUE
672
673
  isNumberAboveOrEqual(.1, 0); // TRUE
673
674
  isNumberAboveOrEqual(-1, -1); // TRUE
@@ -676,7 +677,7 @@ isNumberAboveOrEqual(-10, -9); // FALSE
676
677
 
677
678
  - **isNumberBelow(val:number, comp:number)**
678
679
  Check if a variable is a number below a certain bound
679
- ```js
680
+ ```typescript
680
681
  isNumberBelow(0, 5); // TRUE
681
682
  isNumberBelow(0, .1); // TRUE
682
683
  isNumberBelow(-1, -1); // FALSE
@@ -685,7 +686,7 @@ isNumberBelow(-9, -10); // FALSE
685
686
 
686
687
  - **isNumberBelowOrEqual(val:number, comp:number)**
687
688
  Check if a variable is a number below or equal a certain bound
688
- ```js
689
+ ```typescript
689
690
  isNumberBelowOrEqual(0, 5); // TRUE
690
691
  isNumberBelowOrEqual(0, .1); // TRUE
691
692
  isNumberBelowOrEqual(-1, -1); // TRUE
@@ -694,7 +695,7 @@ isNumberBelowOrEqual(-9, -10); // FALSE
694
695
 
695
696
  - **isNumberBetween(val:number, min:number, max:number)**
696
697
  Check if a variable is a number between a range of numbers
697
- ```js
698
+ ```typescript
698
699
  isNumberBetween(5, 0, 10); // TRUE
699
700
  isNumberBetween(.1, 0, 1); // TRUE
700
701
  isNumberBetween(-.1, -1, 0); // TRUE
@@ -704,7 +705,7 @@ isNumberBetween(-1, 0, 1); // FALSE
704
705
 
705
706
  - **isInteger(val:any)**
706
707
  Check if a variable is an integer
707
- ```js
708
+ ```typescript
708
709
  isInteger('foo'); // FALSE
709
710
  isInteger(4); // TRUE
710
711
  isInteger(0.5); // FALSE
@@ -712,7 +713,7 @@ isInteger(0.5); // FALSE
712
713
 
713
714
  - **isIntegerAbove(val:number, comp:number)**
714
715
  Check if a variable is an integer above a certain bound
715
- ```js
716
+ ```typescript
716
717
  isIntegerAbove(5, 0); // TRUE
717
718
  isIntegerAbove(.1, 0); // FALSE
718
719
  isIntegerAbove(-1, -1); // FALSE
@@ -721,7 +722,7 @@ isIntegerAbove(-10, -9); // FALSE
721
722
 
722
723
  - **isIntegerAboveOrEqual(val:number, comp:number)**
723
724
  Check if a variable is an integer above or equal to a certain bound
724
- ```js
725
+ ```typescript
725
726
  isIntegerAboveOrEqual(5, 0); // TRUE
726
727
  isIntegerAboveOrEqual(.1, 0); // FALSE
727
728
  isIntegerAboveOrEqual(-1, -1); // TRUE
@@ -730,7 +731,7 @@ isIntegerAboveOrEqual(-10, -9); // FALSE
730
731
 
731
732
  - **isIntegerBelow(val:number, comp:number)**
732
733
  Check if a variable is an integer below a certain bound
733
- ```js
734
+ ```typescript
734
735
  isIntegerBelow(0, 5); // TRUE
735
736
  isIntegerBelow(0, .1); // TRUE
736
737
  isIntegerBelow(.4, 5); // FALSE
@@ -740,7 +741,7 @@ isIntegerBelow(-9, -10); // FALSE
740
741
 
741
742
  - **isIntegerBelowOrEqual(val:number, comp:number)**
742
743
  Check if a variable is an integer below or equal to a certain bound
743
- ```js
744
+ ```typescript
744
745
  isIntegerBelowOrEqual(0, 5); // TRUE
745
746
  isIntegerBelowOrEqual(0, .1); // TRUE
746
747
  isIntegerBelowOrEqual(.4, 5); // FALSE
@@ -750,7 +751,7 @@ isIntegerBelowOrEqual(-9, -10); // FALSE
750
751
 
751
752
  - **isIntegerBetween(val:number, min:number, max:number)**
752
753
  Check if a variable is an integer between a range of numbers
753
- ```js
754
+ ```typescript
754
755
  isIntegerBetween(5, 0, 10); // TRUE
755
756
  isIntegerBetween(.1, 0, 1); // FALSE
756
757
  isIntegerBetween(-.1, -1, 0); // FALSE
@@ -760,14 +761,14 @@ isIntegerBetween(-1, 0, 1); // FALSE
760
761
 
761
762
  - **isNumericalNaN(val:any)**
762
763
  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
764
+ ```typescript
764
765
  isNumericalNaN('foo'); // FALSE
765
766
  isNumericalNaN(NaN); // TRUE
766
767
  ```
767
768
 
768
769
  - **toPercentage(val:Number,precision:Number=0,min:Number=0,max:Number=1)**
769
770
  Calculate the percentage of a specific value in a range
770
- ```js
771
+ ```typescript
771
772
  toPercentage(0.50106579, 5); // 50.11658
772
773
  toPercentage(-356, 0, -1000, 1000); // 32
773
774
  toPercentage(0.5); // 50
@@ -775,7 +776,7 @@ toPercentage(0.5); // 50
775
776
 
776
777
  - **round(val:Number,precision:Number=0)**
777
778
  Round a numeric value to a specific amount of decimals
778
- ```js
779
+ ```typescript
779
780
  round(5.123456789, 0); // 5
780
781
  round(5.123456789, 2); // 5.12
781
782
  round(5.123456789, 5); // 5.12346
@@ -783,14 +784,14 @@ round(5.123456789, 5); // 5.12346
783
784
 
784
785
  - **randomBetween(min:Number=0,max:Number=10)**
785
786
  Generate a random numeric value between a min and max range
786
- ```js
787
+ ```typescript
787
788
  randomBetween(); // Will generate a random between 0 and 10
788
789
  randomBetween(25, 100); // Will generate a random between 25 and 100
789
790
  ```
790
791
 
791
792
  - **randomIntBetween(min:Number=0,max:Number=10)**
792
793
  Generate a random numeric value between a min and max range (max not inclusive)
793
- ```js
794
+ ```typescript
794
795
  randomIntBetween(); // Will generate a random between 0 and 10 (10 not inclusive)
795
796
  randomIntBetween(25, 100); // Will generate a random between 25 and 100 (100 not inclusive)
796
797
  ```
@@ -798,14 +799,14 @@ randomIntBetween(25, 100); // Will generate a random between 25 and 100 (100 not
798
799
  ### object
799
800
  - **isObject(val:any)**
800
801
  Check if a variable is of type Object
801
- ```js
802
+ ```typescript
802
803
  isObject({a: 1}); // TRUE
803
804
  isObject(1); // FALSE
804
805
  ```
805
806
 
806
807
  - **isNotEmptyObject(val:any)**
807
808
  Check if a variable a non-empty object
808
- ```js
809
+ ```typescript
809
810
  isNotEmptyObject({a:1}); // TRUE
810
811
  isNotEmptyObject({}); // FALSE
811
812
  isNotEmptyObject('Hi'); // FALSE
@@ -814,19 +815,19 @@ isNotEmptyObject('Hi'); // FALSE
814
815
  - **pick(obj:Object={}, keys:Array[string]=[])**
815
816
  Copies the keys passed in the 'keys' array from the passed object to a new object and returns that object.**
816
817
  <small>If a key wasn't found it will be set as undefined</small>
817
- ```js
818
+ ```typescript
818
819
  pick({a: 1, b: 2, c: 3}, ['a','b']); // {a: 1, b: 2}
819
820
  ```
820
821
 
821
822
  - **merge(target:Object={},obj:Object={})**
822
823
  Merges two objects together, with the preference over the second object.
823
- ```js
824
+ ```typescript
824
825
  merge({a: 1, b: false}, {a: 900, c: 50}); // {a: 900, b: false, c: 50}
825
826
  ```
826
827
 
827
828
  - **define(props:Object, obj:Object={})**
828
829
  Creates an object with the passed accessors set on it
829
- ```js
830
+ ```typescript
830
831
  define(
831
832
  {
832
833
  a: {
@@ -839,7 +840,7 @@ define(
839
840
  // { a : () => ..., b: 2 }
840
841
  ```
841
842
 
842
- ```js
843
+ ```typescript
843
844
  define({
844
845
  a : {
845
846
  enumerable: false,
@@ -851,7 +852,7 @@ define({
851
852
  ### regexp
852
853
  - **isRegExp(val:any)**
853
854
  Check if a variable is an instance of RegExp
854
- ```js
855
+ ```typescript
855
856
  isRegExp('foo'); // FALSE
856
857
  isRegExp(new RegExp('ab+c', 'i')); // TRUE
857
858
  isRegExp(new RegExp(/ab+c/, 'i')); // TRUE
@@ -860,21 +861,21 @@ isRegExp(/ab+c/i); // FALSE
860
861
 
861
862
  - **sanitize(val:string)**
862
863
  Escapes special characters in a string and returns a sanitized version safe for usage in RegExp instances
863
- ```js
864
+ ```typescript
864
865
  sanitizeRegExp('contact@valkyriestudios.be'); // contact@valkyriestudios\\.be
865
866
  ```
866
867
 
867
868
  ### string
868
869
  - **isString(val:any)**
869
870
  Check if a variable is a string
870
- ```js
871
+ ```typescript
871
872
  isString('foo'); // TRUE
872
873
  isString(4); // FALSE
873
874
  ```
874
875
 
875
876
  - **isStringBetween(val:string, min:number, max:number, trimmed:boolean=true)**
876
877
  Check if a variable is between a range of numbers
877
- ```js
878
+ ```typescript
878
879
  isStringBetween('Peter', 4, 10); // TRUE
879
880
  isStringBetween('Jeff', 4, 10); // TRUE
880
881
  isStringBetween('Moe', 4, 10); // FALSE
@@ -885,7 +886,7 @@ isStringBetween(' Joe', 1, 3, false); // FALSE
885
886
 
886
887
  - **isNotEmptyString(val:any, trimmed:boolean=true)**
887
888
  Check if a variable a non-empty string
888
- ```js
889
+ ```typescript
889
890
  isNotEmptyString({a:1}); // FALSE
890
891
  isNotEmptyString(''); // FALSE
891
892
  isNotEmptyString(' '); // FALSE
@@ -895,7 +896,7 @@ isNotEmptyString('Hi'); // TRUE
895
896
 
896
897
  - **shorten(val:any, length:integer, postfix:string=...)**
897
898
  Shorten a string and add a postfix if string went over length
898
- ```js
899
+ ```typescript
899
900
  shorten('To the moon and beyond', 11, '..'); // 'To the moon..'
900
901
  shorten('Hi', 250); // 'Hi'
901
902
  shorten('To the moon and beyond'); // 'To the moon...'
@@ -908,7 +909,7 @@ Humanize an amount of bytes
908
909
  -- option:separator (default:'.'): Override the separator used for floats, eg: '20.034' -> '20,034'
909
910
  -- option:precision (default:2): Override decimal precision for floats: eg: '20.0344233' with precision 2 -> '20.03'
910
911
  -- 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
912
+ ```typescript
912
913
  humanizeBytes(1504230); // '1.4 MB'
913
914
  humanizeBytes(23); // '23 bytes'
914
915
  humanizeBytes(-374237489237); // '-348.5 GB'
@@ -924,7 +925,7 @@ Humanize a number
924
925
  -- option:real (default:false): Set to true to automatically round input numbers
925
926
  -- option:divider (default:1000): Override default divider used for units (used internally for humanizeBytes with 1024 as divider)
926
927
 
927
- ```js
928
+ ```typescript
928
929
  humanizeNumber(4327963279469432); // '4.33q'
929
930
  humanizeNumber(1504230); // '1.5m'
930
931
  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)