@augment-vir/common 31.35.0 → 31.37.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-to-object.js +4 -1
- package/dist/augments/array/cross-product.d.ts +37 -0
- package/dist/augments/array/cross-product.js +51 -0
- package/dist/augments/object/map-entries.js +4 -1
- package/dist/augments/path/universal-path.d.ts +105 -0
- package/dist/augments/path/universal-path.js +111 -0
- package/dist/augments/string/split.js +1 -1
- package/dist/augments/string/substring-index.js +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/package.json +5 -5
- package/dist/augments/array/remove-duplicates.d.ts +0 -60
- package/dist/augments/array/remove-duplicates.js +0 -72
- package/dist/augments/regexp/regexp-flags.d.ts +0 -56
- package/dist/augments/regexp/regexp-flags.js +0 -75
- package/dist/augments/string/remove-duplicate-characters.d.ts +0 -17
- package/dist/augments/string/remove-duplicate-characters.js +0 -22
|
@@ -92,7 +92,10 @@ options = {}) {
|
|
|
92
92
|
if (gotAPromise) {
|
|
93
93
|
return new Promise(async (resolve, reject) => {
|
|
94
94
|
try {
|
|
95
|
-
const entries = filterMap(
|
|
95
|
+
const entries = filterMap(
|
|
96
|
+
/** This does contain promises. */
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
98
|
+
await Promise.all(mappedEntries), (entry) => {
|
|
96
99
|
if (!entry) {
|
|
97
100
|
return undefined;
|
|
98
101
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ArrayElement } from '@augment-vir/core';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the cartesian product (cross product) of an object whose values are arrays. The result is
|
|
4
|
+
* an array of objects where each object contains one picked value from every input array.
|
|
5
|
+
*
|
|
6
|
+
* @category Array
|
|
7
|
+
* @category Package : @augment-vir/common
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {crossProduct} from '@augment-vir/common';
|
|
12
|
+
*
|
|
13
|
+
* const result = crossProduct({
|
|
14
|
+
* a: [
|
|
15
|
+
* 1,
|
|
16
|
+
* 2,
|
|
17
|
+
* 3,
|
|
18
|
+
* ],
|
|
19
|
+
* b: [
|
|
20
|
+
* 'a',
|
|
21
|
+
* 'b',
|
|
22
|
+
* 'c',
|
|
23
|
+
* ],
|
|
24
|
+
* });
|
|
25
|
+
* // result is:
|
|
26
|
+
* // [
|
|
27
|
+
* // {a: 1, b: 'a'}, {a: 2, b: 'a'}, {a: 3, b: 'a'},
|
|
28
|
+
* // {a: 1, b: 'b'}, {a: 2, b: 'b'}, {a: 3, b: 'b'},
|
|
29
|
+
* // {a: 1, b: 'c'}, {a: 2, b: 'c'}, {a: 3, b: 'c'},
|
|
30
|
+
* // ]
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
34
|
+
*/
|
|
35
|
+
export declare function crossProduct<const OriginalValues extends Record<PropertyKey, ReadonlyArray<any>>>(originalValues: OriginalValues): {
|
|
36
|
+
[Key in keyof OriginalValues]: ArrayElement<OriginalValues[Key]>;
|
|
37
|
+
}[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the cartesian product (cross product) of an object whose values are arrays. The result is
|
|
3
|
+
* an array of objects where each object contains one picked value from every input array.
|
|
4
|
+
*
|
|
5
|
+
* @category Array
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import {crossProduct} from '@augment-vir/common';
|
|
11
|
+
*
|
|
12
|
+
* const result = crossProduct({
|
|
13
|
+
* a: [
|
|
14
|
+
* 1,
|
|
15
|
+
* 2,
|
|
16
|
+
* 3,
|
|
17
|
+
* ],
|
|
18
|
+
* b: [
|
|
19
|
+
* 'a',
|
|
20
|
+
* 'b',
|
|
21
|
+
* 'c',
|
|
22
|
+
* ],
|
|
23
|
+
* });
|
|
24
|
+
* // result is:
|
|
25
|
+
* // [
|
|
26
|
+
* // {a: 1, b: 'a'}, {a: 2, b: 'a'}, {a: 3, b: 'a'},
|
|
27
|
+
* // {a: 1, b: 'b'}, {a: 2, b: 'b'}, {a: 3, b: 'b'},
|
|
28
|
+
* // {a: 1, b: 'c'}, {a: 2, b: 'c'}, {a: 3, b: 'c'},
|
|
29
|
+
* // ]
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
33
|
+
*/
|
|
34
|
+
export function crossProduct(originalValues) {
|
|
35
|
+
return Object.entries(originalValues)
|
|
36
|
+
.reverse()
|
|
37
|
+
.filter(([, values,]) => values.length)
|
|
38
|
+
.reduce((accum, [key, values,]) => {
|
|
39
|
+
if (!accum.length) {
|
|
40
|
+
accum = [{}];
|
|
41
|
+
}
|
|
42
|
+
return values.flatMap((value) => {
|
|
43
|
+
return accum.map((partial) => {
|
|
44
|
+
return {
|
|
45
|
+
...partial,
|
|
46
|
+
[key]: value,
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}, []);
|
|
51
|
+
}
|
|
@@ -49,7 +49,10 @@ export function mapObject(originalObject, mapCallback) {
|
|
|
49
49
|
if (gotAPromise) {
|
|
50
50
|
return new Promise(async (resolve, reject) => {
|
|
51
51
|
try {
|
|
52
|
-
const entries = filterMap(
|
|
52
|
+
const entries = filterMap(
|
|
53
|
+
/** This does contain promises. */
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
55
|
+
await Promise.all(mappedEntries), (entry) => {
|
|
53
56
|
if (!entry) {
|
|
54
57
|
return undefined;
|
|
55
58
|
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replaces a path's extension with a new one. If the original path has no extension, `newExtension`
|
|
3
|
+
* will be appended.
|
|
4
|
+
*
|
|
5
|
+
* @category Path : Common
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import {replaceExtension} from '@augment-vir/common';
|
|
11
|
+
*
|
|
12
|
+
* replaceExtension({path: '/users/stuff/file.ts?tail', newExtension: '.js'});
|
|
13
|
+
* // '/users/stuff/file.js?tail'
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
17
|
+
*/
|
|
18
|
+
export declare function replaceExtension({ newExtension, path, }: Readonly<{
|
|
19
|
+
path: string;
|
|
20
|
+
newExtension: string;
|
|
21
|
+
}>): string;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if the given path contains an extension.
|
|
24
|
+
*
|
|
25
|
+
* @category Path : Common
|
|
26
|
+
* @category Package : @augment-vir/common
|
|
27
|
+
* @example
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* import {hasExtension} from '@augment-vir/common';
|
|
31
|
+
*
|
|
32
|
+
* hasExtension('/users/stuff/file.ts?tail'); // true
|
|
33
|
+
* hasExtension('/users/stuff/file?tail'); // false
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
37
|
+
*/
|
|
38
|
+
export declare function hasExtension(path: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Type for `sep` or path separators. Either `'/'` or `'\'`.
|
|
41
|
+
*
|
|
42
|
+
* @category Path : Common
|
|
43
|
+
* @category Package : @augment-vir/common
|
|
44
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
45
|
+
*/
|
|
46
|
+
export type Sep = '/' | '\\';
|
|
47
|
+
/**
|
|
48
|
+
* The default `sep` or path separator for use with universal (Node.js and browser supported) path
|
|
49
|
+
* operations. In the browser, this uses `'/'`. In Node.js, `node:path.sep` is used.
|
|
50
|
+
*
|
|
51
|
+
* @category Path : Common
|
|
52
|
+
* @category Package : @augment-vir/common
|
|
53
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
54
|
+
*/
|
|
55
|
+
export declare const defaultSep: Sep;
|
|
56
|
+
/**
|
|
57
|
+
* Extracts a path's extension, amongst other things, from the given path, without relying on
|
|
58
|
+
* Node.js built-in packages (this works in a browser).
|
|
59
|
+
*
|
|
60
|
+
* @category Path : Common
|
|
61
|
+
* @category Package : @augment-vir/common
|
|
62
|
+
* @example
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* import {extractExtension} from '@augment-vir/common';
|
|
66
|
+
*
|
|
67
|
+
* const results = extractExtension('/users/stuff/file.ts?tail');
|
|
68
|
+
*
|
|
69
|
+
* // results = {
|
|
70
|
+
* // basename: 'file',
|
|
71
|
+
* // dirname: '/users/stuff/',
|
|
72
|
+
* // extension: '.ts',
|
|
73
|
+
* // tail: '?tail',
|
|
74
|
+
* // }
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
78
|
+
*/
|
|
79
|
+
export declare function extractExtension(path: string,
|
|
80
|
+
/**
|
|
81
|
+
* By default, the path separator is determined by {@link defaultSep}. With this input you can
|
|
82
|
+
* override the path separator in use.
|
|
83
|
+
*/
|
|
84
|
+
sepOverride?: '/' | '\\' | undefined): {
|
|
85
|
+
/**
|
|
86
|
+
* The part of the path that is the path to the file. This will be an empty string if there is
|
|
87
|
+
* none. Includes the all trailing and leading slashes, if they exist in `path`.
|
|
88
|
+
*/
|
|
89
|
+
dirname: string;
|
|
90
|
+
/**
|
|
91
|
+
* The file name itself. This will only be an empty string if the given `path` is itself empty.
|
|
92
|
+
* This does not include the extension.
|
|
93
|
+
*/
|
|
94
|
+
basename: string;
|
|
95
|
+
/**
|
|
96
|
+
* The extension extracted from the path. This will be an empty string if there is no extension.
|
|
97
|
+
* This includes a leading dot, if an extension exists.
|
|
98
|
+
*/
|
|
99
|
+
extension: string;
|
|
100
|
+
/**
|
|
101
|
+
* Any query `'?'` and/or hash `'#'` data in the given `path`. This will be an empty string if
|
|
102
|
+
* no query or hash data exists in the given `path`. Includes the leading `'?'` or `'#'`.
|
|
103
|
+
*/
|
|
104
|
+
tail: string;
|
|
105
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { isRuntimeEnv, RuntimeEnv } from '@augment-vir/core';
|
|
2
|
+
import { wrapInTry } from '../function/wrap-in-try.js';
|
|
3
|
+
import { addPrefix } from '../string/prefix.js';
|
|
4
|
+
/**
|
|
5
|
+
* Replaces a path's extension with a new one. If the original path has no extension, `newExtension`
|
|
6
|
+
* will be appended.
|
|
7
|
+
*
|
|
8
|
+
* @category Path : Common
|
|
9
|
+
* @category Package : @augment-vir/common
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import {replaceExtension} from '@augment-vir/common';
|
|
14
|
+
*
|
|
15
|
+
* replaceExtension({path: '/users/stuff/file.ts?tail', newExtension: '.js'});
|
|
16
|
+
* // '/users/stuff/file.js?tail'
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
20
|
+
*/
|
|
21
|
+
export function replaceExtension({ newExtension, path, }) {
|
|
22
|
+
const { basename, dirname, tail } = extractExtension(path);
|
|
23
|
+
return [
|
|
24
|
+
dirname,
|
|
25
|
+
basename,
|
|
26
|
+
addPrefix({ value: newExtension, prefix: '.' }),
|
|
27
|
+
tail,
|
|
28
|
+
].join('');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Checks if the given path contains an extension.
|
|
32
|
+
*
|
|
33
|
+
* @category Path : Common
|
|
34
|
+
* @category Package : @augment-vir/common
|
|
35
|
+
* @example
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* import {hasExtension} from '@augment-vir/common';
|
|
39
|
+
*
|
|
40
|
+
* hasExtension('/users/stuff/file.ts?tail'); // true
|
|
41
|
+
* hasExtension('/users/stuff/file?tail'); // false
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
45
|
+
*/
|
|
46
|
+
export function hasExtension(path) {
|
|
47
|
+
return !!extractExtension(path).extension;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The default `sep` or path separator for use with universal (Node.js and browser supported) path
|
|
51
|
+
* operations. In the browser, this uses `'/'`. In Node.js, `node:path.sep` is used.
|
|
52
|
+
*
|
|
53
|
+
* @category Path : Common
|
|
54
|
+
* @category Package : @augment-vir/common
|
|
55
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
56
|
+
*/
|
|
57
|
+
/* node:coverage ignore next 3: cannot test both on a single system. */
|
|
58
|
+
export const defaultSep = isRuntimeEnv(RuntimeEnv.Web)
|
|
59
|
+
? '/'
|
|
60
|
+
: await wrapInTry(async () => (await import('node:path')).sep, { fallbackValue: '/' });
|
|
61
|
+
/**
|
|
62
|
+
* Extracts a path's extension, amongst other things, from the given path, without relying on
|
|
63
|
+
* Node.js built-in packages (this works in a browser).
|
|
64
|
+
*
|
|
65
|
+
* @category Path : Common
|
|
66
|
+
* @category Package : @augment-vir/common
|
|
67
|
+
* @example
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* import {extractExtension} from '@augment-vir/common';
|
|
71
|
+
*
|
|
72
|
+
* const results = extractExtension('/users/stuff/file.ts?tail');
|
|
73
|
+
*
|
|
74
|
+
* // results = {
|
|
75
|
+
* // basename: 'file',
|
|
76
|
+
* // dirname: '/users/stuff/',
|
|
77
|
+
* // extension: '.ts',
|
|
78
|
+
* // tail: '?tail',
|
|
79
|
+
* // }
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
83
|
+
*/
|
|
84
|
+
export function extractExtension(path,
|
|
85
|
+
/**
|
|
86
|
+
* By default, the path separator is determined by {@link defaultSep}. With this input you can
|
|
87
|
+
* override the path separator in use.
|
|
88
|
+
*/
|
|
89
|
+
sepOverride) {
|
|
90
|
+
const sep = sepOverride || defaultSep;
|
|
91
|
+
const queryIndex = path.indexOf('?');
|
|
92
|
+
const hashIndex = path.indexOf('#');
|
|
93
|
+
const headTailSplitIndex = hashIndex === -1
|
|
94
|
+
? queryIndex
|
|
95
|
+
: queryIndex === -1
|
|
96
|
+
? hashIndex
|
|
97
|
+
: Math.min(hashIndex, queryIndex);
|
|
98
|
+
const head = headTailSplitIndex === -1 ? path : path.slice(0, headTailSplitIndex);
|
|
99
|
+
const tail = headTailSplitIndex === -1 ? '' : path.slice(headTailSplitIndex);
|
|
100
|
+
const lastSep = head.lastIndexOf(sep);
|
|
101
|
+
/** Includes last slash (if present). */
|
|
102
|
+
const dirname = head.slice(0, lastSep + 1);
|
|
103
|
+
const basename = head.slice(lastSep + 1);
|
|
104
|
+
const dotIndex = basename.lastIndexOf('.');
|
|
105
|
+
return {
|
|
106
|
+
dirname,
|
|
107
|
+
basename: dotIndex > 0 ? basename.slice(0, dotIndex) : basename,
|
|
108
|
+
extension: dotIndex > 0 ? basename.slice(dotIndex) : '',
|
|
109
|
+
tail,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addRegExpFlags, setRegExpCaseSensitivity } from '
|
|
1
|
+
import { addRegExpFlags, setRegExpCaseSensitivity } from '@augment-vir/core';
|
|
2
2
|
/**
|
|
3
3
|
* Finds all indexes of a `searchFor` string or RegExp in `searchIn`. Ths is similar to
|
|
4
4
|
* [`''.indexOf`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ export * from './augments/array/awaited/awaited-find.js';
|
|
|
6
6
|
export * from './augments/array/awaited/awaited-for-each.js';
|
|
7
7
|
export * from './augments/array/awaited/awaited-map.js';
|
|
8
8
|
export * from './augments/array/create-array.js';
|
|
9
|
+
export * from './augments/array/cross-product.js';
|
|
9
10
|
export * from './augments/array/ensure-array.js';
|
|
10
11
|
export * from './augments/array/extract-duplicates.js';
|
|
11
12
|
export * from './augments/array/filter.js';
|
|
12
|
-
export * from './augments/array/remove-duplicates.js';
|
|
13
13
|
export * from './augments/array/repeat-array.js';
|
|
14
14
|
export * from './augments/array/shuffle-array.js';
|
|
15
15
|
export * from './augments/array/string-array.js';
|
|
@@ -59,6 +59,7 @@ export * from './augments/object/object-keys.js';
|
|
|
59
59
|
export * from './augments/object/object-sort.js';
|
|
60
60
|
export * from './augments/object/object-values.js';
|
|
61
61
|
export * from './augments/path/esm-path.js';
|
|
62
|
+
export * from './augments/path/universal-path.js';
|
|
62
63
|
export * from './augments/prisma/base-prisma-types.js';
|
|
63
64
|
export * from './augments/prisma/prisma-basic-model.js';
|
|
64
65
|
export * from './augments/prisma/prisma-full-model.js';
|
|
@@ -72,7 +73,6 @@ export * from './augments/random/random-integer.js';
|
|
|
72
73
|
export * from './augments/random/random-string.js';
|
|
73
74
|
export * from './augments/random/seeded-random.js';
|
|
74
75
|
export * from './augments/regexp/match.js';
|
|
75
|
-
export * from './augments/regexp/regexp-flags.js';
|
|
76
76
|
export * from './augments/selection-set/select-collapsed.js';
|
|
77
77
|
export * from './augments/selection-set/select-from.js';
|
|
78
78
|
export * from './augments/selection-set/selection-set.js';
|
|
@@ -83,7 +83,6 @@ export * from './augments/string/comma.js';
|
|
|
83
83
|
export * from './augments/string/indent.js';
|
|
84
84
|
export * from './augments/string/join.js';
|
|
85
85
|
export * from './augments/string/prefix.js';
|
|
86
|
-
export * from './augments/string/remove-duplicate-characters.js';
|
|
87
86
|
export * from './augments/string/replace.js';
|
|
88
87
|
export * from './augments/string/split.js';
|
|
89
88
|
export * from './augments/string/substring-index.js';
|
package/dist/index.js
CHANGED
|
@@ -6,10 +6,10 @@ export * from './augments/array/awaited/awaited-find.js';
|
|
|
6
6
|
export * from './augments/array/awaited/awaited-for-each.js';
|
|
7
7
|
export * from './augments/array/awaited/awaited-map.js';
|
|
8
8
|
export * from './augments/array/create-array.js';
|
|
9
|
+
export * from './augments/array/cross-product.js';
|
|
9
10
|
export * from './augments/array/ensure-array.js';
|
|
10
11
|
export * from './augments/array/extract-duplicates.js';
|
|
11
12
|
export * from './augments/array/filter.js';
|
|
12
|
-
export * from './augments/array/remove-duplicates.js';
|
|
13
13
|
export * from './augments/array/repeat-array.js';
|
|
14
14
|
export * from './augments/array/shuffle-array.js';
|
|
15
15
|
export * from './augments/array/string-array.js';
|
|
@@ -59,6 +59,7 @@ export * from './augments/object/object-keys.js';
|
|
|
59
59
|
export * from './augments/object/object-sort.js';
|
|
60
60
|
export * from './augments/object/object-values.js';
|
|
61
61
|
export * from './augments/path/esm-path.js';
|
|
62
|
+
export * from './augments/path/universal-path.js';
|
|
62
63
|
export * from './augments/prisma/base-prisma-types.js';
|
|
63
64
|
export * from './augments/prisma/prisma-basic-model.js';
|
|
64
65
|
export * from './augments/prisma/prisma-full-model.js';
|
|
@@ -72,7 +73,6 @@ export * from './augments/random/random-integer.js';
|
|
|
72
73
|
export * from './augments/random/random-string.js';
|
|
73
74
|
export * from './augments/random/seeded-random.js';
|
|
74
75
|
export * from './augments/regexp/match.js';
|
|
75
|
-
export * from './augments/regexp/regexp-flags.js';
|
|
76
76
|
export * from './augments/selection-set/select-collapsed.js';
|
|
77
77
|
export * from './augments/selection-set/select-from.js';
|
|
78
78
|
export * from './augments/selection-set/selection-set.js';
|
|
@@ -83,7 +83,6 @@ export * from './augments/string/comma.js';
|
|
|
83
83
|
export * from './augments/string/indent.js';
|
|
84
84
|
export * from './augments/string/join.js';
|
|
85
85
|
export * from './augments/string/prefix.js';
|
|
86
|
-
export * from './augments/string/remove-duplicate-characters.js';
|
|
87
86
|
export * from './augments/string/replace.js';
|
|
88
87
|
export * from './augments/string/split.js';
|
|
89
88
|
export * from './augments/string/substring-index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.37.0",
|
|
4
4
|
"description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"test:web": "virmator --no-deps test web"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/assert": "^31.
|
|
44
|
-
"@augment-vir/core": "^31.
|
|
43
|
+
"@augment-vir/assert": "^31.37.0",
|
|
44
|
+
"@augment-vir/core": "^31.37.0",
|
|
45
45
|
"@date-vir/duration": "^7.4.2",
|
|
46
|
-
"ansi-styles": "^6.2.
|
|
46
|
+
"ansi-styles": "^6.2.3",
|
|
47
47
|
"deepcopy-esm": "^2.1.1",
|
|
48
48
|
"json5": "^2.2.3",
|
|
49
|
-
"type-fest": "^
|
|
49
|
+
"type-fest": "^5.0.0",
|
|
50
50
|
"typed-event-target": "^4.1.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Removes duplicates from an array. Optionally provide a callback for calculating a unique id for
|
|
3
|
-
* entries.
|
|
4
|
-
*
|
|
5
|
-
* @category Array
|
|
6
|
-
* @category Package : @augment-vir/common
|
|
7
|
-
* @example No callback
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* import {removeDuplicates} from '@augment-vir/common';
|
|
11
|
-
*
|
|
12
|
-
* const result = removeDuplicates([
|
|
13
|
-
* 1,
|
|
14
|
-
* 1,
|
|
15
|
-
* 1,
|
|
16
|
-
* 1,
|
|
17
|
-
* 1,
|
|
18
|
-
* 2,
|
|
19
|
-
* 4,
|
|
20
|
-
* ]);
|
|
21
|
-
* // result is `[1, 2, 4]`
|
|
22
|
-
*
|
|
23
|
-
* const exampleEntry = {id: 5};
|
|
24
|
-
*
|
|
25
|
-
* const result2 = removeDuplicates([
|
|
26
|
-
* {id: 1},
|
|
27
|
-
* // this entry will not get filtered out because it's a new object reference
|
|
28
|
-
* {id: 1},
|
|
29
|
-
* exampleEntry,
|
|
30
|
-
* // this `exampleEntry` will get filtered out because it's the same reference as the one above
|
|
31
|
-
* exampleEntry,
|
|
32
|
-
* {id: 4},
|
|
33
|
-
* ]);
|
|
34
|
-
* // result2 is `[{id: 1}, {id: 1}, exampleEntry, {id: 4}]`
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @example With callback
|
|
38
|
-
*
|
|
39
|
-
* ```ts
|
|
40
|
-
* import {removeDuplicates} from '@augment-vir/common';
|
|
41
|
-
*
|
|
42
|
-
* const exampleEntry = {id: 5};
|
|
43
|
-
*
|
|
44
|
-
* const result2 = removeDuplicates(
|
|
45
|
-
* [
|
|
46
|
-
* {id: 1},
|
|
47
|
-
* {id: 1},
|
|
48
|
-
* exampleEntry,
|
|
49
|
-
* exampleEntry,
|
|
50
|
-
* {id: 4},
|
|
51
|
-
* ],
|
|
52
|
-
* (entry) => entry.id,
|
|
53
|
-
* );
|
|
54
|
-
* // result2 is `[{id: 1}, exampleEntry, {id: 4}]`
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* @returns A new array (does not mutate).
|
|
58
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
59
|
-
*/
|
|
60
|
-
export declare function removeDuplicates<const Entry>(originalArray: ReadonlyArray<Entry>, calculateUniqueId?: (entry: Readonly<Entry>) => unknown): Entry[];
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Removes duplicates from an array. Optionally provide a callback for calculating a unique id for
|
|
3
|
-
* entries.
|
|
4
|
-
*
|
|
5
|
-
* @category Array
|
|
6
|
-
* @category Package : @augment-vir/common
|
|
7
|
-
* @example No callback
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* import {removeDuplicates} from '@augment-vir/common';
|
|
11
|
-
*
|
|
12
|
-
* const result = removeDuplicates([
|
|
13
|
-
* 1,
|
|
14
|
-
* 1,
|
|
15
|
-
* 1,
|
|
16
|
-
* 1,
|
|
17
|
-
* 1,
|
|
18
|
-
* 2,
|
|
19
|
-
* 4,
|
|
20
|
-
* ]);
|
|
21
|
-
* // result is `[1, 2, 4]`
|
|
22
|
-
*
|
|
23
|
-
* const exampleEntry = {id: 5};
|
|
24
|
-
*
|
|
25
|
-
* const result2 = removeDuplicates([
|
|
26
|
-
* {id: 1},
|
|
27
|
-
* // this entry will not get filtered out because it's a new object reference
|
|
28
|
-
* {id: 1},
|
|
29
|
-
* exampleEntry,
|
|
30
|
-
* // this `exampleEntry` will get filtered out because it's the same reference as the one above
|
|
31
|
-
* exampleEntry,
|
|
32
|
-
* {id: 4},
|
|
33
|
-
* ]);
|
|
34
|
-
* // result2 is `[{id: 1}, {id: 1}, exampleEntry, {id: 4}]`
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @example With callback
|
|
38
|
-
*
|
|
39
|
-
* ```ts
|
|
40
|
-
* import {removeDuplicates} from '@augment-vir/common';
|
|
41
|
-
*
|
|
42
|
-
* const exampleEntry = {id: 5};
|
|
43
|
-
*
|
|
44
|
-
* const result2 = removeDuplicates(
|
|
45
|
-
* [
|
|
46
|
-
* {id: 1},
|
|
47
|
-
* {id: 1},
|
|
48
|
-
* exampleEntry,
|
|
49
|
-
* exampleEntry,
|
|
50
|
-
* {id: 4},
|
|
51
|
-
* ],
|
|
52
|
-
* (entry) => entry.id,
|
|
53
|
-
* );
|
|
54
|
-
* // result2 is `[{id: 1}, exampleEntry, {id: 4}]`
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* @returns A new array (does not mutate).
|
|
58
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
59
|
-
*/
|
|
60
|
-
export function removeDuplicates(originalArray, calculateUniqueId = (entry) => entry) {
|
|
61
|
-
const grouped = new Map();
|
|
62
|
-
return originalArray.filter((entry) => {
|
|
63
|
-
const uniqueId = calculateUniqueId(entry);
|
|
64
|
-
if (grouped.get(uniqueId)) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
grouped.set(uniqueId, entry);
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a new RegExp by adding the given `flags` to the original RegExp.
|
|
3
|
-
*
|
|
4
|
-
* @category RegExp
|
|
5
|
-
* @category Package : @augment-vir/common
|
|
6
|
-
* @example
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* import {addRegExpFlags} from '@augment-vir/common';
|
|
10
|
-
*
|
|
11
|
-
* addRegExpFlags(/a/i, 'gm');
|
|
12
|
-
* // output is `/a/igm`
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
16
|
-
*/
|
|
17
|
-
export declare function addRegExpFlags(originalRegExpOrString: RegExp | string, flags: string): RegExp;
|
|
18
|
-
/**
|
|
19
|
-
* Creates a new RegExp with the given `flags`.
|
|
20
|
-
*
|
|
21
|
-
* @category RegExp
|
|
22
|
-
* @category Package : @augment-vir/common
|
|
23
|
-
* @example
|
|
24
|
-
*
|
|
25
|
-
* ```ts
|
|
26
|
-
* import {setRegExpFlags} from '@augment-vir/common';
|
|
27
|
-
*
|
|
28
|
-
* setRegExpFlags(/a/i, 'gm');
|
|
29
|
-
* // output is `/a/gm`
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
33
|
-
*/
|
|
34
|
-
export declare function setRegExpFlags(originalRegExpOrString: RegExp | string, flags: string): RegExp;
|
|
35
|
-
/**
|
|
36
|
-
* Creates a new RegExp by adding or removing the case insensitivity flag `'i'`, based on the given
|
|
37
|
-
* `caseSensitive` input. The first input can also be a string and it will be converted into a
|
|
38
|
-
* RegExp.
|
|
39
|
-
*
|
|
40
|
-
* @category RegExp
|
|
41
|
-
* @category Package : @augment-vir/common
|
|
42
|
-
* @example
|
|
43
|
-
*
|
|
44
|
-
* ```ts
|
|
45
|
-
* import {setRegExpCaseSensitivity} from '@augment-vir/common';
|
|
46
|
-
*
|
|
47
|
-
* setRegExpCaseSensitivity(/abc/i, {caseSensitive: true}); // output is `/abc/`
|
|
48
|
-
* setRegExpCaseSensitivity(/abc/, {caseSensitive: false}); // output is `/abc/i`
|
|
49
|
-
* setRegExpCaseSensitivity('abc', {caseSensitive: true}); // output is `/abc/i`
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
53
|
-
*/
|
|
54
|
-
export declare function setRegExpCaseSensitivity(originalRegExpOrString: string | RegExp, { caseSensitive }: {
|
|
55
|
-
caseSensitive: boolean;
|
|
56
|
-
}): RegExp;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { escapeStringForRegExp } from '@augment-vir/core';
|
|
2
|
-
import { removeDuplicateCharacters } from '../string/remove-duplicate-characters.js';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a new RegExp by adding the given `flags` to the original RegExp.
|
|
5
|
-
*
|
|
6
|
-
* @category RegExp
|
|
7
|
-
* @category Package : @augment-vir/common
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* import {addRegExpFlags} from '@augment-vir/common';
|
|
12
|
-
*
|
|
13
|
-
* addRegExpFlags(/a/i, 'gm');
|
|
14
|
-
* // output is `/a/igm`
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
18
|
-
*/
|
|
19
|
-
export function addRegExpFlags(originalRegExpOrString, flags) {
|
|
20
|
-
const allFlags = removeDuplicateCharacters([
|
|
21
|
-
typeof originalRegExpOrString === 'string' ? '' : originalRegExpOrString.flags,
|
|
22
|
-
flags,
|
|
23
|
-
]
|
|
24
|
-
.join('')
|
|
25
|
-
.toLowerCase());
|
|
26
|
-
return setRegExpFlags(originalRegExpOrString, allFlags);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Creates a new RegExp with the given `flags`.
|
|
30
|
-
*
|
|
31
|
-
* @category RegExp
|
|
32
|
-
* @category Package : @augment-vir/common
|
|
33
|
-
* @example
|
|
34
|
-
*
|
|
35
|
-
* ```ts
|
|
36
|
-
* import {setRegExpFlags} from '@augment-vir/common';
|
|
37
|
-
*
|
|
38
|
-
* setRegExpFlags(/a/i, 'gm');
|
|
39
|
-
* // output is `/a/gm`
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
43
|
-
*/
|
|
44
|
-
export function setRegExpFlags(originalRegExpOrString, flags) {
|
|
45
|
-
const allFlags = removeDuplicateCharacters(flags);
|
|
46
|
-
if (typeof originalRegExpOrString === 'string') {
|
|
47
|
-
return new RegExp(escapeStringForRegExp(originalRegExpOrString), allFlags);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
return new RegExp(originalRegExpOrString.source, allFlags);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Creates a new RegExp by adding or removing the case insensitivity flag `'i'`, based on the given
|
|
55
|
-
* `caseSensitive` input. The first input can also be a string and it will be converted into a
|
|
56
|
-
* RegExp.
|
|
57
|
-
*
|
|
58
|
-
* @category RegExp
|
|
59
|
-
* @category Package : @augment-vir/common
|
|
60
|
-
* @example
|
|
61
|
-
*
|
|
62
|
-
* ```ts
|
|
63
|
-
* import {setRegExpCaseSensitivity} from '@augment-vir/common';
|
|
64
|
-
*
|
|
65
|
-
* setRegExpCaseSensitivity(/abc/i, {caseSensitive: true}); // output is `/abc/`
|
|
66
|
-
* setRegExpCaseSensitivity(/abc/, {caseSensitive: false}); // output is `/abc/i`
|
|
67
|
-
* setRegExpCaseSensitivity('abc', {caseSensitive: true}); // output is `/abc/i`
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
71
|
-
*/
|
|
72
|
-
export function setRegExpCaseSensitivity(originalRegExpOrString, { caseSensitive }) {
|
|
73
|
-
const caseSensitivityFlag = caseSensitive ? '' : 'i';
|
|
74
|
-
return addRegExpFlags(originalRegExpOrString, caseSensitivityFlag);
|
|
75
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Removes duplicate characters from any number of strings.
|
|
3
|
-
*
|
|
4
|
-
* @category String
|
|
5
|
-
* @category Package : @augment-vir/common
|
|
6
|
-
* @example
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* import {removeDuplicateCharacters} from '@augment-vir/common';
|
|
10
|
-
*
|
|
11
|
-
* removeDuplicateCharacters('aAaBc', 'QrsAa');
|
|
12
|
-
* // output is `'aABcQrs'`
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
16
|
-
*/
|
|
17
|
-
export declare function removeDuplicateCharacters(...values: ReadonlyArray<string>): string;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { removeDuplicates } from '../array/remove-duplicates.js';
|
|
2
|
-
/**
|
|
3
|
-
* Removes duplicate characters from any number of strings.
|
|
4
|
-
*
|
|
5
|
-
* @category String
|
|
6
|
-
* @category Package : @augment-vir/common
|
|
7
|
-
* @example
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* import {removeDuplicateCharacters} from '@augment-vir/common';
|
|
11
|
-
*
|
|
12
|
-
* removeDuplicateCharacters('aAaBc', 'QrsAa');
|
|
13
|
-
* // output is `'aABcQrs'`
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
17
|
-
*/
|
|
18
|
-
export function removeDuplicateCharacters(...values) {
|
|
19
|
-
const combined = values.join('');
|
|
20
|
-
const deDuped = removeDuplicates(Array.from(combined));
|
|
21
|
-
return Array.from(deDuped).join('');
|
|
22
|
-
}
|