@augment-vir/common 30.0.0 → 30.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.
- package/README.md +11 -0
- package/dist/augments/array/array-map.d.ts +29 -1
- package/dist/augments/array/array-map.js +29 -1
- package/dist/augments/array/array-to-object.d.ts +41 -5
- package/dist/augments/array/array-to-object.js +41 -5
- package/dist/augments/array/awaited/awaited-filter.d.ts +29 -0
- package/dist/augments/array/awaited/awaited-filter.js +29 -0
- package/dist/augments/array/awaited/awaited-for-each.d.ts +28 -3
- package/dist/augments/array/awaited/awaited-for-each.js +28 -3
- package/dist/augments/array/awaited/awaited-map.d.ts +32 -0
- package/dist/augments/array/awaited/awaited-map.js +32 -0
- package/dist/augments/array/filter.d.ts +29 -0
- package/dist/augments/array/filter.js +61 -0
- package/dist/augments/array/remove-duplicates.d.ts +60 -1
- package/dist/augments/array/remove-duplicates.js +61 -2
- package/dist/augments/array/repeat-array.d.ts +22 -0
- package/dist/augments/array/repeat-array.js +22 -0
- package/dist/augments/array/shuffle-array.d.ts +8 -1
- package/dist/augments/array/shuffle-array.js +8 -1
- package/dist/augments/array/string-array.d.ts +8 -0
- package/dist/augments/array/string-array.js +8 -0
- package/dist/augments/enum/enum-value-check.d.ts +30 -0
- package/dist/augments/enum/enum-value-check.js +30 -0
- package/dist/augments/error/combine-errors.d.ts +24 -3
- package/dist/augments/error/combine-errors.js +26 -4
- package/dist/augments/function/call-asynchronously.d.ts +19 -0
- package/dist/augments/function/call-asynchronously.js +19 -0
- package/dist/augments/function/call-with-retries.d.ts +23 -3
- package/dist/augments/function/call-with-retries.js +23 -0
- package/dist/augments/function/debounce.d.ts +71 -4
- package/dist/augments/function/debounce.js +66 -4
- package/dist/augments/function/execution-duration.d.ts +17 -5
- package/dist/augments/function/execution-duration.js +16 -3
- package/dist/augments/function/if-truthy.d.ts +28 -0
- package/dist/augments/function/if-truthy.js +35 -0
- package/dist/augments/function/wrap-in-try.d.ts +12 -4
- package/dist/augments/function/wrap-in-try.js +64 -0
- package/dist/augments/json/append-json.d.ts +3 -3
- package/dist/augments/json/append-json.js +33 -0
- package/dist/augments/json/copy-through-json.d.ts +32 -1
- package/dist/augments/json/copy-through-json.js +32 -1
- package/dist/augments/json/json-compatible.d.ts +37 -9
- package/dist/augments/json/jsonify.d.ts +30 -1
- package/dist/augments/json/jsonify.js +31 -2
- package/dist/augments/log/log-colors.d.ts +41 -0
- package/dist/augments/log/log-colors.js +43 -2
- package/dist/augments/log/log-string.d.ts +21 -0
- package/dist/augments/log/log-string.js +9 -2
- package/dist/augments/log/log-writer.d.ts +22 -0
- package/dist/augments/log/log.d.ts +44 -1
- package/dist/augments/log/log.js +46 -3
- package/dist/augments/log/logger.d.ts +49 -0
- package/dist/augments/log/logger.js +21 -0
- package/dist/augments/number/clamp.d.ts +13 -2
- package/dist/augments/number/clamp.js +12 -1
- package/dist/augments/number/coords.d.ts +6 -2
- package/dist/augments/number/digit.d.ts +7 -0
- package/dist/augments/number/dimensions.d.ts +6 -2
- package/dist/augments/number/min-max.d.ts +9 -2
- package/dist/augments/number/min-max.js +4 -2
- package/dist/augments/number/number-conversion.d.ts +9 -3
- package/dist/augments/number/number-conversion.js +10 -4
- package/dist/augments/number/round.d.ts +19 -0
- package/dist/augments/number/round.js +19 -0
- package/dist/augments/number/scientific.d.ts +18 -1
- package/dist/augments/number/scientific.js +18 -1
- package/dist/augments/number/truncate-number.d.ts +24 -3
- package/dist/augments/number/truncate-number.js +28 -8
- package/dist/augments/number/wrap-number.d.ts +9 -3
- package/dist/augments/number/wrap-number.js +8 -2
- package/dist/augments/object/diff.d.ts +27 -5
- package/dist/augments/object/diff.js +20 -4
- package/dist/augments/object/empty.d.ts +7 -1
- package/dist/augments/object/get-or-set.d.ts +6 -27
- package/dist/augments/object/get-or-set.js +66 -4
- package/dist/augments/object/key-count.d.ts +4 -0
- package/dist/augments/object/map-entries.js +23 -0
- package/dist/augments/object/map-enum.d.ts +7 -0
- package/dist/augments/object/map-enum.js +24 -0
- package/dist/augments/object/map-values.d.ts +25 -13
- package/dist/augments/object/map-values.js +29 -21
- package/dist/augments/object/merge-deep.d.ts +4 -0
- package/dist/augments/object/merge-deep.js +4 -0
- package/dist/augments/object/merge-defined-properties.d.ts +13 -0
- package/dist/augments/object/merge-defined-properties.js +13 -0
- package/dist/augments/object/merge-property-arrays.d.ts +28 -0
- package/dist/augments/object/merge-property-arrays.js +28 -0
- package/dist/augments/object/object-entries.d.ts +27 -0
- package/dist/augments/object/object-entries.js +27 -0
- package/dist/augments/object/object-filter.d.ts +20 -0
- package/dist/augments/object/object-filter.js +20 -0
- package/dist/augments/object/object-keys.d.ts +32 -0
- package/dist/augments/object/object-keys.js +32 -0
- package/dist/augments/object/object-values.d.ts +9 -0
- package/dist/augments/object/object-values.js +9 -0
- package/dist/augments/path/esm-path.d.ts +26 -0
- package/dist/augments/path/esm-path.js +31 -0
- package/dist/augments/prisma/prisma-models.d.ts +40 -3
- package/dist/augments/promise/timed-promise.d.ts +15 -0
- package/dist/augments/promise/timed-promise.js +15 -0
- package/dist/augments/random/random-boolean.d.ts +6 -0
- package/dist/augments/random/random-boolean.js +6 -0
- package/dist/augments/random/random-integer.d.ts +3 -1
- package/dist/augments/random/random-integer.js +3 -1
- package/dist/augments/random/random-string.d.ts +6 -2
- package/dist/augments/random/random-string.js +6 -2
- package/dist/augments/regexp/match.d.ts +10 -0
- package/dist/augments/regexp/match.js +13 -0
- package/dist/augments/regexp/regexp-flags.d.ts +56 -3
- package/dist/augments/regexp/regexp-flags.js +71 -14
- package/dist/augments/regexp/regexp-string.d.ts +4 -0
- package/dist/augments/regexp/regexp-string.js +5 -1
- package/dist/augments/selection-set/select-collapsed.d.ts +46 -3
- package/dist/augments/selection-set/select-collapsed.js +40 -2
- package/dist/augments/selection-set/select-from.d.ts +47 -2
- package/dist/augments/selection-set/select-from.js +48 -1
- package/dist/augments/selection-set/selection-set.d.ts +26 -7
- package/dist/augments/selection-set/selection-set.js +1 -4
- package/dist/augments/string/casing/capitalization.d.ts +15 -1
- package/dist/augments/string/casing/capitalization.js +14 -0
- package/dist/augments/string/casing/casing.d.ts +53 -7
- package/dist/augments/string/casing/casing.js +36 -11
- package/dist/augments/string/casing/kebab-and-camel.d.ts +14 -0
- package/dist/augments/string/casing/kebab-and-camel.js +20 -5
- package/dist/augments/string/comma.d.ts +26 -0
- package/dist/augments/string/{commas.js → comma.js} +21 -2
- package/dist/augments/string/join.d.ts +15 -4
- package/dist/augments/string/join.js +15 -4
- package/dist/augments/string/prefix.d.ts +6 -0
- package/dist/augments/string/prefix.js +4 -0
- package/dist/augments/string/remove-duplicate-characters.d.ts +17 -0
- package/dist/augments/string/remove-duplicate-characters.js +22 -0
- package/dist/augments/string/replace.d.ts +17 -0
- package/dist/augments/string/replace.js +17 -0
- package/dist/augments/string/split.d.ts +29 -2
- package/dist/augments/string/split.js +32 -7
- package/dist/augments/string/substring-index.d.ts +11 -5
- package/dist/augments/string/substring-index.js +12 -3
- package/dist/augments/string/suffix.d.ts +22 -0
- package/dist/augments/string/suffix.js +16 -0
- package/dist/augments/string/white-space.d.ts +8 -1
- package/dist/augments/string/white-space.js +8 -1
- package/dist/augments/string/wrap-string.d.ts +15 -0
- package/dist/augments/string/wrap-string.js +15 -0
- package/dist/augments/type/ensure-type.d.ts +4 -0
- package/dist/augments/type/ensure-type.js +4 -0
- package/dist/augments/type/readonly.d.ts +7 -0
- package/dist/augments/type/readonly.js +7 -0
- package/dist/augments/type/type-recursion.d.ts +93 -1
- package/dist/augments/type/union.d.ts +1 -0
- package/dist/augments/type/union.js +1 -0
- package/dist/augments/type/void-type.d.ts +6 -2
- package/dist/augments/type/writable.d.ts +7 -0
- package/dist/augments/type/writable.js +7 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +6 -4
- package/package.json +15 -5
- package/dist/augments/boolean/if-truthy.d.ts +0 -2
- package/dist/augments/boolean/if-truthy.js +0 -9
- package/dist/augments/file/esm-path.d.ts +0 -4
- package/dist/augments/file/esm-path.js +0 -8
- package/dist/augments/regexp/safe-match.d.ts +0 -1
- package/dist/augments/regexp/safe-match.js +0 -4
- package/dist/augments/string/commas.d.ts +0 -7
|
@@ -2,10 +2,53 @@ import type { AnyObject, Values } from '@augment-vir/core';
|
|
|
2
2
|
import { ExcludeEmpty } from '../object/empty.js';
|
|
3
3
|
import { KeyCount } from '../object/key-count.js';
|
|
4
4
|
import { TsRecurse, TsRecursionStart, TsRecursionTracker, TsTooMuchRecursion } from '../type/type-recursion.js';
|
|
5
|
-
import { GenericSelectionSet,
|
|
5
|
+
import { GenericSelectionSet, SelectFrom, SelectionSet } from './selection-set.js';
|
|
6
|
+
/**
|
|
7
|
+
* The same as {@link selectFrom} except that the final output is collapsed until the first nested
|
|
8
|
+
* value that has more than 1 key or that is not an object.
|
|
9
|
+
*
|
|
10
|
+
* @category Selection
|
|
11
|
+
* @category Package : @augment-vir/common
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import {selectCollapsedFrom} from '@augment-vir/common';
|
|
16
|
+
*
|
|
17
|
+
* selectCollapsedFrom(
|
|
18
|
+
* [
|
|
19
|
+
* {
|
|
20
|
+
* child: {
|
|
21
|
+
* grandChild: 'hi',
|
|
22
|
+
* grandChild2: 3,
|
|
23
|
+
* grandChild3: /something/,
|
|
24
|
+
* },
|
|
25
|
+
* },
|
|
26
|
+
* {
|
|
27
|
+
* child: {
|
|
28
|
+
* grandChild: 'hi',
|
|
29
|
+
* grandChild2: 4,
|
|
30
|
+
* grandChild3: /something/,
|
|
31
|
+
* },
|
|
32
|
+
* },
|
|
33
|
+
* ],
|
|
34
|
+
* {
|
|
35
|
+
* child: {
|
|
36
|
+
* grandChild2: true,
|
|
37
|
+
* },
|
|
38
|
+
* },
|
|
39
|
+
* );
|
|
40
|
+
* // output is `[3, 4]`
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
44
|
+
*/
|
|
6
45
|
export declare function selectCollapsedFrom<Full extends AnyObject, const Selection extends SelectionSet<NoInfer<Full>>>(originalObject: Readonly<Full>, selectionSet: Readonly<Selection>): PickCollapsedSelection<Full, Selection>;
|
|
7
46
|
/**
|
|
8
47
|
* Collapses a selected value to the first part of the selection that contains more than 1 key or
|
|
9
|
-
* that is not an object.
|
|
48
|
+
* that is not an object. This produces the output type for {@link selectCollapsedFrom}.
|
|
49
|
+
*
|
|
50
|
+
* @category Selection
|
|
51
|
+
* @category Package : @augment-vir/common
|
|
52
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
10
53
|
*/
|
|
11
|
-
export type PickCollapsedSelection<Full extends Readonly<AnyObject>, Selection extends SelectionSet<Full>, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? 'Error: recursive object depth is too deep.' : KeyCount<ExcludeEmpty<NonNullable<
|
|
54
|
+
export type PickCollapsedSelection<Full extends Readonly<AnyObject>, Selection extends SelectionSet<Full>, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? 'Error: recursive object depth is too deep.' : KeyCount<ExcludeEmpty<NonNullable<SelectFrom<Full, Selection, Depth>>>> extends 1 ? Selection[keyof SelectFrom<Full, Selection, Depth>] extends GenericSelectionSet ? PickCollapsedSelection<NonNullable<Full[keyof SelectFrom<Full, Selection, Depth>]>, Selection[keyof SelectFrom<Full, Selection, Depth>], TsRecurse<Depth>> | Extract<Full[keyof SelectFrom<Full, Selection, Depth>], undefined | null> : Values<SelectFrom<Full, Selection, Depth>> : SelectFrom<Full, Selection, Depth>;
|
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
import { check } from '@augment-vir/assert';
|
|
2
|
-
import { selectFrom } from './select-from.js';
|
|
3
|
-
|
|
2
|
+
import { selectFrom, shouldPreserveInSelectionSet } from './select-from.js';
|
|
3
|
+
/**
|
|
4
|
+
* The same as {@link selectFrom} except that the final output is collapsed until the first nested
|
|
5
|
+
* value that has more than 1 key or that is not an object.
|
|
6
|
+
*
|
|
7
|
+
* @category Selection
|
|
8
|
+
* @category Package : @augment-vir/common
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import {selectCollapsedFrom} from '@augment-vir/common';
|
|
13
|
+
*
|
|
14
|
+
* selectCollapsedFrom(
|
|
15
|
+
* [
|
|
16
|
+
* {
|
|
17
|
+
* child: {
|
|
18
|
+
* grandChild: 'hi',
|
|
19
|
+
* grandChild2: 3,
|
|
20
|
+
* grandChild3: /something/,
|
|
21
|
+
* },
|
|
22
|
+
* },
|
|
23
|
+
* {
|
|
24
|
+
* child: {
|
|
25
|
+
* grandChild: 'hi',
|
|
26
|
+
* grandChild2: 4,
|
|
27
|
+
* grandChild3: /something/,
|
|
28
|
+
* },
|
|
29
|
+
* },
|
|
30
|
+
* ],
|
|
31
|
+
* {
|
|
32
|
+
* child: {
|
|
33
|
+
* grandChild2: true,
|
|
34
|
+
* },
|
|
35
|
+
* },
|
|
36
|
+
* );
|
|
37
|
+
* // output is `[3, 4]`
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
41
|
+
*/
|
|
4
42
|
export function selectCollapsedFrom(originalObject, selectionSet) {
|
|
5
43
|
const selected = selectFrom(originalObject, selectionSet);
|
|
6
44
|
return collapseObject(selected, selectionSet);
|
|
@@ -1,3 +1,48 @@
|
|
|
1
1
|
import type { AnyObject } from '@augment-vir/core';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { SelectFrom, SelectionSet } from './selection-set.js';
|
|
3
|
+
/**
|
|
4
|
+
* Determine if the given input should be preserved in the selection output, meaning it won't be
|
|
5
|
+
* recursed into.
|
|
6
|
+
*
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
9
|
+
export declare function shouldPreserveInSelectionSet(input: unknown): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Performs a SQL-like nested selection on an object, extracting the selected values.
|
|
12
|
+
*
|
|
13
|
+
* @category Selection
|
|
14
|
+
* @category Package : @augment-vir/common
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import {selectFrom} from '@augment-vir/common';
|
|
19
|
+
*
|
|
20
|
+
* selectFrom(
|
|
21
|
+
* [
|
|
22
|
+
* {
|
|
23
|
+
* child: {
|
|
24
|
+
* grandChild: 'hi',
|
|
25
|
+
* grandChild2: 3,
|
|
26
|
+
* grandChild3: /something/,
|
|
27
|
+
* },
|
|
28
|
+
* },
|
|
29
|
+
* {
|
|
30
|
+
* child: {
|
|
31
|
+
* grandChild: 'hi',
|
|
32
|
+
* grandChild2: 4,
|
|
33
|
+
* grandChild3: /something/,
|
|
34
|
+
* },
|
|
35
|
+
* },
|
|
36
|
+
* ],
|
|
37
|
+
* {
|
|
38
|
+
* child: {
|
|
39
|
+
* grandChild2: true,
|
|
40
|
+
* },
|
|
41
|
+
* },
|
|
42
|
+
* );
|
|
43
|
+
* // output is `[{child: {grandChild2: 3}}, {child: {grandChild2: 4}}]`
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
47
|
+
*/
|
|
48
|
+
export declare function selectFrom<Full extends AnyObject, const Selection extends SelectionSet<NoInfer<Full>>>(originalObject: Readonly<Full>, selectionSet: Readonly<Selection>): SelectFrom<Full, Selection>;
|
|
@@ -1,6 +1,53 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
1
2
|
import { mapObjectValues } from '../object/map-values.js';
|
|
2
3
|
import { omitObjectKeys } from '../object/object-keys.js';
|
|
3
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Determine if the given input should be preserved in the selection output, meaning it won't be
|
|
6
|
+
* recursed into.
|
|
7
|
+
*
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
export function shouldPreserveInSelectionSet(input) {
|
|
11
|
+
return check.isPrimitive(input) || input instanceof RegExp || input instanceof Promise;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Performs a SQL-like nested selection on an object, extracting the selected values.
|
|
15
|
+
*
|
|
16
|
+
* @category Selection
|
|
17
|
+
* @category Package : @augment-vir/common
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import {selectFrom} from '@augment-vir/common';
|
|
22
|
+
*
|
|
23
|
+
* selectFrom(
|
|
24
|
+
* [
|
|
25
|
+
* {
|
|
26
|
+
* child: {
|
|
27
|
+
* grandChild: 'hi',
|
|
28
|
+
* grandChild2: 3,
|
|
29
|
+
* grandChild3: /something/,
|
|
30
|
+
* },
|
|
31
|
+
* },
|
|
32
|
+
* {
|
|
33
|
+
* child: {
|
|
34
|
+
* grandChild: 'hi',
|
|
35
|
+
* grandChild2: 4,
|
|
36
|
+
* grandChild3: /something/,
|
|
37
|
+
* },
|
|
38
|
+
* },
|
|
39
|
+
* ],
|
|
40
|
+
* {
|
|
41
|
+
* child: {
|
|
42
|
+
* grandChild2: true,
|
|
43
|
+
* },
|
|
44
|
+
* },
|
|
45
|
+
* );
|
|
46
|
+
* // output is `[{child: {grandChild2: 3}}, {child: {grandChild2: 4}}]`
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
50
|
+
*/
|
|
4
51
|
export function selectFrom(originalObject, selectionSet) {
|
|
5
52
|
if (Array.isArray(originalObject)) {
|
|
6
53
|
return originalObject.map((originalEntry) => selectFrom(originalEntry, selectionSet));
|
|
@@ -1,18 +1,37 @@
|
|
|
1
1
|
import type { AnyObject } from '@augment-vir/core';
|
|
2
2
|
import { IsAny, IsNever, Primitive, UnionToIntersection } from 'type-fest';
|
|
3
3
|
import { TsRecurse, TsRecursionStart, TsRecursionTracker, TsTooMuchRecursion } from '../type/type-recursion.js';
|
|
4
|
-
export declare function shouldPreserveInSelectionSet(input: unknown): input is SelectionTypesToPreserve;
|
|
5
4
|
/** All types that won't be recursed into when defining a {@link SelectionSet}. */
|
|
6
|
-
|
|
7
|
-
/**
|
|
5
|
+
type SelectionTypesToPreserve = Primitive | RegExp | Promise<any>;
|
|
6
|
+
/**
|
|
7
|
+
* A generic selection set without specific keys. Useful for type parameter baselines.
|
|
8
|
+
*
|
|
9
|
+
* @category Selection
|
|
10
|
+
* @category Package : @augment-vir/common
|
|
11
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
12
|
+
*/
|
|
8
13
|
export type GenericSelectionSet = {
|
|
9
14
|
[Key in PropertyKey]: unknown;
|
|
10
15
|
};
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Performs a SQL-like nested selection on an object, extracting the selected values. This produces
|
|
18
|
+
* the output type for `selectFrom`.
|
|
19
|
+
*
|
|
20
|
+
* @category Selection
|
|
21
|
+
* @category Package : @augment-vir/common
|
|
22
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
23
|
+
*/
|
|
24
|
+
export type SelectFrom<Full extends Readonly<AnyObject>, Selection extends SelectionSet<Full>, Depth extends TsRecursionTracker = TsRecursionStart> = Depth extends TsTooMuchRecursion ? ['Error: recursive object depth is too deep.'] : Full extends ReadonlyArray<infer Element extends any> ? (SelectFrom<Extract<Element, AnyObject>, Selection, TsRecurse<Depth>> | Exclude<Element, AnyObject>)[] : {
|
|
25
|
+
-readonly [Key in keyof Selection as Selection[Key] extends false ? never : Key extends keyof Full ? Key : never]: (Selection[Key] extends GenericSelectionSet ? SelectFrom<NonNullable<Extract<Full[Key], AnyObject>>, Selection[Key], TsRecurse<Depth>> : Full[Key]) | Exclude<Full[Key], AnyObject>;
|
|
14
26
|
};
|
|
15
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Defines a selection set for a given object type. This is used in {@link SelectFrom}.
|
|
29
|
+
*
|
|
30
|
+
* @category Selection
|
|
31
|
+
* @category Package : @augment-vir/common
|
|
32
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
33
|
+
*/
|
|
16
34
|
export type SelectionSet<Full extends Readonly<AnyObject>, Depth extends TsRecursionTracker = TsRecursionStart> = IsAny<Full> extends true ? any : Depth extends TsTooMuchRecursion ? boolean : Full extends ReadonlyArray<infer FullChild extends AnyObject> ? SelectionSet<FullChild, TsRecurse<Depth>> : Partial<{
|
|
17
35
|
[Key in keyof Full]: IsNever<Exclude<Full[Key], SelectionTypesToPreserve>> extends true ? boolean : UnionToIntersection<SelectionSet<NonNullable<Required<Full>[Key]>, TsRecurse<Depth>>> | boolean;
|
|
18
36
|
}>;
|
|
37
|
+
export {};
|
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
import { CasingOptions } from './casing.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Capitalize the first letter of the input _only if_ the given options specifies doing so.
|
|
4
|
+
*
|
|
5
|
+
* @category String
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
8
|
+
*/
|
|
9
|
+
export declare function maybeCapitalize(input: string, casingOptions: Pick<CasingOptions, 'capitalizeFirstLetter'>): string;
|
|
10
|
+
/**
|
|
11
|
+
* Capitalize the first letter of the input.
|
|
12
|
+
*
|
|
13
|
+
* @category String
|
|
14
|
+
* @category Package : @augment-vir/common
|
|
15
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
16
|
+
*/
|
|
3
17
|
export declare function capitalizeFirstLetter<InputGeneric extends string>(input: InputGeneric): Capitalize<InputGeneric>;
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capitalize the first letter of the input _only if_ the given options specifies doing so.
|
|
3
|
+
*
|
|
4
|
+
* @category String
|
|
5
|
+
* @category Package : @augment-vir/common
|
|
6
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
7
|
+
*/
|
|
1
8
|
export function maybeCapitalize(input, casingOptions) {
|
|
2
9
|
return casingOptions.capitalizeFirstLetter ? capitalizeFirstLetter(input) : input;
|
|
3
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Capitalize the first letter of the input.
|
|
13
|
+
*
|
|
14
|
+
* @category String
|
|
15
|
+
* @category Package : @augment-vir/common
|
|
16
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
17
|
+
*/
|
|
4
18
|
export function capitalizeFirstLetter(input) {
|
|
5
19
|
if (!input.length) {
|
|
6
20
|
return '';
|
|
@@ -1,20 +1,62 @@
|
|
|
1
1
|
import { PartialWithUndefined } from '@augment-vir/core';
|
|
2
|
+
/**
|
|
3
|
+
* Options for casing functions in `@augment-vir/common`.
|
|
4
|
+
*
|
|
5
|
+
* @category String
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
8
|
+
*/
|
|
2
9
|
export type CasingOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* Capitalize the first letter of the string.
|
|
12
|
+
*
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
3
15
|
capitalizeFirstLetter: boolean;
|
|
4
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Default options for {@link CasingOptions}.
|
|
19
|
+
*
|
|
20
|
+
* @category String
|
|
21
|
+
* @category Package : @augment-vir/common
|
|
22
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
23
|
+
*/
|
|
5
24
|
export declare const defaultCasingOptions: Required<CasingOptions>;
|
|
6
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The different string cases.
|
|
27
|
+
*
|
|
28
|
+
* @category String
|
|
29
|
+
* @category Package : @augment-vir/common
|
|
30
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
31
|
+
*/
|
|
32
|
+
export declare enum StringCase {
|
|
7
33
|
Upper = "upper",
|
|
8
34
|
Lower = "lower"
|
|
9
35
|
}
|
|
10
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Indicates whether the given string has different lower and upper case variants. (Some strings
|
|
38
|
+
* don't, such as all numbers or `'√'`.)
|
|
39
|
+
*
|
|
40
|
+
* @category String
|
|
41
|
+
* @category Package : @augment-vir/common
|
|
42
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
43
|
+
*/
|
|
11
44
|
export declare function hasCase(input: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Options for {@link isCase}.
|
|
47
|
+
*
|
|
48
|
+
* @category String
|
|
49
|
+
* @category Package : @augment-vir/common
|
|
50
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
51
|
+
*/
|
|
12
52
|
export type IsCaseOptions = {
|
|
13
53
|
/**
|
|
14
|
-
*
|
|
15
|
-
* punctuation, like `'.'` or symbols, like `'√'`).
|
|
54
|
+
* Set to `true` to fail on characters that don't have different upper and lower case versions
|
|
55
|
+
* (such as punctuation, like `'.'` or symbols, like `'√'`).
|
|
56
|
+
*
|
|
57
|
+
* @default false
|
|
16
58
|
*/
|
|
17
|
-
|
|
59
|
+
rejectNoCaseCharacters: boolean;
|
|
18
60
|
};
|
|
19
61
|
/**
|
|
20
62
|
* Checks if the given string is exclusively of the specific case.
|
|
@@ -22,6 +64,10 @@ export type IsCaseOptions = {
|
|
|
22
64
|
* Note that some characters have no casing, such as punctuation (they have no difference between
|
|
23
65
|
* upper and lower casings). By default, those letters always return `true` for this function,
|
|
24
66
|
* regardless of which `caseType` is provided. To instead return `false` for any such characters,
|
|
25
|
-
* pass in an options object and set
|
|
67
|
+
* pass in an options object and set `rejectNoCaseCharacters` to true.
|
|
68
|
+
*
|
|
69
|
+
* @category String
|
|
70
|
+
* @category Package : @augment-vir/common
|
|
71
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
26
72
|
*/
|
|
27
|
-
export declare function isCase(input: string, caseType:
|
|
73
|
+
export declare function isCase(input: string, caseType: StringCase, options?: PartialWithUndefined<IsCaseOptions>): boolean;
|
|
@@ -1,12 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default options for {@link CasingOptions}.
|
|
3
|
+
*
|
|
4
|
+
* @category String
|
|
5
|
+
* @category Package : @augment-vir/common
|
|
6
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
7
|
+
*/
|
|
1
8
|
export const defaultCasingOptions = {
|
|
2
9
|
capitalizeFirstLetter: false,
|
|
3
10
|
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The different string cases.
|
|
13
|
+
*
|
|
14
|
+
* @category String
|
|
15
|
+
* @category Package : @augment-vir/common
|
|
16
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
17
|
+
*/
|
|
18
|
+
export var StringCase;
|
|
19
|
+
(function (StringCase) {
|
|
20
|
+
StringCase["Upper"] = "upper";
|
|
21
|
+
StringCase["Lower"] = "lower";
|
|
22
|
+
})(StringCase || (StringCase = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Indicates whether the given string has different lower and upper case variants. (Some strings
|
|
25
|
+
* don't, such as all numbers or `'√'`.)
|
|
26
|
+
*
|
|
27
|
+
* @category String
|
|
28
|
+
* @category Package : @augment-vir/common
|
|
29
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
30
|
+
*/
|
|
10
31
|
export function hasCase(input) {
|
|
11
32
|
return input.toLowerCase() !== input.toUpperCase();
|
|
12
33
|
}
|
|
@@ -16,23 +37,27 @@ export function hasCase(input) {
|
|
|
16
37
|
* Note that some characters have no casing, such as punctuation (they have no difference between
|
|
17
38
|
* upper and lower casings). By default, those letters always return `true` for this function,
|
|
18
39
|
* regardless of which `caseType` is provided. To instead return `false` for any such characters,
|
|
19
|
-
* pass in an options object and set
|
|
40
|
+
* pass in an options object and set `rejectNoCaseCharacters` to true.
|
|
41
|
+
*
|
|
42
|
+
* @category String
|
|
43
|
+
* @category Package : @augment-vir/common
|
|
44
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
20
45
|
*/
|
|
21
46
|
export function isCase(input, caseType, options) {
|
|
22
|
-
if (!input && options?.
|
|
47
|
+
if (!input && options?.rejectNoCaseCharacters) {
|
|
23
48
|
return false;
|
|
24
49
|
}
|
|
25
50
|
for (const letter of input) {
|
|
26
51
|
if (!hasCase(letter)) {
|
|
27
|
-
if (options?.
|
|
52
|
+
if (options?.rejectNoCaseCharacters) {
|
|
28
53
|
return false;
|
|
29
54
|
}
|
|
30
55
|
else {
|
|
31
56
|
continue;
|
|
32
57
|
}
|
|
33
58
|
}
|
|
34
|
-
else if ((caseType ===
|
|
35
|
-
(caseType ===
|
|
59
|
+
else if ((caseType === StringCase.Upper && letter !== letter.toUpperCase()) ||
|
|
60
|
+
(caseType === StringCase.Lower && letter !== letter.toLowerCase())) {
|
|
36
61
|
return false;
|
|
37
62
|
}
|
|
38
63
|
}
|
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
import { CasingOptions } from './casing.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a kebab-case string to CamelCase.
|
|
4
|
+
*
|
|
5
|
+
* @category String
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
8
|
+
*/
|
|
2
9
|
export declare function kebabCaseToCamelCase(rawKebabCase: string, casingOptions?: Partial<CasingOptions> | undefined): string;
|
|
10
|
+
/**
|
|
11
|
+
* Converts a CamelCase string to kebab-case.
|
|
12
|
+
*
|
|
13
|
+
* @category String
|
|
14
|
+
* @category Package : @augment-vir/common
|
|
15
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
16
|
+
*/
|
|
3
17
|
export declare function camelCaseToKebabCase(rawCamelCase: string): string;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import { mergeDefinedProperties } from '../../object/merge-defined-properties.js';
|
|
1
2
|
import { maybeCapitalize } from './capitalization.js';
|
|
2
|
-
import { defaultCasingOptions, isCase,
|
|
3
|
-
|
|
3
|
+
import { defaultCasingOptions, isCase, StringCase } from './casing.js';
|
|
4
|
+
/**
|
|
5
|
+
* Converts a kebab-case string to CamelCase.
|
|
6
|
+
*
|
|
7
|
+
* @category String
|
|
8
|
+
* @category Package : @augment-vir/common
|
|
9
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
10
|
+
*/
|
|
11
|
+
export function kebabCaseToCamelCase(rawKebabCase, casingOptions = {}) {
|
|
4
12
|
const kebabCase = rawKebabCase.toLowerCase();
|
|
5
13
|
if (!kebabCase.length) {
|
|
6
14
|
return '';
|
|
@@ -17,16 +25,23 @@ export function kebabCaseToCamelCase(rawKebabCase, casingOptions = defaultCasing
|
|
|
17
25
|
return '';
|
|
18
26
|
}
|
|
19
27
|
});
|
|
20
|
-
return maybeCapitalize(camelCase, casingOptions);
|
|
28
|
+
return maybeCapitalize(camelCase, mergeDefinedProperties(defaultCasingOptions, casingOptions));
|
|
21
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts a CamelCase string to kebab-case.
|
|
32
|
+
*
|
|
33
|
+
* @category String
|
|
34
|
+
* @category Package : @augment-vir/common
|
|
35
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
36
|
+
*/
|
|
22
37
|
export function camelCaseToKebabCase(rawCamelCase) {
|
|
23
38
|
const kebabCase = rawCamelCase
|
|
24
39
|
.split('')
|
|
25
40
|
.reduce((accum, currentLetter, index, originalString) => {
|
|
26
41
|
const previousLetter = index > 0 ? originalString[index - 1] || '' : '';
|
|
27
42
|
const nextLetter = index < originalString.length - 1 ? originalString[index + 1] || '' : '';
|
|
28
|
-
const possibleWordBoundary = isCase(previousLetter,
|
|
29
|
-
isCase(nextLetter,
|
|
43
|
+
const possibleWordBoundary = isCase(previousLetter, StringCase.Lower, { rejectNoCaseCharacters: true }) ||
|
|
44
|
+
isCase(nextLetter, StringCase.Lower, { rejectNoCaseCharacters: true });
|
|
30
45
|
if (currentLetter === currentLetter.toLowerCase() ||
|
|
31
46
|
index === 0 ||
|
|
32
47
|
!possibleWordBoundary) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes all commas from the given string.
|
|
3
|
+
*
|
|
4
|
+
* @category String
|
|
5
|
+
* @category Package : @augment-vir/common
|
|
6
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
7
|
+
*/
|
|
8
|
+
export declare function removeCommas(input: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Convert the given number into a string, then add commas like a normal number would have.
|
|
11
|
+
*
|
|
12
|
+
* @category String
|
|
13
|
+
* @category Number
|
|
14
|
+
* @category Package : @augment-vir/common
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import {addCommasToNumber} from '@augment-vir/common';
|
|
19
|
+
*
|
|
20
|
+
* addCommasToNumber(1000123.456);
|
|
21
|
+
* // output is `'1,000,123.456'`
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
25
|
+
*/
|
|
26
|
+
export declare function addCommasToNumber(input: number | string): string;
|
|
@@ -1,12 +1,31 @@
|
|
|
1
|
-
import { safeMatch } from '../regexp/
|
|
1
|
+
import { safeMatch } from '../regexp/match.js';
|
|
2
2
|
/**
|
|
3
3
|
* Removes all commas from the given string.
|
|
4
4
|
*
|
|
5
|
-
* @category String
|
|
5
|
+
* @category String
|
|
6
|
+
* @category Package : @augment-vir/common
|
|
7
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
6
8
|
*/
|
|
7
9
|
export function removeCommas(input) {
|
|
8
10
|
return input.replace(/,/g, '');
|
|
9
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Convert the given number into a string, then add commas like a normal number would have.
|
|
14
|
+
*
|
|
15
|
+
* @category String
|
|
16
|
+
* @category Number
|
|
17
|
+
* @category Package : @augment-vir/common
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import {addCommasToNumber} from '@augment-vir/common';
|
|
22
|
+
*
|
|
23
|
+
* addCommasToNumber(1000123.456);
|
|
24
|
+
* // output is `'1,000,123.456'`
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
28
|
+
*/
|
|
10
29
|
export function addCommasToNumber(input) {
|
|
11
30
|
if (typeof input === 'string' && isNaN(Number(input))) {
|
|
12
31
|
return 'NaN';
|
|
@@ -3,8 +3,19 @@
|
|
|
3
3
|
* item in the list. If the array has a length < 2, the conjunction is not added. If the list is
|
|
4
4
|
* only of length 2, then no commas are added.
|
|
5
5
|
*
|
|
6
|
-
* @
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
6
|
+
* @category String
|
|
7
|
+
* @category Package : @augment-vir/common
|
|
8
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
9
9
|
*/
|
|
10
|
-
export declare function joinWithFinalConjunction(
|
|
10
|
+
export declare function joinWithFinalConjunction(
|
|
11
|
+
/**
|
|
12
|
+
* Array of items to be converted into strings. Works best if these are simply strings to begin
|
|
13
|
+
* with.
|
|
14
|
+
*/
|
|
15
|
+
list: ReadonlyArray<any>,
|
|
16
|
+
/**
|
|
17
|
+
* The conjunction to be used before the final element.
|
|
18
|
+
*
|
|
19
|
+
* @default 'and'
|
|
20
|
+
*/
|
|
21
|
+
conjunction?: string): string;
|
|
@@ -3,11 +3,22 @@
|
|
|
3
3
|
* item in the list. If the array has a length < 2, the conjunction is not added. If the list is
|
|
4
4
|
* only of length 2, then no commas are added.
|
|
5
5
|
*
|
|
6
|
-
* @
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
6
|
+
* @category String
|
|
7
|
+
* @category Package : @augment-vir/common
|
|
8
|
+
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
|
|
9
9
|
*/
|
|
10
|
-
export function joinWithFinalConjunction(
|
|
10
|
+
export function joinWithFinalConjunction(
|
|
11
|
+
/**
|
|
12
|
+
* Array of items to be converted into strings. Works best if these are simply strings to begin
|
|
13
|
+
* with.
|
|
14
|
+
*/
|
|
15
|
+
list,
|
|
16
|
+
/**
|
|
17
|
+
* The conjunction to be used before the final element.
|
|
18
|
+
*
|
|
19
|
+
* @default 'and'
|
|
20
|
+
*/
|
|
21
|
+
conjunction = 'and') {
|
|
11
22
|
if (list.length < 2) {
|
|
12
23
|
/**
|
|
13
24
|
* If there are not multiple things in the list to join, just turn the list into a string
|