@augment-vir/common 21.3.6 → 21.5.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.
@@ -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?.name}" did not match expected constructor "${matchValue.constructor}"`);
82
+ throwKeyError(`constructor "${testValue?.constructor
83
+ ?.name}" did not match expected constructor "${matchValue.constructor}"`);
83
84
  }
84
85
  }
85
86
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.callAsynchronously = exports.wrapPromiseInTimeout = exports.PromiseTimeoutError = exports.isPromiseLike = void 0;
3
+ exports.executeWithRetries = exports.callAsynchronously = exports.wrapPromiseInTimeout = exports.PromiseTimeoutError = exports.isPromiseLike = void 0;
4
4
  const typed_has_property_1 = require("../object/typed-has-property");
5
5
  function isPromiseLike(input) {
6
6
  if ((0, typed_has_property_1.typedHasProperty)(input, 'then') && typeof input.then === 'function') {
@@ -48,3 +48,17 @@ async function callAsynchronously(callback) {
48
48
  return await Promise.resolve().then(() => callback());
49
49
  }
50
50
  exports.callAsynchronously = callAsynchronously;
51
+ async function executeWithRetries(retryCount, callback) {
52
+ let currentRetry = 0;
53
+ while (currentRetry < retryCount) {
54
+ try {
55
+ const result = await callback();
56
+ return result;
57
+ }
58
+ catch (error) {
59
+ currentRetry++;
60
+ }
61
+ }
62
+ throw new Error('Retry max reached.');
63
+ }
64
+ exports.executeWithRetries = executeWithRetries;
@@ -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?.name}" did not match expected constructor "${matchValue.constructor}"`);
77
+ throwKeyError(`constructor "${testValue?.constructor
78
+ ?.name}" did not match expected constructor "${matchValue.constructor}"`);
78
79
  }
79
80
  }
80
81
  }
@@ -41,3 +41,16 @@ export function wrapPromiseInTimeout(durationMs, originalPromise) {
41
41
  export async function callAsynchronously(callback) {
42
42
  return await Promise.resolve().then(() => callback());
43
43
  }
44
+ export async function executeWithRetries(retryCount, callback) {
45
+ let currentRetry = 0;
46
+ while (currentRetry < retryCount) {
47
+ try {
48
+ const result = await callback();
49
+ return result;
50
+ }
51
+ catch (error) {
52
+ currentRetry++;
53
+ }
54
+ }
55
+ throw new Error('Retry max reached.');
56
+ }
@@ -4,3 +4,7 @@ export declare function wrapNumber({ max, min, value }: {
4
4
  max: number;
5
5
  min: number;
6
6
  }): number;
7
+ export declare function round(inputs: {
8
+ number: number;
9
+ digits: number;
10
+ }): number;
@@ -12,3 +12,4 @@ export declare function wrapPromiseInTimeout<PromiseValueType>(durationMs: numbe
12
12
  * function was originally synchronous.
13
13
  */
14
14
  export declare function callAsynchronously<T>(callback: () => MaybePromise<T>): Promise<T>;
15
+ export declare function executeWithRetries<T>(retryCount: number, callback: () => T): Promise<T>;
@@ -9,4 +9,5 @@ export declare function assertLengthAtLeast<ArrayElementGeneric, LengthGeneric e
9
9
  export type MappedTuple<Tuple extends ReadonlyArray<any>, NewValueType> = {
10
10
  [I in keyof Tuple]: NewValueType;
11
11
  };
12
+ export type MaybeTuple<T> = T | AtLeastTuple<T, 1>;
12
13
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "21.3.6",
3
+ "version": "21.5.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.4.0"
28
+ "type-fest": "^4.6.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "typescript": "^5.2.2"