@augment-vir/common 31.0.0 → 31.0.1

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.
Files changed (38) hide show
  1. package/dist/augments/array/array-map.d.ts +3 -12
  2. package/dist/augments/array/array-map.js +3 -12
  3. package/dist/augments/array/array-to-object.d.ts +1 -7
  4. package/dist/augments/array/array-to-object.js +6 -24
  5. package/dist/augments/array/awaited/awaited-filter.d.ts +3 -12
  6. package/dist/augments/array/awaited/awaited-filter.js +3 -12
  7. package/dist/augments/array/awaited/awaited-for-each.d.ts +3 -12
  8. package/dist/augments/array/awaited/awaited-for-each.js +3 -12
  9. package/dist/augments/array/awaited/awaited-map.d.ts +3 -12
  10. package/dist/augments/array/awaited/awaited-map.js +3 -12
  11. package/dist/augments/array/filter.d.ts +1 -11
  12. package/dist/augments/array/filter.js +2 -16
  13. package/dist/augments/array/remove-duplicates.d.ts +2 -16
  14. package/dist/augments/array/remove-duplicates.js +2 -16
  15. package/dist/augments/array/repeat-array.d.ts +1 -5
  16. package/dist/augments/array/repeat-array.js +1 -5
  17. package/dist/augments/enum/enum-value-check.d.ts +1 -11
  18. package/dist/augments/enum/enum-value-check.js +1 -11
  19. package/dist/augments/error/combine-errors.d.ts +1 -4
  20. package/dist/augments/error/combine-errors.js +1 -4
  21. package/dist/augments/json/append-json.js +1 -11
  22. package/dist/augments/json/copy-through-json.d.ts +2 -8
  23. package/dist/augments/json/copy-through-json.js +2 -8
  24. package/dist/augments/json/jsonify.d.ts +2 -8
  25. package/dist/augments/json/jsonify.js +2 -8
  26. package/dist/augments/log/log-colors.js +10 -33
  27. package/dist/augments/number/truncate-number.js +12 -35
  28. package/dist/augments/object/diff.js +5 -20
  29. package/dist/augments/object/map-entries.js +3 -9
  30. package/dist/augments/object/merge-deep.js +2 -2
  31. package/dist/augments/object/merge-defined-properties.js +1 -1
  32. package/dist/augments/object/merge-property-arrays.d.ts +2 -8
  33. package/dist/augments/object/merge-property-arrays.js +3 -9
  34. package/dist/augments/object/object-entries.js +1 -4
  35. package/dist/augments/object/object-filter.js +1 -1
  36. package/dist/augments/regexp/regexp-flags.js +1 -4
  37. package/dist/augments/string/comma.js +2 -6
  38. package/package.json +3 -3
@@ -12,18 +12,9 @@ import { Writable } from '../type/writable.js';
12
12
  * ```ts
13
13
  * import {typedMap} from '@augment-vir/common';
14
14
  *
15
- * const result = await typedMap(
16
- * [
17
- * 1,
18
- * 2,
19
- * 3,
20
- * 4,
21
- * 5,
22
- * ],
23
- * (value) => {
24
- * return value + 1;
25
- * },
26
- * );
15
+ * const result = await typedMap([1, 2, 3, 4, 5], (value) => {
16
+ * return value + 1;
17
+ * });
27
18
  * ```
28
19
  *
29
20
  * @returns A new array (does not mutate).
@@ -10,18 +10,9 @@
10
10
  * ```ts
11
11
  * import {typedMap} from '@augment-vir/common';
12
12
  *
13
- * const result = await typedMap(
14
- * [
15
- * 1,
16
- * 2,
17
- * 3,
18
- * 4,
19
- * 5,
20
- * ],
21
- * (value) => {
22
- * return value + 1;
23
- * },
24
- * );
13
+ * const result = await typedMap([1, 2, 3, 4, 5], (value) => {
14
+ * return value + 1;
15
+ * });
25
16
  * ```
26
17
  *
27
18
  * @returns A new array (does not mutate).
@@ -10,13 +10,7 @@ import { type MaybePromise } from '@augment-vir/core';
10
10
  * ```ts
11
11
  * import {arrayToObject} from '@augment-vir/common';
12
12
  *
13
- * const result = arrayToObject(
14
- * [
15
- * 'a',
16
- * 'b',
17
- * ],
18
- * (value) => `key-${value}`,
19
- * );
13
+ * const result = arrayToObject(['a', 'b'], (value) => `key-${value}`);
20
14
  * // result is `{key-a: ['a'], key-b: ['b']}`
21
15
  * ```
22
16
  */
