@augment-vir/common 31.73.5 → 32.1.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.
@@ -26,7 +26,7 @@
26
26
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
27
27
  */
28
28
  export function filterOutIndexes(array, indexes) {
29
- return array.filter((_, index) => !indexes.includes(index));
29
+ return array.filter((entry, index) => !indexes.includes(index));
30
30
  }
31
31
  /**
32
32
  * Performs
@@ -23,9 +23,14 @@ import { ensureErrorAndPrependMessage, wait } from '@augment-vir/core';
23
23
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
24
24
  */
25
25
  export function retry(maxRetries, callback, options = {}) {
26
- return internalRetry(0, maxRetries, callback, options);
26
+ return internalRetry({
27
+ currentRetry: 0,
28
+ maxRetries,
29
+ callback,
30
+ options,
31
+ });
27
32
  }
28
- function internalRetry(currentRetry, maxRetries, callback, options = {}) {
33
+ function internalRetry({ currentRetry, maxRetries, callback, options = {}, }) {
29
34
  try {
30
35
  const result = callback({
31
36
  retryCount: currentRetry,
@@ -42,7 +47,12 @@ function internalRetry(currentRetry, maxRetries, callback, options = {}) {
42
47
  if (options.interval) {
43
48
  await wait(options.interval);
44
49
  }
45
- return internalRetry(currentRetry + 1, maxRetries, callback, options);
50
+ return internalRetry({
51
+ currentRetry: currentRetry + 1,
52
+ maxRetries,
53
+ callback,
54
+ options,
55
+ });
46
56
  }
47
57
  });
48
58
  }
@@ -55,10 +65,20 @@ function internalRetry(currentRetry, maxRetries, callback, options = {}) {
55
65
  throw ensureErrorAndPrependMessage(error, 'Retry max reached');
56
66
  }
57
67
  else if (options.interval) {
58
- return wait(options.interval).then(() => internalRetry(currentRetry + 1, maxRetries, callback, options));
68
+ return wait(options.interval).then(() => internalRetry({
69
+ currentRetry: currentRetry + 1,
70
+ maxRetries,
71
+ callback,
72
+ options,
73
+ }));
59
74
  }
60
75
  else {
61
- return internalRetry(currentRetry + 1, maxRetries, callback, options);
76
+ return internalRetry({
77
+ currentRetry: currentRetry + 1,
78
+ maxRetries,
79
+ callback,
80
+ options,
81
+ });
62
82
  }
63
83
  }
64
84
  }
@@ -41,11 +41,17 @@ function combineBeforeAndAfterDot({ beforeDot, afterDot = '', maxLength, }) {
41
41
  return beforeDot;
42
42
  }
