@augment-vir/common 21.5.1 → 21.6.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/dist/cjs/augments/common-number.js +39 -10
- package/dist/cjs/augments/string/suffixes.js +3 -3
- package/dist/cjs/index.js +0 -1
- package/dist/esm/augments/common-number.js +34 -8
- package/dist/esm/augments/string/suffixes.js +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/types/augments/common-number.d.ts +28 -10
- package/dist/types/index.d.ts +0 -1
- package/package.json +1 -1
- package/dist/cjs/augments/number.js +0 -29
- package/dist/esm/augments/number.js +0 -23
- package/dist/types/augments/number.d.ts +0 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.clamp = exports.round = exports.wrapNumber = exports.toEnsuredNumber = exports.ensureMinAndMax = exports.doesRequireScientificNotation = exports.convertIntoNumber = exports.addCommasToNumber = exports.NaNString = void 0;
|
|
4
4
|
const common_string_1 = require("./common-string");
|
|
5
5
|
const regexp_1 = require("./regexp");
|
|
6
6
|
exports.NaNString = String(NaN);
|
|
@@ -25,15 +25,6 @@ function addCommasToNumber(input) {
|
|
|
25
25
|
].join('');
|
|
26
26
|
}
|
|
27
27
|
exports.addCommasToNumber = addCommasToNumber;
|
|
28
|
-
function clamp(
|
|
29
|
-
/**
|
|
30
|
-
* This uses a destructured object so that consumers cannot get confused as to which input is
|
|
31
|
-
* which (which would be easy to do since they're all of the same type).
|
|
32
|
-
*/
|
|
33
|
-
{ value, min, max, }) {
|
|
34
|
-
return Math.max(Math.min(value, max), min);
|
|
35
|
-
}
|
|
36
|
-
exports.clamp = clamp;
|
|
37
28
|
function convertIntoNumber(input) {
|
|
38
29
|
if (typeof input === 'number') {
|
|
39
30
|
return input;
|
|
@@ -63,3 +54,41 @@ function ensureMinAndMax({ min, max }) {
|
|
|
63
54
|
}
|
|
64
55
|
}
|
|
65
56
|
exports.ensureMinAndMax = ensureMinAndMax;
|
|
57
|
+
function toEnsuredNumber(input) {
|
|
58
|
+
const numeric = Number(input);
|
|
59
|
+
if (isNaN(numeric)) {
|
|
60
|
+
throw new Error(`Cannot convert given input to a number: ${input}`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return numeric;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.toEnsuredNumber = toEnsuredNumber;
|
|
67
|
+
/**
|
|
68
|
+
* If the given value is outside the given min/max bounds, instead of clamping the number (as the
|
|
69
|
+
* `clamp` function does), this function wraps the value around to the next bound.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* wrapNumber({min: 0, max: 100, value: 101}) == 0;
|
|
73
|
+
*/
|
|
74
|
+
function wrapNumber({ max, min, value }) {
|
|
75
|
+
if (value > max) {
|
|
76
|
+
return min;
|
|
77
|
+
}
|
|
78
|
+
else if (value < min) {
|
|
79
|
+
return max;
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
exports.wrapNumber = wrapNumber;
|
|
84
|
+
function round(inputs) {
|
|
85
|
+
const digitFactor = Math.pow(10, inputs.digits);
|
|
86
|
+
const multiplied = inputs.number * digitFactor;
|
|
87
|
+
return Number((Math.round(multiplied) / digitFactor).toFixed(inputs.digits));
|
|
88
|
+
}
|
|
89
|
+
exports.round = round;
|
|
90
|
+
/** Clamp's the given value to within the min and max bounds, inclusive. */
|
|
91
|
+
function clamp({ value, min, max }) {
|
|
92
|
+
return Math.min(Math.max(value, min), max);
|
|
93
|
+
}
|
|
94
|
+
exports.clamp = clamp;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeSuffix = exports.addSuffix = exports.removePercent = exports.addPercent = exports.removePx = exports.addPx = exports.pxSuffix = exports.percentSuffix = void 0;
|
|
4
|
-
const
|
|
4
|
+
const common_number_1 = require("../common-number");
|
|
5
5
|
exports.percentSuffix = '%';
|
|
6
6
|
exports.pxSuffix = 'px';
|
|
7
7
|
function addPx(input) {
|
|
@@ -9,7 +9,7 @@ function addPx(input) {
|
|
|
9
9
|
}
|
|
10
10
|
exports.addPx = addPx;
|
|
11
11
|
function removePx(input) {
|
|
12
|
-
return (0,
|
|
12
|
+
return (0, common_number_1.toEnsuredNumber)(removeSuffix({ value: input, suffix: exports.pxSuffix }));
|
|
13
13
|
}
|
|
14
14
|
exports.removePx = removePx;
|
|
15
15
|
function addPercent(input) {
|
|
@@ -17,7 +17,7 @@ function addPercent(input) {
|
|
|
17
17
|
}
|
|
18
18
|
exports.addPercent = addPercent;
|
|
19
19
|
function removePercent(input) {
|
|
20
|
-
return (0,
|
|
20
|
+
return (0, common_number_1.toEnsuredNumber)(removeSuffix({ value: input, suffix: exports.percentSuffix }));
|
|
21
21
|
}
|
|
22
22
|
exports.removePercent = removePercent;
|
|
23
23
|
function addSuffix({ value, suffix, }) {
|
package/dist/cjs/index.js
CHANGED
|
@@ -26,7 +26,6 @@ __exportStar(require("./augments/function"), exports);
|
|
|
26
26
|
__exportStar(require("./augments/json"), exports);
|
|
27
27
|
__exportStar(require("./augments/json-compatible"), exports);
|
|
28
28
|
__exportStar(require("./augments/map"), exports);
|
|
29
|
-
__exportStar(require("./augments/number"), exports);
|
|
30
29
|
__exportStar(require("./augments/object/enum"), exports);
|
|
31
30
|
__exportStar(require("./augments/object/filter-object"), exports);
|
|
32
31
|
__exportStar(require("./augments/object/has-key"), exports);
|
|
@@ -21,14 +21,6 @@ export function addCommasToNumber(input) {
|
|
|
21
21
|
decimalString,
|
|
22
22
|
].join('');
|
|
23
23
|
}
|
|
24
|
-
export function clamp(
|
|
25
|
-
/**
|
|
26
|
-
* This uses a destructured object so that consumers cannot get confused as to which input is
|
|
27
|
-
* which (which would be easy to do since they're all of the same type).
|
|
28
|
-
*/
|
|
29
|
-
{ value, min, max, }) {
|
|
30
|
-
return Math.max(Math.min(value, max), min);
|
|
31
|
-
}
|
|
32
24
|
export function convertIntoNumber(input) {
|
|
33
25
|
if (typeof input === 'number') {
|
|
34
26
|
return input;
|
|
@@ -55,3 +47,37 @@ export function ensureMinAndMax({ min, max }) {
|
|
|
55
47
|
return { min, max };
|
|
56
48
|
}
|
|
57
49
|
}
|
|
50
|
+
export function toEnsuredNumber(input) {
|
|
51
|
+
const numeric = Number(input);
|
|
52
|
+
if (isNaN(numeric)) {
|
|
53
|
+
throw new Error(`Cannot convert given input to a number: ${input}`);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return numeric;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* If the given value is outside the given min/max bounds, instead of clamping the number (as the
|
|
61
|
+
* `clamp` function does), this function wraps the value around to the next bound.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* wrapNumber({min: 0, max: 100, value: 101}) == 0;
|
|
65
|
+
*/
|
|
66
|
+
export function wrapNumber({ max, min, value }) {
|
|
67
|
+
if (value > max) {
|
|
68
|
+
return min;
|
|
69
|
+
}
|
|
70
|
+
else if (value < min) {
|
|
71
|
+
return max;
|
|
72
|
+
}
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
export function round(inputs) {
|
|
76
|
+
const digitFactor = Math.pow(10, inputs.digits);
|
|
77
|
+
const multiplied = inputs.number * digitFactor;
|
|
78
|
+
return Number((Math.round(multiplied) / digitFactor).toFixed(inputs.digits));
|
|
79
|
+
}
|
|
80
|
+
/** Clamp's the given value to within the min and max bounds, inclusive. */
|
|
81
|
+
export function clamp({ value, min, max }) {
|
|
82
|
+
return Math.min(Math.max(value, min), max);
|
|
83
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -10,7 +10,6 @@ export * from './augments/function';
|
|
|
10
10
|
export * from './augments/json';
|
|
11
11
|
export * from './augments/json-compatible';
|
|
12
12
|
export * from './augments/map';
|
|
13
|
-
export * from './augments/number';
|
|
14
13
|
export * from './augments/object/enum';
|
|
15
14
|
export * from './augments/object/filter-object';
|
|
16
15
|
export * from './augments/object/has-key';
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
export declare const NaNString: string;
|
|
2
2
|
export declare function addCommasToNumber(input: number | string): string;
|
|
3
|
-
export declare function clamp(
|
|
4
|
-
/**
|
|
5
|
-
* This uses a destructured object so that consumers cannot get confused as to which input is
|
|
6
|
-
* which (which would be easy to do since they're all of the same type).
|
|
7
|
-
*/
|
|
8
|
-
{ value, min, max, }: {
|
|
9
|
-
value: number;
|
|
10
|
-
min: number;
|
|
11
|
-
max: number;
|
|
12
|
-
}): number;
|
|
13
3
|
export declare function convertIntoNumber(input: unknown): number;
|
|
14
4
|
export declare function doesRequireScientificNotation(input: number): boolean;
|
|
15
5
|
/**
|
|
@@ -23,3 +13,31 @@ export declare function ensureMinAndMax({ min, max }: {
|
|
|
23
13
|
min: number;
|
|
24
14
|
max: number;
|
|
25
15
|
};
|
|
16
|
+
export declare function toEnsuredNumber(input: any): number;
|
|
17
|
+
/**
|
|
18
|
+
* If the given value is outside the given min/max bounds, instead of clamping the number (as the
|
|
19
|
+
* `clamp` function does), this function wraps the value around to the next bound.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* wrapNumber({min: 0, max: 100, value: 101}) == 0;
|
|
23
|
+
*/
|
|
24
|
+
export declare function wrapNumber({ max, min, value }: {
|
|
25
|
+
value: number;
|
|
26
|
+
max: number;
|
|
27
|
+
min: number;
|
|
28
|
+
}): number;
|
|
29
|
+
export declare function round(inputs: {
|
|
30
|
+
number: number;
|
|
31
|
+
digits: number;
|
|
32
|
+
}): number;
|
|
33
|
+
/** Clamp's the given value to within the min and max bounds, inclusive. */
|
|
34
|
+
export declare function clamp({ value, min, max }: {
|
|
35
|
+
value: number;
|
|
36
|
+
min: number;
|
|
37
|
+
max: number;
|
|
38
|
+
}): number;
|
|
39
|
+
/** Standard box dimensions. */
|
|
40
|
+
export type Dimensions = {
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export * from './augments/function';
|
|
|
10
10
|
export * from './augments/json';
|
|
11
11
|
export * from './augments/json-compatible';
|
|
12
12
|
export * from './augments/map';
|
|
13
|
-
export * from './augments/number';
|
|
14
13
|
export * from './augments/object/enum';
|
|
15
14
|
export * from './augments/object/filter-object';
|
|
16
15
|
export * from './augments/object/has-key';
|
package/package.json
CHANGED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.round = exports.wrapNumber = exports.toEnsuredNumber = void 0;
|
|
4
|
-
function toEnsuredNumber(input) {
|
|
5
|
-
const numeric = Number(input);
|
|
6
|
-
if (isNaN(numeric)) {
|
|
7
|
-
throw new Error(`Cannot convert given input to a number: ${input}`);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
return numeric;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.toEnsuredNumber = toEnsuredNumber;
|
|
14
|
-
function wrapNumber({ max, min, value }) {
|
|
15
|
-
if (value > max) {
|
|
16
|
-
return min;
|
|
17
|
-
}
|
|
18
|
-
else if (value < min) {
|
|
19
|
-
return max;
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
}
|
|
23
|
-
exports.wrapNumber = wrapNumber;
|
|
24
|
-
function round(inputs) {
|
|
25
|
-
const digitFactor = Math.pow(10, inputs.digits);
|
|
26
|
-
const multiplied = inputs.number * digitFactor;
|
|
27
|
-
return Number((Math.round(multiplied) / digitFactor).toFixed(inputs.digits));
|
|
28
|
-
}
|
|
29
|
-
exports.round = round;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function toEnsuredNumber(input) {
|
|
2
|
-
const numeric = Number(input);
|
|
3
|
-
if (isNaN(numeric)) {
|
|
4
|
-
throw new Error(`Cannot convert given input to a number: ${input}`);
|
|
5
|
-
}
|
|
6
|
-
else {
|
|
7
|
-
return numeric;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export function wrapNumber({ max, min, value }) {
|
|
11
|
-
if (value > max) {
|
|
12
|
-
return min;
|
|
13
|
-
}
|
|
14
|
-
else if (value < min) {
|
|
15
|
-
return max;
|
|
16
|
-
}
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
export function round(inputs) {
|
|
20
|
-
const digitFactor = Math.pow(10, inputs.digits);
|
|
21
|
-
const multiplied = inputs.number * digitFactor;
|
|
22
|
-
return Number((Math.round(multiplied) / digitFactor).toFixed(inputs.digits));
|
|
23
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare function toEnsuredNumber(input: any): number;
|
|
2
|
-
export declare function wrapNumber({ max, min, value }: {
|
|
3
|
-
value: number;
|
|
4
|
-
max: number;
|
|
5
|
-
min: number;
|
|
6
|
-
}): number;
|
|
7
|
-
export declare function round(inputs: {
|
|
8
|
-
number: number;
|
|
9
|
-
digits: number;
|
|
10
|
-
}): number;
|