@augment-vir/common 21.3.5 → 21.4.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/error.js +14 -1
- package/dist/cjs/augments/number.js +7 -1
- package/dist/cjs/augments/object/matches-object-shape.js +2 -1
- package/dist/esm/augments/error.js +14 -1
- package/dist/esm/augments/number.js +5 -0
- package/dist/esm/augments/object/matches-object-shape.js +2 -1
- package/dist/types/augments/number.d.ts +4 -0
- package/dist/types/augments/tuple.d.ts +1 -0
- package/package.json +2 -2
|
@@ -54,7 +54,20 @@ function ensureErrorAndPrependMessage(maybeError, prependMessage) {
|
|
|
54
54
|
exports.ensureErrorAndPrependMessage = ensureErrorAndPrependMessage;
|
|
55
55
|
function wrapInTry(inputs) {
|
|
56
56
|
try {
|
|
57
|
-
|
|
57
|
+
const returnValue = inputs.callback();
|
|
58
|
+
if (returnValue instanceof Promise) {
|
|
59
|
+
return returnValue.catch((error) => {
|
|
60
|
+
if (inputs.catchCallback) {
|
|
61
|
+
return inputs.catchCallback(error);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return inputs.fallbackValue;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return returnValue;
|
|
70
|
+
}
|
|
58
71
|
}
|
|
59
72
|
catch (error) {
|
|
60
73
|
if (inputs.catchCallback) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wrapNumber = exports.toEnsuredNumber = void 0;
|
|
3
|
+
exports.round = exports.wrapNumber = exports.toEnsuredNumber = void 0;
|
|
4
4
|
function toEnsuredNumber(input) {
|
|
5
5
|
const numeric = Number(input);
|
|
6
6
|
if (isNaN(numeric)) {
|
|
@@ -21,3 +21,9 @@ function wrapNumber({ max, min, value }) {
|
|
|
21
21
|
return value;
|
|
22
22
|
}
|
|
23
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;
|
|
@@ -79,7 +79,8 @@ function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps
|
|
|
79
79
|
if ((0, typed_has_property_1.typedHasProperty)(matchValue, 'constructor')) {
|
|
80
80
|
if (!(0, typed_has_property_1.typedHasProperty)(testValue, 'constructor') ||
|
|
81
81
|
testValue.constructor !== matchValue.constructor) {
|
|
82
|
-
throwKeyError(`constructor "${testValue?.constructor
|
|
82
|
+
throwKeyError(`constructor "${testValue?.constructor
|
|
83
|
+
?.name}" did not match expected constructor "${matchValue.constructor}"`);
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
}
|
|
@@ -46,7 +46,20 @@ export function ensureErrorAndPrependMessage(maybeError, prependMessage) {
|
|
|
46
46
|
}
|
|
47
47
|
export function wrapInTry(inputs) {
|
|
48
48
|
try {
|
|
49
|
-
|
|
49
|
+
const returnValue = inputs.callback();
|
|
50
|
+
if (returnValue instanceof Promise) {
|
|
51
|
+
return returnValue.catch((error) => {
|
|
52
|
+
if (inputs.catchCallback) {
|
|
53
|
+
return inputs.catchCallback(error);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return inputs.fallbackValue;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return returnValue;
|
|
62
|
+
}
|
|
50
63
|
}
|
|
51
64
|
catch (error) {
|
|
52
65
|
if (inputs.catchCallback) {
|
|
@@ -16,3 +16,8 @@ export function wrapNumber({ max, min, value }) {
|
|
|
16
16
|
}
|
|
17
17
|
return value;
|
|
18
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
|
+
}
|
|
@@ -74,7 +74,8 @@ function compareInnerValue(testValue, matchValue, throwKeyError, allowExtraProps
|
|
|
74
74
|
if (typedHasProperty(matchValue, 'constructor')) {
|
|
75
75
|
if (!typedHasProperty(testValue, 'constructor') ||
|
|
76
76
|
testValue.constructor !== matchValue.constructor) {
|
|
77
|
-
throwKeyError(`constructor "${testValue?.constructor
|
|
77
|
+
throwKeyError(`constructor "${testValue?.constructor
|
|
78
|
+
?.name}" did not match expected constructor "${matchValue.constructor}"`);
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.4.0",
|
|
4
4
|
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/electrovir/augment-vir/issues"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"browser-or-node": "^2.1.1",
|
|
28
|
-
"type-fest": "^4.
|
|
28
|
+
"type-fest": "^4.6.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"typescript": "^5.2.2"
|