@@ -14,13 +14,7 @@ import { filterMap } from './filter.js';
14
14
  * ```ts
15
15
  * import {arrayToObject} from '@augment-vir/common';
16
16
  *
17
- * const result = arrayToObject(
18
- * [
19
- * 'a',
20
- * 'b',
21
- * ],
22
- * (value) => `key-${value}`,
23
- * );
17
+ * const result = arrayToObject(['a', 'b'], (value) => `key-${value}`);
24
18
  * // result is `{key-a: ['a'], key-b: ['b']}`
25
19
  * ```
26
20
  */
@@ -46,15 +40,9 @@ export function groupArrayBy(inputArray, callback) {
46
40
  * ```ts
47
41
  * import {arrayToObject} from '@augment-vir/common';
48
42
  *
49
- * const result = arrayToObject(
50
- * [
51
- * 'a',
52
- * 'b',
53
- * ],
54
- * (value) => {
55
- * return {key: `key-${value}`, value};
56
- * },
57
- * );
43
+ * const result = arrayToObject(['a', 'b'], (value) => {
44
+ * return {key: `key-${value}`, value};
45
+ * });
58
46
  * // result is `{key-a: 'a', key-b: 'b'}`
59
47
  * ```
60
48
  *
@@ -71,10 +59,7 @@ export function arrayToObject(inputArray, callback) {
71
59
  return output;
72
60
  }
73
61
  else if (output) {
74
- return [
75
- output.key,
76
- output.value,
77
- ];
62
+ return [output.key, output.value];
78
63
  }
79
64
  else {
80
65
  return undefined;
@@ -92,10 +77,7 @@ export function arrayToObject(inputArray, callback) {
92
77
  return entry;
93
78
  }
94
79
  else {
95
- return [
96
- entry.key,
97
- entry.value,
98
- ];
80
+ return [entry.key, entry.value];
99
81
  }
100
82
  }, check.isTruthy);
101
83
  resolve(typedObjectFromEntries(entries));
@@ -10,18 +10,9 @@
10
10
  * ```ts
11
11
  * import {awaitedFilter} from '@augment-vir/common';
12
12
  *
13
- * const result = await awaitedFilter(
14
- * [
15
- * 1,
16
- * 2,
17
- * 3,
18
- * 4,
19
- * 5,
20
- * ],
21
- * async (value) => {
22
- * return await Promise.resolve(value > 2);
23
- * },
24
- * );
13
+ * const result = await awaitedFilter([1, 2, 3, 4, 5], async (value) => {
14
+ * return await Promise.resolve(value > 2);
15
+ * });
25
16
  * ```
26
17
  *
27
18
  * @returns A new array (does not mutate).
@@ -11,18 +11,9 @@ import { awaitedBlockingMap } from './awaited-map.js';
11
11
  * ```ts
12
12
  * import {awaitedFilter} from '@augment-vir/common';
13
13
  *
14
- * const result = await awaitedFilter(
15
- * [
16
- * 1,
17
- * 2,
18
- * 3,
19
- * 4,
20
- * 5,
21
- * ],
22
- * async (value) => {
23
- * return await Promise.resolve(value > 2);
24
- * },
25
- * );
14
+ * const result = await awaitedFilter([1, 2, 3, 4, 5], async (value) => {
15
+ * return await Promise.resolve(value > 2);
16
+ * });
26
17
  * ```
27
18
  *
28
19
  * @returns A new array (does not mutate).
@@ -12,18 +12,9 @@
12
12
  * ```ts
13
13
  * import {awaitedForEach} from '@augment-vir/common';
14
14
  *
15
- * await awaitedForEach(
16
- * [
17
- * 1,
18
- * 2,
19
- * 3,
20
- * 4,
21
- * 5,
22
- * ],
23
- * async (value) => {
24
- * await Promise.resolve(value);
25
- * },
26
- * );
15
+ * await awaitedForEach([1, 2, 3, 4, 5], async (value) => {
16
+ * await Promise.resolve(value);
17
+ * });
27
18
  * ```
28
19
  *
29
20
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
@@ -13,18 +13,9 @@ import { awaitedBlockingMap } from './awaited-map.js';
13
13
  * ```ts
14
14
  * import {awaitedForEach} from '@augment-vir/common';
15
15
  *
16
- * await awaitedForEach(
17
- * [
18
- * 1,
19
- * 2,
20
- * 3,
21
- * 4,
22
- * 5,
23
- * ],
24
- * async (value) => {
25
- * await Promise.resolve(value);
26
- * },
27
- * );
16
+ * await awaitedForEach([1, 2, 3, 4, 5], async (value) => {
17
+ * await Promise.resolve(value);
18
+ * });
28
19
  * ```
29
20
  *
