@augment-vir/common 31.67.0 → 31.68.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/augments/array/array-pagination.js +3 -1
- package/dist/augments/array/repeat-array.js +3 -1
- package/dist/augments/array/shuffle-array.js +4 -1
- package/dist/augments/function/debounce.js +4 -1
- package/dist/augments/function/execution-duration.js +3 -1
- package/dist/augments/interval/blocking-interval.js +3 -1
- package/dist/augments/log/log-colors.js +4 -1
- package/dist/augments/log/log-countdown.js +3 -1
- package/dist/augments/log/log-string.js +8 -2
- package/dist/augments/log/log.js +12 -3
- package/dist/augments/number/truncate-number.js +6 -3
- package/dist/augments/object/constructor-instance-map.d.ts +36 -0
- package/dist/augments/object/constructor-instance-map.js +77 -0
- package/dist/augments/object/merge-deep.js +4 -2
- package/dist/augments/object/merge-defined-properties.js +3 -1
- package/dist/augments/path/esm-path.js +4 -1
- package/dist/augments/path/sanitize-path.js +0 -2
- package/dist/augments/path/universal-path.js +8 -3
- package/dist/augments/promise/promise-queue.js +6 -2
- package/dist/augments/promise/timed-promise.js +6 -2
- package/dist/augments/random/random-boolean.js +4 -1
- package/dist/augments/random/random-integer.js +4 -1
- package/dist/augments/string/casing/kebab-and-camel.js +6 -2
- package/dist/augments/string/split.js +3 -1
- package/dist/augments/string/substring-index.js +7 -2
- package/dist/augments/string/suffix.js +16 -4
- package/dist/augments/string/wrap-string.js +7 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +5 -5
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export function getArrayPage(originalArray, options) {
|
|
27
|
-
const chunks = chunkArray(originalArray, {
|
|
27
|
+
const chunks = chunkArray(originalArray, {
|
|
28
|
+
chunkSize: options.countPerPage,
|
|
29
|
+
});
|
|
28
30
|
return chunks[options.getPage];
|
|
29
31
|
}
|
|
30
32
|
/**
|
|
@@ -21,5 +21,7 @@
|
|
|
21
21
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
22
22
|
*/
|
|
23
23
|
export function repeatArray(repeatCount, array) {
|
|
24
|
-
return Array.from({
|
|
24
|
+
return Array.from({
|
|
25
|
+
length: repeatCount,
|
|
26
|
+
}, () => [...array]).flat();
|
|
25
27
|
}
|
|
@@ -10,7 +10,10 @@ import { randomString } from '../random/random-string.js';
|
|
|
10
10
|
export function shuffleArray(input) {
|
|
11
11
|
return input
|
|
12
12
|
.map((value) => {
|
|
13
|
-
return {
|
|
13
|
+
return {
|
|
14
|
+
value,
|
|
15
|
+
sort: randomString(),
|
|
16
|
+
};
|
|
14
17
|
})
|
|
15
18
|
.sort((a, b) => a.sort.localeCompare(b.sort))
|
|
16
19
|
.map(({ value }) => value);
|
|
@@ -107,6 +107,9 @@ export class Debounce {
|
|
|
107
107
|
}, this.debounceDuration.milliseconds);
|
|
108
108
|
}
|
|
109
109
|
this.nextCallTimestamp =
|
|
110
|
-
now +
|
|
110
|
+
now +
|
|
111
|
+
convertDuration(this.debounceDuration, {
|
|
112
|
+
milliseconds: true,
|
|
113
|
+
}).milliseconds;
|
|
111
114
|
}
|
|
112
115
|
}
|
|
@@ -25,7 +25,9 @@ export function measureExecutionDuration(callback) {
|
|
|
25
25
|
try {
|
|
26
26
|
await result;
|
|
27
27
|
const endTime = Date.now();
|
|
28
|
-
resolve({
|
|
28
|
+
resolve({
|
|
29
|
+
milliseconds: endTime - startTime,
|
|
30
|
+
});
|
|
29
31
|
}
|
|
30
32
|
catch (caught) {
|
|
31
33
|
reject(ensureError(caught));
|
|
@@ -20,7 +20,9 @@ export function createBlockingInterval(callback, interval) {
|
|
|
20
20
|
finally {
|
|
21
21
|
isExecuting = false;
|
|
22
22
|
}
|
|
23
|
-
}, convertDuration(interval, {
|
|
23
|
+
}, convertDuration(interval, {
|
|
24
|
+
milliseconds: true,
|
|
25
|
+
}).milliseconds);
|
|
24
26
|
return {
|
|
25
27
|
intervalId,
|
|
26
28
|
clearInterval() {
|
|
@@ -117,7 +117,10 @@ export const defaultLogColorConfig = {
|
|
|
117
117
|
colors: [logColors.normalWeight],
|
|
118
118
|
logType: LogOutputType.Standard,
|
|
119
119
|
},
|
|
120
|
-
[LogColorKey.Plain]: {
|
|
120
|
+
[LogColorKey.Plain]: {
|
|
121
|
+
colors: [],
|
|
122
|
+
logType: LogOutputType.Standard,
|
|
123
|
+
},
|
|
121
124
|
[LogColorKey.Reset]: {
|
|
122
125
|
colors: [logColors.reset],
|
|
123
126
|
logType: LogOutputType.Standard,
|
|
@@ -9,7 +9,9 @@ import { log } from './log.js';
|
|
|
9
9
|
*/
|
|
10
10
|
export async function logCountdown(start, logCallback = log.warning) {
|
|
11
11
|
logCallback(String(start));
|
|
12
|
-
await wait({
|
|
12
|
+
await wait({
|
|
13
|
+
seconds: 1.5,
|
|
14
|
+
});
|
|
13
15
|
if (start) {
|
|
14
16
|
return await logCountdown(start - 1, logCallback);
|
|
15
17
|
}
|
|
@@ -28,7 +28,10 @@ async function createToLogString() {
|
|
|
28
28
|
? ''
|
|
29
29
|
: options.colorConfig[LogColorKey.Reset].colors.join(''),
|
|
30
30
|
].join('');
|
|
31
|
-
return {
|
|
31
|
+
return {
|
|
32
|
+
text,
|
|
33
|
+
css: undefined,
|
|
34
|
+
};
|
|
32
35
|
};
|
|
33
36
|
},
|
|
34
37
|
/**
|
|
@@ -60,7 +63,10 @@ async function createToLogString() {
|
|
|
60
63
|
? ''
|
|
61
64
|
: options.colorConfig[LogColorKey.Reset].colors.join(''),
|
|
62
65
|
].join('');
|
|
63
|
-
return {
|
|
66
|
+
return {
|
|
67
|
+
text,
|
|
68
|
+
css,
|
|
69
|
+
};
|
|
64
70
|
};
|
|
65
71
|
},
|
|
66
72
|
/* node:coverage enable */
|
package/dist/augments/log/log.js
CHANGED
|
@@ -24,11 +24,17 @@ isRuntimeEnv(RuntimeEnv.Node)
|
|
|
24
24
|
: /* node:coverage enable */
|
|
25
25
|
{
|
|
26
26
|
[LogOutputType.Error]({ text, css }) {
|
|
27
|
-
console.error(addPrefix({
|
|
27
|
+
console.error(addPrefix({
|
|
28
|
+
value: text,
|
|
29
|
+
prefix: '%c',
|
|
30
|
+
}), css);
|
|
28
31
|
},
|
|
29
32
|
[LogOutputType.Standard]({ text, css }) {
|
|
30
33
|
// eslint-disable-next-line no-console
|
|
31
|
-
console.log(addPrefix({
|
|
34
|
+
console.log(addPrefix({
|
|
35
|
+
value: text,
|
|
36
|
+
prefix: '%c',
|
|
37
|
+
}), css);
|
|
32
38
|
},
|
|
33
39
|
};
|
|
34
40
|
/**
|
|
@@ -81,5 +87,8 @@ export function createArrayLogger(options) {
|
|
|
81
87
|
logs.stdout.push(text);
|
|
82
88
|
},
|
|
83
89
|
}, options);
|
|
84
|
-
return {
|
|
90
|
+
return {
|
|
91
|
+
log,
|
|
92
|
+
logs,
|
|
93
|
+
};
|
|
85
94
|
}
|
|
@@ -158,10 +158,13 @@ export function truncateNumber(originalValue, { customSuffixes = defaultTruncati
|
|
|
158
158
|
// handle edge cases
|
|
159
159
|
if (isNaN(inputNumber) || inputNumber === Infinity) {
|
|
160
160
|
return String(inputNumber);
|
|
161
|
+
// handle too big or too small edge cases
|
|
161
162
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
else if (requiresScientificNotation(inputNumber)) {
|
|
164
|
+
return truncateScientificNotation({
|
|
165
|
+
input: inputNumber,
|
|
166
|
+
maxLength,
|
|
167
|
+
});
|
|
165
168
|
}
|
|
166
169
|
const numberAsString = String(inputNumber);
|
|
167
170
|
const smallResult = handleSmallNumbers(numberAsString, maxLength);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type AnyObject } from '@augment-vir/core';
|
|
2
|
+
import { type AbstractConstructor, type Constructor } from 'type-fest';
|
|
3
|
+
/**
|
|
4
|
+
* Map all ancestor constructors of an object to a set of objects.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class ConstructorInstanceMap {
|
|
9
|
+
/**
|
|
10
|
+
* The top most constructor to allow in the map. If this constructor is ever reached, the
|
|
11
|
+
* recursive mapping stops.
|
|
12
|
+
*/
|
|
13
|
+
protected readonly topMostConstructor?: Function | undefined;
|
|
14
|
+
/** A map of constructors to their added instances. */
|
|
15
|
+
readonly map: Map<Function, Set<AnyObject>>;
|
|
16
|
+
readonly isDestroyed: boolean;
|
|
17
|
+
constructor(
|
|
18
|
+
/**
|
|
19
|
+
* The top most constructor to allow in the map. If this constructor is ever reached, the
|
|
20
|
+
* recursive mapping stops.
|
|
21
|
+
*/
|
|
22
|
+
topMostConstructor?: Function | undefined);
|
|
23
|
+
/**
|
|
24
|
+
* Add a new instance, mapping each of its ancestor constructors to it inside
|
|
25
|
+
* {@link ConstructorInstanceMap.map}.
|
|
26
|
+
*/
|
|
27
|
+
add(instance: AnyObject): void;
|
|
28
|
+
/** Gets all added instances of the given constructor. */
|
|
29
|
+
getInstances<T>(constructor: AbstractConstructor<T> | Constructor<T>): Set<T>;
|
|
30
|
+
/** Remove an instance, removing it from all mappings inside {@link ConstructorInstanceMap.map}. */
|
|
31
|
+
remove(instance: AnyObject): void;
|
|
32
|
+
/** Recursively map all ancestor prototypes to the given instance. */
|
|
33
|
+
protected traverseConstructors(instance: AnyObject, prototype: any, operation: 'add' | 'remove'): void;
|
|
34
|
+
/** Clean up the internal map. */
|
|
35
|
+
destroy(): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
2
|
+
import { makeWritable } from '../type/writable.js';
|
|
3
|
+
import { getOrSetFromMap } from './get-or-set.js';
|
|
4
|
+
/**
|
|
5
|
+
* Map all ancestor constructors of an object to a set of objects.
|
|
6
|
+
*
|
|
7
|
+
* @category Internal
|
|
8
|
+
*/
|
|
9
|
+
export class ConstructorInstanceMap {
|
|
10
|
+
topMostConstructor;
|
|
11
|
+
/** A map of constructors to their added instances. */
|
|
12
|
+
map = new Map();
|
|
13
|
+
isDestroyed = false;
|
|
14
|
+
constructor(
|
|
15
|
+
/**
|
|
16
|
+
* The top most constructor to allow in the map. If this constructor is ever reached, the
|
|
17
|
+
* recursive mapping stops.
|
|
18
|
+
*/
|
|
19
|
+
topMostConstructor) {
|
|
20
|
+
this.topMostConstructor = topMostConstructor;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Add a new instance, mapping each of its ancestor constructors to it inside
|
|
24
|
+
* {@link ConstructorInstanceMap.map}.
|
|
25
|
+
*/
|
|
26
|
+
add(instance) {
|
|
27
|
+
if (this.isDestroyed) {
|
|
28
|
+
throw new Error('Cannot operate on destroyed ConstructorMap.');
|
|
29
|
+
}
|
|
30
|
+
this.traverseConstructors(instance, Object.getPrototypeOf(instance), 'add');
|
|
31
|
+
}
|
|
32
|
+
/** Gets all added instances of the given constructor. */
|
|
33
|
+
getInstances(constructor) {
|
|
34
|
+
if (this.isDestroyed) {
|
|
35
|
+
throw new Error('Cannot operate on destroyed ConstructorMap.');
|
|
36
|
+
}
|
|
37
|
+
return getOrSetFromMap(this.map, constructor, () => new Set());
|
|
38
|
+
}
|
|
39
|
+
/** Remove an instance, removing it from all mappings inside {@link ConstructorInstanceMap.map}. */
|
|
40
|
+
remove(instance) {
|
|
41
|
+
if (this.isDestroyed) {
|
|
42
|
+
throw new Error('Cannot operate on destroyed ConstructorMap.');
|
|
43
|
+
}
|
|
44
|
+
this.traverseConstructors(instance, Object.getPrototypeOf(instance), 'remove');
|
|
45
|
+
}
|
|
46
|
+
/** Recursively map all ancestor prototypes to the given instance. */
|
|
47
|
+
traverseConstructors(instance, prototype, operation) {
|
|
48
|
+
const constructor = prototype.constructor;
|
|
49
|
+
if (!constructor ||
|
|
50
|
+
constructor === Function ||
|
|
51
|
+
constructor === Object ||
|
|
52
|
+
constructor === this.topMostConstructor) {
|
|
53
|
+
/** Stop recursing into constructors. */
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (operation === 'add') {
|
|
57
|
+
const set = getOrSetFromMap(this.map, constructor, () => new Set());
|
|
58
|
+
set.add(instance);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const set = this.map.get(constructor);
|
|
62
|
+
if (set) {
|
|
63
|
+
set.delete(instance);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
this.traverseConstructors(instance, Object.getPrototypeOf(prototype), operation);
|
|
67
|
+
}
|
|
68
|
+
/** Clean up the internal map. */
|
|
69
|
+
destroy() {
|
|
70
|
+
if (this.isDestroyed) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
makeWritable(this).isDestroyed = true;
|
|
74
|
+
this.map.clear();
|
|
75
|
+
delete this.map;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -14,7 +14,7 @@ export function mergeDeep(...inputs) {
|
|
|
14
14
|
// nothing to merge if no inputs
|
|
15
15
|
return {};
|
|
16
16
|
}
|
|
17
|
-
if (inputs.length === 1) {
|
|
17
|
+
else if (inputs.length === 1) {
|
|
18
18
|
// nothing to merge if only one input
|
|
19
19
|
return inputs[0];
|
|
20
20
|
}
|
|
@@ -28,7 +28,9 @@ export function mergeDeep(...inputs) {
|
|
|
28
28
|
}
|
|
29
29
|
else if (!check.isObject(result)) {
|
|
30
30
|
/** If result isn't an object then we need to make it into one. */
|
|
31
|
-
result = {
|
|
31
|
+
result = {
|
|
32
|
+
...individualInput,
|
|
33
|
+
};
|
|
32
34
|
}
|
|
33
35
|
Object.entries(individualInput).forEach(([key, value,]) => {
|
|
34
36
|
if (!mergeProps[key]) {
|
|
@@ -17,7 +17,9 @@ import { getObjectTypedEntries } from './object-entries.js';
|
|
|
17
17
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
18
18
|
*/
|
|
19
19
|
export function mergeDefinedProperties(original, ...overrides) {
|
|
20
|
-
const finalObject = {
|
|
20
|
+
const finalObject = {
|
|
21
|
+
...original,
|
|
22
|
+
};
|
|
21
23
|
overrides.forEach((entry) => {
|
|
22
24
|
if (!entry) {
|
|
23
25
|
return;
|
|
@@ -23,7 +23,10 @@ import { removeSuffix } from '../string/suffix.js';
|
|
|
23
23
|
*/
|
|
24
24
|
export function getEsmPath(importMeta) {
|
|
25
25
|
const filePath = new URL('', importMeta.url).pathname;
|
|
26
|
-
const dirPath = removeSuffix({
|
|
26
|
+
const dirPath = removeSuffix({
|
|
27
|
+
value: new URL('.', importMeta.url).pathname,
|
|
28
|
+
suffix: '/',
|
|
29
|
+
});
|
|
27
30
|
return {
|
|
28
31
|
filePath,
|
|
29
32
|
dirPath,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable unicorn/prefer-code-point */
|
|
2
|
-
/* eslint-disable sonarjs/no-control-regex */
|
|
3
2
|
/* eslint-disable no-control-regex */
|
|
4
3
|
import { getByteLength } from '../string/length.js';
|
|
5
4
|
import { safeSplit } from '../string/split.js';
|
|
@@ -90,7 +89,6 @@ function truncate(string, byteLength) {
|
|
|
90
89
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
91
90
|
segment = string[i];
|
|
92
91
|
if (isHighSurrogate(codePoint) && isLowSurrogate(string.charCodeAt(i + 1))) {
|
|
93
|
-
// eslint-disable-next-line sonarjs/updated-loop-counter
|
|
94
92
|
i += 1;
|
|
95
93
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
96
94
|
segment += string[i];
|
|
@@ -23,7 +23,10 @@ export function replaceExtension({ newExtension, path, }) {
|
|
|
23
23
|
return [
|
|
24
24
|
dirname,
|
|
25
25
|
basename,
|
|
26
|
-
addPrefix({
|
|
26
|
+
addPrefix({
|
|
27
|
+
value: newExtension,
|
|
28
|
+
prefix: '.',
|
|
29
|
+
}),
|
|
27
30
|
tail,
|
|
28
31
|
].join('');
|
|
29
32
|
}
|
|
@@ -54,10 +57,12 @@ export function hasExtension(path) {
|
|
|
54
57
|
* @category Package : @augment-vir/common
|
|
55
58
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
56
59
|
*/
|
|
57
|
-
/* node:coverage ignore next
|
|
60
|
+
/* node:coverage ignore next 5: cannot test both on a single system. */
|
|
58
61
|
export const defaultSep = isRuntimeEnv(RuntimeEnv.Web)
|
|
59
62
|
? '/'
|
|
60
|
-
: await wrapInTry(async () => (await import('node:path')).sep, {
|
|
63
|
+
: await wrapInTry(async () => (await import('node:path')).sep, {
|
|
64
|
+
fallbackValue: '/',
|
|
65
|
+
});
|
|
61
66
|
/**
|
|
62
67
|
* Extracts a path's extension, amongst other things, from the given path, without relying on
|
|
63
68
|
* Node.js built-in packages (this works in a browser).
|
|
@@ -99,10 +99,14 @@ export class PromiseQueue extends ListenTarget {
|
|
|
99
99
|
this.currentlyAwaiting = item;
|
|
100
100
|
item.original()
|
|
101
101
|
.then((result) => {
|
|
102
|
-
this.handleItemSettle({
|
|
102
|
+
this.handleItemSettle({
|
|
103
|
+
resolution: result,
|
|
104
|
+
});
|
|
103
105
|
})
|
|
104
106
|
.catch((error) => {
|
|
105
|
-
this.handleItemSettle({
|
|
107
|
+
this.handleItemSettle({
|
|
108
|
+
rejection: error,
|
|
109
|
+
});
|
|
106
110
|
});
|
|
107
111
|
return true;
|
|
108
112
|
}
|
|
@@ -14,7 +14,9 @@ export class PromiseTimeoutError extends Error {
|
|
|
14
14
|
constructor(duration, failureMessage) {
|
|
15
15
|
super([
|
|
16
16
|
failureMessage,
|
|
17
|
-
`Promised timed out after ${convertDuration(duration, {
|
|
17
|
+
`Promised timed out after ${convertDuration(duration, {
|
|
18
|
+
milliseconds: true,
|
|
19
|
+
}).milliseconds} ms.`,
|
|
18
20
|
]
|
|
19
21
|
.filter(check.isTruthy)
|
|
20
22
|
.join(': '));
|
|
@@ -33,7 +35,9 @@ export function wrapPromiseInTimeout(duration, originalPromise, failureMessage)
|
|
|
33
35
|
const isInfinity = Object.values(duration).some((value) => value && check.isInfinite(value));
|
|
34
36
|
const milliseconds = isInfinity
|
|
35
37
|
? Infinity
|
|
36
|
-
: convertDuration(duration, {
|
|
38
|
+
: convertDuration(duration, {
|
|
39
|
+
milliseconds: true,
|
|
40
|
+
}).milliseconds;
|
|
37
41
|
return new Promise(async (resolve, reject) => {
|
|
38
42
|
const timeoutId = milliseconds === Infinity
|
|
39
43
|
? undefined
|
|
@@ -24,7 +24,10 @@ import { randomInteger } from './random-integer.js';
|
|
|
24
24
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
25
25
|
*/
|
|
26
26
|
export function randomBoolean(percentLikelyToBeTrue = 50) {
|
|
27
|
-
return (randomInteger({
|
|
27
|
+
return (randomInteger({
|
|
28
|
+
min: 0,
|
|
29
|
+
max: 99,
|
|
30
|
+
}) <
|
|
28
31
|
clamp(Math.floor(percentLikelyToBeTrue), {
|
|
29
32
|
min: 0,
|
|
30
33
|
max: 100,
|
|
@@ -10,7 +10,10 @@ import { ensureMinMax } from '@augment-vir/core';
|
|
|
10
10
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
11
11
|
*/
|
|
12
12
|
export function randomInteger({ min: rawMin, max: rawMax }) {
|
|
13
|
-
const { min, max } = ensureMinMax({
|
|
13
|
+
const { min, max } = ensureMinMax({
|
|
14
|
+
min: Math.floor(rawMin),
|
|
15
|
+
max: Math.floor(rawMax),
|
|
16
|
+
});
|
|
14
17
|
const range = max - min + 1;
|
|
15
18
|
const bitsNeeded = Math.ceil(Math.log2(range));
|
|
16
19
|
const neededBytes = Math.ceil(bitsNeeded / 8);
|
|
@@ -40,8 +40,12 @@ export function camelCaseToKebabCase(rawCamelCase) {
|
|
|
40
40
|
.reduce((accum, currentLetter, index, originalString) => {
|
|
41
41
|
const previousLetter = index > 0 ? originalString[index - 1] || '' : '';
|
|
42
42
|
const nextLetter = index < originalString.length - 1 ? originalString[index + 1] || '' : '';
|
|
43
|
-
const possibleWordBoundary = isCase(previousLetter, StringCase.Lower, {
|
|
44
|
-
|
|
43
|
+
const possibleWordBoundary = isCase(previousLetter, StringCase.Lower, {
|
|
44
|
+
rejectNoCaseCharacters: true,
|
|
45
|
+
}) ||
|
|
46
|
+
isCase(nextLetter, StringCase.Lower, {
|
|
47
|
+
rejectNoCaseCharacters: true,
|
|
48
|
+
});
|
|
45
49
|
if (currentLetter === currentLetter.toLowerCase() ||
|
|
46
50
|
index === 0 ||
|
|
47
51
|
!possibleWordBoundary) {
|
|
@@ -24,7 +24,9 @@ export function splitIncludeSplit(original, splitDelimiter, { caseSensitive }) {
|
|
|
24
24
|
caseSensitive,
|
|
25
25
|
includeLength: true,
|
|
26
26
|
});
|
|
27
|
-
const splitter = setRegExpCaseSensitivity(splitDelimiter, {
|
|
27
|
+
const splitter = setRegExpCaseSensitivity(splitDelimiter, {
|
|
28
|
+
caseSensitive,
|
|
29
|
+
});
|
|
28
30
|
const splits = original.split(splitter);
|
|
29
31
|
return splits.reduce((accum, current, index) => {
|
|
30
32
|
// this will be undefined on the last index
|
|
@@ -9,7 +9,9 @@ import { addRegExpFlags, setRegExpCaseSensitivity } from '@augment-vir/core';
|
|
|
9
9
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
10
10
|
*/
|
|
11
11
|
export function findSubstringIndexes({ searchIn, searchFor, caseSensitive, includeLength, }) {
|
|
12
|
-
const searchRegExp = addRegExpFlags(setRegExpCaseSensitivity(searchFor, {
|
|
12
|
+
const searchRegExp = addRegExpFlags(setRegExpCaseSensitivity(searchFor, {
|
|
13
|
+
caseSensitive,
|
|
14
|
+
}), 'g');
|
|
13
15
|
const indexes = [];
|
|
14
16
|
const indexesAndLengths = [];
|
|
15
17
|
searchIn.replace(searchRegExp, (...matchResults) => {
|
|
@@ -29,7 +31,10 @@ export function findSubstringIndexes({ searchIn, searchFor, caseSensitive, inclu
|
|
|
29
31
|
if (typeof regExpMatch !== 'string') {
|
|
30
32
|
throw new TypeError(`regExpMatch should've been a string but was ${typeof regExpMatch}!`);
|
|
31
33
|
}
|
|
32
|
-
indexesAndLengths.push({
|
|
34
|
+
indexesAndLengths.push({
|
|
35
|
+
index: matchIndex,
|
|
36
|
+
length: regExpMatch.length,
|
|
37
|
+
});
|
|
33
38
|
indexes.push(matchIndex);
|
|
34
39
|
const originalMatch = matchResults[0];
|
|
35
40
|
// this is used as a type safety catch and cannot actually be triggered on purpose
|
|
@@ -23,7 +23,10 @@ export const pxSuffix = 'px';
|
|
|
23
23
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
24
24
|
*/
|
|
25
25
|
export function addPx(input) {
|
|
26
|
-
return addSuffix({
|
|
26
|
+
return addSuffix({
|
|
27
|
+
value: input,
|
|
28
|
+
suffix: pxSuffix,
|
|
29
|
+
});
|
|
27
30
|
}
|
|
28
31
|
/**
|
|
29
32
|
* Removes the `'px'` suffix from a string if it exists.
|
|
@@ -34,7 +37,10 @@ export function addPx(input) {
|
|
|
34
37
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
35
38
|
*/
|
|
36
39
|
export function removePx(input) {
|
|
37
|
-
return toEnsuredNumber(removeSuffix({
|
|
40
|
+
return toEnsuredNumber(removeSuffix({
|
|
41
|
+
value: input,
|
|
42
|
+
suffix: pxSuffix,
|
|
43
|
+
}));
|
|
38
44
|
}
|
|
39
45
|
/**
|
|
40
46
|
* Adds the `'%'` suffix to a string if it does not already exist.
|
|
@@ -44,7 +50,10 @@ export function removePx(input) {
|
|
|
44
50
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
45
51
|
*/
|
|
46
52
|
export function addPercent(input) {
|
|
47
|
-
return addSuffix({
|
|
53
|
+
return addSuffix({
|
|
54
|
+
value: input,
|
|
55
|
+
suffix: percentSuffix,
|
|
56
|
+
});
|
|
48
57
|
}
|
|
49
58
|
/**
|
|
50
59
|
* Removes the `'%'` suffix from a string if it exists.
|
|
@@ -55,7 +64,10 @@ export function addPercent(input) {
|
|
|
55
64
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
56
65
|
*/
|
|
57
66
|
export function removePercent(input) {
|
|
58
|
-
return toEnsuredNumber(removeSuffix({
|
|
67
|
+
return toEnsuredNumber(removeSuffix({
|
|
68
|
+
value: input,
|
|
69
|
+
suffix: percentSuffix,
|
|
70
|
+
}));
|
|
59
71
|
}
|
|
60
72
|
/**
|
|
61
73
|
* Adds a suffix to a string if it does not already exist.
|
|
@@ -16,5 +16,11 @@ import { addSuffix } from './suffix.js';
|
|
|
16
16
|
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
17
17
|
*/
|
|
18
18
|
export function wrapString({ value, wrapper }) {
|
|
19
|
-
return addPrefix({
|
|
19
|
+
return addPrefix({
|
|
20
|
+
value: addSuffix({
|
|
21
|
+
value,
|
|
22
|
+
suffix: wrapper,
|
|
23
|
+
}),
|
|
24
|
+
prefix: wrapper,
|
|
25
|
+
});
|
|
20
26
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export * from './augments/number/round.js';
|
|
|
45
45
|
export * from './augments/number/scientific.js';
|
|
46
46
|
export * from './augments/number/truncate-number.js';
|
|
47
47
|
export * from './augments/number/wrap-number.js';
|
|
48
|
+
export * from './augments/object/constructor-instance-map.js';
|
|
48
49
|
export * from './augments/object/deep-copy.js';
|
|
49
50
|
export * from './augments/object/deep-value.js';
|
|
50
51
|
export * from './augments/object/diff.js';
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,7 @@ export * from './augments/number/round.js';
|
|
|
45
45
|
export * from './augments/number/scientific.js';
|
|
46
46
|
export * from './augments/number/truncate-number.js';
|
|
47
47
|
export * from './augments/number/wrap-number.js';
|
|
48
|
+
export * from './augments/object/constructor-instance-map.js';
|
|
48
49
|
export * from './augments/object/deep-copy.js';
|
|
49
50
|
export * from './augments/object/deep-value.js';
|
|
50
51
|
export * from './augments/object/diff.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.68.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -40,14 +40,14 @@
|
|
|
40
40
|
"test:web": "virmator --no-deps test web"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^31.
|
|
44
|
-
"@augment-vir/core": "^31.
|
|
45
|
-
"@date-vir/duration": "^8.
|
|
43
|
+
"@augment-vir/assert": "^31.68.0",
|
|
44
|
+
"@augment-vir/core": "^31.68.0",
|
|
45
|
+
"@date-vir/duration": "^8.2.0",
|
|
46
46
|
"ansi-styles": "^6.2.3",
|
|
47
47
|
"deepcopy-esm": "^2.1.1",
|
|
48
48
|
"json5": "^2.2.3",
|
|
49
49
|
"type-fest": "^5.4.4",
|
|
50
|
-
"typed-event-target": "^4.
|
|
50
|
+
"typed-event-target": "^4.2.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@web/dev-server-esbuild": "^1.0.5",
|