@valkyriestudios/utils 11.0.0 → 11.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/array/dedupe.d.ts +8 -0
  2. package/array/is.d.ts +8 -0
  3. package/array/isNotEmpty.d.ts +8 -0
  4. package/array/join.d.ts +36 -0
  5. package/array/mapFn.d.ts +40 -0
  6. package/array/mapKey.d.ts +38 -0
  7. package/array/mapPrimitive.d.ts +40 -0
  8. package/array/shuffle.d.ts +9 -0
  9. package/array/sort.d.ts +58 -0
  10. package/boolean/is.d.ts +8 -0
  11. package/caching/memoize.d.ts +10 -0
  12. package/date/addUTC.d.ts +10 -0
  13. package/date/diff.d.ts +10 -0
  14. package/{dist/date → date}/endOfUTC.d.ts +8 -0
  15. package/date/is.d.ts +8 -0
  16. package/date/nowUnix.d.ts +6 -0
  17. package/date/nowUnixMs.d.ts +6 -0
  18. package/{dist/date → date}/startOfUTC.d.ts +8 -0
  19. package/date/toUTC.d.ts +8 -0
  20. package/date/toUnix.d.ts +8 -0
  21. package/{dist/deep → deep}/freeze.d.ts +7 -0
  22. package/deep/get.d.ts +27 -0
  23. package/{dist/deep → deep}/seal.d.ts +7 -0
  24. package/deep/set.d.ts +42 -0
  25. package/equal.d.ts +10 -0
  26. package/function/is.d.ts +8 -0
  27. package/function/noop.d.ts +6 -0
  28. package/function/noopresolve.d.ts +9 -0
  29. package/function/noopreturn.d.ts +8 -0
  30. package/function/sleep.d.ts +9 -0
  31. package/hash/fnv1A.d.ts +10 -0
  32. package/hash/guid.d.ts +6 -0
  33. package/index.d.ts +358 -0
  34. package/number/is.d.ts +8 -0
  35. package/number/isAbove.d.ts +9 -0
  36. package/number/isAboveOrEqual.d.ts +9 -0
  37. package/number/isBelow.d.ts +9 -0
  38. package/number/isBelowOrEqual.d.ts +10 -0
  39. package/number/isBetween.d.ts +12 -0
  40. package/number/isInteger.d.ts +8 -0
  41. package/number/isIntegerAbove.d.ts +9 -0
  42. package/number/isIntegerAboveOrEqual.d.ts +10 -0
  43. package/number/isIntegerBelow.d.ts +9 -0
  44. package/number/isIntegerBelowOrEqual.d.ts +10 -0
  45. package/number/isIntegerBetween.d.ts +12 -0
  46. package/number/isNumericalNaN.d.ts +8 -0
  47. package/number/randomBetween.d.ts +9 -0
  48. package/number/randomIntBetween.d.ts +10 -0
  49. package/number/round.d.ts +9 -0
  50. package/number/toPercentage.d.ts +11 -0
  51. package/object/define.d.ts +15 -0
  52. package/object/is.d.ts +8 -0
  53. package/object/isNotEmpty.d.ts +8 -0
  54. package/object/merge.d.ts +18 -0
  55. package/object/pick.d.ts +13 -0
  56. package/package.json +1 -305
  57. package/regexp/is.d.ts +8 -0
  58. package/regexp/sanitize.d.ts +11 -0
  59. package/string/humanizeBytes.d.ts +40 -0
  60. package/string/humanizeNumber.d.ts +52 -0
  61. package/string/is.d.ts +8 -0
  62. package/string/isBetween.d.ts +13 -0
  63. package/string/isNotEmpty.d.ts +9 -0
  64. package/string/shorten.d.ts +10 -0
  65. package/dist/array/dedupe.d.ts +0 -1
  66. package/dist/array/is.d.ts +0 -1
  67. package/dist/array/isNotEmpty.d.ts +0 -1
  68. package/dist/array/join.d.ts +0 -8
  69. package/dist/array/mapFn.d.ts +0 -14
  70. package/dist/array/mapKey.d.ts +0 -12
  71. package/dist/array/mapPrimitive.d.ts +0 -10
  72. package/dist/array/shuffle.d.ts +0 -1
  73. package/dist/array/sort.d.ts +0 -11
  74. package/dist/boolean/is.d.ts +0 -1
  75. package/dist/caching/memoize.d.ts +0 -1
  76. package/dist/date/addUTC.d.ts +0 -1
  77. package/dist/date/diff.d.ts +0 -1
  78. package/dist/date/is.d.ts +0 -1
  79. package/dist/date/nowUnix.d.ts +0 -1
  80. package/dist/date/nowUnixMs.d.ts +0 -1
  81. package/dist/date/toUTC.d.ts +0 -1
  82. package/dist/date/toUnix.d.ts +0 -1
  83. package/dist/deep/get.d.ts +0 -5
  84. package/dist/deep/set.d.ts +0 -5
  85. package/dist/equal.d.ts +0 -2
  86. package/dist/function/is.d.ts +0 -1
  87. package/dist/function/noop.d.ts +0 -1
  88. package/dist/function/noopresolve.d.ts +0 -1
  89. package/dist/function/noopreturn.d.ts +0 -1
  90. package/dist/function/sleep.d.ts +0 -1
  91. package/dist/hash/fnv1A.d.ts +0 -1
  92. package/dist/hash/guid.d.ts +0 -1
  93. package/dist/number/is.d.ts +0 -1
  94. package/dist/number/isAbove.d.ts +0 -1
  95. package/dist/number/isAboveOrEqual.d.ts +0 -1
  96. package/dist/number/isBelow.d.ts +0 -1
  97. package/dist/number/isBelowOrEqual.d.ts +0 -1
  98. package/dist/number/isBetween.d.ts +0 -1
  99. package/dist/number/isInteger.d.ts +0 -1
  100. package/dist/number/isIntegerAbove.d.ts +0 -1
  101. package/dist/number/isIntegerAboveOrEqual.d.ts +0 -1
  102. package/dist/number/isIntegerBelow.d.ts +0 -1
  103. package/dist/number/isIntegerBelowOrEqual.d.ts +0 -1
  104. package/dist/number/isIntegerBetween.d.ts +0 -1
  105. package/dist/number/isNumericalNaN.d.ts +0 -1
  106. package/dist/number/randomBetween.d.ts +0 -1
  107. package/dist/number/randomIntBetween.d.ts +0 -1
  108. package/dist/number/round.d.ts +0 -1
  109. package/dist/number/toPercentage.d.ts +0 -1
  110. package/dist/object/define.d.ts +0 -7
  111. package/dist/object/is.d.ts +0 -1
  112. package/dist/object/isNotEmpty.d.ts +0 -1
  113. package/dist/object/merge.d.ts +0 -8
  114. package/dist/object/pick.d.ts +0 -5
  115. package/dist/regexp/is.d.ts +0 -1
  116. package/dist/regexp/sanitize.d.ts +0 -1
  117. package/dist/string/humanizeBytes.d.ts +0 -8
  118. package/dist/string/humanizeNumber.d.ts +0 -10
  119. package/dist/string/is.d.ts +0 -1
  120. package/dist/string/isBetween.d.ts +0 -1
  121. package/dist/string/isNotEmpty.d.ts +0 -1
  122. package/dist/string/shorten.d.ts +0 -1
  123. /package/{dist/array → array}/dedupe.js +0 -0
  124. /package/{dist/array → array}/is.js +0 -0
  125. /package/{dist/array → array}/isNotEmpty.js +0 -0
  126. /package/{dist/array → array}/join.js +0 -0
  127. /package/{dist/array → array}/mapFn.js +0 -0
  128. /package/{dist/array → array}/mapKey.js +0 -0
  129. /package/{dist/array → array}/mapPrimitive.js +0 -0
  130. /package/{dist/array → array}/shuffle.js +0 -0
  131. /package/{dist/array → array}/sort.js +0 -0
  132. /package/{dist/boolean → boolean}/is.js +0 -0
  133. /package/{dist/caching → caching}/memoize.js +0 -0
  134. /package/{dist/date → date}/addUTC.js +0 -0
  135. /package/{dist/date → date}/diff.js +0 -0
  136. /package/{dist/date → date}/endOfUTC.js +0 -0
  137. /package/{dist/date → date}/is.js +0 -0
  138. /package/{dist/date → date}/nowUnix.js +0 -0
  139. /package/{dist/date → date}/nowUnixMs.js +0 -0
  140. /package/{dist/date → date}/startOfUTC.js +0 -0
  141. /package/{dist/date → date}/toUTC.js +0 -0
  142. /package/{dist/date → date}/toUnix.js +0 -0
  143. /package/{dist/deep → deep}/freeze.js +0 -0
  144. /package/{dist/deep → deep}/get.js +0 -0
  145. /package/{dist/deep → deep}/seal.js +0 -0
  146. /package/{dist/deep → deep}/set.js +0 -0
  147. /package/{dist/equal.js → equal.js} +0 -0
  148. /package/{dist/function → function}/is.js +0 -0
  149. /package/{dist/function → function}/noop.js +0 -0
  150. /package/{dist/function → function}/noopresolve.js +0 -0
  151. /package/{dist/function → function}/noopreturn.js +0 -0
  152. /package/{dist/function → function}/sleep.js +0 -0
  153. /package/{dist/hash → hash}/fnv1A.js +0 -0
  154. /package/{dist/hash → hash}/guid.js +0 -0
  155. /package/{dist/is.d.ts → is.d.ts} +0 -0
  156. /package/{dist/is.js → is.js} +0 -0
  157. /package/{dist/number → number}/is.js +0 -0
  158. /package/{dist/number → number}/isAbove.js +0 -0
  159. /package/{dist/number → number}/isAboveOrEqual.js +0 -0
  160. /package/{dist/number → number}/isBelow.js +0 -0
  161. /package/{dist/number → number}/isBelowOrEqual.js +0 -0
  162. /package/{dist/number → number}/isBetween.js +0 -0
  163. /package/{dist/number → number}/isInteger.js +0 -0
  164. /package/{dist/number → number}/isIntegerAbove.js +0 -0
  165. /package/{dist/number → number}/isIntegerAboveOrEqual.js +0 -0
  166. /package/{dist/number → number}/isIntegerBelow.js +0 -0
  167. /package/{dist/number → number}/isIntegerBelowOrEqual.js +0 -0
  168. /package/{dist/number → number}/isIntegerBetween.js +0 -0
  169. /package/{dist/number → number}/isNumericalNaN.js +0 -0
  170. /package/{dist/number → number}/randomBetween.js +0 -0
  171. /package/{dist/number → number}/randomIntBetween.js +0 -0
  172. /package/{dist/number → number}/round.js +0 -0
  173. /package/{dist/number → number}/toPercentage.js +0 -0
  174. /package/{dist/object → object}/define.js +0 -0
  175. /package/{dist/object → object}/is.js +0 -0
  176. /package/{dist/object → object}/isNotEmpty.js +0 -0
  177. /package/{dist/object → object}/merge.js +0 -0
  178. /package/{dist/object → object}/pick.js +0 -0
  179. /package/{dist/regexp → regexp}/is.js +0 -0
  180. /package/{dist/regexp → regexp}/sanitize.js +0 -0
  181. /package/{dist/string → string}/humanizeBytes.js +0 -0
  182. /package/{dist/string → string}/humanizeNumber.js +0 -0
  183. /package/{dist/string → string}/is.js +0 -0
  184. /package/{dist/string → string}/isBetween.js +0 -0
  185. /package/{dist/string → string}/isNotEmpty.js +0 -0
  186. /package/{dist/string → string}/shorten.js +0 -0
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Dedupes the provided array
3
+ *
4
+ * @param val - Array to dedupe
5
+ *
6
+ * @returns Deduped array
7
+ */
8
+ export default function dedupe(val: any[]): any[];
package/array/is.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Check whether or not a provided value is an array
3
+ *
4
+ * @param val - Value to verify
5
+ *
6
+ * @returns Whether or not the value is an array
7
+ */
8
+ export default function isArray(val: any): boolean;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Check whether or not a provided value is an array with content
3
+ *
4
+ * @param val - Value to verify
5
+ *
6
+ * @returns Whether or not the value is an array with content
7
+ */
8
+ export default function isNotEmptyArray(val: any): boolean;
@@ -0,0 +1,36 @@
1
+ interface joinOptions {
2
+ /**
3
+ * Delimiter to join with
4
+ * (default=' ')
5
+ * eg: join(['hello', 'world', {delim: '_'}]) -> 'hello_world'
6
+ */
7
+ delim?: string;
8
+ /**
9
+ * Trim after joining or not
10
+ * (default=true)
11
+ * eg: join([' hello', 'world '], {trim: true}) -> 'hello world'
12
+ */
13
+ trim?: boolean;
14
+ /**
15
+ * Automatically trim all string values
16
+ * (default=true)
17
+ * eg: join([' hello ', ' world '], {valtrim: true}) -> 'hello world'
18
+ */
19
+ valtrim?: boolean;
20
+ /**
21
+ * Automatically round all numeric values
22
+ * (default=false)
23
+ * eg: join([5.432, 'world', 1.2], {valround: 1}) -> '5.4 world 1.2'
24
+ */
25
+ valround?: number;
26
+ }
27
+ /**
28
+ * Join an array of values while autofiltering any non-string/non-number elements
29
+ *
30
+ * @param val - Array of values to join
31
+ * @param opts - Join options
32
+ *
33
+ * @returns Joined array as string
34
+ */
35
+ export default function join(val: any[], opts?: joinOptions): string;
36
+ export {};
@@ -0,0 +1,40 @@
1
+ interface mapOptions {
2
+ /**
3
+ * Allow merging existing keys or not, if not keys will be overriden if they exist
4
+ * (default=false)
5
+ *
6
+ * Example:
7
+ * mapFn([{uid: 12, a: 'hi'}, {uid: 12, b: 'ho'}], el => el.uid, {merge: true})
8
+ * Output:
9
+ * {12: {uid: 12, a: 'hi', b: 'ho'}}
10
+ * Output if merge is false
11
+ * {12: {uid: 12, b: 'ho'}}
12
+ */
13
+ merge?: boolean;
14
+ }
15
+ interface kvMap {
16
+ [key: string]: {
17
+ [key: string]: any;
18
+ };
19
+ }
20
+ /**
21
+ * Map an object array into a kv-object through a function that generates a key. Returning a non-string,
22
+ * non-numeric value from the function (eg: false) will filter out the object.
23
+ *
24
+ * Example:
25
+ * mapFn([{uid: 12, name: 'Peter'}, {uid: 15, name: 'Jonas'}], el => el.uid);
26
+ * Output:
27
+ * {12: {uid: 12, name: 'Peter'}, 15: {uid: 15, name: 'Jonas'}}
28
+ *
29
+ * @param val - Array to map
30
+ * @param fn - Handler function which is run for each of the objects and should return a string or number
31
+ * @param opts - Options object to override built-in defaults
32
+ *
33
+ * @returns KV-Map object
34
+ */
35
+ export default function mapFn(arr: {
36
+ [key: string]: any;
37
+ }[], fn: (entry: {
38
+ [key: string]: any;
39
+ }) => (string | number | boolean), opts?: mapOptions): kvMap;
40
+ export {};
@@ -0,0 +1,38 @@
1
+ interface mapOptions {
2
+ /**
3
+ * Allow merging existing keys or not, if not keys will be overriden if they exist
4
+ * (default=false)
5
+ *
6
+ * Example:
7
+ * mapKey([{uid: 12, a: 'hi'}, {uid: 12, b: 'ho'}], 'uid', {merge: true})
8
+ * Output:
9
+ * {12: {uid: 12, a: 'hi', b: 'ho'}}
10
+ * Output if merge is false
11
+ * {12: {uid: 12, b: 'ho'}}
12
+ */
13
+ merge?: boolean;
14
+ }
15
+ interface kvMap {
16
+ [key: string]: {
17
+ [key: string]: any;
18
+ };
19
+ }
20
+ /**
21
+ * Map an object array into a kv-object by passing a common key that exists on the objects. Objects for
22
+ * which the key doesn't exist will be filtered out automatically
23
+ *
24
+ * Example:
25
+ * mapKey([{uid: 12, name: 'Peter'}, {uid: 15, name: 'Jonas'}], 'uid');
26
+ * Output:
27
+ * {12: {uid: 12, name: 'Peter'}, 15: {uid: 15, name: 'Jonas'}}
28
+ *
29
+ * @param val - Array to map
30
+ * @param key - Key to map by
31
+ * @param opts - Options object to override built-in defaults
32
+ *
33
+ * @returns KV-Map object
34
+ */
35
+ export default function mapKey(arr: {
36
+ [key: string]: any;
37
+ }[], key: string, opts?: mapOptions): kvMap;
38
+ export {};
@@ -0,0 +1,40 @@
1
+ interface mapOptions {
2
+ /**
3
+ * Automatically trim all string values
4
+ * (default=false)
5
+ * eg: join([' hello ', ' world '], {valtrim: true}) -> 'hello world'
6
+ */
7
+ valtrim?: boolean;
8
+ /**
9
+ * Automatically round all numeric values
10
+ * (default=false)
11
+ * eg: mapPrimitive([5.432, 5.4, 5.43, 4.2, 4.1], {valround: true}) -> {'5.432': 5, '5.4': 5, '5.43': 5, '4.2': 4, '4.1': 4}
12
+ * eg: mapPrimitive([5.432, 5.43, 4.21, 4.1], {valround: 1}) -> {'5.432': 5.4, '5.43': 5.4, '4.21': 4.2, '4.1': 4.1}
13
+ */
14
+ valround?: boolean | number;
15
+ /**
16
+ * Automaticaly round all keys from numeric values
17
+ * (default=false)
18
+ * eg: mapPrimitive([5.432, 5.4, 5.43, 4.2, 4.1], {keyround: true}) -> {5: 5.43, 4: 4.1}
19
+ */
20
+ keyround?: boolean;
21
+ }
22
+ interface mapReturn {
23
+ [key: string]: string | number;
24
+ }
25
+ /**
26
+ * Map an array of primitive values (numbers/strings) into a kv-object
27
+ * non-numeric and non-string values will be filtered out
28
+ *
29
+ * Example:
30
+ * mapPrimitive(['hello', 'hello', 'foo', 'bar']);
31
+ * Output:
32
+ * {hello: 'hello', foo: 'foo', bar: 'bar'}
33
+ *
34
+ * @param val - Array to map
35
+ * @param opts - Options object to override built-in defaults
36
+ *
37
+ * @returns KV-Map object
38
+ */
39
+ export default function mapPrimitive(arr: any[], opts?: mapOptions): mapReturn;
40
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shuffle an array using a Fisher-Yates shuffle O(n)
3
+ * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
4
+ *
5
+ * Take Note: The passed array will be changed and edited in place
6
+ *
7
+ * @param val - Array to shuffle
8
+ */
9
+ export default function shuffle(arr: any[]): void;
@@ -0,0 +1,58 @@
1
+ interface sortOptions {
2
+ /**
3
+ * Filter function to apply to the array before sorting
4
+ * (default=isNotEmptyObject)
5
+ */
6
+ filter_fn?: (el: any) => boolean;
7
+ /**
8
+ * Remove objects that don't have the key or where the key is falsy
9
+ * (default=false)
10
+ */
11
+ nokey_hide?: boolean;
12
+ /**
13
+ * Move invalid values (eg: non-objects or objects that don't match the key/function passed) to the end of the sorted array
14
+ * (default=true)
15
+ */
16
+ nokey_atend?: boolean;
17
+ }
18
+ interface sortObject {
19
+ [key: string]: any;
20
+ }
21
+ type sortByFunction = (el: sortObject) => string;
22
+ /**
23
+ * Sort an array of objects, uses an implementation of Tony Hoare's quicksort
24
+ * (https://cs.stanford.edu/people/eroberts/courses/soco/projects/2008-09/tony-hoare/quicksort.html)
25
+ *
26
+ * Example:
27
+ * sort([
28
+ * {test: 'Peter'},
29
+ * {test: 'Jack'},
30
+ * {test: 'Pony'},
31
+ * {test: 'John'},
32
+ * {test: 'Joe'},
33
+ * {test: 'Bob'},
34
+ * {test: 'Alice'},
35
+ * ], 'test', 'desc');
36
+ * Output:
37
+ * [{test: 'Pony'}, {test: 'Peter'}, {test: 'John'}, {test: 'Joe'}, {test: 'Jack'}, {test: 'Bob'}, {test: 'Alice'}]
38
+ *
39
+ * Example w/ Function:
40
+ * sort([
41
+ * {test: 'Peter'},
42
+ * {test: 'Pony'},
43
+ * {test: 'JOHn'},
44
+ * {test: 'Joe'},
45
+ * ], el => el.test.toLowerCase(), 'desc');
46
+ * Output:
47
+ * [{test: 'Pony'}, {test: 'Peter'}, {test: 'JOHn'}, {test: 'Joe'}]
48
+ *
49
+ * @param val - Array to sort
50
+ * @param by - Either a string (key) or a function
51
+ * @param dir - (default='asc') Direction to sort in (asc or desc)
52
+ * @param opts - Sort options
53
+ *
54
+ * @returns Sorted array
55
+ * @throws {Error}
56
+ */
57
+ export default function sort(arr: sortObject[], by: string | sortByFunction, dir?: 'asc' | 'desc', opts?: sortOptions): sortObject[];
58
+ export {};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Check whether or not a provided value is a boolean
3
+ *
4
+ * @param val - Value to verify
5
+ *
6
+ * @returns Whether or not the value is a boolean
7
+ */
8
+ export default function isBoolean(val: any): boolean;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Turn a function into a memoized function. An optional resolver function can be passed which allows custom cache key generation.
3
+ *
4
+ * Example:
5
+ * const memoized_function = memoize((a) => fnv1A(a));
6
+ *
7
+ * @param fn - Function to memoize
8
+ * @param resolver - Optional resolver function to generate cache key. If not passed the first argument is used as map key
9
+ */
10
+ export default function memoize(fn: Function, resolver?: Function): Function;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Adds the provided amount of a specific key to the provided date
3
+ *
4
+ * @param val - Date to set to end of
5
+ * @param amount - (default=0) Amount of key to add
6
+ * @param key - (default='millisecond') Key to set
7
+ *
8
+ * @returns New date with provided amount of key added
9
+ */
10
+ export default function addUTC(val: Date, amount?: number, key?: 'years' | 'year' | 'months' | 'month' | 'days' | 'day' | 'hours' | 'hour' | 'minutes' | 'minute' | 'seconds' | 'second' | 'milliseconds' | 'millisecond'): Date;
package/date/diff.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Compute the diff between two dates in the provided key
3
+ *
4
+ * @param val_a - Date to diff against
5
+ * @param val_b - Date to diff with
6
+ * @param key - (default='millisecond') Key to diff in
7
+ *
8
+ * @returns Numerical diff between two dates
9
+ */
10
+ export default function diff(val_a: Date, val_b: Date, key?: 'week' | 'weeks' | 'day' | 'days' | 'hour' | 'hours' | 'minute' | 'minutes' | 'second' | 'seconds' | 'millisecond' | 'milliseconds'): number;
@@ -1 +1,9 @@
1
+ /**
2
+ * Sets the provided date to end of UTC of provided key
3
+ *
4
+ * @param val - Date to set to end of
5
+ * @param key - (default='millisecond') Key to set
6
+ *
7
+ * @returns New date set to end of key
8
+ */
1
9
  export default function endOfUTC(val: Date, key?: 'year' | 'quarter' | 'month' | 'week' | 'week_sun' | 'week_mon' | 'week_tue' | 'week_wed' | 'week_thu' | 'week_fri' | 'week_sat' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond'): Date;
package/date/is.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Check whether or not a provided value is a Date
3
+ *
4
+ * @param val - Value to verify
5
+ *
6
+ * @returns Whether or not the value is a Date
7
+ */
8
+ export default function isDate(val: any): boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Compute the current unix timestamp in seconds
3
+ *
4
+ * @returns Current unix timestamp in seconds
5
+ */
6
+ export default function nowUnix(): number;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Compute the current unix timestamp in milliseconds
3
+ *
4
+ * @returns Current unix timestamp in milliseconds
5
+ */
6
+ export default function nowUnixMs(): number;
@@ -1 +1,9 @@
1
+ /**
2
+ * Sets the provided date to start of UTC of provided key
3
+ *
4
+ * @param val - Date to set to start of
5
+ * @param key - (default='millisecond') Key to set
6
+ *
7
+ * @returns New date set to start of key
8
+ */
1
9
  export default function startOfUTC(val: Date, key?: 'year' | 'quarter' | 'month' | 'week' | 'week_sun' | 'week_mon' | 'week_tue' | 'week_wed' | 'week_thu' | 'week_fri' | 'week_sat' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond'): Date;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Sets a passed date to UTC
3
+ *
4
+ * @param val - Date to set to UTC
5
+ *
6
+ * @returns New date object set to the UTC contents of the passed date
7
+ */
8
+ export default function toUTC(val: Date): Date;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns the unix time in seconds of the passed date
3
+ *
4
+ * @param val - Date to get the unix time for
5
+ *
6
+ * @returns Unix time in seconds
7
+ */
8
+ export default function toUnix(val: Date): number;
@@ -3,5 +3,12 @@ type deepInput = {
3
3
  } | {
4
4
  [key: string]: any;
5
5
  }[] | any[];
6
+ /**
7
+ * Recursively freezes all properties of an object
8
+ *
9
+ * @param obj - Object to deep freeze
10
+ *
11
+ * @returns Deeply frozen object
12
+ */
6
13
  export default function deepFreeze(obj: deepInput): Readonly<deepInput>;
7
14
  export {};
package/deep/get.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Get a property's value deep inside the structure of an array/object
3
+ *
4
+ * Example:
5
+ * const myObj = {
6
+ * a: 2,
7
+ * b: [
8
+ * {price : 2},
9
+ * {price : 4},
10
+ * ],
11
+ * };
12
+ * deepGet(myObj, 'b[0].price');
13
+ * Output:
14
+ * 2
15
+ *
16
+ * @param val - Object/Array to get the value from
17
+ * @param path - Path string to deeply get the value at
18
+ * @param get_parent - If passed as true retrieves the parent of where the value lives
19
+ *
20
+ * @returns Value stored at property or undefined
21
+ * @throws {TypeError}
22
+ */
23
+ export default function deepGet(obj: {
24
+ [key: string]: any;
25
+ } | {
26
+ [key: string]: any;
27
+ }[] | any[], path: string, get_parent?: boolean): any | undefined;
@@ -3,5 +3,12 @@ type deepInput = {
3
3
  } | {
4
4
  [key: string]: any;
5
5
  }[] | any[];
6
+ /**
7
+ * Recursively seals all properties of an object
8
+ *
9
+ * @param obj - Object to deep seal
10
+ *
11
+ * @returns Deeply sealed object
12
+ */
6
13
  export default function deepSeal(obj: deepInput): deepInput;
7
14
  export {};
package/deep/set.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Sets a property and its value deep in the structure of an object
3
+ *
4
+ * Example:
5
+ * const myObj = {a: 2};
6
+ * deepSet(myObj, 'b.c.d.e', 4);
7
+ * Output:
8
+ * {
9
+ * a: 2,
10
+ * b: {
11
+ * c: {
12
+ * d: {
13
+ * e: 4
14
+ * }
15
+ * }
16
+ * }
17
+ * }
18
+ *
19
+ * Example:
20
+ * const myObj = {a: 2, b: [{price: 2}]};
21
+ * deepSet(myObj, 'b[0].price', 4);
22
+ * Output:
23
+ * {
24
+ * a: 2,
25
+ * b: [
26
+ * {price: 4}
27
+ * ]
28
+ * }
29
+ *
30
+ * @param val - Object to set the value on
31
+ * @param path - Path string to deeply set the value at
32
+ * @param value - Value to set (if using defineProperty can be an accessor object)
33
+ * @param define - Whether or not the property should be directly assigned or set using Object.defineProperty
34
+ *
35
+ * @returns True or false depending on whether or not the property was set correctly
36
+ * @throws {TypeError}
37
+ */
38
+ export default function deepSet(obj: {
39
+ [key: string]: any;
40
+ } | {
41
+ [key: string]: any;
42
+ }[] | any[], path: string, value: any, define?: boolean): boolean;
package/equal.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Compute whether or not two provided values are deeply equal
3
+ *
4
+ * @param a - Value to compare against
5
+ * @param b - Value to compare with
6
+ *
7
+ * @returns Whether or not they are equal
8
+ */
9
+ declare function equal(a: any, b: any): boolean;
10
+ export default equal;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Check whether or not a provided value is a Function
3
+ *
4
+ * @param val - Value to verify
5
+ *
6
+ * @returns Whether or not the value is a Function
7
+ */
8
+ export default function isFunction(val: any): boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * No-Operation (noop) function that does nothing and simply returns.
3
+ *
4
+ * @returns Void
5
+ */
6
+ export default function noop(): void;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * No-Operation (noop) resolver that simply returns a promise
3
+ * that resolves with the value that was passed to it
4
+ *
5
+ * @param val - Value to be resolved with
6
+ *
7
+ * @returns Promise that resolves with passed value
8
+ */
9
+ export default function noopresolve(val?: any): Promise<any>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * No-Operation (noop) function that returns the value passed to it when called.
3
+ *
4
+ * @param val - Value to return
5
+ *
6
+ * @returns Passed value
7
+ */
8
+ export default function noopreturn(val?: any): any;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns a promise that resolves after X milliseconds, useful in
3
+ * async scenarios where we wish to wait for a specific periodic of time
4
+ *
5
+ * @param ms - (default=1000) Amount of milliseconds to wait for
6
+ *
7
+ * @returns Promise that resolves after X milliseconds
8
+ */
9
+ export default function sleep(ms?: number): Promise<void>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Convert a provided value into a Fowler-Noll-Vo 1A hash
3
+ * For more info: https://tools.ietf.org/html/draft-eastlake-fnv-03
4
+ *
5
+ * @param data - Value to be converted
6
+ * @param offset - (default=2166136261) FNV prime to use
7
+ *
8
+ * @returns FNV1A hash of provided value
9
+ */
10
+ export default function fnv1A(data: any, offset?: number): number;
package/hash/guid.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Generate a unique identifier (guid) according to RFC4122
3
+ *
4
+ * @returns Generated guid string
5
+ */
6
+ export default function guid(): string;