30
21
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
@@ -13,18 +13,9 @@
13
13
  * ```ts
14
14
  * import {awaitedBlockingMap} from '@augment-vir/common';
15
15
  *
16
- * const result = await awaitedBlockingMap(
17
- * [
18
- * 1,
19
- * 2,
20
- * 3,
21
- * 4,
22
- * 5,
23
- * ],
24
- * async (value) => {
25
- * return await Promise.resolve(value);
26
- * },
27
- * );
16
+ * const result = await awaitedBlockingMap([1, 2, 3, 4, 5], async (value) => {
17
+ * return await Promise.resolve(value);
18
+ * });
28
19
  * ```
29
20
  *
30
21
  * @returns A new array (does not mutate).
@@ -13,18 +13,9 @@
13
13
  * ```ts
14
14
  * import {awaitedBlockingMap} from '@augment-vir/common';
15
15
  *
16
- * const result = await awaitedBlockingMap(
17
- * [
18
- * 1,
19
- * 2,
20
- * 3,
21
- * 4,
22
- * 5,
23
- * ],
24
- * async (value) => {
25
- * return await Promise.resolve(value);
26
- * },
27
- * );
16
+ * const result = await awaitedBlockingMap([1, 2, 3, 4, 5], async (value) => {
17
+ * return await Promise.resolve(value);
18
+ * });
28
19
  * ```
29
20
  *
30
21
  * @returns A new array (does not mutate).
@@ -8,17 +8,7 @@
8
8
  * ```ts
9
9
  * import {filterOutIndexes} from '@augment-vir/common';
10
10
  *
11
- * const result = filterOutIndexes(
12
- * [
13
- * 'a',
14
- * 'b',
15
- * '',
16
- * ],
17
- * [
18
- * 0,
19
- * 2,
20
- * ],
21
- * );
11
+ * const result = filterOutIndexes(['a', 'b', ''], [0, 2]);
22
12
  * // result is `['b']`
23
13
  * ```
24
14
  *
@@ -8,17 +8,7 @@
8
8
  * ```ts
9
9
  * import {filterOutIndexes} from '@augment-vir/common';
10
10
  *
11
- * const result = filterOutIndexes(
12
- * [
13
- * 'a',
14
- * 'b',
15
- * '',
16
- * ],
17
- * [
18
- * 0,
19
- * 2,
20
- * ],
21
- * );
11
+ * const result = filterOutIndexes(['a', 'b', ''], [0, 2]);
22
12
  * // result is `['b']`
23
13
  * ```
24
14
  *
