@valkyriestudios/utils 12.20.0 → 12.22.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 (87) hide show
  1. package/README.md +389 -160
  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 +110 -42
  18. package/date/index.d.ts +2 -1
  19. package/date/index.js +3 -1
  20. package/date/is.d.ts +1 -3
  21. package/date/isFormat.d.ts +0 -1
  22. package/date/isLeap.d.ts +7 -0
  23. package/date/isLeap.js +11 -0
  24. package/date/nowUnix.d.ts +0 -2
  25. package/date/nowUnixMs.d.ts +0 -2
  26. package/date/setTimeUTC.d.ts +1 -2
  27. package/date/startOfUTC.d.ts +4 -5
  28. package/date/toUTC.d.ts +1 -3
  29. package/date/toUnix.d.ts +1 -3
  30. package/deep/freeze.d.ts +1 -3
  31. package/deep/get.d.ts +5 -7
  32. package/deep/seal.d.ts +1 -3
  33. package/deep/set.d.ts +0 -1
  34. package/equal.d.ts +2 -4
  35. package/formdata/index.d.ts +2 -1
  36. package/formdata/index.js +3 -1
  37. package/formdata/is.d.ts +1 -3
  38. package/formdata/toObject.d.ts +23 -0
  39. package/formdata/toObject.js +58 -0
  40. package/function/is.d.ts +1 -3
  41. package/function/isAsync.d.ts +1 -3
  42. package/function/noop.d.ts +0 -2
  43. package/function/noop.js +1 -2
  44. package/function/noopresolve.d.ts +0 -2
  45. package/function/noopreturn.d.ts +0 -2
  46. package/function/sleep.d.ts +1 -3
  47. package/hash/fnv1A.d.ts +2 -4
  48. package/hash/guid.d.ts +0 -2
  49. package/index.d.ts +39 -10
  50. package/number/is.d.ts +1 -3
  51. package/number/isAbove.d.ts +2 -4
  52. package/number/isAboveOrEqual.d.ts +2 -4
  53. package/number/isBelow.d.ts +2 -4
  54. package/number/isBelowOrEqual.d.ts +2 -4
  55. package/number/isBetween.d.ts +3 -5
  56. package/number/isBetween.js +4 -6
  57. package/number/isInteger.d.ts +1 -3
  58. package/number/isIntegerAbove.d.ts +2 -4
  59. package/number/isIntegerAboveOrEqual.d.ts +2 -4
  60. package/number/isIntegerBelow.d.ts +2 -4
  61. package/number/isIntegerBelowOrEqual.d.ts +2 -4
  62. package/number/isIntegerBetween.d.ts +3 -5
  63. package/number/isIntegerBetween.js +4 -6
  64. package/number/isNumericalNaN.d.ts +1 -3
  65. package/number/randomBetween.d.ts +2 -4
  66. package/number/randomIntBetween.d.ts +2 -4
  67. package/number/round.d.ts +2 -4
  68. package/number/round.js +5 -3
  69. package/number/toPercentage.d.ts +4 -6
  70. package/object/define.d.ts +0 -2
  71. package/object/is.d.ts +1 -3
  72. package/object/isNotEmpty.d.ts +2 -6
  73. package/object/merge.d.ts +2 -4
  74. package/object/merge.js +2 -3
  75. package/object/pick.d.ts +0 -2
  76. package/package.json +1 -1
  77. package/regexp/is.d.ts +1 -3
  78. package/regexp/sanitize.d.ts +1 -3
  79. package/regexp/sanitize.js +2 -1
  80. package/string/humanizeBytes.d.ts +1 -3
  81. package/string/humanizeNumber.d.ts +2 -4
  82. package/string/humanizeNumber.js +2 -2
  83. package/string/is.d.ts +1 -3
  84. package/string/isBetween.d.ts +4 -6
  85. package/string/isNotEmpty.d.ts +2 -4
  86. package/string/shorten.d.ts +0 -2
  87. package/string/shorten.js +1 -1
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,23 @@
1
+ type toObjectConfig = {
2
+ /**
3
+ * Pass array of keys that should not be normalized into number/bool when seen
4
+ */
5
+ raw?: string[];
6
+ };
7
+ /**
8
+ * Converts a FormData instance to a json object
9
+ * Eg:
10
+ * const form = new FormData();
11
+ * form.append('name', 'Alice');
12
+ * form.append('hobbies', 'reading');
13
+ * form.append('hobbies', 'writing');
14
+ * form.append('emptyField', '');
15
+ * toObject(form);
16
+ *
17
+ * {name: 'Alice', hobbies: ['reading', 'writing'], emptyField: ''}
18
+ *
19
+ * @param {FormData} val - FormData instance to convert to an object
20
+ * @param {}
21
+ */
22
+ declare function toObject<T extends Record<string, unknown>>(form: FormData, config?: toObjectConfig): T;
23
+ export { toObject, toObject as default };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toObject = toObject;
4
+ exports.default = toObject;
5
+ const RGX_CLOSE = /\]/g;
6
+ function assignValue(acc, rawkey, value) {
7
+ let cursor = acc;
8
+ const keys = rawkey.replace(RGX_CLOSE, '').split(/\[|\./);
9
+ for (let i = 0; i < keys.length; i++) {
10
+ const key = keys[i];
11
+ if (i === keys.length - 1) {
12
+ if (cursor[key] !== undefined) {
13
+ if (Array.isArray(cursor[key])) {
14
+ cursor[key].push(value);
15
+ }
16
+ else {
17
+ cursor[key] = [cursor[key], value];
18
+ }
19
+ }
20
+ else {
21
+ cursor[key] = value;
22
+ }
23
+ return;
24
+ }
25
+ if (Array.isArray(cursor)) {
26
+ const index = Number(key);
27
+ if (!cursor[index])
28
+ cursor[index] = isNaN(Number(keys[i + 1])) ? {} : [];
29
+ cursor = cursor[index];
30
+ }
31
+ else {
32
+ if (!cursor[key])
33
+ cursor[key] = isNaN(Number(keys[i + 1])) ? {} : [];
34
+ cursor = cursor[key];
35
+ }
36
+ }
37
+ }
38
+ function toObject(form, config) {
39
+ if (!(form instanceof FormData))
40
+ throw new Error('formdata/toObject: Value is not an instance of FormData');
41
+ const set = new Set(Array.isArray(config?.raw) ? config.raw : []);
42
+ const acc = {};
43
+ form.forEach((value, key) => {
44
+ let normalizedValue = value;
45
+ if (typeof value === 'string' && !set.has(key)) {
46
+ const lower = value.toLowerCase();
47
+ normalizedValue = (lower === 'true'
48
+ ? true
49
+ : lower === 'false'
50
+ ? false
51
+ : !isNaN(Number(value)) && value.trim() !== ''
52
+ ? Number(value)
53
+ : value);
54
+ }
55
+ assignValue(acc, key, normalizedValue);
56
+ });
57
+ return acc;
58
+ }
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/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,25 +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
  }
