@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.
- package/README.md +389 -160
- package/array/dedupe.d.ts +0 -2
- package/array/groupBy.d.ts +0 -1
- package/array/is.d.ts +1 -3
- package/array/isNotEmpty.d.ts +1 -3
- package/array/join.d.ts +0 -2
- package/array/join.js +3 -2
- package/array/mapFn.js +1 -1
- package/array/mapPrimitive.d.ts +0 -2
- package/array/sort.d.ts +0 -2
- package/array/split.d.ts +0 -2
- package/boolean/is.d.ts +1 -3
- package/date/addUTC.d.ts +5 -6
- package/date/diff.d.ts +5 -6
- package/date/endOfUTC.d.ts +4 -5
- package/date/format.d.ts +16 -2
- package/date/format.js +110 -42
- package/date/index.d.ts +2 -1
- package/date/index.js +3 -1
- package/date/is.d.ts +1 -3
- package/date/isFormat.d.ts +0 -1
- package/date/isLeap.d.ts +7 -0
- package/date/isLeap.js +11 -0
- package/date/nowUnix.d.ts +0 -2
- package/date/nowUnixMs.d.ts +0 -2
- package/date/setTimeUTC.d.ts +1 -2
- package/date/startOfUTC.d.ts +4 -5
- package/date/toUTC.d.ts +1 -3
- package/date/toUnix.d.ts +1 -3
- package/deep/freeze.d.ts +1 -3
- package/deep/get.d.ts +5 -7
- package/deep/seal.d.ts +1 -3
- package/deep/set.d.ts +0 -1
- package/equal.d.ts +2 -4
- package/formdata/index.d.ts +2 -1
- package/formdata/index.js +3 -1
- package/formdata/is.d.ts +1 -3
- package/formdata/toObject.d.ts +23 -0
- package/formdata/toObject.js +58 -0
- package/function/is.d.ts +1 -3
- package/function/isAsync.d.ts +1 -3
- package/function/noop.d.ts +0 -2
- package/function/noop.js +1 -2
- package/function/noopresolve.d.ts +0 -2
- package/function/noopreturn.d.ts +0 -2
- package/function/sleep.d.ts +1 -3
- package/hash/fnv1A.d.ts +2 -4
- package/hash/guid.d.ts +0 -2
- package/index.d.ts +39 -10
- package/number/is.d.ts +1 -3
- package/number/isAbove.d.ts +2 -4
- package/number/isAboveOrEqual.d.ts +2 -4
- package/number/isBelow.d.ts +2 -4
- package/number/isBelowOrEqual.d.ts +2 -4
- package/number/isBetween.d.ts +3 -5
- package/number/isBetween.js +4 -6
- package/number/isInteger.d.ts +1 -3
- package/number/isIntegerAbove.d.ts +2 -4
- package/number/isIntegerAboveOrEqual.d.ts +2 -4
- package/number/isIntegerBelow.d.ts +2 -4
- package/number/isIntegerBelowOrEqual.d.ts +2 -4
- package/number/isIntegerBetween.d.ts +3 -5
- package/number/isIntegerBetween.js +4 -6
- package/number/isNumericalNaN.d.ts +1 -3
- package/number/randomBetween.d.ts +2 -4
- package/number/randomIntBetween.d.ts +2 -4
- package/number/round.d.ts +2 -4
- package/number/round.js +5 -3
- package/number/toPercentage.d.ts +4 -6
- package/object/define.d.ts +0 -2
- package/object/is.d.ts +1 -3
- package/object/isNotEmpty.d.ts +2 -6
- package/object/merge.d.ts +2 -4
- package/object/merge.js +2 -3
- package/object/pick.d.ts +0 -2
- package/package.json +1 -1
- package/regexp/is.d.ts +1 -3
- package/regexp/sanitize.d.ts +1 -3
- package/regexp/sanitize.js +2 -1
- package/string/humanizeBytes.d.ts +1 -3
- package/string/humanizeNumber.d.ts +2 -4
- package/string/humanizeNumber.js +2 -2
- package/string/is.d.ts +1 -3
- package/string/isBetween.d.ts +4 -6
- package/string/isNotEmpty.d.ts +2 -4
- package/string/shorten.d.ts +0 -2
- 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 };
|
package/formdata/index.d.ts
CHANGED
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 };
|
package/function/isAsync.d.ts
CHANGED
|
@@ -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 };
|
package/function/noop.d.ts
CHANGED
package/function/noop.js
CHANGED
|
@@ -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 };
|
package/function/noopreturn.d.ts
CHANGED
package/function/sleep.d.ts
CHANGED
|
@@ -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
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 };
|
package/number/isAbove.d.ts
CHANGED
|
@@ -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 };
|
package/number/isBelow.d.ts
CHANGED
|
@@ -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 };
|
package/number/isBetween.d.ts
CHANGED
|
@@ -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 };
|
package/number/isBetween.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
}
|
package/number/isInteger.d.ts
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
}
|
package/number/toPercentage.d.ts
CHANGED
|
@@ -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 };
|
package/object/define.d.ts
CHANGED
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;
|