@@ -43,11 +33,7 @@ export function filterOutIndexes(array, indexes) {
43
33
  * import {filterMap} from '@augment-vir/common';
44
34
  *
45
35
  * const result = filterMap(
46
- * [
47
- * 'a',
48
- * 'b',
49
- * '',
50
- * ],
36
+ * ['a', 'b', ''],
51
37
  * // map callback
52
38
  * (value) => {
53
39
  * return `value-${value}`;
@@ -9,15 +9,7 @@
9
9
  * ```ts
10
10
  * import {removeDuplicates} from '@augment-vir/common';
11
11
  *
12
- * const result = removeDuplicates([
13
- * 1,
14
- * 1,
15
- * 1,
16
- * 1,
17
- * 1,
18
- * 2,
19
- * 4,
20
- * ]);
12
+ * const result = removeDuplicates([1, 1, 1, 1, 1, 2, 4]);
21
13
  * // result is `[1, 2, 4]`
22
14
  *
23
15
  * const exampleEntry = {id: 5};
@@ -42,13 +34,7 @@
42
34
  * const exampleEntry = {id: 5};
43
35
  *
44
36
  * const result2 = removeDuplicates(
45
- * [
46
- * {id: 1},
47
- * {id: 1},
48
- * exampleEntry,
49
- * exampleEntry,
50
- * {id: 4},
51
- * ],
37
+ * [{id: 1}, {id: 1}, exampleEntry, exampleEntry, {id: 4}],
52
38
  * (entry) => entry.id,
53
39
  * );
54
40
  * // result2 is `[{id: 1}, exampleEntry, {id: 4}]`
@@ -9,15 +9,7 @@
9
9
  * ```ts
10
10
  * import {removeDuplicates} from '@augment-vir/common';
11
11
  *
12
- * const result = removeDuplicates([
13
- * 1,
14
- * 1,
15
- * 1,
16
- * 1,
17
- * 1,
18
- * 2,
19
- * 4,
20
- * ]);
12
+ * const result = removeDuplicates([1, 1, 1, 1, 1, 2, 4]);
21
13
  * // result is `[1, 2, 4]`
22
14
  *
23
15
  * const exampleEntry = {id: 5};
@@ -42,13 +34,7 @@
42
34
  * const exampleEntry = {id: 5};
43
35
  *
44
36
  * const result2 = removeDuplicates(
45
- * [
46
- * {id: 1},
47
- * {id: 1},
48
- * exampleEntry,
49
- * exampleEntry,
50
- * {id: 4},
51
- * ],
37
+ * [{id: 1}, {id: 1}, exampleEntry, exampleEntry, {id: 4}],
52
38
  * (entry) => entry.id,
53
39
  * );
54
40
  * // result2 is `[{id: 1}, exampleEntry, {id: 4}]`
@@ -9,11 +9,7 @@
9
9
  * ```ts
10
10
  * import {repeatArray} from '@augment-vir/common';
11
11
  *
12
- * const result = repeatArray(3, [
13
- * 'a',
14
- * 'b',
15
- * 'c',
16
- * ]);
12
+ * const result = repeatArray(3, ['a', 'b', 'c']);
17
13
  * // result is `['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']`
18
14
  * ```
19
15
  *
@@ -9,11 +9,7 @@
9
9
  * ```ts
10
10
  * import {repeatArray} from '@augment-vir/common';
11
11
  *
12
- * const result = repeatArray(3, [
13
- * 'a',
14
- * 'b',
15
- * 'c',
16
- * ]);
12
+ * const result = repeatArray(3, ['a', 'b', 'c']);
17
13
  * // result is `['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']`
18
14
  * ```
19
15
  *
@@ -13,17 +13,7 @@ import type { EnumBaseType } from '@augment-vir/core';
13
13
  * B = 'b',
14
14
  * }
15
15
  *
16
- * const result = filterToEnumValues(
17
- * [
18
- * 1,
19
- * 2,
20
- * 3,
21
- * 'a',
22
- * 'b',
23
- * MyEnum.A,
24
- * ],
25
- * MyEnum,
26
- * ); // result is `[MyEnum.A, MyEnum.B, MyEnum.A]`
16
+ * const result = filterToEnumValues([1, 2, 3, 'a', 'b', MyEnum.A], MyEnum); // result is `[MyEnum.A, MyEnum.B, MyEnum.A]`
27
17
  * ```
28
18
  *
29
19
  * @returns A new array (does not mutate).
@@ -13,17 +13,7 @@ import { check } from '@augment-vir/assert';
13
13
  * B = 'b',
14
14
  * }
15
15
  *
16
- * const result = filterToEnumValues(
17
- * [
18
- * 1,
19
- * 2,
20
- * 3,
21
- * 'a',
22
- * 'b',
23
- * MyEnum.A,
24
- * ],
25
- * MyEnum,
26
- * ); // result is `[MyEnum.A, MyEnum.B, MyEnum.A]`
16
+ * const result = filterToEnumValues([1, 2, 3, 'a', 'b', MyEnum.A], MyEnum); // result is `[MyEnum.A, MyEnum.B, MyEnum.A]`
27
17
  * ```
28
18
  *
29
19
  * @returns A new array (does not mutate).
@@ -12,10 +12,7 @@
12
12
  * ```ts
13
13
  * import {combineErrors} from '@augment-vir/common';
14
14
  *
15
- * const result1 = combineErrors([
16
- * new Error('message 1'),
17
- * new Error('message 2'),
18
- * ]); // result1 is a single error with the message 'message 1\nmessage 2'
15
+ * const result1 = combineErrors([new Error('message 1'), new Error('message 2')]); // result1 is a single error with the message 'message 1\nmessage 2'
19
16
  * ```
20
17
  *
21
18
  * @returns A single error.
@@ -14,10 +14,7 @@ import { extractErrorMessage } from '@augment-vir/core';
14
14
  * ```ts
15
15
  * import {combineErrors} from '@augment-vir/common';
16
16
  *
17
- * const result1 = combineErrors([
18
- * new Error('message 1'),
19
- * new Error('message 2'),
20
- * ]); // result1 is a single error with the message 'message 1\nmessage 2'
17
+ * const result1 = combineErrors([new Error('message 1'), new Error('message 2')]); // result1 is a single error with the message 'message 1\nmessage 2'
21
18
  * ```
22
19
  *
23
20
  * @returns A single error.
@@ -18,17 +18,7 @@ import { copyThroughJson } from './copy-through-json.js';
18
18
  * // `result2` will be `[{a: 'a'}, {b: 'b'}, {a: 'q'}, 'r']`
19
19
  * const result2 = appendJson([{a: 'a'}], {b: 'b'}, {a: 'q'}, 'r');
20
20
  * // `result3` will be `['a', ['b', 'c'], 'd', 'e']`
21
- * const result3 = appendJson(
22
- * ['a'],
23
- * [
24
- * [
25
- * 'b',
26
- * 'c',
27
- * ],
28
- * ],
29
- * ['d'],
30
- * 'e',
31
- * );
21
+ * const result3 = appendJson(['a'], [['b', 'c']], ['d'], 'e');
32
22
  * ```
33
23
  *
34
24
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
@@ -16,14 +16,8 @@ import { Jsonify, Writable } from 'type-fest';
16
16
  * // `copy2` will be `{map: {}, b: 'b'}`
17
17
  * const copy2 = copyThroughJson({
18
18
  * map: new Map([
19
- * [
20
- * 'q',
21
- * 'r',
22
- * ],
23
- * [
24
- * 's',
25
- * 't',
26
- * ],
19
+ * ['q', 'r'],
20
+ * ['s', 't'],
27
21
  * ]),
28
22
  * b: 'b',
29
23
  * });
@@ -15,14 +15,8 @@
15
15
  * // `copy2` will be `{map: {}, b: 'b'}`
16
16
  * const copy2 = copyThroughJson({
17
17
  * map: new Map([
18
- * [
19
- * 'q',
20
- * 'r',
21
- * ],
22
- * [
23
- * 's',
24
- * 't',
25
- * ],
18
+ * ['q', 'r'],
19
+ * ['s', 't'],
26
20
  * ]),
27
21
  * b: 'b',
28
22
  * });
@@ -13,14 +13,8 @@ import { Jsonify } from 'type-fest';
13
13
  * // `result` is `{b: 'b'}`
14
14
  * const result = jsonify({
15
15
  * map: new Map([
16
- * [
17
- * 'q',
18
- * 'r',
19
- * ],
20
- * [
21
- * 's',
22
- * 't',
23
- * ],
16
+ * ['q', 'r'],
17
+ * ['s', 't'],
24
18
  * ]),
25
19
  * b: 'b',
26
20
  * });
@@ -13,14 +13,8 @@ import JSON5 from 'json5';
13
13
  * // `result` is `{b: 'b'}`
14
14
  * const result = jsonify({
15
15
  * map: new Map([
16
- * [
17
- * 'q',
18
- * 'r',
19
- * ],
20
- * [
21
- * 's',
22
- * 't',
23
- * ],
16
+ * ['q', 'r'],
17
+ * ['s', 't'],
24
18
  * ]),
25
19
  * b: 'b',
26
20
  * });
@@ -91,67 +91,44 @@ export const logColors = await determineDefaultLogColors();
91
91
  */
92
92
  export const defaultLogColorConfig = {
93
93
  [LogColorKey.Bold]: {
94
- colors: [
95
- logColors.bold,
96
- ],
94
+ colors: [logColors.bold],
97
95
  logType: LogOutputType.Standard,
98
96
  },
99
97
  [LogColorKey.Debug]: {
100
- colors: [
101
- logColors.debug,
102
- ],
98
+ colors: [logColors.debug],
103
99
  logType: LogOutputType.Standard,
104
100
  },
105
101
  [LogColorKey.Faint]: {
106
- colors: [
107
- logColors.faint,
108
- ],
102
+ colors: [logColors.faint],
109
103
  logType: LogOutputType.Standard,
110
104
  },
111
105
  [LogColorKey.Info]: {
112
- colors: [
113
- logColors.info,
114
- ],
106
+ colors: [logColors.info],
115
107
  logType: LogOutputType.Standard,
116
108
  },
117
109
  [LogColorKey.Mutate]: {
118
- colors: [
119
- logColors.mutate,
120
- logColors.bold,
121
- ],
110
+ colors: [logColors.mutate, logColors.bold],
122
111
  logType: LogOutputType.Standard,
123
112
  },
124
113
  [LogColorKey.NormalWeight]: {
125
- colors: [
126
- logColors.normalWeight,
127
- ],
114
+ colors: [logColors.normalWeight],
128
115
  logType: LogOutputType.Standard,
129
116
  },
130
117
  [LogColorKey.Plain]: { colors: [], logType: LogOutputType.Standard },
131
118
  [LogColorKey.Reset]: {
132
- colors: [
133
- logColors.reset,
134
- ],
119
+ colors: [logColors.reset],
135
120
  logType: LogOutputType.Standard,
136
121
  },
137
122
  [LogColorKey.Success]: {
138
- colors: [
139
- logColors.success,
140
- logColors.bold,
141
- ],
123
+ colors: [logColors.success, logColors.bold],
142
124
  logType: LogOutputType.Standard,
143
125
  },
144
126
  [LogColorKey.Error]: {
145
- colors: [
146
- logColors.error,
147
- logColors.bold,
148
- ],
127
+ colors: [logColors.error, logColors.bold],
149
128
  logType: LogOutputType.Error,
150
129
  },
151
130
  [LogColorKey.Warning]: {
152
- colors: [
153
- logColors.warning,
154
- ],
131
+ colors: [logColors.warning],
155
132
  logType: LogOutputType.Error,
156
133
  },
157
134
  };
@@ -32,31 +32,21 @@ function combineBeforeAndAfterDot({ beforeDot, afterDot = '', maxLength, }) {
32
32
  if (!Number(slicedAfterDot)) {
33
33
  return beforeDot;
34
34
  }
35
- return [
36
- beforeDot,
37
- slicedAfterDot,
38
- ].join('.');
35
+ return [beforeDot, slicedAfterDot].join('.');
39
36
  }
40
37
  }
41
38
  return beforeDot;
42
39
  }
43
40
  function truncateBigNumber(numberAsString, suffixes, maxLength) {
44
- const [beforeDot, afterDot,] = safeSplit(numberAsString, '.');
41
+ const [beforeDot, afterDot] = safeSplit(numberAsString, '.');
45
42
  const withCommas = addCommasToNumber(beforeDot);
46
43
  const truncationDepth = safeMatch(withCommas, /,/g).length;
47
44
  const suffix = suffixes[truncationDepth - 1];
48
- const [beforeComma, afterComma,] = safeSplit(withCommas, ',');
49
- const trailing = [
50
- afterComma,
51
- afterDot,
52
- ].join('');
45
+ const [beforeComma, afterComma] = safeSplit(withCommas, ',');
46
+ const trailing = [afterComma, afterDot].join('');
53
47
  if (beforeComma.length + 1 > maxLength) {
54
48
  // will look like 0.9M
55
- return [
56
- '0.',
57
- beforeComma[0],
58
- suffixes[truncationDepth],
59
- ].join('');
49
+ return ['0.', beforeComma[0], suffixes[truncationDepth]].join('');
60
50
  }
61
51
  else {
62
52
  const combined = combineBeforeAndAfterDot({
@@ -64,32 +54,22 @@ function truncateBigNumber(numberAsString, suffixes, maxLength) {
64
54
  afterDot: trailing,
65
55
  maxLength: maxLength - 1 /* -1 to account for the suffix*/,
66
56
  });
67
- return [
68
- combined,
69
- suffix,
70
- ].join('');
57
+ return [combined, suffix].join('');
71
58
  }
72
59
  }
73
60
  const minScientificNotationLength = '1e+'.length;
74
61
  function truncateScientificNotation({ input, maxLength, }) {
75
62
  const valueString = String(input);
76
- const [beforeExponent, rawExponent,] = safeSplit(valueString, 'e');
63
+ const [beforeExponent, rawExponent] = safeSplit(valueString, 'e');
77
64
  const exponent = rawExponent.replace(/^[-+]/, '');
78
65
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
79
66
  const plusOrMinus = rawExponent[0];
80
- const eSuffix = [
81
- 'e',
82
- plusOrMinus,
83
- exponent,
84
- ].join('');
85
- const [beforeDot, afterDot,] = safeSplit(beforeExponent, '.');
67
+ const eSuffix = ['e', plusOrMinus, exponent].join('');
68
+ const [beforeDot, afterDot] = safeSplit(beforeExponent, '.');
86
69
  const minLength = exponent.length + minScientificNotationLength;
87
70
  if (minLength === maxLength) {
88
71
  // this will look like "4e+4" or "5e-234"
89
- return [
90
- beforeDot,
91
- eSuffix,
92
- ].join('');
72
+ return [beforeDot, eSuffix].join('');
93
73
  }
94
74
  else if (minLength > maxLength) {
95
75
  // in this case the number is either way too big or way to small for its exponent to fit within the max length so we just jump to 0 or Infinity
@@ -107,14 +87,11 @@ function truncateScientificNotation({ input, maxLength, }) {
107
87
  beforeDot,
108
88
  maxLength: maxLength - exponent.length + minScientificNotationLength,
109
89
  });
110
- return [
111
- beforeE,
112
- eSuffix,
113
- ].join('');
90
+ return [beforeE, eSuffix].join('');
114
91
  }
115
92
  }
116
93
  function handleSmallNumbers(numberAsString, maxLength) {
117
- const [beforeDot, afterDot,] = safeSplit(addCommasToNumber(numberAsString), '.');
94
+ const [beforeDot, afterDot] = safeSplit(addCommasToNumber(numberAsString), '.');
118
95
  if (beforeDot.length <= maxLength) {
119
96
  return combineBeforeAndAfterDot({
120
97
  beforeDot,
@@ -10,10 +10,7 @@ import { getObjectTypedKeys } from '@augment-vir/core';
10
10
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
11
11
  */
12
12
  export function diffObjects(object0, object1) {
13
- const allObjectKeys = Array.from(new Set([
14
- ...getObjectTypedKeys(object0),
15
- ...getObjectTypedKeys(object1),
16
- ]));
13
+ const allObjectKeys = Array.from(new Set([...getObjectTypedKeys(object0), ...getObjectTypedKeys(object1)]));
17
14
  const diffOutput = allObjectKeys.reduce((accum, objectKey) => {
18
15
  const value0 = object0[objectKey];
19
16
  const value1 = object1[objectKey];
@@ -32,10 +29,7 @@ export function diffObjects(object0, object1) {
32
29
  accum[0][objectKey] = diffOutput[0];
33
30
  }
34
31
  return accum;
35
- }, [
36
- {},
37
- {},
38
- ]);
32
+ }, [{}, {}]);
39
33
  if (!Object.keys(diffOutput[0]).length && !Object.keys(diffOutput[1]).length) {
40
34
  return [];
41
35
  }
@@ -53,10 +47,7 @@ export function diffObjects(object0, object1) {
53
47
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
54
48
  */
55
49
  export function diffArrays(array0, array1) {
56
- const allArrayIndexes = Array.from(new Set([
57
- ...Object.keys(array0),
58
- ...Object.keys(array1),
59
- ].map((index) => Number(index)))).sort();
50
+ const allArrayIndexes = Array.from(new Set([...Object.keys(array0), ...Object.keys(array1)].map((index) => Number(index)))).sort();
60
51
  const diffArrays = allArrayIndexes.reduce((accum, arrayIndex) => {
61
52
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
62
53
  const value0 = array0[arrayIndex];
@@ -72,10 +63,7 @@ export function diffArrays(array0, array1) {
72
63
  }
73
64
  }
74
65
  return accum;
75
- }, [
76
- [],
77
- [],
78
- ]);
66
+ }, [[], []]);
79
67
  if (!diffArrays[0].length && !diffArrays[1].length) {
80
68
  return [];
81
69
  }
@@ -99,10 +87,7 @@ areEqual = (value0, value1) => value0 === value1) {
99
87
  return [];
100
88
  }
101
89
  else {
102
- return [
103
- value0,
104
- value1,
105
- ];
90
+ return [value0, value1];
106
91
  }
107
92
  }
108
93
  const orderedValueDiffs = [
@@ -29,17 +29,14 @@ export function mapObject(originalObject, mapCallback) {
29
29
  try {
30
30
  let gotAPromise = false;
31
31
  const mappedEntries = getObjectTypedEntries(originalObject)
32
- .map(([originalKey, originalValue,]) => {
32
+ .map(([originalKey, originalValue]) => {
33
33
  const output = mapCallback(originalKey, originalValue, originalObject);
34
34
  if (output instanceof Promise) {
35
35
  gotAPromise = true;
36
36
  return output;
37
37
  }
38
38
  else if (output) {
39
- return [
40
- output.key,
41
- output.value,
42
- ];
39
+ return [output.key, output.value];
43
40
  }
44
41
  else {
45
42
  return undefined;
@@ -57,10 +54,7 @@ export function mapObject(originalObject, mapCallback) {
57
54
  return entry;
58
55
  }
59
56
  else {
60
- return [
61
- entry.key,
62
- entry.value,
63
- ];
57
+ return [entry.key, entry.value];
64
58
  }
65
59
  }, check.isTruthy);
66
60
  resolve(typedObjectFromEntries(entries));
@@ -30,7 +30,7 @@ export function mergeDeep(...inputs) {
30
30
  /** If result isn't an object then we need to make it into one. */
31
31
  result = { ...individualInput };
32
32
  }
33
- Object.entries(individualInput).forEach(([key, value,]) => {
33
+ Object.entries(individualInput).forEach(([key, value]) => {
34
34
  if (!mergeProps[key]) {
35
35
  mergeProps[key] = [];
36
36
  }
@@ -38,7 +38,7 @@ export function mergeDeep(...inputs) {
38
38
  });
39
39
  });
40
40
  if (check.isObject(result)) {
41
- Object.entries(mergeProps).forEach(([key, mergeValues,]) => {
41
+ Object.entries(mergeProps).forEach(([key, mergeValues]) => {
42
42
  const newValue = mergeDeep(...mergeValues);
43
43
  if (newValue === undefined && key in result) {
44
44
  delete result[key];
@@ -22,7 +22,7 @@ export function mergeDefinedProperties(original, ...overrides) {
22
22
  if (!entry) {
23
23
  return;
24
24
  }
25
- getObjectTypedEntries(entry).forEach(([key, value,]) => {
25
+ getObjectTypedEntries(entry).forEach(([key, value]) => {
26
26
  if (value != undefined) {
27
27
  finalObject[key] = value;
28
28
  }
@@ -10,16 +10,10 @@
10
10
  *
11
11
  * mergePropertyArrays(
12
12
  * {
13
- * a: [
14
- * 'a',
15
- * 'b',
16
- * ],
13
+ * a: ['a', 'b'],
17
14
  * },
18
15
  * {
19
- * a: [
20
- * 'c',
21
- * 'd',
22
- * ],
16
+ * a: ['c', 'd'],
23
17
  * },
24
18
  * ); // output is `{a: ['a', 'b', 'c', 'd']}`
25
19
  * ```
@@ -11,16 +11,10 @@ import { getOrSet } from './get-or-set.js';
11
11
  *
12
12
  * mergePropertyArrays(
13
13
  * {
14
- * a: [
15
- * 'a',
16
- * 'b',
17
- * ],
14
+ * a: ['a', 'b'],
18
15
  * },
19
16
  * {
20
- * a: [
21
- * 'c',
22
- * 'd',
23
- * ],
17
+ * a: ['c', 'd'],
24
18
  * },
25
19
  * ); // output is `{a: ['a', 'b', 'c', 'd']}`
26
20
  * ```
@@ -30,7 +24,7 @@ import { getOrSet } from './get-or-set.js';
30
24
  export function mergePropertyArrays(...inputs) {
31
25
  const combined = {};
32
26
  inputs.forEach((input) => {
33
- Object.entries(input).forEach(([key, newArray,]) => {
27
+ Object.entries(input).forEach(([key, newArray]) => {
34
28
  const currentArray = getOrSet(combined, key, () => []);
35
29
  currentArray.push(...newArray);
36
30
  });
@@ -9,10 +9,7 @@ import { getObjectTypedKeys } from '@augment-vir/core';
9
9
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
10
10
  */
11
11
  export function getObjectTypedEntries(input) {
12
- return getObjectTypedKeys(input).map((key) => [
13
- key,
14
- input[key],
15
- ]);
12
+ return getObjectTypedKeys(input).map((key) => [key, input[key]]);
16
13
  }
17
14
  /**
18
15
  * Create an object from an array of entries. This is the same as
@@ -20,7 +20,7 @@ import { getObjectTypedEntries, typedObjectFromEntries } from './object-entries.
20
20
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
21
21
  */
22
22
  export function filterObject(inputObject, callback) {
23
- const filteredEntries = getObjectTypedEntries(inputObject).filter(([key, value,]) => {
23
+ const filteredEntries = getObjectTypedEntries(inputObject).filter(([key, value]) => {
24
24
  return callback(key, value, inputObject);
25
25
  });
26
26
  return typedObjectFromEntries(filteredEntries);
@@ -17,10 +17,7 @@ import { escapeStringForRegExp } from './regexp-string.js';
17
17
  * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
18
18
  */
19
19
  export function addRegExpFlags(originalRegExpOrString, flags) {
20
- const allFlags = removeDuplicateCharacters([
21
- typeof originalRegExpOrString === 'string' ? '' : originalRegExpOrString.flags,
22
- flags,
23
- ]
20
+ const allFlags = removeDuplicateCharacters([typeof originalRegExpOrString === 'string' ? '' : originalRegExpOrString.flags, flags]
24
21
  .join('')
25
22
  .toLowerCase());
26
23
  return setRegExpFlags(originalRegExpOrString, allFlags);
@@ -33,16 +33,12 @@ export function addCommasToNumber(input) {
33
33
  const numericValue = Number(input);
34
34
  const isNegative = numericValue < 0;
35
35
  const stringValue = String(Math.abs(numericValue));
36
- const [digits = '', decimalValues,] = stringValue.split('.');
36
+ const [digits = '', decimalValues] = stringValue.split('.');
37
37
  const decimalString = decimalValues ? `.${decimalValues}` : '';
38
38
  const separated = safeMatch(digits.split('').reverse().join(''), /.{1,3}/g)
39
39
  .reverse()
40
40
  .map((entry) => entry.split('').reverse().join(''));
41
41
  const valueWithCommas = separated.join(',');
42
42
  const negativeMarker = isNegative ? '-' : '';
43
- return [
44
- negativeMarker,
45
- valueWithCommas,
46
- decimalString,
47
- ].join('');
43
+ return [negativeMarker, valueWithCommas, decimalString].join('');
48
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "31.0.0",
3
+ "version": "31.0.1",
4
4
  "description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
5
5
  "keywords": [
6
6
  "augment",
@@ -39,8 +39,8 @@
39
39
  "test:web": "virmator --no-deps test web"
40
40
  },
41
41
  "dependencies": {
42
- "@augment-vir/assert": "^31.0.0",
43
- "@augment-vir/core": "^31.0.0",
42
+ "@augment-vir/assert": "^31.0.1",
43
+ "@augment-vir/core": "^31.0.1",
44
44
  "@date-vir/duration": "^7.0.1",
45
45
  "ansi-styles": "^6.2.1",
46
46
  "json5": "^2.2.3",