43
43
  function truncateBigNumber(numberAsString, suffixes, maxLength) {
44
- const [beforeDot, afterDot,] = safeSplit(numberAsString, '.');
44
+ const [beforeDot, afterDot,] = safeSplit({
45
+ value: numberAsString,
46
+ splitter: '.',
47
+ });
45
48
  const withCommas = addCommasToNumber(beforeDot);
46
49
  const truncationDepth = safeMatch(withCommas, /,/g).length;
47
50
  const suffix = suffixes[truncationDepth - 1];
48
- const [beforeComma, afterComma,] = safeSplit(withCommas, ',');
51
+ const [beforeComma, afterComma,] = safeSplit({
52
+ value: withCommas,
53
+ splitter: ',',
54
+ });
49
55
  const trailing = [
50
56
  afterComma,
51
57
  afterDot,
@@ -73,7 +79,10 @@ function truncateBigNumber(numberAsString, suffixes, maxLength) {
73
79
  const minScientificNotationLength = '1e+'.length;
74
80
  function truncateScientificNotation({ input, maxLength, }) {
75
81
  const valueString = String(input);
76
- const [beforeExponent, rawExponent,] = safeSplit(valueString, 'e');
82
+ const [beforeExponent, rawExponent,] = safeSplit({
83
+ value: valueString,
84
+ splitter: 'e',
85
+ });
77
86
  const exponent = rawExponent.replace(/^[-+]/, '');
78
87
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
79
88
  const plusOrMinus = rawExponent[0];
@@ -82,7 +91,10 @@ function truncateScientificNotation({ input, maxLength, }) {
82
91
  plusOrMinus,
83
92
  exponent,
84
93
  ].join('');
85
- const [beforeDot, afterDot,] = safeSplit(beforeExponent, '.');
94
+ const [beforeDot, afterDot,] = safeSplit({
95
+ value: beforeExponent,
96
+ splitter: '.',
97
+ });
86
98
  const minLength = exponent.length + minScientificNotationLength;
87
99
  if (minLength === maxLength) {
88
100
  // this will look like "4e+4" or "5e-234"
@@ -114,7 +126,10 @@ function truncateScientificNotation({ input, maxLength, }) {
114
126
  }
115
127
  }
116
128
  function handleSmallNumbers(numberAsString, maxLength) {
117
- const [beforeDot, afterDot,] = safeSplit(addCommasToNumber(numberAsString), '.');
129
+ const [beforeDot, afterDot,] = safeSplit({
130
+ value: addCommasToNumber(numberAsString),
131
+ splitter: '.',
132
+ });
118
133
  if (beforeDot.length <= maxLength) {
119
134
  return combineBeforeAndAfterDot({
120
135
  beforeDot,
@@ -30,7 +30,10 @@ export function sanitizeFileName(original) {
30
30
  const extension = extractExtension(sanitized).extension;
31
31
  if (extension) {
32
32
  return [
33
- safeSplit(sanitized, extension)[0],
33
+ safeSplit({
34
+ value: sanitized,
35
+ splitter: extension,
36
+ })[0],
34
37
  extension.replaceAll('_', ''),
35
38
  ].join('');
36
39
  }
@@ -36,7 +36,7 @@ export type SeededRandomState = [
36
36
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
37
37
  */
38
38
  export declare class SeededRandom {
39
- private readonly alea;
39
+ protected readonly alea: AleaRandom;
40
40
  /** Generate a new {@link SeededRandom} instance from a seed. */
41
41
  static fromSeed(seed: string | number): SeededRandom;
42
42
  /** Generate a new {@link SeededRandom} instance from a specific state. */
@@ -50,7 +50,7 @@ export declare class SeededRandom {
50
50
  * This constructor is private. Use {@link SeededRandom.fromSeed} or
51
51
  * {@link SeededRandom.fromState} instead.
52
52
  */
53
- private constructor();
53
+ protected constructor(alea: AleaRandom);
54
54
  /** Generates the next deterministic pseudo random number. */
55
55
  next(): number;
56
56
  /**
@@ -60,3 +60,42 @@ export declare class SeededRandom {
60
60
  */
61
61
  clone(): SeededRandom;
62
62
  }
63
+ /**
64
+ * Alea algorithm has the following license from http://baagoe.com/en/RandomMusings/javascript. The
65
+ * code has been modified to fit into a class structure and simplify code flow and arguments. The
66
+ * algorithm itself has not changed.
67
+ *
68
+ * Copyright (C) 2010 by Johannes Baagøe (baagoe@baagoe.org)
69
+ *
70
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
71
+ * associated documentation files (the "Software"), to deal in the Software without restriction,
72
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
73
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
74
+ * furnished to do so, subject to the following conditions:
75
+ *
76
+ * The above copyright notice and this permission notice shall be included in all copies or
77
+ * substantial portions of the Software.
78
+ *
79
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
80
+ * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
81
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
82
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
83
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
84
+ */
85
+ /** Alea v0.9 */
86
+ declare class AleaRandom {
87
+ protected n: number;
88
+ protected s: [
89
+ number,
90
+ number,
91
+ number,
92
+ number
93
+ ];
94
+ /** Mash v0.9. */
95
+ protected mash(input: any): number;
96
+ constructor(seed: string | number);
97
+ next(): number;
98
+ importState(state: typeof this.s): void;
99
+ exportState(): typeof this.s;
100
+ }
101
+ export {};
@@ -9,10 +9,15 @@
9
9
  * ```ts
10
10
  * import {replaceStringAtIndex} from '@augment-vir/common';
11
11
  *
12
- * replaceStringAtIndex('eat the waffles', 4, 'his'); // outputs `'eat his waffles'`
13
- * replaceStringAtIndex('eat the waffles', 4, 'my', 3); // outputs `'eat my waffles'`
12
+ * replaceStringAtIndex({original: 'eat the waffles', start: 4, replacement: 'his'}); // outputs `'eat his waffles'`
13
+ * replaceStringAtIndex({original: 'eat the waffles', start: 4, replacement: 'my', length: 3}); // outputs `'eat my waffles'`
14
14
  * ```
15
15
  *
16
16
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
17
  */
18
- export declare function replaceStringAtIndex(originalString: string, start: number, newString: string, length?: number): string;
18
+ export declare function replaceStringAtIndex({ original, start, replacement, length, }: Readonly<{
19
+ original: string;
20
+ start: number;
21
+ replacement: string;
22
+ length?: number | undefined;
23
+ }>): string;
@@ -9,14 +9,14 @@
9
9
  * ```ts
10
10
  * import {replaceStringAtIndex} from '@augment-vir/common';
11
11
  *
12
- * replaceStringAtIndex('eat the waffles', 4, 'his'); // outputs `'eat his waffles'`
13
- * replaceStringAtIndex('eat the waffles', 4, 'my', 3); // outputs `'eat my waffles'`
12
+ * replaceStringAtIndex({original: 'eat the waffles', start: 4, replacement: 'his'}); // outputs `'eat his waffles'`
13
+ * replaceStringAtIndex({original: 'eat the waffles', start: 4, replacement: 'my', length: 3}); // outputs `'eat my waffles'`
14
14
  * ```
15
15
  *
16
16
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
17
17
  */
18
- export function replaceStringAtIndex(originalString, start, newString, length = newString.length) {
19
- const before = originalString.slice(0, Math.max(0, start));
20
- const after = originalString.slice(Math.max(0, start + length));
21
- return `${before}${newString}${after}`;
18
+ export function replaceStringAtIndex({ original, start, replacement, length = replacement.length, }) {
19
+ const before = original.slice(0, Math.max(0, start));
20
+ const after = original.slice(Math.max(0, start + length));
21
+ return `${before}${replacement}${after}`;
22
22
  }
@@ -28,4 +28,7 @@ export declare function splitIncludeSplit(original: string, splitDelimiter: stri
28
28
  * @category Package : @augment-vir/common
29
29
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
30
30
  */
31
- export declare function safeSplit(input: string, splitString: string): AtLeastTuple<string, 1>;
31
+ export declare function safeSplit({ value, splitter, }: Readonly<{
32
+ value: string;
33
+ splitter: string;
34
+ }>): AtLeastTuple<string, 1>;
@@ -50,6 +50,6 @@ export function splitIncludeSplit(original, splitDelimiter, { caseSensitive }) {
50
50
  * @category Package : @augment-vir/common
51
51
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
52
52
  */
53
- export function safeSplit(input, splitString) {
54
- return input.split(splitString);
53
+ export function safeSplit({ value, splitter, }) {
54
+ return value.split(splitter);
55
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "31.73.5",
3
+ "version": "32.1.0",
4
4
  "description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
5
5
  "keywords": [
6
6
  "augment",
@@ -40,9 +40,9 @@
40
40
  "test:web": "virmator --no-deps test web"
41
41
  },
42
42
  "dependencies": {
43
- "@augment-vir/assert": "^31.73.5",
44
- "@augment-vir/core": "^31.73.5",
45
- "@date-vir/duration": "^8.5.0",
43
+ "@augment-vir/assert": "^32.1.0",
44
+ "@augment-vir/core": "^32.1.0",
45
+ "@date-vir/duration": "^8.6.1",
46
46
  "@paralleldrive/cuid2": "^3.3.0",
47
47
  "ansi-styles": "^6.2.3",
48
48
  "deepcopy-esm": "^2.1.2",
@@ -56,7 +56,7 @@
56
56
  "@web/test-runner-playwright": "^0.11.1",
57
57
  "execute-in-browser": "^1.0.9",
58
58
  "istanbul-smart-text-reporter": "^1.1.5",
59
- "runstorm": "^1.0.2",
59
+ "runstorm": "^1.0.4",
60
60
  "typescript": "^6.0.3"
61
61
  },
62
62
  "engines": {