@valkyriestudios/utils 10.0.0 → 11.1.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 (255) hide show
  1. package/README.md +1 -1
  2. package/dist/array/dedupe.d.ts +8 -0
  3. package/dist/array/dedupe.js +19 -0
  4. package/dist/array/is.d.ts +8 -0
  5. package/dist/array/is.js +6 -0
  6. package/dist/array/isNotEmpty.d.ts +8 -0
  7. package/dist/array/isNotEmpty.js +6 -0
  8. package/dist/array/join.d.ts +36 -0
  9. package/dist/array/join.js +24 -0
  10. package/dist/array/mapFn.d.ts +40 -0
  11. package/{src/array/mapFn.mjs → dist/array/mapFn.js} +13 -15
  12. package/dist/array/mapKey.d.ts +38 -0
  13. package/dist/array/mapKey.js +27 -0
  14. package/dist/array/mapPrimitive.d.ts +40 -0
  15. package/dist/array/mapPrimitive.js +27 -0
  16. package/dist/array/shuffle.d.ts +9 -0
  17. package/dist/array/shuffle.js +11 -0
  18. package/dist/array/sort.d.ts +58 -0
  19. package/dist/array/sort.js +92 -0
  20. package/dist/boolean/is.d.ts +8 -0
  21. package/dist/boolean/is.js +6 -0
  22. package/dist/caching/memoize.d.ts +10 -0
  23. package/dist/caching/memoize.js +15 -0
  24. package/dist/date/addUTC.d.ts +10 -0
  25. package/{src/date/addUTC.mjs → dist/date/addUTC.js} +11 -26
  26. package/dist/date/diff.d.ts +10 -0
  27. package/dist/date/diff.js +38 -0
  28. package/dist/date/endOfUTC.d.ts +9 -0
  29. package/dist/date/endOfUTC.js +52 -0
  30. package/dist/date/is.d.ts +8 -0
  31. package/dist/date/is.js +6 -0
  32. package/dist/date/nowUnix.d.ts +6 -0
  33. package/dist/date/nowUnix.js +6 -0
  34. package/dist/date/nowUnixMs.d.ts +6 -0
  35. package/dist/date/nowUnixMs.js +6 -0
  36. package/dist/date/startOfUTC.d.ts +9 -0
  37. package/dist/date/startOfUTC.js +52 -0
  38. package/dist/date/toUTC.d.ts +8 -0
  39. package/dist/date/toUTC.js +9 -0
  40. package/dist/date/toUnix.d.ts +8 -0
  41. package/dist/date/toUnix.js +9 -0
  42. package/dist/deep/freeze.d.ts +14 -0
  43. package/dist/deep/freeze.js +23 -0
  44. package/dist/deep/get.d.ts +27 -0
  45. package/dist/deep/get.js +41 -0
  46. package/dist/deep/seal.d.ts +14 -0
  47. package/dist/deep/seal.js +23 -0
  48. package/dist/deep/set.d.ts +42 -0
  49. package/dist/deep/set.js +52 -0
  50. package/dist/equal.d.ts +10 -0
  51. package/dist/equal.js +43 -0
  52. package/dist/function/is.d.ts +8 -0
  53. package/dist/function/is.js +6 -0
  54. package/dist/function/noop.d.ts +6 -0
  55. package/dist/function/noop.js +5 -0
  56. package/dist/function/noopresolve.d.ts +9 -0
  57. package/dist/function/noopresolve.js +6 -0
  58. package/dist/function/noopreturn.d.ts +8 -0
  59. package/dist/function/noopreturn.js +6 -0
  60. package/dist/function/sleep.d.ts +9 -0
  61. package/dist/function/sleep.js +8 -0
  62. package/dist/hash/fnv1A.d.ts +10 -0
  63. package/dist/hash/fnv1A.js +51 -0
  64. package/dist/hash/guid.d.ts +6 -0
  65. package/{src/hash/guid.mjs → dist/hash/guid.js} +9 -14
  66. package/dist/index.d.ts +358 -0
  67. package/dist/is.d.ts +75 -0
  68. package/dist/is.js +77 -0
  69. package/dist/number/is.d.ts +8 -0
  70. package/dist/number/is.js +6 -0
  71. package/dist/number/isAbove.d.ts +9 -0
  72. package/dist/number/isAbove.js +6 -0
  73. package/dist/number/isAboveOrEqual.d.ts +9 -0
  74. package/dist/number/isAboveOrEqual.js +6 -0
  75. package/dist/number/isBelow.d.ts +9 -0
  76. package/dist/number/isBelow.js +6 -0
  77. package/dist/number/isBelowOrEqual.d.ts +10 -0
  78. package/dist/number/isBelowOrEqual.js +6 -0
  79. package/dist/number/isBetween.d.ts +12 -0
  80. package/dist/number/isBetween.js +11 -0
  81. package/dist/number/isInteger.d.ts +8 -0
  82. package/dist/number/isInteger.js +6 -0
  83. package/dist/number/isIntegerAbove.d.ts +9 -0
  84. package/dist/number/isIntegerAbove.js +6 -0
  85. package/dist/number/isIntegerAboveOrEqual.d.ts +10 -0
  86. package/dist/number/isIntegerAboveOrEqual.js +6 -0
  87. package/dist/number/isIntegerBelow.d.ts +9 -0
  88. package/dist/number/isIntegerBelow.js +6 -0
  89. package/dist/number/isIntegerBelowOrEqual.d.ts +10 -0
  90. package/dist/number/isIntegerBelowOrEqual.js +6 -0
  91. package/dist/number/isIntegerBetween.d.ts +12 -0
  92. package/dist/number/isIntegerBetween.js +11 -0
  93. package/dist/number/isNumericalNaN.d.ts +8 -0
  94. package/dist/number/isNumericalNaN.js +6 -0
  95. package/dist/number/randomBetween.d.ts +9 -0
  96. package/dist/number/randomBetween.js +9 -0
  97. package/dist/number/randomIntBetween.d.ts +10 -0
  98. package/dist/number/randomIntBetween.js +9 -0
  99. package/dist/number/round.d.ts +9 -0
  100. package/dist/number/round.js +10 -0
  101. package/dist/number/toPercentage.d.ts +11 -0
  102. package/dist/number/toPercentage.js +11 -0
  103. package/dist/object/define.d.ts +15 -0
  104. package/dist/object/define.js +9 -0
  105. package/dist/object/is.d.ts +8 -0
  106. package/dist/object/is.js +7 -0
  107. package/dist/object/isNotEmpty.d.ts +8 -0
  108. package/dist/object/isNotEmpty.js +6 -0
  109. package/dist/object/merge.d.ts +18 -0
  110. package/dist/object/merge.js +20 -0
  111. package/dist/object/pick.d.ts +13 -0
  112. package/dist/object/pick.js +34 -0
  113. package/dist/regexp/is.d.ts +8 -0
  114. package/dist/regexp/is.js +6 -0
  115. package/dist/regexp/sanitize.d.ts +11 -0
  116. package/dist/regexp/sanitize.js +8 -0
  117. package/dist/string/humanizeBytes.d.ts +40 -0
  118. package/{src/string/humanizeBytes.mjs → dist/string/humanizeBytes.js} +7 -10
  119. package/dist/string/humanizeNumber.d.ts +52 -0
  120. package/dist/string/humanizeNumber.js +60 -0
  121. package/dist/string/is.d.ts +8 -0
  122. package/dist/string/is.js +6 -0
  123. package/dist/string/isBetween.d.ts +13 -0
  124. package/dist/string/isBetween.js +14 -0
  125. package/dist/string/isNotEmpty.d.ts +9 -0
  126. package/dist/string/isNotEmpty.js +8 -0
  127. package/dist/string/shorten.d.ts +10 -0
  128. package/dist/string/shorten.js +11 -0
  129. package/package.json +112 -46
  130. package/tsconfig.types.json +12 -0
  131. package/tsconfig.types_all.json +12 -0
  132. package/array/dedupe.js +0 -33
  133. package/array/is.js +0 -9
  134. package/array/isNotEmpty.js +0 -9
  135. package/array/join.js +0 -38
  136. package/array/mapFn.js +0 -37
  137. package/array/mapKey.js +0 -36
  138. package/array/mapPrimitive.js +0 -38
  139. package/array/shuffle.js +0 -14
  140. package/array/sort.js +0 -125
  141. package/boolean/is.js +0 -9
  142. package/caching/memoize.js +0 -19
  143. package/date/addUTC.js +0 -60
  144. package/date/diff.js +0 -40
  145. package/date/endOfUTC.js +0 -55
  146. package/date/is.js +0 -9
  147. package/date/nowUnix.js +0 -9
  148. package/date/nowUnixMs.js +0 -9
  149. package/date/startOfUTC.js +0 -55
  150. package/date/toUTC.js +0 -12
  151. package/date/toUnix.js +0 -12
  152. package/deep/define.js +0 -12
  153. package/deep/freeze.js +0 -17
  154. package/deep/get.js +0 -29
  155. package/deep/seal.js +0 -17
  156. package/deep/set.js +0 -26
  157. package/equal.js +0 -35
  158. package/function/is.js +0 -8
  159. package/function/noop.js +0 -7
  160. package/function/noopresolve.js +0 -10
  161. package/function/noopreturn.js +0 -8
  162. package/function/sleep.js +0 -13
  163. package/hash/fnv1A.js +0 -44
  164. package/hash/guid.js +0 -16
  165. package/is.js +0 -319
  166. package/number/is.js +0 -9
  167. package/number/isAbove.js +0 -8
  168. package/number/isAboveOrEqual.js +0 -8
  169. package/number/isBelow.js +0 -8
  170. package/number/isBelowOrEqual.js +0 -8
  171. package/number/isBetween.js +0 -9
  172. package/number/isInteger.js +0 -9
  173. package/number/isIntegerAbove.js +0 -8
  174. package/number/isIntegerAboveOrEqual.js +0 -8
  175. package/number/isIntegerBelow.js +0 -8
  176. package/number/isIntegerBelowOrEqual.js +0 -8
  177. package/number/isIntegerBetween.js +0 -9
  178. package/number/isNumericalNaN.js +0 -9
  179. package/number/randomBetween.js +0 -11
  180. package/number/randomIntBetween.js +0 -11
  181. package/number/round.js +0 -12
  182. package/number/toPercentage.js +0 -15
  183. package/object/define.js +0 -11
  184. package/object/is.js +0 -10
  185. package/object/isNotEmpty.js +0 -9
  186. package/object/merge.js +0 -19
  187. package/object/pick.js +0 -41
  188. package/regexp/is.js +0 -9
  189. package/regexp/sanitize.js +0 -9
  190. package/src/array/dedupe.mjs +0 -24
  191. package/src/array/is.mjs +0 -5
  192. package/src/array/isNotEmpty.mjs +0 -5
  193. package/src/array/join.mjs +0 -29
  194. package/src/array/mapKey.mjs +0 -31
  195. package/src/array/mapPrimitive.mjs +0 -30
  196. package/src/array/shuffle.mjs +0 -14
  197. package/src/array/sort.mjs +0 -101
  198. package/src/boolean/is.mjs +0 -5
  199. package/src/caching/memoize.mjs +0 -22
  200. package/src/date/diff.mjs +0 -46
  201. package/src/date/endOfUTC.mjs +0 -130
  202. package/src/date/is.mjs +0 -5
  203. package/src/date/nowUnix.mjs +0 -5
  204. package/src/date/nowUnixMs.mjs +0 -5
  205. package/src/date/startOfUTC.mjs +0 -129
  206. package/src/date/toUTC.mjs +0 -19
  207. package/src/date/toUnix.mjs +0 -11
  208. package/src/deep/define.mjs +0 -7
  209. package/src/deep/freeze.mjs +0 -20
  210. package/src/deep/get.mjs +0 -52
  211. package/src/deep/seal.mjs +0 -20
  212. package/src/deep/set.mjs +0 -46
  213. package/src/equal.mjs +0 -65
  214. package/src/function/is.mjs +0 -6
  215. package/src/function/noop.mjs +0 -5
  216. package/src/function/noopresolve.mjs +0 -6
  217. package/src/function/noopreturn.mjs +0 -6
  218. package/src/function/sleep.mjs +0 -12
  219. package/src/hash/fnv1A.mjs +0 -53
  220. package/src/is.mjs +0 -86
  221. package/src/number/is.mjs +0 -5
  222. package/src/number/isAbove.mjs +0 -6
  223. package/src/number/isAboveOrEqual.mjs +0 -6
  224. package/src/number/isBelow.mjs +0 -6
  225. package/src/number/isBelowOrEqual.mjs +0 -6
  226. package/src/number/isBetween.mjs +0 -13
  227. package/src/number/isInteger.mjs +0 -5
  228. package/src/number/isIntegerAbove.mjs +0 -6
  229. package/src/number/isIntegerAboveOrEqual.mjs +0 -6
  230. package/src/number/isIntegerBelow.mjs +0 -6
  231. package/src/number/isIntegerBelowOrEqual.mjs +0 -6
  232. package/src/number/isIntegerBetween.mjs +0 -13
  233. package/src/number/isNumericalNaN.mjs +0 -5
  234. package/src/number/randomBetween.mjs +0 -11
  235. package/src/number/randomIntBetween.mjs +0 -11
  236. package/src/number/round.mjs +0 -10
  237. package/src/number/toPercentage.mjs +0 -14
  238. package/src/object/define.mjs +0 -10
  239. package/src/object/is.mjs +0 -7
  240. package/src/object/isNotEmpty.mjs +0 -5
  241. package/src/object/merge.mjs +0 -25
  242. package/src/object/pick.mjs +0 -35
  243. package/src/regexp/is.mjs +0 -5
  244. package/src/regexp/sanitize.mjs +0 -10
  245. package/src/string/humanizeNumber.mjs +0 -82
  246. package/src/string/is.mjs +0 -5
  247. package/src/string/isBetween.mjs +0 -16
  248. package/src/string/isNotEmpty.mjs +0 -6
  249. package/src/string/shorten.mjs +0 -20
  250. package/string/humanizeBytes.js +0 -21
  251. package/string/humanizeNumber.js +0 -54
  252. package/string/is.js +0 -9
  253. package/string/isBetween.js +0 -11
  254. package/string/isNotEmpty.js +0 -11
  255. package/string/shorten.js +0 -11
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_1 = require("./is");
4
+ const SECOND_IN_MILLISECONDS = 1000;
5
+ const MINUTE_IN_MILLISECONDS = SECOND_IN_MILLISECONDS * 60;
6
+ const HOUR_IN_MILLISECONDS = MINUTE_IN_MILLISECONDS * 60;
7
+ const DAY_IN_MILLISECONDS = HOUR_IN_MILLISECONDS * 24;
8
+ const WEEK_IN_MILLISECONDS = DAY_IN_MILLISECONDS * 7;
9
+ function diff(val_a, val_b, key = 'millisecond') {
10
+ if (!(0, is_1.default)(val_a) ||
11
+ !(0, is_1.default)(val_b))
12
+ throw new TypeError('Diff requires date objects for both values');
13
+ if (typeof key !== 'string')
14
+ throw new TypeError('Key needs to be a string');
15
+ const diff_in_ms = val_a.valueOf() - val_b.valueOf();
16
+ switch (key) {
17
+ case 'week':
18
+ case 'weeks':
19
+ return diff_in_ms / WEEK_IN_MILLISECONDS;
20
+ case 'day':
21
+ case 'days':
22
+ return diff_in_ms / DAY_IN_MILLISECONDS;
23
+ case 'hour':
24
+ case 'hours':
25
+ return diff_in_ms / HOUR_IN_MILLISECONDS;
26
+ case 'minute':
27
+ case 'minutes':
28
+ return diff_in_ms / MINUTE_IN_MILLISECONDS;
29
+ case 'second':
30
+ case 'seconds':
31
+ return diff_in_ms / SECOND_IN_MILLISECONDS;
32
+ case 'millisecond':
33
+ case 'milliseconds':
34
+ default:
35
+ return diff_in_ms;
36
+ }
37
+ }
38
+ exports.default = diff;
@@ -0,0 +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
+ */
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;
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_1 = require("./is");
4
+ const WEEK_END = {
5
+ week: 0,
6
+ week_sun: 6,
7
+ week_mon: 0,
8
+ week_tue: 1,
9
+ week_wed: 2,
10
+ week_thu: 3,
11
+ week_fri: 4,
12
+ week_sat: 5,
13
+ };
14
+ function endOfUTC(val, key = 'millisecond') {
15
+ if (!(0, is_1.default)(val))
16
+ throw new TypeError('endOfUTC requires a date object');
17
+ if (typeof key !== 'string')
18
+ throw new TypeError('Key needs to be a string with content');
19
+ switch (key) {
20
+ case 'year':
21
+ return new Date(Date.UTC(val.getUTCFullYear(), 11, 31, 23, 59, 59, 999));
22
+ case 'quarter': {
23
+ return new Date(Date.UTC(val.getUTCFullYear(), (val.getUTCMonth() - (val.getUTCMonth() % 3)) + 3, 0, 23, 59, 59, 999));
24
+ }
25
+ case 'month':
26
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth() + 1, 0, 23, 59, 59, 999));
27
+ case 'week':
28
+ case 'week_sun':
29
+ case 'week_mon':
30
+ case 'week_tue':
31
+ case 'week_wed':
32
+ case 'week_thu':
33
+ case 'week_fri':
34
+ case 'week_sat': {
35
+ const UTC_DAY = val.getUTCDay();
36
+ const UTC_EOD = WEEK_END[key];
37
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate() + (UTC_DAY <= UTC_EOD ? UTC_EOD - UTC_DAY : (7 - UTC_DAY) + UTC_EOD), 23, 59, 59, 999));
38
+ }
39
+ case 'day':
40
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), 23, 59, 59, 999));
41
+ case 'hour':
42
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), 59, 59, 999));
43
+ case 'minute':
44
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), 59, 999));
45
+ case 'second':
46
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), 999));
47
+ case 'millisecond':
48
+ default:
49
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), val.getUTCMilliseconds()));
50
+ }
51
+ }
52
+ exports.default = endOfUTC;
@@ -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
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isDate(val) {
4
+ return Object.prototype.toString.call(val) === '[object Date]' && !isNaN(val);
5
+ }
6
+ exports.default = isDate;
@@ -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
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function nowUnix() {
4
+ return Math.floor(Date.now() / 1000);
5
+ }
6
+ exports.default = nowUnix;
@@ -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;
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function nowUnixMs() {
4
+ return Math.floor(Date.now());
5
+ }
6
+ exports.default = nowUnixMs;
@@ -0,0 +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
+ */
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,52 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_1 = require("./is");
4
+ const WEEK_START = {
5
+ week: 1,
6
+ week_sun: 0,
7
+ week_mon: 1,
8
+ week_tue: 2,
9
+ week_wed: 3,
10
+ week_thu: 4,
11
+ week_fri: 5,
12
+ week_sat: 6,
13
+ };
14
+ function startOfUTC(val, key = 'millisecond') {
15
+ if (!(0, is_1.default)(val))
16
+ throw new TypeError('startOfUTC requires a date object');
17
+ if (typeof key !== 'string')
18
+ throw new TypeError('Key needs to be a string with content');
19
+ switch (key) {
20
+ case 'year':
21
+ return new Date(Date.UTC(val.getUTCFullYear(), 0, 1, 0, 0, 0, 0));
22
+ case 'quarter': {
23
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth() - (val.getUTCMonth() % 3), 1, 0, 0, 0, 0));
24
+ }
25
+ case 'month':
26
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), 1, 0, 0, 0, 0));
27
+ case 'week':
28
+ case 'week_sun':
29
+ case 'week_mon':
30
+ case 'week_tue':
31
+ case 'week_wed':
32
+ case 'week_thu':
33
+ case 'week_fri':
34
+ case 'week_sat': {
35
+ const UTC_DAY = val.getUTCDay();
36
+ const UTC_SOD = WEEK_START[key];
37
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate() - (UTC_DAY < UTC_SOD ? (7 - UTC_SOD) + UTC_DAY : UTC_DAY - UTC_SOD), 0, 0, 0, 0));
38
+ }
39
+ case 'day':
40
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), 0, 0, 0, 0));
41
+ case 'hour':
42
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), 0, 0, 0));
43
+ case 'minute':
44
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), 0, 0));
45
+ case 'second':
46
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), 0));
47
+ case 'millisecond':
48
+ default:
49
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), val.getUTCMilliseconds()));
50
+ }
51
+ }
52
+ exports.default = startOfUTC;
@@ -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,9 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_1 = require("./is");
4
+ function toUTC(val) {
5
+ if (!(0, is_1.default)(val))
6
+ throw new TypeError('toUTC requires a date object');
7
+ return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), val.getUTCMilliseconds()));
8
+ }
9
+ exports.default = toUTC;
@@ -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;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const is_1 = require("./is");
4
+ function toUnix(val) {
5
+ if (!(0, is_1.default)(val))
6
+ throw new TypeError('toUnix requires a date object');
7
+ return Math.floor(val.valueOf() / 1000);
8
+ }
9
+ exports.default = toUnix;
@@ -0,0 +1,14 @@
1
+ type deepInput = {
2
+ [key: string]: any;
3
+ } | {
4
+ [key: string]: any;
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
+ */
13
+ export default function deepFreeze(obj: deepInput): Readonly<deepInput>;
14
+ export {};
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function deep(obj) {
4
+ if (Array.isArray(obj)) {
5
+ for (const el of obj)
6
+ deep(el);
7
+ }
8
+ else {
9
+ for (const key of Object.keys(obj)) {
10
+ if (Object.prototype.toString.call(obj[key]) === '[object Object]' ||
11
+ Array.isArray(obj[key]))
12
+ deep(obj[key]);
13
+ }
14
+ }
15
+ return Object.freeze(obj);
16
+ }
17
+ function deepFreeze(obj) {
18
+ if (Object.prototype.toString.call(obj) !== '[object Object]' &&
19
+ !Array.isArray(obj))
20
+ throw new TypeError('Only objects/arrays can be frozen');
21
+ return deep(obj);
22
+ }
23
+ exports.default = deepFreeze;
@@ -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;
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function deepGet(obj, path, get_parent = false) {
4
+ if (Object.prototype.toString.call(obj) !== '[object Object]' &&
5
+ !Array.isArray(obj))
6
+ throw new TypeError('Deepget is only supported for objects');
7
+ if (typeof path !== 'string')
8
+ throw new TypeError('No path was given');
9
+ const path_s = path.trim();
10
+ if (path_s.length === 0)
11
+ throw new TypeError('No path was given');
12
+ const parts = path_s
13
+ .replace(/\[/g, '.')
14
+ .replace(/(\.){2,}/g, '.')
15
+ .replace(/(^\.|\.$|\])/g, '')
16
+ .split('.');
17
+ if (parts.length === 0 || (parts.length === 1 && get_parent))
18
+ return obj;
19
+ if (get_parent)
20
+ parts.pop();
21
+ let cursor = obj;
22
+ while (parts.length > 0) {
23
+ if (Array.isArray(cursor)) {
24
+ const ix = parseInt(parts.shift());
25
+ if (!Number.isInteger(ix) || ix < 0 || ix > (cursor.length - 1))
26
+ return undefined;
27
+ cursor = cursor[ix];
28
+ }
29
+ else if (Object.prototype.toString.call(cursor) === '[object Object]') {
30
+ const key = parts.shift();
31
+ if (!Object.prototype.hasOwnProperty.call(cursor, key))
32
+ return undefined;
33
+ cursor = cursor[key];
34
+ }
35
+ if ((!Array.isArray(cursor) && Object.prototype.toString.call(cursor) !== '[object Object]') &&
36
+ parts.length > 0)
37
+ return undefined;
38
+ }
39
+ return cursor;
40
+ }
41
+ exports.default = deepGet;
@@ -0,0 +1,14 @@
1
+ type deepInput = {
2
+ [key: string]: any;
3
+ } | {
4
+ [key: string]: any;
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
+ */
13
+ export default function deepSeal(obj: deepInput): deepInput;
14
+ export {};
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function deep(obj) {
4
+ if (Array.isArray(obj)) {
5
+ for (const el of obj)
6
+ deep(el);
7
+ }
8
+ else {
9
+ for (const key of Object.keys(obj)) {
10
+ if (Object.prototype.toString.call(obj[key]) === '[object Object]' ||
11
+ Array.isArray(obj[key]))
12
+ deep(obj[key]);
13
+ }
14
+ }
15
+ return Object.seal(obj);
16
+ }
17
+ function deepSeal(obj) {
18
+ if (Object.prototype.toString.call(obj) !== '[object Object]' &&
19
+ !Array.isArray(obj))
20
+ throw new TypeError('Only objects/arrays can be sealed');
21
+ return deep(obj);
22
+ }
23
+ exports.default = deepSeal;
@@ -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;
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function deepSet(obj, path, value, define = false) {
4
+ if (Object.prototype.toString.call(obj) !== '[object Object]' &&
5
+ !Array.isArray(obj))
6
+ throw new TypeError('Deepset is only supported for objects');
7
+ if (typeof path !== 'string')
8
+ throw new TypeError('No path was given');
9
+ if (/__proto__|constructor|prototype/.test(path))
10
+ throw new TypeError('Malicious path provided');
11
+ const path_s = path.trim();
12
+ if (path_s.length === 0)
13
+ throw new TypeError('No path was given');
14
+ const parts = path_s
15
+ .replace(/\[/g, '.')
16
+ .replace(/(\.){2,}/g, '.')
17
+ .replace(/(^\.|\.$|\])/g, '')
18
+ .split('.');
19
+ for (let i = 0; i < parts.length - 1; i++) {
20
+ if (parts[i] === '')
21
+ continue;
22
+ if (Array.isArray(obj)) {
23
+ const idx = parseInt(parts[i]);
24
+ if (!Number.isInteger(idx) || idx < 0)
25
+ throw new TypeError('Invalid path provided');
26
+ if (!obj[idx])
27
+ obj[idx] = {};
28
+ obj = obj[idx];
29
+ }
30
+ else {
31
+ if (!obj[parts[i]])
32
+ obj[parts[i]] = {};
33
+ obj = obj[parts[i]];
34
+ }
35
+ }
36
+ if (!Array.isArray(obj) && Object.prototype.toString.call(obj) !== '[object Object]')
37
+ return false;
38
+ if (define) {
39
+ Object.defineProperty(obj, parts[parts.length - 1], value);
40
+ }
41
+ else if (Array.isArray(obj)) {
42
+ const idx = parseInt(parts[parts.length - 1]);
43
+ if (!Number.isInteger(idx) || idx < 0)
44
+ throw new TypeError('Invalid path provided');
45
+ obj[idx] = value;
46
+ }
47
+ else {
48
+ obj[parts[parts.length - 1]] = value;
49
+ }
50
+ return true;
51
+ }
52
+ exports.default = deepSet;
@@ -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;
package/dist/equal.js ADDED
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const isNumericalNaN_1 = require("./number/isNumericalNaN");
4
+ function isArrayEqual(a, b) {
5
+ if (a.length !== b.length)
6
+ return false;
7
+ for (let i = a.length - 1; i >= 0; i--) {
8
+ if (equal(a[i], b[i]))
9
+ continue;
10
+ return false;
11
+ }
12
+ return true;
13
+ }
14
+ function isObjectEqual(a, b) {
15
+ const keys_a = Object.keys(a);
16
+ if (keys_a.length !== Object.keys(b).length)
17
+ return false;
18
+ for (let i = keys_a.length - 1; i >= 0; i--) {
19
+ if (equal(a[keys_a[i]], b[keys_a[i]]))
20
+ continue;
21
+ return false;
22
+ }
23
+ return true;
24
+ }
25
+ function equal(a, b) {
26
+ if (a instanceof Date &&
27
+ b instanceof Date)
28
+ return a.valueOf() === b.valueOf();
29
+ if (Object.prototype.toString.call(a) === '[object RegExp]' &&
30
+ Object.prototype.toString.call(b) === '[object RegExp]')
31
+ return String(a) === String(b);
32
+ if (Array.isArray(a) &&
33
+ Array.isArray(b))
34
+ return isArrayEqual(a, b);
35
+ if (Object.prototype.toString.call(a) === '[object Object]' &&
36
+ Object.prototype.toString.call(b) === '[object Object]')
37
+ return isObjectEqual(a, b);
38
+ if ((0, isNumericalNaN_1.default)(a)) {
39
+ return (0, isNumericalNaN_1.default)(b);
40
+ }
41
+ return a === b;
42
+ }
43
+ exports.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
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isFunction(val) {
4
+ return typeof val === 'function';
5
+ }
6
+ exports.default = isFunction;
@@ -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,5 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function noop() {
4
+ }
5
+ exports.default = noop;
@@ -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,6 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function noopresolve(val) {
4
+ return new Promise(resolve => resolve(val));
5
+ }
6
+ exports.default = noopresolve;
@@ -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,6 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function noopreturn(val) {
4
+ return val;
5
+ }
6
+ exports.default = noopreturn;
@@ -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,8 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function sleep(ms = 1000) {
4
+ return new Promise(resolve => {
5
+ setTimeout(() => resolve(), Number.isFinite(ms) && ms > 0 ? Math.round(ms) : 0);
6
+ });
7
+ }
8
+ exports.default = sleep;
@@ -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;