150
165
  declare module "date/isFormat" {
151
166
  function isDateFormat(input: unknown, spec: string): input is string;
152
167
  export { isDateFormat, isDateFormat as default };
153
168
  }
169
+ declare module "date/isLeap" {
170
+ function isLeap(val: Date): boolean;
171
+ export { isLeap, isLeap as default };
172
+ }
154
173
  declare module "date/nowUnix" {
155
174
  function nowUnix(): number;
156
175
  export { nowUnix, nowUnix as default };
@@ -174,7 +193,8 @@ declare module "date/setTimeUTC" {
174
193
  export { setTimeUTC, setTimeUTC as default };
175
194
  }
176
195
  declare module "date/startOfUTC" {
177
- 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;
178
198
  export { startOfUTC, startOfUTC as default };
179
199
  }
180
200
  declare module "date/toUnix" {
@@ -192,21 +212,30 @@ declare module "date/index" {
192
212
  import { format } from "date/format";
193
213
  import { isDateFormat } from "date/isFormat";
194
214
  import { isDate } from "date/is";
215
+ import { isLeap } from "date/isLeap";
195
216
  import { nowUnix } from "date/nowUnix";
196
217
  import { nowUnixMs } from "date/nowUnixMs";
197
218
  import { setTimeUTC } from "date/setTimeUTC";
198
219
  import { startOfUTC } from "date/startOfUTC";
199
220
  import { toUnix } from "date/toUnix";
200
221
  import { toUTC } from "date/toUTC";
201
- export { addUTC, diff, endOfUTC, format, isDateFormat as isFormat, isDateFormat, 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 };
202
223
  }
203
224
  declare module "formdata/is" {
204
225
  function isFormData(val: unknown): val is FormData;
205
226
  export { isFormData, isFormData as default };
206
227
  }
228
+ declare module "formdata/toObject" {
229
+ type toObjectConfig = {
230
+ raw?: string[];
231
+ };
232
+ function toObject<T extends Record<string, unknown>>(form: FormData, config?: toObjectConfig): T;
233
+ export { toObject, toObject as default };
234
+ }
207
235
  declare module "formdata/index" {
208
236
  import { isFormData } from "formdata/is";
209
- export { isFormData, isFormData as is };
237
+ import { toObject } from "formdata/toObject";
238
+ export { isFormData, isFormData as is, toObject };
210
239
  }
211
240
  declare module "function/is" {
212
241
  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 };
@@ -3,10 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNumberBetween = isNumberBetween;
4
4
  exports.default = isNumberBetween;
5
5
  function isNumberBetween(val, min, max) {
6
- if (!Number.isFinite(val) ||
7
- !Number.isFinite(min) ||
8
- !Number.isFinite(max) ||
9
- min >= max)
10
- return false;
11
- return val >= min && val <= max;
6
+ return (Number.isFinite(val) &&
7
+ Number.isFinite(min) &&
8
+ Number.isFinite(max) &&
9
+ (val >= min && val <= max));
12
10
  }
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Check whether or not a provided value is an integer
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is an integer
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isInteger(val: unknown): val is number;
9
7
  export { isInteger, isInteger as default };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Check whether or not the provided value is an integer 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 isIntegerAbove(val: unknown, ref: number): val is number;
10
8
  export { isIntegerAbove, isIntegerAbove as default };
@@ -2,10 +2,8 @@
2
2
  * Check whether or not the provided value is an integer above or equal
3
3
  * to another value
4
4
  *
5
- * @param val - Value to verify
6
- * @param ref - Reference the provided value needs to be above or equal to
7
- *
8
- * @returns Whether or not the value is above or equal to the reference
5
+ * @param {unknown} val - Value to verify
6
+ * @param {number} ref - Reference the provided value needs to be above or equal to
9
7
  */
10
8
  declare function isIntegerAboveOrEqual(val: unknown, ref: number): val is number;
11
9
  export { isIntegerAboveOrEqual, isIntegerAboveOrEqual as default };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Check whether or not the provided value is an integer 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 isIntegerBelow(val: unknown, ref: number): val is number;
10
8
  export { isIntegerBelow, isIntegerBelow as default };
@@ -2,10 +2,8 @@
2
2
  * Check whether or not the provided value is an integer 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 isIntegerBelowOrEqual(val: unknown, ref: number): val is number;
11
9
  export { isIntegerBelowOrEqual, isIntegerBelowOrEqual 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 an integer 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 isIntegerBetween(val: unknown, min: number, max: number): val is number;
13
11
  export { isIntegerBetween, isIntegerBetween as default };
@@ -3,10 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isIntegerBetween = isIntegerBetween;
4
4
  exports.default = isIntegerBetween;
5
5
  function isIntegerBetween(val, min, max) {
6
- if (!Number.isInteger(val) ||
7
- !Number.isFinite(min) ||
8
- !Number.isFinite(max) ||
9
- min >= max)
10
- return false;
11
- return val >= min && val <= max;
6
+ return (Number.isInteger(val) &&
7
+ Number.isFinite(min) &&
8
+ Number.isFinite(max) &&
9
+ (val >= min && val <= max));
12
10
  }
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Check whether or not the provided value is a numerical NaN
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is a numerical NaN
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isNumericalNaN(val: unknown): boolean;
9
7
  export { isNumericalNaN, isNumericalNaN as default };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Generates a random number between the provided lower and upper bound
3
3
  *
4
- * @param min - (default=0) Lower bound
5
- * @param max - (default=10) Upper bound
6
- *
7
- * @returns Random number between min and max
4
+ * @param {number} min - (default=0) Lower bound
5
+ * @param {number} max - (default=10) Upper bound
8
6
  */
9
7
  declare function randomBetween(min?: number, max?: number): number;
10
8
  export { randomBetween, randomBetween as default };
@@ -2,10 +2,8 @@
2
2
  * Generates a random integer between the provided lower and upper bound,
3
3
  * not inclusive of the upper bound
4
4
  *
5
- * @param min - (default=0) Lower bound
6
- * @param max - (default=10) Upper bound
7
- *
8
- * @returns Random integer between min and max
5
+ * @param {number} min - (default=0) Lower bound
6
+ * @param {number} max - (default=10) Upper bound
9
7
  */
10
8
  declare function randomIntBetween(min?: number, max?: number): number;
11
9
  export { randomIntBetween, randomIntBetween as default };
package/number/round.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * Rounds the provided value to a certain precision
3
3
  *
4
- * @param val - Value to round
5
- * @param precision - (default=0) Amount of decimals precision to round to
6
- *
7
- * @returns Rounded value according to decimal precision provided
4
+ * @param {number} val - Value to round
5
+ * @param {number} precision - (default=0) Amount of decimals precision to round to
8
6
  */
9
7
  declare function round(val: number, precision?: number): number;
10
8
  export { round, round as default };
package/number/round.js CHANGED
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.round = round;
4
4
  exports.default = round;
5
+ const ROUND_EPSILON = 1 + Number.EPSILON;
5
6
  function round(val, precision = 0) {
6
7
  if (!Number.isFinite(val))
7
8
  throw new TypeError('Value should be numeric');
8
- const exp = Math.pow(10, Number.isInteger(precision) && precision > 0 ? precision : 0);
9
- const num = (val * exp) * (1 + Number.EPSILON);
10
- return Math.round(num) / exp;
9
+ if (!Number.isInteger(precision) || precision <= 0)
10
+ return Math.round(val * ROUND_EPSILON);
11
+ const exp = Math.pow(10, precision);
12
+ return Math.round((val * exp) * ROUND_EPSILON) / exp;
11
13
  }
@@ -1,12 +1,10 @@
1
1
  /**
2
2
  * Converts a number into a percentage respective to a provided range
3
3
  *
4
- * @param val - Value to convert into a percentage for the provided range
5
- * @param precision - (default=0) Amount of decimals precision to use
6
- * @param min - (default=0) Lower bound of the range the value is to be converted to percentage for
7
- * @param max - (default=1) Upper bound of the range the value is to be converted to percentage for
8
- *
9
- * @returns Percentage value respective to the provided range
4
+ * @param {number} val - Value to convert into a percentage for the provided range
5
+ * @param {number} precision - (default=0) Amount of decimals precision to use
6
+ * @param {number} min - (default=0) Lower bound of the range the value is to be converted to percentage for
7
+ * @param {number} max - (default=1) Upper bound of the range the value is to be converted to percentage for
10
8
  */
11
9
  declare function toPercentage(val: number, precision?: number, min?: number, max?: number): number;
12
10
  export { toPercentage, toPercentage as default };
@@ -3,8 +3,6 @@
3
3
  *
4
4
  * @param props - Object with properties to define
5
5
  * @param obj - (default={}) Object to define on top of
6
- *
7
- * @returns Object with the defined properties
8
6
  */
9
7
  declare function define(props: {
10
8
  [key: string]: any;
package/object/is.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Check whether or not a provided value is an object
3
3
  *
4
- * @param val - Value to verify
5
- *
6
- * @returns Whether or not the value is an object
4
+ * @param {unknown} val - Value to verify
7
5
  */
8
6
  declare function isObject(val: unknown): val is {
9
7
  [key: string]: any;