@augment-vir/common 4.6.1 → 5.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/dist/{augments → cjs/augments}/ansi.d.ts +0 -0
- package/dist/{augments → cjs/augments}/ansi.js +0 -0
- package/dist/{augments → cjs/augments}/array.d.ts +1 -8
- package/dist/cjs/augments/array.js +25 -0
- package/dist/cjs/augments/async.d.ts +14 -0
- package/dist/cjs/augments/async.js +29 -0
- package/dist/{augments/number.d.ts → cjs/augments/common-number.d.ts} +8 -3
- package/dist/{augments/number.js → cjs/augments/common-number.js} +39 -11
- package/dist/{augments/string.d.ts → cjs/augments/common-string.d.ts} +14 -4
- package/dist/{augments/string.js → cjs/augments/common-string.js} +30 -27
- package/dist/{augments → cjs/augments}/date.d.ts +1 -1
- package/dist/{augments → cjs/augments}/date.js +2 -2
- package/dist/cjs/augments/environment.d.ts +1 -0
- package/dist/cjs/augments/environment.js +7 -0
- package/dist/{augments → cjs/augments}/error.d.ts +0 -0
- package/dist/{augments → cjs/augments}/error.js +0 -0
- package/dist/{augments → cjs/augments}/function.d.ts +0 -0
- package/dist/{augments → cjs/augments}/function.js +0 -0
- package/dist/{augments → cjs/augments}/object.d.ts +0 -0
- package/dist/{augments → cjs/augments}/object.js +0 -0
- package/dist/{augments → cjs/augments}/promise.d.ts +0 -0
- package/dist/{augments → cjs/augments}/promise.js +0 -0
- package/dist/{augments → cjs/augments}/regexp.d.ts +0 -0
- package/dist/{augments → cjs/augments}/regexp.js +0 -0
- package/dist/{augments → cjs/augments}/tuple.d.ts +0 -0
- package/dist/{augments → cjs/augments}/tuple.js +0 -0
- package/dist/{augments → cjs/augments}/type-of.d.ts +0 -0
- package/dist/{augments → cjs/augments}/type-of.js +2 -0
- package/dist/{augments → cjs/augments}/type.d.ts +0 -0
- package/dist/{augments → cjs/augments}/type.js +0 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +4 -3
- package/dist/{index.js → cjs/index.js} +4 -3
- package/dist/esm/augments/ansi.d.ts +1 -0
- package/dist/esm/augments/ansi.js +24 -0
- package/dist/esm/augments/array.d.ts +13 -0
- package/dist/esm/augments/array.js +17 -0
- package/dist/esm/augments/async.d.ts +14 -0
- package/dist/esm/augments/async.js +23 -0
- package/dist/esm/augments/common-number.d.ts +32 -0
- package/dist/esm/augments/common-number.js +105 -0
- package/dist/esm/augments/common-string.d.ts +44 -0
- package/dist/esm/augments/common-string.js +180 -0
- package/dist/esm/augments/date.d.ts +26 -0
- package/dist/esm/augments/date.js +74 -0
- package/dist/esm/augments/environment.d.ts +1 -0
- package/dist/esm/augments/environment.js +3 -0
- package/dist/esm/augments/error.d.ts +8 -0
- package/dist/esm/augments/error.js +36 -0
- package/dist/esm/augments/function.d.ts +1 -0
- package/dist/esm/augments/function.js +3 -0
- package/dist/esm/augments/object.d.ts +63 -0
- package/dist/esm/augments/object.js +252 -0
- package/dist/esm/augments/promise.d.ts +23 -0
- package/dist/esm/augments/promise.js +84 -0
- package/dist/esm/augments/regexp.d.ts +3 -0
- package/dist/esm/augments/regexp.js +14 -0
- package/dist/esm/augments/tuple.d.ts +8 -0
- package/dist/esm/augments/tuple.js +3 -0
- package/dist/esm/augments/type-of.d.ts +17 -0
- package/dist/esm/augments/type-of.js +12 -0
- package/dist/esm/augments/type.d.ts +54 -0
- package/dist/esm/augments/type.js +24 -0
- package/dist/esm/index.d.ts +15 -0
- package/dist/esm/index.js +15 -0
- package/dist/types/augments/ansi.d.ts +1 -0
- package/dist/types/augments/array.d.ts +13 -0
- package/dist/types/augments/async.d.ts +14 -0
- package/dist/types/augments/common-number.d.ts +32 -0
- package/dist/types/augments/common-string.d.ts +44 -0
- package/dist/types/augments/date.d.ts +26 -0
- package/dist/types/augments/environment.d.ts +1 -0
- package/dist/types/augments/error.d.ts +8 -0
- package/dist/types/augments/function.d.ts +1 -0
- package/dist/types/augments/object.d.ts +63 -0
- package/dist/types/augments/promise.d.ts +23 -0
- package/dist/types/augments/regexp.d.ts +3 -0
- package/dist/types/augments/tuple.d.ts +8 -0
- package/dist/types/augments/type-of.d.ts +17 -0
- package/dist/types/augments/type.d.ts +54 -0
- package/dist/types/index.d.ts +15 -0
- package/package.json +6 -6
- package/dist/augments/array.js +0 -44
- package/dist/augments/type-test.d.ts +0 -3
- package/dist/augments/type-test.js +0 -2
|
File without changes
|
|
File without changes
|
|
@@ -4,14 +4,7 @@ export declare function filterOutIndexes<T>(array: ReadonlyArray<T>, indexes: Re
|
|
|
4
4
|
export declare function flatten2dArray<T>(array2d: ReadonlyArray<ReadonlyArray<T>>): T[];
|
|
5
5
|
export declare type AtLeastOneEntryArray<ArrayGeneric extends ReadonlyArray<any>> = AtLeastTuple<ArrayElement<ArrayGeneric>, 1>;
|
|
6
6
|
export declare function trimArrayStrings(input: ReadonlyArray<string>): string[];
|
|
7
|
-
|
|
8
|
-
* Acts like calling Array.prototype.forEach in that all elements are executed upon in order, and
|
|
9
|
-
* each execution is blocking. Meaning, the callback won't be called on element 2 until the callback
|
|
10
|
-
* has finished its call on element 1.
|
|
11
|
-
*/
|
|
12
|
-
export declare function awaitedForEach<OriginalGeneric>(input: ReadonlyArray<OriginalGeneric>, callback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => void | PromiseLike<void>): Promise<void>;
|
|
13
|
-
export declare function awaitedBlockingMap<OriginalGeneric, MappedGeneric>(input: ReadonlyArray<OriginalGeneric>, callback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => MappedGeneric | PromiseLike<MappedGeneric>): Promise<Awaited<MappedGeneric>[]>;
|
|
14
|
-
export declare function isInTypedArray<T>(array: ReadonlyArray<T>, input: any): input is T;
|
|
7
|
+
export declare function typedArrayIncludes<T>(array: ReadonlyArray<T>, input: unknown): input is T;
|
|
15
8
|
declare type MapCallbackType<ArrayType extends ReadonlyArray<any>, OutputType> = (value: ArrayElement<ArrayType>, index: number, array: ArrayType) => OutputType;
|
|
16
9
|
/** Preserves tuple types. */
|
|
17
10
|
export declare function typedMap<InputArrayGeneric extends ReadonlyArray<any>, OutputType>(arrayToMap: InputArrayGeneric, mapCallback: MapCallbackType<InputArrayGeneric, OutputType>): {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.typedMap = exports.typedArrayIncludes = exports.trimArrayStrings = exports.flatten2dArray = exports.filterOutIndexes = void 0;
|
|
4
|
+
function filterOutIndexes(array, indexes) {
|
|
5
|
+
return array.filter((_, index) => !indexes.includes(index));
|
|
6
|
+
}
|
|
7
|
+
exports.filterOutIndexes = filterOutIndexes;
|
|
8
|
+
function flatten2dArray(array2d) {
|
|
9
|
+
const flattened = array2d.reduce((accum, row) => accum.concat(row), []);
|
|
10
|
+
return flattened;
|
|
11
|
+
}
|
|
12
|
+
exports.flatten2dArray = flatten2dArray;
|
|
13
|
+
function trimArrayStrings(input) {
|
|
14
|
+
return input.map((line) => line.trim()).filter((line) => line !== '');
|
|
15
|
+
}
|
|
16
|
+
exports.trimArrayStrings = trimArrayStrings;
|
|
17
|
+
function typedArrayIncludes(array, input) {
|
|
18
|
+
return array.includes(input);
|
|
19
|
+
}
|
|
20
|
+
exports.typedArrayIncludes = typedArrayIncludes;
|
|
21
|
+
/** Preserves tuple types. */
|
|
22
|
+
function typedMap(arrayToMap, mapCallback) {
|
|
23
|
+
return arrayToMap.map(mapCallback);
|
|
24
|
+
}
|
|
25
|
+
exports.typedMap = typedMap;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Acts like calling Array.prototype.forEach in that all elements are executed upon in order, and
|
|
3
|
+
* each execution is blocking. Meaning, the callback won't be called on element 2 until the callback
|
|
4
|
+
* has finished its call on element 1.
|
|
5
|
+
*/
|
|
6
|
+
export declare function awaitedForEach<OriginalGeneric>(input: ReadonlyArray<OriginalGeneric>, callback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => void | PromiseLike<void>): Promise<void>;
|
|
7
|
+
export declare function awaitedBlockingMap<OriginalGeneric, MappedGeneric>(input: ReadonlyArray<OriginalGeneric>, callback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => MappedGeneric | PromiseLike<MappedGeneric>): Promise<Awaited<MappedGeneric>[]>;
|
|
8
|
+
export declare function awaitedFilter<OriginalGeneric>(arrayInput: ReadonlyArray<OriginalGeneric>, filterCallback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => Promise<unknown>, options?: {
|
|
9
|
+
/**
|
|
10
|
+
* Each call to the filter callback is blocking, meaning the next one won't start until the
|
|
11
|
+
* current one finishes. By default this is false.
|
|
12
|
+
*/
|
|
13
|
+
blocking?: boolean | undefined;
|
|
14
|
+
}): Promise<OriginalGeneric[]>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.awaitedFilter = exports.awaitedBlockingMap = exports.awaitedForEach = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Acts like calling Array.prototype.forEach in that all elements are executed upon in order, and
|
|
6
|
+
* each execution is blocking. Meaning, the callback won't be called on element 2 until the callback
|
|
7
|
+
* has finished its call on element 1.
|
|
8
|
+
*/
|
|
9
|
+
async function awaitedForEach(input, callback) {
|
|
10
|
+
await awaitedBlockingMap(input, callback);
|
|
11
|
+
}
|
|
12
|
+
exports.awaitedForEach = awaitedForEach;
|
|
13
|
+
async function awaitedBlockingMap(input, callback) {
|
|
14
|
+
const mappedValues = await input.reduce(async (accumPromise, currentElement, index, wholeArray) => {
|
|
15
|
+
const accum = await accumPromise;
|
|
16
|
+
const mappedValue = await callback(currentElement, index, wholeArray);
|
|
17
|
+
accum.push(mappedValue);
|
|
18
|
+
return accum;
|
|
19
|
+
}, Promise.resolve([]));
|
|
20
|
+
return mappedValues;
|
|
21
|
+
}
|
|
22
|
+
exports.awaitedBlockingMap = awaitedBlockingMap;
|
|
23
|
+
async function awaitedFilter(arrayInput, filterCallback, options) {
|
|
24
|
+
const callbackResults = (options === null || options === void 0 ? void 0 : options.blocking)
|
|
25
|
+
? await awaitedBlockingMap(arrayInput, filterCallback)
|
|
26
|
+
: await Promise.all(arrayInput.map(filterCallback));
|
|
27
|
+
return arrayInput.filter((originalValue, index) => !!callbackResults[index]);
|
|
28
|
+
}
|
|
29
|
+
exports.awaitedFilter = awaitedFilter;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare function addCommasToNumber(input: number): string;
|
|
1
2
|
export declare function clamp(
|
|
2
3
|
/**
|
|
3
4
|
* This uses a destructured object so that consumers cannot get confused as to which input is
|
|
@@ -9,8 +10,8 @@ export declare function clamp(
|
|
|
9
10
|
max: number;
|
|
10
11
|
}): number;
|
|
11
12
|
/**
|
|
12
|
-
* This truncates a number such that is will
|
|
13
|
-
*
|
|
13
|
+
* This truncates a number such that is will at a max have 6 characters including suffix, decimal
|
|
14
|
+
* point, or comma.
|
|
14
15
|
*
|
|
15
16
|
* Default suffixes are:
|
|
16
17
|
*
|
|
@@ -24,4 +25,8 @@ export declare function clamp(
|
|
|
24
25
|
* 'Z', // zetta- sextillion
|
|
25
26
|
* 'Y', // yotta- septillion
|
|
26
27
|
*/
|
|
27
|
-
export declare function truncateNumber(originalValue: unknown,
|
|
28
|
+
export declare function truncateNumber(originalValue: unknown, { customSuffixes, suppressErrorLogging, customErrorLogCallback, }?: {
|
|
29
|
+
customSuffixes?: ReadonlyArray<string>;
|
|
30
|
+
suppressErrorLogging?: boolean;
|
|
31
|
+
customErrorLogCallback?: (...args: any) => void;
|
|
32
|
+
}): string;
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.truncateNumber = exports.clamp = void 0;
|
|
3
|
+
exports.truncateNumber = exports.clamp = exports.addCommasToNumber = void 0;
|
|
4
|
+
const common_string_1 = require("./common-string");
|
|
5
|
+
const regexp_1 = require("./regexp");
|
|
6
|
+
function addCommasToNumber(input) {
|
|
7
|
+
const stringValue = String(input);
|
|
8
|
+
const [digits, decimalValues,] = stringValue.split('.');
|
|
9
|
+
const decimalString = decimalValues ? `.${decimalValues}` : '';
|
|
10
|
+
const separated = (0, regexp_1.safeMatch)(digits.split('').reverse().join(''), /.{1,3}/g)
|
|
11
|
+
.reverse()
|
|
12
|
+
.map((entry) => entry.split('').reverse().join(''));
|
|
13
|
+
const withCommas = separated.join(',');
|
|
14
|
+
return `${withCommas}${decimalString}`;
|
|
15
|
+
}
|
|
16
|
+
exports.addCommasToNumber = addCommasToNumber;
|
|
4
17
|
function clamp(
|
|
5
18
|
/**
|
|
6
19
|
* This uses a destructured object so that consumers cannot get confused as to which input is
|
|
@@ -22,16 +35,16 @@ const defaultTruncationSuffixes = [
|
|
|
22
35
|
'Y', // yotta- septillion
|
|
23
36
|
];
|
|
24
37
|
function recursiveTruncation(value, recursionDepth = 0, decimalValues = '') {
|
|
25
|
-
var _a
|
|
38
|
+
var _a;
|
|
26
39
|
if (value.includes('e+')) {
|
|
27
40
|
throw new Error(`Number is too large, it cannot be truncated: ${value}`);
|
|
28
41
|
}
|
|
29
42
|
else if (value.includes('e-')) {
|
|
30
43
|
throw new Error(`Number is too small, it cannot be truncated: ${value}`);
|
|
31
44
|
}
|
|
32
|
-
const split =
|
|
45
|
+
const split = (0, common_string_1.typedSplit)(value, '.');
|
|
33
46
|
decimalValues = (_a = split[1]) !== null && _a !== void 0 ? _a : decimalValues;
|
|
34
|
-
const amount =
|
|
47
|
+
const amount = split[0];
|
|
35
48
|
if (amount.length > 3) {
|
|
36
49
|
decimalValues = amount.slice(-3);
|
|
37
50
|
return recursiveTruncation(amount.slice(0, -3), recursionDepth + 1, decimalValues);
|
|
@@ -44,8 +57,8 @@ function recursiveTruncation(value, recursionDepth = 0, decimalValues = '') {
|
|
|
44
57
|
}
|
|
45
58
|
const maxDecimals = 4;
|
|
46
59
|
/**
|
|
47
|
-
* This truncates a number such that is will
|
|
48
|
-
*
|
|
60
|
+
* This truncates a number such that is will at a max have 6 characters including suffix, decimal
|
|
61
|
+
* point, or comma.
|
|
49
62
|
*
|
|
50
63
|
* Default suffixes are:
|
|
51
64
|
*
|
|
@@ -59,13 +72,19 @@ const maxDecimals = 4;
|
|
|
59
72
|
* 'Z', // zetta- sextillion
|
|
60
73
|
* 'Y', // yotta- septillion
|
|
61
74
|
*/
|
|
62
|
-
function truncateNumber(originalValue,
|
|
75
|
+
function truncateNumber(originalValue, { customSuffixes, suppressErrorLogging, customErrorLogCallback, } = {}) {
|
|
63
76
|
try {
|
|
64
|
-
const value = typeof originalValue === 'number'
|
|
77
|
+
const value = typeof originalValue === 'number'
|
|
78
|
+
? originalValue
|
|
79
|
+
: typeof originalValue === 'string'
|
|
80
|
+
? Number((0, common_string_1.removeCommasFromNumberString)(originalValue))
|
|
81
|
+
: Number(originalValue);
|
|
65
82
|
if (isNaN(value)) {
|
|
66
83
|
throw new Error(`${originalValue} could not be converted into a number.`);
|
|
67
84
|
}
|
|
68
|
-
const
|
|
85
|
+
const stringValue = String(value);
|
|
86
|
+
const results = recursiveTruncation(stringValue);
|
|
87
|
+
const suffixes = customSuffixes !== null && customSuffixes !== void 0 ? customSuffixes : defaultTruncationSuffixes;
|
|
69
88
|
const suffix = suffixes[results.recursionDepth];
|
|
70
89
|
if (suffix === undefined) {
|
|
71
90
|
throw new Error(`Number is too large, could not truncate: ${value}`);
|
|
@@ -73,10 +92,19 @@ function truncateNumber(originalValue, suffixes = defaultTruncationSuffixes) {
|
|
|
73
92
|
const decimalPlaces = maxDecimals - (results.value.length - 1) - suffix.length;
|
|
74
93
|
const decimalValues = results.decimalValues.replace(/0+$/, '').slice(0, decimalPlaces);
|
|
75
94
|
const withDecimal = decimalValues.length ? `.${decimalValues}` : '';
|
|
76
|
-
|
|
95
|
+
const combined = `${results.value}${withDecimal}${suffix}`;
|
|
96
|
+
if (combined.length > stringValue.length + 1) {
|
|
97
|
+
return addCommasToNumber(value);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return combined;
|
|
101
|
+
}
|
|
77
102
|
}
|
|
78
103
|
catch (error) {
|
|
79
|
-
console.error
|
|
104
|
+
const errorCallback = customErrorLogCallback ? customErrorLogCallback : console.error;
|
|
105
|
+
if (!suppressErrorLogging) {
|
|
106
|
+
errorCallback(error);
|
|
107
|
+
}
|
|
80
108
|
return String(originalValue);
|
|
81
109
|
}
|
|
82
110
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AtLeastTuple } from './tuple';
|
|
1
2
|
/**
|
|
2
3
|
* Join elements into a string with commas separating each value. Add a conjunction before the final
|
|
3
4
|
* item in the list. If the array has a length < 2, the conjunction is not added. If the list is
|
|
@@ -18,7 +19,7 @@ export declare function splitIncludeSplit(original: string, splitterInput: strin
|
|
|
18
19
|
export declare type CasingOptions = {
|
|
19
20
|
capitalizeFirstLetter: boolean;
|
|
20
21
|
};
|
|
21
|
-
export declare function capitalizeFirstLetter(input:
|
|
22
|
+
export declare function capitalizeFirstLetter<InputGeneric extends string>(input: InputGeneric): Capitalize<InputGeneric>;
|
|
22
23
|
export declare function kebabCaseToCamelCase(rawKebabCase: string, casingOptions?: Partial<CasingOptions> | undefined): string;
|
|
23
24
|
export declare function camelCaseToKebabCase(rawCamelCase: string): string;
|
|
24
25
|
export declare function replaceStringAtIndex(originalString: string, start: number, newString: string, length?: number): string;
|
|
@@ -27,8 +28,17 @@ export declare function replaceStringAtIndex(originalString: string, start: numb
|
|
|
27
28
|
* parsed as RegExp syntax.
|
|
28
29
|
*/
|
|
29
30
|
export declare function escapeStringForRegExp(input: string): string;
|
|
30
|
-
export declare function getAllIndexesOf
|
|
31
|
+
export declare function getAllIndexesOf<IncludeLength extends boolean | undefined>({ searchIn, searchFor, caseSensitive, includeLength, }: {
|
|
32
|
+
searchIn: string;
|
|
33
|
+
searchFor: string | RegExp;
|
|
34
|
+
/**
|
|
35
|
+
* CaseSensitive only applies when the input is a string. Otherwise, the RegExp's "i" flag is
|
|
36
|
+
* used to determine case sensitivity.
|
|
37
|
+
*/
|
|
38
|
+
caseSensitive: boolean;
|
|
39
|
+
includeLength?: IncludeLength;
|
|
40
|
+
}): IncludeLength extends true ? {
|
|
31
41
|
index: number;
|
|
32
42
|
length: number;
|
|
33
|
-
}[];
|
|
34
|
-
export declare function
|
|
43
|
+
}[] : number[];
|
|
44
|
+
export declare function typedSplit(input: string, splitString: string): AtLeastTuple<string, 1>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAllIndexesOf = exports.escapeStringForRegExp = exports.replaceStringAtIndex = exports.camelCaseToKebabCase = exports.kebabCaseToCamelCase = exports.capitalizeFirstLetter = exports.splitIncludeSplit = exports.collapseWhiteSpace = exports.removeCommasFromNumberString = exports.removeColor = exports.removeAnsiEscapeCodes = exports.joinWithFinalConjunction = void 0;
|
|
3
|
+
exports.typedSplit = exports.getAllIndexesOf = exports.escapeStringForRegExp = exports.replaceStringAtIndex = exports.camelCaseToKebabCase = exports.kebabCaseToCamelCase = exports.capitalizeFirstLetter = exports.splitIncludeSplit = exports.collapseWhiteSpace = exports.removeCommasFromNumberString = exports.removeColor = exports.removeAnsiEscapeCodes = exports.joinWithFinalConjunction = void 0;
|
|
4
4
|
const ansi_1 = require("./ansi");
|
|
5
5
|
const regexp_1 = require("./regexp");
|
|
6
6
|
/**
|
|
@@ -48,7 +48,12 @@ function collapseWhiteSpace(input) {
|
|
|
48
48
|
exports.collapseWhiteSpace = collapseWhiteSpace;
|
|
49
49
|
/** Same as String.prototype.split but includes the delimiter to split by in the output array. */
|
|
50
50
|
function splitIncludeSplit(original, splitterInput, caseSensitive) {
|
|
51
|
-
const indexLengths = getAllIndexesOf(
|
|
51
|
+
const indexLengths = getAllIndexesOf({
|
|
52
|
+
searchIn: original,
|
|
53
|
+
searchFor: splitterInput,
|
|
54
|
+
caseSensitive,
|
|
55
|
+
includeLength: true,
|
|
56
|
+
});
|
|
52
57
|
const splitter = makeCaseInsensitiveRegExp(splitterInput, caseSensitive);
|
|
53
58
|
const splits = original.split(splitter);
|
|
54
59
|
const splitterIncluded = splits.reduce((accum, current, index) => {
|
|
@@ -70,15 +75,14 @@ const defaultCasingOptions = {
|
|
|
70
75
|
capitalizeFirstLetter: false,
|
|
71
76
|
};
|
|
72
77
|
function capitalizeFirstLetter(input) {
|
|
73
|
-
var _a;
|
|
74
78
|
if (!input.length) {
|
|
75
79
|
return '';
|
|
76
80
|
}
|
|
77
|
-
const firstLetter =
|
|
78
|
-
return firstLetter.toUpperCase() + input.slice(1);
|
|
81
|
+
const firstLetter = input[0];
|
|
82
|
+
return (firstLetter.toUpperCase() + input.slice(1));
|
|
79
83
|
}
|
|
80
84
|
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
81
|
-
function maybeCapitalize(input, casingOptions
|
|
85
|
+
function maybeCapitalize(input, casingOptions) {
|
|
82
86
|
return casingOptions.capitalizeFirstLetter ? capitalizeFirstLetter(input) : input;
|
|
83
87
|
}
|
|
84
88
|
function kebabCaseToCamelCase(rawKebabCase, casingOptions = defaultCasingOptions) {
|
|
@@ -109,9 +113,8 @@ function camelCaseToKebabCase(rawCamelCase) {
|
|
|
109
113
|
const kebabCase = rawCamelCase
|
|
110
114
|
.split('')
|
|
111
115
|
.reduce((accum, currentLetter, index, originalString) => {
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
const nextLetter = index < originalString.length ? (_b = originalString[index + 1]) !== null && _b !== void 0 ? _b : '' : '';
|
|
116
|
+
const previousLetter = index > 0 ? originalString[index - 1] : '';
|
|
117
|
+
const nextLetter = index < originalString.length - 1 ? originalString[index + 1] : '';
|
|
115
118
|
const possibleWordBoundary = isLowerCase(previousLetter) || isLowerCase(nextLetter);
|
|
116
119
|
if (currentLetter === currentLetter.toLowerCase() ||
|
|
117
120
|
index === 0 ||
|
|
@@ -148,45 +151,45 @@ function makeCaseInsensitiveRegExp(searchForInput, caseSensitive) {
|
|
|
148
151
|
: new RegExp(escapeStringForRegExp(searchForInput), regExpFlags);
|
|
149
152
|
return searchFor;
|
|
150
153
|
}
|
|
151
|
-
function getAllIndexesOf(searchIn,
|
|
152
|
-
|
|
153
|
-
* CaseSensitive only applies when the input is a string. Otherwise, the RegExp's "i" flag is
|
|
154
|
-
* used to determine case sensitivity.
|
|
155
|
-
*/
|
|
156
|
-
caseSensitive, includeLength = false) {
|
|
157
|
-
const searchFor = makeCaseInsensitiveRegExp(searchForInput, caseSensitive);
|
|
154
|
+
function getAllIndexesOf({ searchIn, searchFor, caseSensitive, includeLength, }) {
|
|
155
|
+
const searchRegExp = makeCaseInsensitiveRegExp(searchFor, caseSensitive);
|
|
158
156
|
const indexes = [];
|
|
159
157
|
const indexesAndLengths = [];
|
|
160
|
-
searchIn.replace(
|
|
158
|
+
searchIn.replace(searchRegExp, (...matchResults) => {
|
|
161
159
|
/**
|
|
162
160
|
* Grabbing the second to last entry in the array (rather than the second) takes capture
|
|
163
161
|
* groups into account.
|
|
164
162
|
*/
|
|
165
163
|
const matchIndex = matchResults[matchResults.length - 2];
|
|
164
|
+
// this is used as a type safety catch and cannot actually be triggered on purpose
|
|
165
|
+
// istanbul ignore next
|
|
166
166
|
if (typeof matchIndex !== 'number') {
|
|
167
|
-
throw new Error(`Match index "${matchIndex}" is not a number. Searching for "${
|
|
167
|
+
throw new Error(`Match index "${matchIndex}" is not a number. Searching for "${searchFor}" in "${searchIn}".`);
|
|
168
168
|
}
|
|
169
169
|
const regExpMatch = matchResults[0];
|
|
170
|
+
// this is used as a type safety catch and cannot actually be triggered on purpose
|
|
171
|
+
// istanbul ignore next
|
|
170
172
|
if (typeof regExpMatch !== 'string') {
|
|
171
173
|
throw new Error(`regExpMatch should've been a string but was ${typeof regExpMatch}!`);
|
|
172
174
|
}
|
|
173
175
|
indexesAndLengths.push({ index: matchIndex, length: regExpMatch.length });
|
|
174
176
|
indexes.push(matchIndex);
|
|
175
177
|
const originalMatch = matchResults[0];
|
|
178
|
+
// this is used as a type safety catch and cannot actually be triggered on purpose
|
|
179
|
+
// istanbul ignore next
|
|
176
180
|
if (typeof originalMatch !== 'string') {
|
|
177
|
-
throw new Error(`Original match when searching for "${
|
|
181
|
+
throw new Error(`Original match when searching for "${searchFor}" in "${searchIn}" at index ${matchIndex} is not a string.`);
|
|
178
182
|
}
|
|
179
183
|
/**
|
|
180
|
-
* Don't actually change any text. What we do here doesn't matter because we're not
|
|
181
|
-
* the output of the .replace method, we're just producing side effects.
|
|
184
|
+
* Don't actually change any text. What we do here doesn't matter because we're not
|
|
185
|
+
* using the output of the .replace method, we're just producing side effects.
|
|
182
186
|
*/
|
|
183
187
|
return originalMatch;
|
|
184
188
|
});
|
|
185
|
-
|
|
186
|
-
return indexesAndLengths;
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
return indexes;
|
|
190
|
-
}
|
|
189
|
+
return (includeLength ? indexesAndLengths : indexes);
|
|
191
190
|
}
|
|
192
191
|
exports.getAllIndexesOf = getAllIndexesOf;
|
|
192
|
+
function typedSplit(input, splitString) {
|
|
193
|
+
return input.split(splitString);
|
|
194
|
+
}
|
|
195
|
+
exports.typedSplit = typedSplit;
|
|
@@ -15,7 +15,7 @@ export declare function createDateFromSlashFormat(slashFormatString: string, yea
|
|
|
15
15
|
/**
|
|
16
16
|
* @param commaFormatString Should be at string of the form "monthName dayNumber, fullYear" Example:
|
|
17
17
|
* "May 19, 2005"
|
|
18
|
-
* @param ignoreInvalidMonth Set to true to ignore invalid months
|
|
18
|
+
* @param ignoreInvalidMonth Set to true to ignore invalid months and just use the current UTC month
|
|
19
19
|
*/
|
|
20
20
|
export declare function createDateFromNamedCommaFormat(commaFormatString: string, ignoreInvalidMonth?: boolean): Date;
|
|
21
21
|
/**
|
|
@@ -44,7 +44,7 @@ exports.createDateFromSlashFormat = createDateFromSlashFormat;
|
|
|
44
44
|
/**
|
|
45
45
|
* @param commaFormatString Should be at string of the form "monthName dayNumber, fullYear" Example:
|
|
46
46
|
* "May 19, 2005"
|
|
47
|
-
* @param ignoreInvalidMonth Set to true to ignore invalid months
|
|
47
|
+
* @param ignoreInvalidMonth Set to true to ignore invalid months and just use the current UTC month
|
|
48
48
|
*/
|
|
49
49
|
function createDateFromNamedCommaFormat(commaFormatString, ignoreInvalidMonth = false) {
|
|
50
50
|
const [monthName, dayNumber, fullYear,] = commaFormatString.replace(',', '').split(' ');
|
|
@@ -56,7 +56,7 @@ function createDateFromNamedCommaFormat(commaFormatString, ignoreInvalidMonth =
|
|
|
56
56
|
let monthIndex = longMonthIndex === -1 ? shortMonthIndex : longMonthIndex;
|
|
57
57
|
if (monthIndex === -1) {
|
|
58
58
|
if (ignoreInvalidMonth) {
|
|
59
|
-
monthIndex =
|
|
59
|
+
monthIndex = new Date().getUTCMonth();
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
throw new InvalidDateError(`Month name ${monthName} was not found.`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isBrowser(): boolean;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isTypeOfWithArray = exports.typeOfWithArray = void 0;
|
|
4
|
+
// this function is not used at run time, it's only here for types
|
|
5
|
+
// istanbul ignore next
|
|
4
6
|
function getTypeOf(x) {
|
|
5
7
|
return typeof x;
|
|
6
8
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export * from './augments/ansi';
|
|
2
2
|
export * from './augments/array';
|
|
3
|
+
export * from './augments/async';
|
|
4
|
+
export * from './augments/common-number';
|
|
5
|
+
export * from './augments/common-string';
|
|
3
6
|
export * from './augments/date';
|
|
7
|
+
export * from './augments/environment';
|
|
4
8
|
export * from './augments/error';
|
|
5
9
|
export * from './augments/function';
|
|
6
|
-
export * from './augments/number';
|
|
7
10
|
export * from './augments/object';
|
|
8
11
|
export * from './augments/promise';
|
|
9
12
|
export * from './augments/regexp';
|
|
10
|
-
export * from './augments/string';
|
|
11
13
|
export * from './augments/tuple';
|
|
12
14
|
export * from './augments/type';
|
|
13
15
|
export * from './augments/type-of';
|
|
14
|
-
export * from './augments/type-test';
|
|
@@ -16,15 +16,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./augments/ansi"), exports);
|
|
18
18
|
__exportStar(require("./augments/array"), exports);
|
|
19
|
+
__exportStar(require("./augments/async"), exports);
|
|
20
|
+
__exportStar(require("./augments/common-number"), exports);
|
|
21
|
+
__exportStar(require("./augments/common-string"), exports);
|
|
19
22
|
__exportStar(require("./augments/date"), exports);
|
|
23
|
+
__exportStar(require("./augments/environment"), exports);
|
|
20
24
|
__exportStar(require("./augments/error"), exports);
|
|
21
25
|
__exportStar(require("./augments/function"), exports);
|
|
22
|
-
__exportStar(require("./augments/number"), exports);
|
|
23
26
|
__exportStar(require("./augments/object"), exports);
|
|
24
27
|
__exportStar(require("./augments/promise"), exports);
|
|
25
28
|
__exportStar(require("./augments/regexp"), exports);
|
|
26
|
-
__exportStar(require("./augments/string"), exports);
|
|
27
29
|
__exportStar(require("./augments/tuple"), exports);
|
|
28
30
|
__exportStar(require("./augments/type"), exports);
|
|
29
31
|
__exportStar(require("./augments/type-of"), exports);
|
|
30
|
-
__exportStar(require("./augments/type-test"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ansiRegex: RegExp;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// cspell:disable
|
|
2
|
+
/*
|
|
3
|
+
Copied from
|
|
4
|
+
https://github.com/chalk/ansi-regex/blob/1b337add136eb520764634a328e2f6354398eee5/index.js
|
|
5
|
+
because the published ansi-regex package exports this in a manner that Jest can't handle and the
|
|
6
|
+
latest version of the package that doesn't do that has a security vulnerability. The package has
|
|
7
|
+
the following license from
|
|
8
|
+
https://github.com/chalk/ansi-regex/blob/1b337add136eb520764634a328e2f6354398eee5/license
|
|
9
|
+
|
|
10
|
+
MIT License
|
|
11
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
18
|
+
*/
|
|
19
|
+
// cspell:enable
|
|
20
|
+
const patterns = [
|
|
21
|
+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
22
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
|
|
23
|
+
];
|
|
24
|
+
export const ansiRegex = new RegExp(patterns.join('|'), 'g');
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AtLeastTuple } from './tuple';
|
|
2
|
+
import { ArrayElement } from './type';
|
|
3
|
+
export declare function filterOutIndexes<T>(array: ReadonlyArray<T>, indexes: ReadonlyArray<number>): T[];
|
|
4
|
+
export declare function flatten2dArray<T>(array2d: ReadonlyArray<ReadonlyArray<T>>): T[];
|
|
5
|
+
export declare type AtLeastOneEntryArray<ArrayGeneric extends ReadonlyArray<any>> = AtLeastTuple<ArrayElement<ArrayGeneric>, 1>;
|
|
6
|
+
export declare function trimArrayStrings(input: ReadonlyArray<string>): string[];
|
|
7
|
+
export declare function typedArrayIncludes<T>(array: ReadonlyArray<T>, input: unknown): input is T;
|
|
8
|
+
declare type MapCallbackType<ArrayType extends ReadonlyArray<any>, OutputType> = (value: ArrayElement<ArrayType>, index: number, array: ArrayType) => OutputType;
|
|
9
|
+
/** Preserves tuple types. */
|
|
10
|
+
export declare function typedMap<InputArrayGeneric extends ReadonlyArray<any>, OutputType>(arrayToMap: InputArrayGeneric, mapCallback: MapCallbackType<InputArrayGeneric, OutputType>): {
|
|
11
|
+
[Index in keyof InputArrayGeneric]: OutputType;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function filterOutIndexes(array, indexes) {
|
|
2
|
+
return array.filter((_, index) => !indexes.includes(index));
|
|
3
|
+
}
|
|
4
|
+
export function flatten2dArray(array2d) {
|
|
5
|
+
const flattened = array2d.reduce((accum, row) => accum.concat(row), []);
|
|
6
|
+
return flattened;
|
|
7
|
+
}
|
|
8
|
+
export function trimArrayStrings(input) {
|
|
9
|
+
return input.map((line) => line.trim()).filter((line) => line !== '');
|
|
10
|
+
}
|
|
11
|
+
export function typedArrayIncludes(array, input) {
|
|
12
|
+
return array.includes(input);
|
|
13
|
+
}
|
|
14
|
+
/** Preserves tuple types. */
|
|
15
|
+
export function typedMap(arrayToMap, mapCallback) {
|
|
16
|
+
return arrayToMap.map(mapCallback);
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Acts like calling Array.prototype.forEach in that all elements are executed upon in order, and
|
|
3
|
+
* each execution is blocking. Meaning, the callback won't be called on element 2 until the callback
|
|
4
|
+
* has finished its call on element 1.
|
|
5
|
+
*/
|
|
6
|
+
export declare function awaitedForEach<OriginalGeneric>(input: ReadonlyArray<OriginalGeneric>, callback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => void | PromiseLike<void>): Promise<void>;
|
|
7
|
+
export declare function awaitedBlockingMap<OriginalGeneric, MappedGeneric>(input: ReadonlyArray<OriginalGeneric>, callback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => MappedGeneric | PromiseLike<MappedGeneric>): Promise<Awaited<MappedGeneric>[]>;
|
|
8
|
+
export declare function awaitedFilter<OriginalGeneric>(arrayInput: ReadonlyArray<OriginalGeneric>, filterCallback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => Promise<unknown>, options?: {
|
|
9
|
+
/**
|
|
10
|
+
* Each call to the filter callback is blocking, meaning the next one won't start until the
|
|
11
|
+
* current one finishes. By default this is false.
|
|
12
|
+
*/
|
|
13
|
+
blocking?: boolean | undefined;
|
|
14
|
+
}): Promise<OriginalGeneric[]>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Acts like calling Array.prototype.forEach in that all elements are executed upon in order, and
|
|
3
|
+
* each execution is blocking. Meaning, the callback won't be called on element 2 until the callback
|
|
4
|
+
* has finished its call on element 1.
|
|
5
|
+
*/
|
|
6
|
+
export async function awaitedForEach(input, callback) {
|
|
7
|
+
await awaitedBlockingMap(input, callback);
|
|
8
|
+
}
|
|
9
|
+
export async function awaitedBlockingMap(input, callback) {
|
|
10
|
+
const mappedValues = await input.reduce(async (accumPromise, currentElement, index, wholeArray) => {
|
|
11
|
+
const accum = await accumPromise;
|
|
12
|
+
const mappedValue = await callback(currentElement, index, wholeArray);
|
|
13
|
+
accum.push(mappedValue);
|
|
14
|
+
return accum;
|
|
15
|
+
}, Promise.resolve([]));
|
|
16
|
+
return mappedValues;
|
|
17
|
+
}
|
|
18
|
+
export async function awaitedFilter(arrayInput, filterCallback, options) {
|
|
19
|
+
const callbackResults = (options === null || options === void 0 ? void 0 : options.blocking)
|
|
20
|
+
? await awaitedBlockingMap(arrayInput, filterCallback)
|
|
21
|
+
: await Promise.all(arrayInput.map(filterCallback));
|
|
22
|
+
return arrayInput.filter((originalValue, index) => !!callbackResults[index]);
|
|
23
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare function addCommasToNumber(input: number): string;
|
|
2
|
+
export declare function clamp(
|
|
3
|
+
/**
|
|
4
|
+
* This uses a destructured object so that consumers cannot get confused as to which input is
|
|
5
|
+
* which (which would be easy to do since they're all of the same type).
|
|
6
|
+
*/
|
|
7
|
+
{ value, min, max, }: {
|
|
8
|
+
value: number;
|
|
9
|
+
min: number;
|
|
10
|
+
max: number;
|
|
11
|
+
}): number;
|
|
12
|
+
/**
|
|
13
|
+
* This truncates a number such that is will at a max have 6 characters including suffix, decimal
|
|
14
|
+
* point, or comma.
|
|
15
|
+
*
|
|
16
|
+
* Default suffixes are:
|
|
17
|
+
*
|
|
18
|
+
* '', // no suffix, numbers below 1000
|
|
19
|
+
* 'k', // thousand
|
|
20
|
+
* 'M', // million
|
|
21
|
+
* 'B', // billion
|
|
22
|
+
* 'T', // trillion
|
|
23
|
+
* 'P', // peta-, quadrillion
|
|
24
|
+
* 'E', // exa- quintillion
|
|
25
|
+
* 'Z', // zetta- sextillion
|
|
26
|
+
* 'Y', // yotta- septillion
|
|
27
|
+
*/
|
|
28
|
+
export declare function truncateNumber(originalValue: unknown, { customSuffixes, suppressErrorLogging, customErrorLogCallback, }?: {
|
|
29
|
+
customSuffixes?: ReadonlyArray<string>;
|
|
30
|
+
suppressErrorLogging?: boolean;
|
|
31
|
+
customErrorLogCallback?: (...args: any) => void;
|
|
32
|
+
}): string;
|