@valkyriestudios/utils 12.19.0 → 12.21.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 (91) hide show
  1. package/README.md +384 -161
  2. package/array/dedupe.d.ts +0 -2
  3. package/array/groupBy.d.ts +0 -1
  4. package/array/is.d.ts +1 -3
  5. package/array/isNotEmpty.d.ts +1 -3
  6. package/array/join.d.ts +0 -2
  7. package/array/join.js +3 -2
  8. package/array/mapFn.js +1 -1
  9. package/array/mapPrimitive.d.ts +0 -2
  10. package/array/sort.d.ts +0 -2
  11. package/array/split.d.ts +0 -2
  12. package/boolean/is.d.ts +1 -3
  13. package/date/addUTC.d.ts +5 -6
  14. package/date/diff.d.ts +5 -6
  15. package/date/endOfUTC.d.ts +4 -5
  16. package/date/format.d.ts +16 -2
  17. package/date/format.js +175 -73
  18. package/date/index.d.ts +3 -1
  19. package/date/index.js +6 -1
  20. package/date/is.d.ts +1 -3
  21. package/date/isFormat.d.ts +11 -0
  22. package/date/isFormat.js +110 -0
  23. package/date/isLeap.d.ts +7 -0
  24. package/date/isLeap.js +11 -0
  25. package/date/nowUnix.d.ts +0 -2
  26. package/date/nowUnixMs.d.ts +0 -2
  27. package/date/setTimeUTC.d.ts +1 -2
  28. package/date/startOfUTC.d.ts +4 -5
  29. package/date/toUTC.d.ts +1 -3
  30. package/date/toUnix.d.ts +1 -3
  31. package/deep/freeze.d.ts +1 -3
  32. package/deep/get.d.ts +5 -7
  33. package/deep/seal.d.ts +1 -3
  34. package/deep/set.d.ts +0 -1
  35. package/equal.d.ts +2 -4
  36. package/formdata/index.d.ts +2 -1
  37. package/formdata/index.js +3 -1
  38. package/formdata/is.d.ts +1 -3
  39. package/formdata/toObject.d.ts +16 -0
  40. package/formdata/toObject.js +23 -0
  41. package/function/is.d.ts +1 -3
  42. package/function/isAsync.d.ts +1 -3
  43. package/function/noop.d.ts +0 -2
  44. package/function/noop.js +1 -2
  45. package/function/noopresolve.d.ts +0 -2
  46. package/function/noopreturn.d.ts +0 -2
  47. package/function/sleep.d.ts +1 -3
  48. package/hash/fnv1A.d.ts +2 -4
  49. package/hash/fnv1A.js +2 -2
  50. package/hash/guid.d.ts +0 -2
  51. package/index.d.ts +41 -10
  52. package/number/is.d.ts +1 -3
  53. package/number/isAbove.d.ts +2 -4
  54. package/number/isAboveOrEqual.d.ts +2 -4
  55. package/number/isBelow.d.ts +2 -4
  56. package/number/isBelowOrEqual.d.ts +2 -4
  57. package/number/isBetween.d.ts +3 -5
  58. package/number/isBetween.js +4 -6
  59. package/number/isInteger.d.ts +1 -3
  60. package/number/isIntegerAbove.d.ts +2 -4
  61. package/number/isIntegerAboveOrEqual.d.ts +2 -4
  62. package/number/isIntegerBelow.d.ts +2 -4
  63. package/number/isIntegerBelowOrEqual.d.ts +2 -4
  64. package/number/isIntegerBetween.d.ts +3 -5
  65. package/number/isIntegerBetween.js +4 -6
  66. package/number/isNumericalNaN.d.ts +1 -3
  67. package/number/randomBetween.d.ts +2 -4
  68. package/number/randomIntBetween.d.ts +2 -4
  69. package/number/round.d.ts +2 -4
  70. package/number/round.js +5 -3
  71. package/number/toPercentage.d.ts +4 -6
  72. package/object/define.d.ts +0 -2
  73. package/object/is.d.ts +1 -3
  74. package/object/isNotEmpty.d.ts +2 -6
  75. package/object/merge.d.ts +2 -4
  76. package/object/merge.js +2 -3
  77. package/object/pick.d.ts +0 -2
  78. package/object/pick.js +2 -3
  79. package/package.json +1 -1
  80. package/regexp/is.d.ts +1 -3
  81. package/regexp/sanitize.d.ts +1 -3
  82. package/regexp/sanitize.js +2 -1
  83. package/string/humanizeBytes.d.ts +1 -3
  84. package/string/humanizeBytes.js +5 -11
  85. package/string/humanizeNumber.d.ts +2 -4
  86. package/string/humanizeNumber.js +13 -15
  87. package/string/is.d.ts +1 -3
  88. package/string/isBetween.d.ts +4 -6
  89. package/string/isNotEmpty.d.ts +2 -4
  90. package/string/shorten.d.ts +0 -2
  91. package/string/shorten.js +1 -4
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDateFormat = isDateFormat;
4
+ exports.default = isDateFormat;
5
+ const SPECIAL_CHARS = /[.*+?^${}()|[\]\\]/g;
6
+ const TOKENS = [
7
+ ['YYYY', /\d{4}/.source, (raw, context) => {
8
+ context.year = parseInt(raw, 10);
9
+ return context.year > 0;
10
+ }],
11
+ ['MM', /(?:0[1-9]|1[0-2])/.source, (raw, context) => {
12
+ context.month = parseInt(raw, 10);
13
+ return context.month >= 1 && context.month <= 12;
14
+ }],
15
+ ['DD', /(?:0[1-9]|[12][0-9]|3[01])/.source, (raw, context) => {
16
+ context.day = parseInt(raw, 10);
17
+ return context.day >= 1 && context.day <= 31;
18
+ }],
19
+ ['HH', /(?:[01][0-9]|2[0-3])/.source, (raw, context) => {
20
+ context.hour = parseInt(raw, 10);
21
+ return context.hour >= 0 && context.hour <= 23;
22
+ }],
23
+ ['mm', /[0-5][0-9]/.source, () => true],
24
+ ['ss', /[0-5][0-9]/.source, () => true],
25
+ ['SSS', /\d{3}/.source, () => true],
26
+ ['Q', /[1-4]/.source, () => true],
27
+ ['A', /(?:AM|PM)/.source, (raw, context) => {
28
+ context.is12 = 1;
29
+ return raw === 'AM' || raw === 'PM';
30
+ }],
31
+ ['a', /(?:am|pm)/.source, (raw, context) => {
32
+ context.is12 = 1;
33
+ return raw === 'am' || raw === 'pm';
34
+ }],
35
+ ['Z', /Z|[+-](?:0[0-9]|1[0-4]):[0-5][0-9]/.source, raw => {
36
+ if (raw === 'Z')
37
+ return true;
38
+ let hour = parseInt(raw[1] + raw[2], 10);
39
+ if (raw[0] === '-')
40
+ hour = -hour;
41
+ const minutes = parseInt(raw[4] + raw[5], 10);
42
+ if (hour === 14 || hour === -12)
43
+ return minutes === 0;
44
+ return hour >= -11 && hour < 14 && [0, 15, 30, 45].indexOf(minutes) >= 0;
45
+ }],
46
+ ];
47
+ const SPEC_ALIASES = {
48
+ ISO: 'YYYY-MM-DDTHH:mm:ss.SSSZ',
49
+ };
50
+ const spec_pat_cache = {};
51
+ function compileSpec(spec) {
52
+ if (spec in spec_pat_cache)
53
+ return spec_pat_cache[spec];
54
+ const tokens = [];
55
+ let pat = '';
56
+ let cursor = 0;
57
+ while (cursor < spec.length) {
58
+ if (spec[cursor] === '[') {
59
+ const end_idx = spec.indexOf(']', cursor);
60
+ if (end_idx === -1)
61
+ throw new Error('isDateFormat: Unmatched [ in format string');
62
+ pat += spec.slice(cursor + 1, end_idx).replace(SPECIAL_CHARS, '\\$&');
63
+ cursor = end_idx + 1;
64
+ }
65
+ else {
66
+ const token_idx = TOKENS.findIndex(([token_key]) => spec.startsWith(token_key, cursor));
67
+ if (token_idx >= 0) {
68
+ const [token_key, token_rgx] = TOKENS[token_idx];
69
+ pat += '(' + token_rgx + ')';
70
+ tokens.push(token_idx);
71
+ cursor += token_key.length;
72
+ }
73
+ else {
74
+ pat += spec[cursor].replace(SPECIAL_CHARS, '\\$&');
75
+ cursor++;
76
+ }
77
+ }
78
+ }
79
+ spec_pat_cache[spec] = { rgx: RegExp('^' + pat + '$'), tokens };
80
+ return spec_pat_cache[spec];
81
+ }
82
+ function isDateFormat(input, spec) {
83
+ if (typeof input !== 'string' || input.trim().length === 0) {
84
+ throw new TypeError('isDateFormat: input must be a non-empty string');
85
+ }
86
+ if (typeof spec !== 'string') {
87
+ throw new TypeError('isDateFormat: spec must be a string');
88
+ }
89
+ const { tokens, rgx } = compileSpec(SPEC_ALIASES[spec] || spec);
90
+ if (!tokens.length)
91
+ return false;
92
+ const patMatch = rgx.exec(input);
93
+ if (!patMatch)
94
+ return false;
95
+ const matches = patMatch.slice(1);
96
+ const context = {};
97
+ for (let i = 0; i < matches.length; i++) {
98
+ if (!TOKENS[tokens[i]][2](matches[i], context))
99
+ return false;
100
+ }
101
+ const { is12, day, month, year } = context;
102
+ if (day && month) {
103
+ const date = new Date(year || 2024, month - 1, day);
104
+ if (date.getDate() !== day || date.getMonth() !== month - 1)
105
+ return false;
106
+ }
107
+ if (is12 && 'hour' in context && context.hour > 11)
108
+ return false;
109
+ return true;
110
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Check whether or not a provided value is a leap year
3
+ *
4
+ * @param {Date} val - Value to verify
5
+ */
6
+ declare function isLeap(val: Date): boolean;
7
+ export { isLeap, isLeap as default };
package/date/isLeap.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLeap = isLeap;
4
+ exports.default = isLeap;
5
+ const is_1 = require("./is");
6
+ function isLeap(val) {
7
+ if (!(0, is_1.isDate)(val))
8
+ return false;
9
+ const year = val.getUTCFullYear();
10
+ return (((year % 4) === 0) && ((year % 100) !== 0)) || ((year % 400) === 0);
11
+ }
package/date/nowUnix.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  /**
2
2
  * Compute the current unix timestamp in seconds
3
- *
4
- * @returns Current unix timestamp in seconds
5
3
  */
6
4
  declare function nowUnix(): number;
7
5
  export { nowUnix, nowUnix as default };
@@ -1,7 +1,5 @@
1
1
  /**
2
2
  * Compute the current unix timestamp in milliseconds
3
- *
4
- * @returns Current unix timestamp in milliseconds
5
3
  */
6
4
  declare function nowUnixMs(): number;
7
5
  export { nowUnixMs, nowUnixMs as default };
@@ -8,8 +8,7 @@ export type TimeProps = {
8
8
  * Sets the time on a provided date object and returns it
9
9
  *
10
10
  * @param {Date} val - Date to set the time for
11
- * @param {Time} props - Time props to set the time to
12
- * @returns {Date} New date with provided amount of key added
11
+ * @param {TimeProps} props - Time props to set the time to
13
12
  */
14
13
  declare function setTimeUTC(val: Date, props: TimeProps): Date;
15
14
  export { setTimeUTC, setTimeUTC as default };
@@ -1,10 +1,9 @@
1
+ export type StartOfUTCKey = 'year' | 'quarter' | 'month' | 'week' | 'week_sun' | 'week_mon' | 'week_tue' | 'week_wed' | 'week_thu' | 'week_fri' | 'week_sat' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
1
2
  /**
2
3
  * Sets the provided date to start of UTC of provided key
3
4
  *
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
5
+ * @param {Date} val - Date to set to start of
6
+ * @param {StartOfUTCKey} key - (default='millisecond') Key to set
8
7
  */
9
- declare 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;
8
+ declare function startOfUTC(val: Date, key?: StartOfUTCKey): Date;
10
9
  export { startOfUTC, startOfUTC as default };
package/date/toUTC.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Sets a passed date to UTC
3
3
  *
4
- * @param val - Date to set to UTC
5
- *
6
- * @returns New date object set to the UTC contents of the passed date
4
+ * @param {Date} val - Date to set to UTC
7
5
  */
8
6
  declare function toUTC(val: Date): Date;
9
7
  export { toUTC, toUTC as default };
package/date/toUnix.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Returns the unix time in seconds of the passed date
3
3
  *
4
- * @param val - Date to get the unix time for
5
- *
6
- * @returns Unix time in seconds
4
+ * @param {Date} val - Date to get the unix time for
7
5
  */
8
6
  declare function toUnix(val: Date): number;
9
7
  export { toUnix, toUnix as default };
package/deep/freeze.d.ts CHANGED
@@ -9,9 +9,7 @@ type Frozen<T> = {
9
9
  /**
10
10
  * Recursively freezes all properties of an object
11
11
  *
12
- * @param obj - Object to deep freeze
13
- *
14
- * @returns Deeply frozen object
12
+ * @param {deepInput} obj - Object to deep freeze
15
13
  */
16
14
  declare function deepFreeze<T extends deepInput>(obj: T): Frozen<T>;
17
15
  export { deepFreeze, deepFreeze as default };
package/deep/get.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ type ObjectType = {
2
+ [key: string]: any;
3
+ };
4
+ type ArrayType = any[];
5
+ type DeepGetResult<T extends ObjectType | ArrayType, P extends string> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? T[Key] extends ObjectType | ArrayType ? DeepGetResult<T[Key], Rest> : undefined : T extends ArrayType ? number extends keyof T ? DeepGetResult<T[number], Rest> : undefined : undefined : P extends `${infer Key}[${infer Index}]` ? Key extends keyof T ? T[Key] extends ArrayType ? Index extends `${number}` ? DeepGetResult<T[Key][number], ''> : undefined : undefined : T extends ArrayType ? number extends keyof T ? DeepGetResult<T[number], `[${Index}]`> : undefined : undefined : P extends keyof T ? T[P] : T extends ArrayType ? number extends keyof T ? T[number] : undefined : undefined;
1
6
  /**
2
7
  * Get a property's value deep inside the structure of an array/object
3
8
  *
@@ -16,14 +21,7 @@
16
21
  * @param val - Object/Array to get the value from
17
22
  * @param path - Path string to deeply get the value at
18
23
  * @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
24
  * @throws {TypeError}
22
25
  */
23
- type ObjectType = {
24
- [key: string]: any;
25
- };
26
- type ArrayType = any[];
27
- type DeepGetResult<T extends ObjectType | ArrayType, P extends string> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? T[Key] extends ObjectType | ArrayType ? DeepGetResult<T[Key], Rest> : undefined : T extends ArrayType ? number extends keyof T ? DeepGetResult<T[number], Rest> : undefined : undefined : P extends `${infer Key}[${infer Index}]` ? Key extends keyof T ? T[Key] extends ArrayType ? Index extends `${number}` ? DeepGetResult<T[Key][number], ''> : undefined : undefined : T extends ArrayType ? number extends keyof T ? DeepGetResult<T[number], `[${Index}]`> : undefined : undefined : P extends keyof T ? T[P] : T extends ArrayType ? number extends keyof T ? T[number] : undefined : undefined;
28
26
  declare function deepGet<T extends ObjectType | ArrayType, P extends string>(obj: T, path: P, get_parent?: boolean): DeepGetResult<T, P> | undefined;
29
27
  export { deepGet, deepGet as default };
package/deep/seal.d.ts CHANGED
@@ -9,9 +9,7 @@ type Sealed<T> = {
9
9
  /**
10
10
  * Recursively seals all properties of an object
11
11
  *
12
- * @param obj - Object to deep seal
13
- *
14
- * @returns Deeply sealed object
12
+ * @param {deepInput} obj - Object to deep seal
15
13
  */
16
14
  declare function deepSeal<T extends deepInput>(obj: T): Sealed<T>;
17
15
  export { deepSeal, deepSeal as default };
package/deep/set.d.ts CHANGED
@@ -31,7 +31,6 @@
31
31
  * @param path - Path string to deeply set the value at
32
32
  * @param value - Value to set (if using defineProperty can be an accessor object)
33
33
  * @param define - Whether or not the property should be directly assigned or set using Object.defineProperty
34
- *
35
34
  * @returns True or false depending on whether or not the property was set correctly
36
35
  * @throws {TypeError}
37
36
  */
package/equal.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Compute whether or not two provided values are deeply equal
3
3
  *
4
- * @param a - Value to compare against
5
- * @param b - Value to compare with
6
- *
7
- * @returns Whether or not they are equal
4
+ * @param {any} a - Value to compare against
5
+ * @param {any} b - Value to compare with
8
6
  */
9
7
  declare function equal(a: any, b: any): boolean;
10
8
  export { equal, equal as default };
@@ -1,2 +1,3 @@
1
1
  import { isFormData } from './is';
2
- export { isFormData, isFormData as is };
2
+ import { toObject } from './toObject';
3
+ export { isFormData, isFormData as is, toObject };
package/formdata/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.is = exports.isFormData = void 0;
3
+ exports.toObject = exports.is = exports.isFormData = void 0;
4
4
  const is_1 = require("./is");
5
5
  Object.defineProperty(exports, "isFormData", { enumerable: true, get: function () { return is_1.isFormData; } });
6
6
  Object.defineProperty(exports, "is", { enumerable: true, get: function () { return is_1.isFormData; } });
7
+ const toObject_1 = require("./toObject");
8
+ Object.defineProperty(exports, "toObject", { enumerable: true, get: function () { return toObject_1.toObject; } });
package/formdata/is.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Check whether or not a provided value is an instance of FormData
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is an instance of FormData
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isFormData(val: unknown): val is FormData;
9
7
  export { isFormData, isFormData as default };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Converts a FormData instance to a json object
3
+ * Eg:
4
+ * const form = new FormData();
5
+ * form.append('name', 'Alice');
6
+ * form.append('hobbies', 'reading');
7
+ * form.append('hobbies', 'writing');
8
+ * form.append('emptyField', '');
9
+ * toObject(form);
10
+ *
11
+ * {name: 'Alice', hobbies: ['reading', 'writing'], emptyField: ''}
12
+ *
13
+ * @param {FormData} val - FormData instance to convert to an object
14
+ */
15
+ declare function toObject<T extends Record<string, unknown>>(form: FormData): T;
16
+ export { toObject, toObject as default };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toObject = toObject;
4
+ exports.default = toObject;
5
+ function toObject(form) {
6
+ if (!(form instanceof FormData))
7
+ throw new Error('formdata/toObject: Value is not an instance of FormData');
8
+ const acc = {};
9
+ form.forEach((value, key) => {
10
+ if (acc[key] !== undefined) {
11
+ if (Array.isArray(acc[key])) {
12
+ acc[key].push(value);
13
+ }
14
+ else {
15
+ acc[key] = [acc[key], value];
16
+ }
17
+ }
18
+ else {
19
+ acc[key] = value;
20
+ }
21
+ });
22
+ return acc;
23
+ }
package/function/is.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Check whether or not a provided value is a Function
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is a Function
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isFunction(val: unknown): val is (...args: unknown[]) => unknown;
9
7
  export { isFunction, isFunction as default };
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Chceck whether or not a provided value is an async function
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is an async function
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isAsyncFunction(val: unknown): val is (...args: unknown[]) => Promise<unknown>;
9
7
  export { isAsyncFunction, isAsyncFunction as default };
@@ -1,7 +1,5 @@
1
1
  /**
2
2
  * No-Operation (noop) function that does nothing and simply returns.
3
- *
4
- * @returns Void
5
3
  */
6
4
  declare function noop(): void;
7
5
  export { noop, noop as default };
package/function/noop.js CHANGED
@@ -2,5 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.noop = noop;
4
4
  exports.default = noop;
5
- function noop() {
6
- }
5
+ function noop() { }
@@ -3,8 +3,6 @@
3
3
  * that resolves with the value that was passed to it
4
4
  *
5
5
  * @param val - Value to be resolved with
6
- *
7
- * @returns Promise that resolves with passed value
8
6
  */
9
7
  declare function noopresolve<T>(val?: T): Promise<T | undefined>;
10
8
  export { noopresolve, noopresolve as default };
@@ -2,8 +2,6 @@
2
2
  * No-Operation (noop) function that returns the value passed to it when called.
3
3
  *
4
4
  * @param val - Value to return
5
- *
6
- * @returns Passed value
7
5
  */
8
6
  declare function noopreturn<T>(val?: T): T | undefined;
9
7
  export { noopreturn, noopreturn as default };
@@ -2,9 +2,7 @@
2
2
  * Returns a promise that resolves after X milliseconds, useful in
3
3
  * async scenarios where we wish to wait for a specific periodic of time
4
4
  *
5
- * @param ms - (default=1000) Amount of milliseconds to wait for
6
- *
7
- * @returns Promise that resolves after X milliseconds
5
+ * @param {number} ms - (default=1000) Amount of milliseconds to wait for
8
6
  */
9
7
  declare function sleep(ms?: number): Promise<void>;
10
8
  export { sleep, sleep as default };
package/hash/fnv1A.d.ts CHANGED
@@ -2,10 +2,8 @@
2
2
  * Convert a provided value into a Fowler-Noll-Vo 1A hash
3
3
  * For more info: https://tools.ietf.org/html/draft-eastlake-fnv-03
4
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
5
+ * @param {unknown} data - Value to be converted
6
+ * @param {number} offset - (default=2166136261) FNV prime to use
9
7
  */
10
8
  declare function fnv1A(data: unknown, offset?: number): number;
11
9
  export { fnv1A, fnv1A as default };
package/hash/fnv1A.js CHANGED
@@ -28,11 +28,11 @@ function fnv1A(data, offset = FNV_32) {
28
28
  if (data === null) {
29
29
  sanitized = REPL_NULL;
30
30
  }
31
- else if (Array.isArray(data) || data.toString() === '[object Object]') {
31
+ else if (Array.isArray(data) || Object.prototype.toString.call(data) === '[object Object]') {
32
32
  sanitized = JSON.stringify(data);
33
33
  }
34
34
  else if (data instanceof RegExp) {
35
- sanitized = data.toString();
35
+ sanitized = String(data);
36
36
  }
37
37
  else if (data instanceof Date) {
38
38
  sanitized = String(data.getTime());
package/hash/guid.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  /**
2
2
  * Generate a unique identifier (guid) according to RFC4122
3
- *
4
- * @returns Generated guid string
5
3
  */
6
4
  declare function guid(): string;
7
5
  export { guid, guid as default };
package/index.d.ts CHANGED
@@ -66,9 +66,7 @@ declare module "array/mapPrimitive" {
66
66
  export { mapPrimitive, mapPrimitive as default };
67
67
  }
68
68
  declare module "object/isNotEmpty" {
69
- function isNotEmptyObject(val: unknown): val is {
70
- [key: string]: any;
71
- };
69
+ function isNotEmptyObject(val: unknown): val is Record<string, any>;
72
70
  export { isNotEmptyObject, isNotEmptyObject as default };
73
71
  }
74
72
  declare module "array/groupBy" {
@@ -132,21 +130,46 @@ declare module "date/is" {
132
130
  export { isDate, isDate as default };
133
131
  }
134
132
  declare module "date/addUTC" {
135
- function addUTC(val: Date, amt?: number, key?: 'years' | 'year' | 'months' | 'month' | 'days' | 'day' | 'hours' | 'hour' | 'minutes' | 'minute' | 'seconds' | 'second' | 'milliseconds' | 'millisecond'): Date;
133
+ export type AddUTCKey = 'years' | 'year' | 'months' | 'month' | 'days' | 'day' | 'hours' | 'hour' | 'minutes' | 'minute' | 'seconds' | 'second' | 'milliseconds' | 'millisecond';
134
+ function addUTC(val: Date, amt?: number, key?: AddUTCKey): Date;
136
135
  export { addUTC, addUTC as default };
137
136
  }
138
137
  declare module "date/diff" {
139
- function diff(val_a: Date, val_b: Date, key?: 'week' | 'weeks' | 'day' | 'days' | 'hour' | 'hours' | 'minute' | 'minutes' | 'second' | 'seconds' | 'millisecond' | 'milliseconds'): number;
138
+ export type DiffKey = 'week' | 'weeks' | 'day' | 'days' | 'hour' | 'hours' | 'minute' | 'minutes' | 'second' | 'seconds' | 'millisecond' | 'milliseconds';
139
+ function diff(val_a: Date, val_b: Date, key?: DiffKey): number;
140
140
  export { diff, diff as default };
141
141
  }
142
142
  declare module "date/endOfUTC" {
143
- 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;
143
+ export type EndOfUTCKey = 'year' | 'quarter' | 'month' | 'week' | 'week_sun' | 'week_mon' | 'week_tue' | 'week_wed' | 'week_thu' | 'week_fri' | 'week_sat' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
144
+ function endOfUTC(val: Date, key?: EndOfUTCKey): Date;
144
145
  export { endOfUTC, endOfUTC as default };
145
146
  }
146
147
  declare module "date/format" {
147
- function format(val: Date, spec: string, locale?: string, zone?: string): string;
148
+ const WEEK_STARTS: {
149
+ readonly mon: "mon";
150
+ readonly sun: "sun";
151
+ readonly sat: "sat";
152
+ };
153
+ export type WEEK_START = keyof typeof WEEK_STARTS;
154
+ function format(val: Date, spec: string, locale?: string, zone?: string, sow?: WEEK_START): string;
155
+ namespace format {
156
+ var getLocale: () => string;
157
+ var setLocale: (locale: string) => void;
158
+ var getZone: () => string;
159
+ var setZone: (zone: string) => void;
160
+ var getStartOfWeek: () => "mon" | "sun" | "sat";
161
+ var setStartOfWeek: (sow: WEEK_START) => void;
162
+ }
148
163
  export { format, format as default };
149
164
  }
165
+ declare module "date/isFormat" {
166
+ function isDateFormat(input: unknown, spec: string): input is string;
167
+ export { isDateFormat, isDateFormat as default };
168
+ }
169
+ declare module "date/isLeap" {
170
+ function isLeap(val: Date): boolean;
171
+ export { isLeap, isLeap as default };
172
+ }
150
173
  declare module "date/nowUnix" {
151
174
  function nowUnix(): number;
152
175
  export { nowUnix, nowUnix as default };
@@ -170,7 +193,8 @@ declare module "date/setTimeUTC" {
170
193
  export { setTimeUTC, setTimeUTC as default };
171
194
  }
172
195
  declare module "date/startOfUTC" {
173
- 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;
196
+ export type StartOfUTCKey = 'year' | 'quarter' | 'month' | 'week' | 'week_sun' | 'week_mon' | 'week_tue' | 'week_wed' | 'week_thu' | 'week_fri' | 'week_sat' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
197
+ function startOfUTC(val: Date, key?: StartOfUTCKey): Date;
174
198
  export { startOfUTC, startOfUTC as default };
175
199
  }
176
200
  declare module "date/toUnix" {
@@ -186,22 +210,29 @@ declare module "date/index" {
186
210
  import { diff } from "date/diff";
187
211
  import { endOfUTC } from "date/endOfUTC";
188
212
  import { format } from "date/format";
213
+ import { isDateFormat } from "date/isFormat";
189
214
  import { isDate } from "date/is";
215
+ import { isLeap } from "date/isLeap";
190
216
  import { nowUnix } from "date/nowUnix";
191
217
  import { nowUnixMs } from "date/nowUnixMs";
192
218
  import { setTimeUTC } from "date/setTimeUTC";
193
219
  import { startOfUTC } from "date/startOfUTC";
194
220
  import { toUnix } from "date/toUnix";
195
221
  import { toUTC } from "date/toUTC";
196
- export { addUTC, diff, endOfUTC, format, isDate, isDate as is, nowUnix, nowUnixMs, setTimeUTC, startOfUTC, toUnix, toUTC };
222
+ export { addUTC, diff, endOfUTC, format, isDateFormat as isFormat, isDateFormat, isDate, isDate as is, isLeap, nowUnix, nowUnixMs, setTimeUTC, startOfUTC, toUnix, toUTC };
197
223
  }
198
224
  declare module "formdata/is" {
199
225
  function isFormData(val: unknown): val is FormData;
200
226
  export { isFormData, isFormData as default };
201
227
  }
228
+ declare module "formdata/toObject" {
229
+ function toObject<T extends Record<string, unknown>>(form: FormData): T;
230
+ export { toObject, toObject as default };
231
+ }
202
232
  declare module "formdata/index" {
203
233
  import { isFormData } from "formdata/is";
204
- export { isFormData, isFormData as is };
234
+ import { toObject } from "formdata/toObject";
235
+ export { isFormData, isFormData as is, toObject };
205
236
  }
206
237
  declare module "function/is" {
207
238
  function isFunction(val: unknown): val is (...args: unknown[]) => unknown;
package/number/is.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Check whether or not a provided value is a number
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is a number
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isNumber(val: unknown): val is number;
9
7
  export { isNumber, isNumber as default };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Check whether or not the provided value is a number above another value
3
3
  *
4
- * @param val - Value to verify
5
- * @param ref - Reference the provided value needs to be above
6
- *
7
- * @returns Whether or not the value is above the reference
4
+ * @param {unknown} val - Value to verify
5
+ * @param {number} ref - Reference the provided value needs to be above
8
6
  */
9
7
  declare function isNumberAbove(val: unknown, ref: number): val is number;
10
8
  export { isNumberAbove, isNumberAbove as default };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Check whether or not the provided value is a number above or equal to another value
3
3
  *
4
- * @param val - Value to verify
5
- * @param ref - Reference the provided value needs to be above or equal to
6
- *
7
- * @returns Whether or not the value is above or equal to the reference
4
+ * @param {unknown} val - Value to verify
5
+ * @param {number} ref - Reference the provided value needs to be above or equal to
8
6
  */
9
7
  declare function isNumberAboveOrEqual(val: unknown, ref: number): val is number;
10
8
  export { isNumberAboveOrEqual, isNumberAboveOrEqual as default };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Check whether or not the provided value is a number below another value
3
3
  *
4
- * @param val - Value to verify
5
- * @param ref - Reference the provided value needs to be below
6
- *
7
- * @returns Whether or not the value is below the reference
4
+ * @param {unknown} val - Value to verify
5
+ * @param {number} ref - Reference the provided value needs to be below
8
6
  */
9
7
  declare function isNumberBelow(val: unknown, ref: number): val is number;
10
8
  export { isNumberBelow, isNumberBelow as default };
@@ -2,10 +2,8 @@
2
2
  * Check whether or not the provided value is a number below or
3
3
  * equal to another value
4
4
  *
5
- * @param val - Value to verify
6
- * @param ref - Reference the provided value needs to be below or equal to
7
- *
8
- * @returns Whether or not the value is below or equal to the reference
5
+ * @param {unknown} val - Value to verify
6
+ * @param {number} ref - Reference the provided value needs to be below or equal to
9
7
  */
10
8
  declare function isNumberBelowOrEqual(val: unknown, ref: number): val is number;
11
9
  export { isNumberBelowOrEqual, isNumberBelowOrEqual as default };
@@ -3,11 +3,9 @@
3
3
  * inclusive of min and max
4
4
  * equal to another value
5
5
  *
6
- * @param val - Value to verify
7
- * @param min - Lower boundary
8
- * @param max - Upper boundary
9
- *
10
- * @returns Whether or not the value is a number between min and max inclusive
6
+ * @param {unknown} val - Value to verify
7
+ * @param {number} min - Lower boundary
8
+ * @param {number} max - Upper boundary
11
9
  */
12
10
  declare function isNumberBetween(val: unknown, min: number, max: number): val is number;
13
11
  export { isNumberBetween, isNumberBetween as default };