@valkyriestudios/utils 9.0.0 → 11.0.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 +2 -2
- package/dist/array/dedupe.d.ts +1 -0
- package/dist/array/dedupe.js +19 -0
- package/dist/array/is.d.ts +1 -0
- package/dist/array/is.js +6 -0
- package/dist/array/isNotEmpty.d.ts +1 -0
- package/dist/array/isNotEmpty.js +6 -0
- package/dist/array/join.d.ts +8 -0
- package/dist/array/join.js +24 -0
- package/dist/array/mapFn.d.ts +14 -0
- package/dist/array/mapFn.js +28 -0
- package/dist/array/mapKey.d.ts +12 -0
- package/dist/array/mapKey.js +27 -0
- package/dist/array/mapPrimitive.d.ts +10 -0
- package/dist/array/mapPrimitive.js +27 -0
- package/dist/array/shuffle.d.ts +1 -0
- package/dist/array/shuffle.js +11 -0
- package/dist/array/sort.d.ts +11 -0
- package/dist/array/sort.js +92 -0
- package/dist/boolean/is.d.ts +1 -0
- package/dist/boolean/is.js +6 -0
- package/dist/caching/memoize.d.ts +1 -0
- package/dist/caching/memoize.js +15 -0
- package/dist/date/addUTC.d.ts +1 -0
- package/{src/date/addUTC.mjs → dist/date/addUTC.js} +11 -26
- package/dist/date/diff.d.ts +1 -0
- package/dist/date/diff.js +38 -0
- package/dist/date/endOfUTC.d.ts +1 -0
- package/dist/date/endOfUTC.js +52 -0
- package/dist/date/is.d.ts +1 -0
- package/dist/date/is.js +6 -0
- package/dist/date/nowUnix.d.ts +1 -0
- package/dist/date/nowUnix.js +6 -0
- package/dist/date/nowUnixMs.d.ts +1 -0
- package/dist/date/nowUnixMs.js +6 -0
- package/dist/date/startOfUTC.d.ts +1 -0
- package/dist/date/startOfUTC.js +52 -0
- package/dist/date/toUTC.d.ts +1 -0
- package/dist/date/toUTC.js +9 -0
- package/dist/date/toUnix.d.ts +1 -0
- package/dist/date/toUnix.js +9 -0
- package/dist/deep/freeze.d.ts +7 -0
- package/dist/deep/freeze.js +23 -0
- package/dist/deep/get.d.ts +5 -0
- package/dist/deep/get.js +41 -0
- package/dist/deep/seal.d.ts +7 -0
- package/dist/deep/seal.js +23 -0
- package/dist/deep/set.d.ts +5 -0
- package/dist/deep/set.js +52 -0
- package/dist/equal.d.ts +2 -0
- package/dist/equal.js +43 -0
- package/dist/function/is.d.ts +1 -0
- package/dist/function/is.js +6 -0
- package/dist/function/noop.d.ts +1 -0
- package/dist/function/noop.js +5 -0
- package/dist/function/noopresolve.d.ts +1 -0
- package/dist/function/noopresolve.js +6 -0
- package/dist/function/noopreturn.d.ts +1 -0
- package/dist/function/noopreturn.js +6 -0
- package/dist/function/sleep.d.ts +1 -0
- package/dist/function/sleep.js +8 -0
- package/dist/hash/fnv1A.d.ts +1 -0
- package/dist/hash/fnv1A.js +51 -0
- package/dist/hash/guid.d.ts +1 -0
- package/{src/hash/guid.mjs → dist/hash/guid.js} +9 -14
- package/dist/is.d.ts +75 -0
- package/dist/is.js +77 -0
- package/dist/number/is.d.ts +1 -0
- package/dist/number/is.js +6 -0
- package/dist/number/isAbove.d.ts +1 -0
- package/dist/number/isAbove.js +6 -0
- package/dist/number/isAboveOrEqual.d.ts +1 -0
- package/dist/number/isAboveOrEqual.js +6 -0
- package/dist/number/isBelow.d.ts +1 -0
- package/dist/number/isBelow.js +6 -0
- package/dist/number/isBelowOrEqual.d.ts +1 -0
- package/dist/number/isBelowOrEqual.js +6 -0
- package/dist/number/isBetween.d.ts +1 -0
- package/dist/number/isBetween.js +11 -0
- package/dist/number/isInteger.d.ts +1 -0
- package/dist/number/isInteger.js +6 -0
- package/dist/number/isIntegerAbove.d.ts +1 -0
- package/dist/number/isIntegerAbove.js +6 -0
- package/dist/number/isIntegerAboveOrEqual.d.ts +1 -0
- package/dist/number/isIntegerAboveOrEqual.js +6 -0
- package/dist/number/isIntegerBelow.d.ts +1 -0
- package/dist/number/isIntegerBelow.js +6 -0
- package/dist/number/isIntegerBelowOrEqual.d.ts +1 -0
- package/dist/number/isIntegerBelowOrEqual.js +6 -0
- package/dist/number/isIntegerBetween.d.ts +1 -0
- package/dist/number/isIntegerBetween.js +11 -0
- package/dist/number/isNumericalNaN.d.ts +1 -0
- package/dist/number/isNumericalNaN.js +6 -0
- package/dist/number/randomBetween.d.ts +1 -0
- package/dist/number/randomBetween.js +9 -0
- package/dist/number/randomIntBetween.d.ts +1 -0
- package/dist/number/randomIntBetween.js +9 -0
- package/dist/number/round.d.ts +1 -0
- package/dist/number/round.js +10 -0
- package/dist/number/toPercentage.d.ts +1 -0
- package/dist/number/toPercentage.js +11 -0
- package/dist/object/define.d.ts +7 -0
- package/dist/object/define.js +9 -0
- package/dist/object/is.d.ts +1 -0
- package/dist/object/is.js +7 -0
- package/dist/object/isNotEmpty.d.ts +1 -0
- package/dist/object/isNotEmpty.js +6 -0
- package/dist/object/merge.d.ts +8 -0
- package/dist/object/merge.js +20 -0
- package/dist/object/pick.d.ts +5 -0
- package/dist/object/pick.js +34 -0
- package/dist/regexp/is.d.ts +1 -0
- package/dist/regexp/is.js +6 -0
- package/dist/regexp/sanitize.d.ts +1 -0
- package/dist/regexp/sanitize.js +8 -0
- package/dist/string/humanizeBytes.d.ts +8 -0
- package/dist/string/humanizeBytes.js +24 -0
- package/dist/string/humanizeNumber.d.ts +10 -0
- package/dist/string/humanizeNumber.js +60 -0
- package/dist/string/is.d.ts +1 -0
- package/dist/string/is.js +6 -0
- package/dist/string/isBetween.d.ts +1 -0
- package/dist/string/isBetween.js +14 -0
- package/dist/string/isNotEmpty.d.ts +1 -0
- package/dist/string/isNotEmpty.js +8 -0
- package/dist/string/shorten.d.ts +1 -0
- package/dist/string/shorten.js +11 -0
- package/package.json +303 -46
- package/CHANGELOG.md +0 -474
- package/array/dedupe.js +0 -33
- package/array/is.js +0 -9
- package/array/isNotEmpty.js +0 -9
- package/array/join.js +0 -41
- package/array/mapFn.js +0 -42
- package/array/mapKey.js +0 -38
- package/array/mapPrimitive.js +0 -43
- package/array/shuffle.js +0 -14
- package/array/sort.js +0 -125
- package/boolean/is.js +0 -9
- package/caching/memoize.js +0 -21
- package/date/addUTC.js +0 -60
- package/date/diff.js +0 -40
- package/date/endOfUTC.js +0 -55
- package/date/is.js +0 -9
- package/date/nowUnix.js +0 -9
- package/date/nowUnixMs.js +0 -9
- package/date/startOfUTC.js +0 -55
- package/date/toUTC.js +0 -10
- package/date/toUnix.js +0 -10
- package/deep/define.js +0 -12
- package/deep/freeze.js +0 -18
- package/deep/get.js +0 -31
- package/deep/seal.js +0 -18
- package/deep/set.js +0 -28
- package/equal.js +0 -37
- package/function/is.js +0 -8
- package/function/noop.js +0 -7
- package/function/noopresolve.js +0 -10
- package/function/noopreturn.js +0 -8
- package/function/sleep.js +0 -13
- package/hash/fnv1A.js +0 -49
- package/hash/guid.js +0 -16
- package/is.js +0 -319
- package/number/is.js +0 -9
- package/number/isAbove.js +0 -8
- package/number/isAboveOrEqual.js +0 -8
- package/number/isBelow.js +0 -8
- package/number/isBelowOrEqual.js +0 -8
- package/number/isBetween.js +0 -9
- package/number/isInteger.js +0 -9
- package/number/isIntegerAbove.js +0 -8
- package/number/isIntegerAboveOrEqual.js +0 -8
- package/number/isIntegerBelow.js +0 -8
- package/number/isIntegerBelowOrEqual.js +0 -8
- package/number/isIntegerBetween.js +0 -9
- package/number/isNumericalNaN.js +0 -9
- package/number/randomBetween.js +0 -11
- package/number/randomIntBetween.js +0 -11
- package/number/round.js +0 -12
- package/number/toPercentage.js +0 -15
- package/object/define.js +0 -12
- package/object/is.js +0 -11
- package/object/isNotEmpty.js +0 -10
- package/object/merge.js +0 -20
- package/object/pick.js +0 -41
- package/regexp/is.js +0 -11
- package/regexp/sanitize.js +0 -12
- package/src/array/dedupe.mjs +0 -24
- package/src/array/is.mjs +0 -5
- package/src/array/isNotEmpty.mjs +0 -5
- package/src/array/join.mjs +0 -31
- package/src/array/mapFn.mjs +0 -34
- package/src/array/mapKey.mjs +0 -31
- package/src/array/mapPrimitive.mjs +0 -29
- package/src/array/shuffle.mjs +0 -14
- package/src/array/sort.mjs +0 -102
- package/src/boolean/is.mjs +0 -5
- package/src/caching/memoize.mjs +0 -24
- package/src/date/diff.mjs +0 -46
- package/src/date/endOfUTC.mjs +0 -130
- package/src/date/is.mjs +0 -5
- package/src/date/nowUnix.mjs +0 -5
- package/src/date/nowUnixMs.mjs +0 -5
- package/src/date/startOfUTC.mjs +0 -129
- package/src/date/toUTC.mjs +0 -17
- package/src/date/toUnix.mjs +0 -9
- package/src/deep/define.mjs +0 -7
- package/src/deep/freeze.mjs +0 -22
- package/src/deep/get.mjs +0 -51
- package/src/deep/seal.mjs +0 -22
- package/src/deep/set.mjs +0 -45
- package/src/equal.mjs +0 -67
- package/src/function/is.mjs +0 -6
- package/src/function/noop.mjs +0 -5
- package/src/function/noopresolve.mjs +0 -6
- package/src/function/noopreturn.mjs +0 -6
- package/src/function/sleep.mjs +0 -12
- package/src/hash/fnv1A.mjs +0 -58
- package/src/is.mjs +0 -86
- package/src/number/is.mjs +0 -5
- package/src/number/isAbove.mjs +0 -6
- package/src/number/isAboveOrEqual.mjs +0 -6
- package/src/number/isBelow.mjs +0 -6
- package/src/number/isBelowOrEqual.mjs +0 -6
- package/src/number/isBetween.mjs +0 -13
- package/src/number/isInteger.mjs +0 -5
- package/src/number/isIntegerAbove.mjs +0 -6
- package/src/number/isIntegerAboveOrEqual.mjs +0 -6
- package/src/number/isIntegerBelow.mjs +0 -6
- package/src/number/isIntegerBelowOrEqual.mjs +0 -6
- package/src/number/isIntegerBetween.mjs +0 -13
- package/src/number/isNumericalNaN.mjs +0 -5
- package/src/number/randomBetween.mjs +0 -11
- package/src/number/randomIntBetween.mjs +0 -11
- package/src/number/round.mjs +0 -10
- package/src/number/toPercentage.mjs +0 -14
- package/src/object/define.mjs +0 -12
- package/src/object/is.mjs +0 -7
- package/src/object/isNotEmpty.mjs +0 -7
- package/src/object/merge.mjs +0 -27
- package/src/object/pick.mjs +0 -33
- package/src/regexp/is.mjs +0 -7
- package/src/regexp/sanitize.mjs +0 -12
- package/src/string/humanizeBytes.mjs +0 -29
- package/src/string/humanizeNumber.mjs +0 -84
- package/src/string/is.mjs +0 -5
- package/src/string/isBetween.mjs +0 -18
- package/src/string/isNotEmpty.mjs +0 -6
- package/src/string/shorten.mjs +0 -21
- package/string/humanizeBytes.js +0 -23
- package/string/humanizeNumber.js +0 -56
- package/string/is.js +0 -9
- package/string/isBetween.js +0 -14
- package/string/isNotEmpty.js +0 -11
- package/string/shorten.js +0 -15
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isIntegerBetween(val: any, min: number, max: number): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function isIntegerBetween(val, min, max) {
|
|
4
|
+
if (!Number.isInteger(val) ||
|
|
5
|
+
!Number.isFinite(min) ||
|
|
6
|
+
!Number.isFinite(max) ||
|
|
7
|
+
min >= max)
|
|
8
|
+
return false;
|
|
9
|
+
return val >= min && val <= max;
|
|
10
|
+
}
|
|
11
|
+
exports.default = isIntegerBetween;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isNumericalNaN(val: any): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function randomBetween(min?: number, max?: number): number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function randomBetween(min = 0, max = 10) {
|
|
4
|
+
if (!Number.isFinite(min) ||
|
|
5
|
+
!Number.isFinite(max))
|
|
6
|
+
throw new TypeError('Min/Max should be numeric');
|
|
7
|
+
return (Math.random() * (max - min)) + min;
|
|
8
|
+
}
|
|
9
|
+
exports.default = randomBetween;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function randomIntBetween(min?: number, max?: number): number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function randomIntBetween(min = 0, max = 10) {
|
|
4
|
+
if (!Number.isFinite(min) ||
|
|
5
|
+
!Number.isFinite(max))
|
|
6
|
+
throw new TypeError('Min/Max should be numeric');
|
|
7
|
+
return Math.floor((Math.random() * (max - min)) + min);
|
|
8
|
+
}
|
|
9
|
+
exports.default = randomIntBetween;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function round(val: number, precision?: number): number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function round(val, precision = 0) {
|
|
4
|
+
if (!Number.isFinite(val))
|
|
5
|
+
throw new TypeError('Value should be numeric');
|
|
6
|
+
const exp = Math.pow(10, Number.isInteger(precision) && precision > 0 ? precision : 0);
|
|
7
|
+
const num = (val * exp) * (1 + Number.EPSILON);
|
|
8
|
+
return Math.round(num) / exp;
|
|
9
|
+
}
|
|
10
|
+
exports.default = round;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function toPercentage(val: number, precision?: number, min?: number, max?: number): number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const round_1 = require("./round");
|
|
4
|
+
function toPercentage(val, precision = 0, min = 0, max = 1) {
|
|
5
|
+
if (!Number.isFinite(val) ||
|
|
6
|
+
!Number.isFinite(min) ||
|
|
7
|
+
!Number.isFinite(max))
|
|
8
|
+
throw new TypeError('value/min/max should be numeric');
|
|
9
|
+
return (0, round_1.default)(((val - min) / (max - min)) * 100, precision);
|
|
10
|
+
}
|
|
11
|
+
exports.default = toPercentage;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function define(props, obj = {}) {
|
|
4
|
+
if (Object.prototype.toString.call(props) !== '[object Object]' ||
|
|
5
|
+
Object.prototype.toString.call(obj) !== '[object Object]')
|
|
6
|
+
throw new TypeError('Please pass an object as the value for props and obj');
|
|
7
|
+
return Object.defineProperties(obj, props);
|
|
8
|
+
}
|
|
9
|
+
exports.default = define;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isObject(val: any): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isNotEmptyObject(val: any): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function merge(target, source = {}) {
|
|
4
|
+
if (Object.prototype.toString.call(target) !== '[object Object]' ||
|
|
5
|
+
Object.prototype.toString.call(source) !== '[object Object]')
|
|
6
|
+
throw new TypeError('Please pass a target and object to merge');
|
|
7
|
+
return Object.keys(target).reduce((acc, key) => {
|
|
8
|
+
if (Object.prototype.toString.call(target[key]) === '[object Object]' &&
|
|
9
|
+
!Array.isArray(target[key])) {
|
|
10
|
+
acc[key] = source[key] ? merge(target[key], source[key]) : target[key];
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
acc[key] = Object.prototype.hasOwnProperty.call(source, key)
|
|
14
|
+
? source[key]
|
|
15
|
+
: target[key];
|
|
16
|
+
}
|
|
17
|
+
return acc;
|
|
18
|
+
}, {});
|
|
19
|
+
}
|
|
20
|
+
exports.default = merge;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const get_1 = require("../deep/get");
|
|
4
|
+
const set_1 = require("../deep/set");
|
|
5
|
+
function pick(obj, keys) {
|
|
6
|
+
if (Object.prototype.toString.call(obj) !== '[object Object]' ||
|
|
7
|
+
!Array.isArray(keys) ||
|
|
8
|
+
keys.length === 0)
|
|
9
|
+
throw new TypeError('Please pass an object to pick from and a keys array');
|
|
10
|
+
const map = {};
|
|
11
|
+
let key_deep = false;
|
|
12
|
+
let val;
|
|
13
|
+
for (const key of keys) {
|
|
14
|
+
if (typeof key !== 'string')
|
|
15
|
+
continue;
|
|
16
|
+
const sanitized = key.trim();
|
|
17
|
+
if (sanitized.length === 0)
|
|
18
|
+
continue;
|
|
19
|
+
key_deep = /(\.|\[)/g.test(sanitized);
|
|
20
|
+
val = key_deep
|
|
21
|
+
? (0, get_1.default)(obj, sanitized)
|
|
22
|
+
: obj[sanitized];
|
|
23
|
+
if (val === undefined)
|
|
24
|
+
continue;
|
|
25
|
+
if (key_deep) {
|
|
26
|
+
(0, set_1.default)(map, sanitized, val);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
map[sanitized] = val;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return map;
|
|
33
|
+
}
|
|
34
|
+
exports.default = pick;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isRegExp(val: any): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function sanitizeRegExp(val: string): string | false;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const humanizeNumber_1 = require("./humanizeNumber");
|
|
4
|
+
const isNotEmpty_1 = require("../string/isNotEmpty");
|
|
5
|
+
function humanizeBytes(val, options = {}) {
|
|
6
|
+
const has_opts = Object.prototype.toString.call(options) === '[object Object]';
|
|
7
|
+
return (0, humanizeNumber_1.default)(val, {
|
|
8
|
+
delim: has_opts && typeof options.delim === 'string'
|
|
9
|
+
? options.delim
|
|
10
|
+
: ',',
|
|
11
|
+
separator: has_opts && typeof options.separator === 'string' && options.separator.trim().length > 0
|
|
12
|
+
? options.separator
|
|
13
|
+
: '.',
|
|
14
|
+
precision: has_opts && Number.isInteger(options.precision) && options.precision >= 0
|
|
15
|
+
? options.precision
|
|
16
|
+
: 2,
|
|
17
|
+
units: has_opts && Array.isArray(options.units) && options.units.length > 0
|
|
18
|
+
? options.units.filter(el => (0, isNotEmpty_1.default)(el))
|
|
19
|
+
: [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB'],
|
|
20
|
+
divider: 1024,
|
|
21
|
+
real: true,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.default = humanizeBytes;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface humanizeNumberOptions {
|
|
2
|
+
delim?: string;
|
|
3
|
+
separator?: string;
|
|
4
|
+
precision?: number;
|
|
5
|
+
units?: string[] | boolean;
|
|
6
|
+
divider?: number;
|
|
7
|
+
real?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export default function humanizeNumber(val: number | string, options?: humanizeNumberOptions): string;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const is_1 = require("../boolean/is");
|
|
4
|
+
const is_2 = require("../string/is");
|
|
5
|
+
const round_1 = require("../number/round");
|
|
6
|
+
function humanizeNumber(val, options = {}) {
|
|
7
|
+
const has_opts = Object.prototype.toString.call(options) === '[object Object]';
|
|
8
|
+
const OPTS = {
|
|
9
|
+
delim: has_opts && typeof options.delim === 'string'
|
|
10
|
+
? options.delim
|
|
11
|
+
: ',',
|
|
12
|
+
separator: has_opts && typeof options.separator === 'string' && options.separator.trim().length > 0
|
|
13
|
+
? options.separator
|
|
14
|
+
: '.',
|
|
15
|
+
precision: has_opts && Number.isInteger(options.precision) && options.precision >= 0
|
|
16
|
+
? options.precision
|
|
17
|
+
: 2,
|
|
18
|
+
units: has_opts && ((Array.isArray(options.units) && options.units.length > 0) || options.units === false)
|
|
19
|
+
? options.units ? options.units.filter(is_2.default) : false
|
|
20
|
+
: ['', 'k', 'm', 'b', 't', 'q'],
|
|
21
|
+
divider: has_opts && Number.isInteger(options.divider) && options.divider > 1
|
|
22
|
+
? options.divider
|
|
23
|
+
: 1000,
|
|
24
|
+
real: has_opts && (0, is_1.default)(options.real)
|
|
25
|
+
? options.real
|
|
26
|
+
: false,
|
|
27
|
+
};
|
|
28
|
+
let normalized;
|
|
29
|
+
if (OPTS.real) {
|
|
30
|
+
normalized = typeof val === 'string' ? parseInt(val.trim(), 10) : Number.isFinite(val) ? Math.round(val) : 0;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
normalized = typeof val === 'string' ? parseFloat(val) : Number.isFinite(val) ? val : 0;
|
|
34
|
+
}
|
|
35
|
+
if (!Number.isFinite(normalized) || normalized === 0) {
|
|
36
|
+
return `0${Array.isArray(OPTS.units) && OPTS.units.length > 0 ? OPTS.units[0] : ''}`;
|
|
37
|
+
}
|
|
38
|
+
const sign = normalized < 0 ? '-' : '';
|
|
39
|
+
normalized = Math.abs(normalized);
|
|
40
|
+
let postfix = '';
|
|
41
|
+
if (Array.isArray(OPTS.units) && OPTS.units.length > 0) {
|
|
42
|
+
let unit_ix = 0;
|
|
43
|
+
while (normalized >= OPTS.divider) {
|
|
44
|
+
unit_ix++;
|
|
45
|
+
normalized = normalized / OPTS.divider;
|
|
46
|
+
if (unit_ix === OPTS.units.length - 1)
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
postfix = OPTS.units[unit_ix];
|
|
50
|
+
}
|
|
51
|
+
normalized = (0, round_1.default)(normalized, OPTS.precision);
|
|
52
|
+
const humanized = `${normalized}`.split('.');
|
|
53
|
+
humanized[0] = humanized[0].split('').reverse().map((char, ix, original) => {
|
|
54
|
+
if (ix > 0 && ix < original.length && ix % 3 === 0)
|
|
55
|
+
return char + OPTS.delim;
|
|
56
|
+
return char;
|
|
57
|
+
}).reverse().join('');
|
|
58
|
+
return `${sign}${humanized.join(OPTS.separator)}${postfix}`;
|
|
59
|
+
}
|
|
60
|
+
exports.default = humanizeNumber;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isString(val: any): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isStringBetween(val: any, min: number, max: number, trimmed?: boolean): boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function isStringBetween(val, min, max, trimmed = true) {
|
|
4
|
+
if (typeof val !== 'string' ||
|
|
5
|
+
!Number.isFinite(min) ||
|
|
6
|
+
min < 0 ||
|
|
7
|
+
!Number.isFinite(max) ||
|
|
8
|
+
max < 0 ||
|
|
9
|
+
min >= max)
|
|
10
|
+
return false;
|
|
11
|
+
const length = (trimmed === true ? val.trim() : val).length;
|
|
12
|
+
return length >= min && length <= max;
|
|
13
|
+
}
|
|
14
|
+
exports.default = isStringBetween;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isNotEmptyString(val: any, trimmed?: boolean): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function isNotEmptyString(val, trimmed = true) {
|
|
4
|
+
if (typeof val !== 'string')
|
|
5
|
+
return false;
|
|
6
|
+
return (trimmed === true ? val.trim() : val).length > 0;
|
|
7
|
+
}
|
|
8
|
+
exports.default = isNotEmptyString;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function shorten(val: string, length: number, postfix?: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function shorten(val, length, postfix = '...') {
|
|
4
|
+
if (typeof val !== 'string')
|
|
5
|
+
return '';
|
|
6
|
+
if (typeof postfix !== 'string' || !Number.isFinite(length) || length <= 0)
|
|
7
|
+
return val;
|
|
8
|
+
const sanitized = val.trim();
|
|
9
|
+
return sanitized.length <= length ? sanitized : `${sanitized.substr(0, length)}${postfix}`;
|
|
10
|
+
}
|
|
11
|
+
exports.default = shorten;
|