@augment-vir/common 12.13.0 → 13.0.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/cjs/augments/common-number.d.ts +11 -0
- package/dist/cjs/augments/common-number.js +14 -1
- package/dist/cjs/augments/error.d.ts +1 -3
- package/dist/cjs/augments/error.js +3 -4
- package/dist/cjs/augments/object/map-object.d.ts +1 -2
- package/dist/cjs/augments/object/map-object.js +4 -4
- package/dist/cjs/augments/promise.d.ts +2 -0
- package/dist/cjs/augments/string/uuid.d.ts +2 -0
- package/dist/cjs/augments/string/uuid.js +8 -0
- package/dist/cjs/augments/type.d.ts +0 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/esm/augments/common-number.d.ts +11 -0
- package/dist/esm/augments/common-number.js +12 -0
- package/dist/esm/augments/error.d.ts +1 -3
- package/dist/esm/augments/error.js +1 -2
- package/dist/esm/augments/object/map-object.d.ts +1 -2
- package/dist/esm/augments/object/map-object.js +1 -1
- package/dist/esm/augments/promise.d.ts +2 -0
- package/dist/esm/augments/string/uuid.d.ts +2 -0
- package/dist/esm/augments/string/uuid.js +4 -0
- package/dist/esm/augments/type.d.ts +0 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/types/augments/common-number.d.ts +11 -0
- package/dist/types/augments/error.d.ts +1 -3
- package/dist/types/augments/object/map-object.d.ts +1 -2
- package/dist/types/augments/promise.d.ts +2 -0
- package/dist/types/augments/string/uuid.d.ts +2 -0
- package/dist/types/augments/type.d.ts +0 -1
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -12,4 +12,15 @@ export declare function clamp(
|
|
|
12
12
|
}): number;
|
|
13
13
|
export declare function convertIntoNumber(input: unknown): number;
|
|
14
14
|
export declare function doesRequireScientificNotation(input: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
|
|
17
|
+
* that is not the case, the returned value is the given min and max values swapped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ensureMinAndMax({ min, max }: {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
}): {
|
|
23
|
+
min: number;
|
|
24
|
+
max: number;
|
|
25
|
+
};
|
|
15
26
|
//# sourceMappingURL=common-number.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.doesRequireScientificNotation = exports.convertIntoNumber = exports.clamp = exports.addCommasToNumber = exports.NaNString = void 0;
|
|
3
|
+
exports.ensureMinAndMax = exports.doesRequireScientificNotation = exports.convertIntoNumber = exports.clamp = exports.addCommasToNumber = exports.NaNString = void 0;
|
|
4
4
|
const common_string_1 = require("./common-string");
|
|
5
5
|
const regexp_1 = require("./regexp");
|
|
6
6
|
exports.NaNString = String(NaN);
|
|
@@ -43,3 +43,16 @@ function doesRequireScientificNotation(input) {
|
|
|
43
43
|
return String(input).includes('e');
|
|
44
44
|
}
|
|
45
45
|
exports.doesRequireScientificNotation = doesRequireScientificNotation;
|
|
46
|
+
/**
|
|
47
|
+
* Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
|
|
48
|
+
* that is not the case, the returned value is the given min and max values swapped.
|
|
49
|
+
*/
|
|
50
|
+
function ensureMinAndMax({ min, max }) {
|
|
51
|
+
if (min > max) {
|
|
52
|
+
return { min: max, max: min };
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return { min, max };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.ensureMinAndMax = ensureMinAndMax;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { NoInputsFunction } from '
|
|
2
|
-
import { AtLeastTuple } from './tuple';
|
|
3
|
-
import { UnPromise } from './type';
|
|
1
|
+
import { AtLeastTuple, NoInputsFunction, UnPromise } from '..';
|
|
4
2
|
export declare function combineErrors(errors: AtLeastTuple<Error, 1>): Error;
|
|
5
3
|
export declare function combineErrors(errors: ReadonlyArray<never>): undefined;
|
|
6
4
|
export declare function combineErrors(errors: ReadonlyArray<Error>): Error | undefined;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeAndReturnError = exports.ensureError = exports.extractErrorMessage = exports.combineErrorMessages = exports.combineErrors = void 0;
|
|
4
|
-
const
|
|
5
|
-
const promise_1 = require("./promise");
|
|
4
|
+
const __1 = require("..");
|
|
6
5
|
function combineErrors(errors) {
|
|
7
6
|
if (!errors || errors.length === 0) {
|
|
8
7
|
return undefined;
|
|
@@ -18,7 +17,7 @@ function combineErrorMessages(errors) {
|
|
|
18
17
|
if (!errors) {
|
|
19
18
|
return '';
|
|
20
19
|
}
|
|
21
|
-
return errors.map(extractErrorMessage).filter(
|
|
20
|
+
return errors.map(extractErrorMessage).filter(__1.isTruthy).join('\n');
|
|
22
21
|
}
|
|
23
22
|
exports.combineErrorMessages = combineErrorMessages;
|
|
24
23
|
function extractErrorMessage(error) {
|
|
@@ -46,7 +45,7 @@ function executeAndReturnError(callback) {
|
|
|
46
45
|
let caughtError;
|
|
47
46
|
try {
|
|
48
47
|
const result = callback();
|
|
49
|
-
if ((0,
|
|
48
|
+
if ((0, __1.isPromiseLike)(result)) {
|
|
50
49
|
return new Promise(async (resolve) => {
|
|
51
50
|
try {
|
|
52
51
|
const output = await result;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { UnPromise } from '
|
|
2
|
-
import { PropertyValueType } from './object';
|
|
1
|
+
import { PropertyValueType, UnPromise } from '../..';
|
|
3
2
|
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
|
|
4
3
|
[MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
|
|
5
4
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mapObjectValues = exports.mapObjectValuesSync = void 0;
|
|
4
|
-
const
|
|
4
|
+
const __1 = require("../..");
|
|
5
5
|
/**
|
|
6
6
|
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
7
7
|
* that this will not wrap the return value in a promise if any of the new object values are
|
|
@@ -17,7 +17,7 @@ const object_entries_1 = require("./object-entries");
|
|
|
17
17
|
*/
|
|
18
18
|
function mapObjectValuesSync(inputObject) {
|
|
19
19
|
function innerMap(mapCallback) {
|
|
20
|
-
const mappedObject = (0,
|
|
20
|
+
const mappedObject = (0, __1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => {
|
|
21
21
|
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
|
|
22
22
|
return {
|
|
23
23
|
...accum,
|
|
@@ -35,7 +35,7 @@ exports.mapObjectValuesSync = mapObjectValuesSync;
|
|
|
35
35
|
*/
|
|
36
36
|
function mapObjectValues(inputObject, mapCallback) {
|
|
37
37
|
let gotAPromise = false;
|
|
38
|
-
const mappedObject = (0,
|
|
38
|
+
const mappedObject = (0, __1.getObjectTypedKeys)(inputObject).reduce((accum, currentKey) => {
|
|
39
39
|
const mappedValue = mapCallback(currentKey, inputObject[currentKey], inputObject);
|
|
40
40
|
if (mappedValue instanceof Promise) {
|
|
41
41
|
gotAPromise = true;
|
|
@@ -48,7 +48,7 @@ function mapObjectValues(inputObject, mapCallback) {
|
|
|
48
48
|
if (gotAPromise) {
|
|
49
49
|
return new Promise(async (resolve, reject) => {
|
|
50
50
|
try {
|
|
51
|
-
await Promise.all((0,
|
|
51
|
+
await Promise.all((0, __1.getObjectTypedKeys)(mappedObject).map(async (key) => {
|
|
52
52
|
const value = await mappedObject[key];
|
|
53
53
|
mappedObject[key] = value;
|
|
54
54
|
}));
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare function wait(delayMs: number): Promise<void>;
|
|
2
2
|
export declare function waitValue<ResolutionValue>(delayMs: number, returnValue: ResolutionValue): Promise<ResolutionValue>;
|
|
3
3
|
export declare function isPromiseLike<T>(input: T | unknown): input is T extends PromiseLike<infer ValueType> ? PromiseLike<ValueType> : PromiseLike<unknown>;
|
|
4
|
+
export type UnPromise<T> = T extends PromiseLike<infer PromiseType> ? Awaited<PromiseType> : T;
|
|
5
|
+
export type MaybePromise<T> = Promise<UnPromise<T>> | UnPromise<T>;
|
|
4
6
|
export declare class PromiseTimeoutError extends Error {
|
|
5
7
|
readonly durationMs: number;
|
|
6
8
|
readonly message: string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUuid = void 0;
|
|
4
|
+
const uuidRegExp = /[\d\w]{8}-[\d\w]{4}-[\d\w]{4}-[\d\w]{4}-[\d\w]{12}/;
|
|
5
|
+
function isUuid(maybeUuid) {
|
|
6
|
+
return !!maybeUuid.match(uuidRegExp);
|
|
7
|
+
}
|
|
8
|
+
exports.isUuid = isUuid;
|
|
@@ -34,7 +34,6 @@ export type RequiredAndNotNullBy<T, K extends keyof T> = Omit<T, K> & Required<{
|
|
|
34
34
|
}>;
|
|
35
35
|
/** If type T = type U, then type Y. Else type N. */
|
|
36
36
|
export type IfEquals<T, U, Y = unknown, N = never> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? Y : N;
|
|
37
|
-
export type UnPromise<T> = T extends PromiseLike<infer PromiseType> ? Awaited<PromiseType> : T;
|
|
38
37
|
/**
|
|
39
38
|
* This function returns another function that simply returns whatever input it's given. However, it
|
|
40
39
|
* also checks that the input matches the original wrapNarrowTypeWithTypeCheck's generic, while
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export * from './augments/promise';
|
|
|
23
23
|
export * from './augments/regexp';
|
|
24
24
|
export * from './augments/runtime-type-of';
|
|
25
25
|
export * from './augments/string/url';
|
|
26
|
+
export * from './augments/string/uuid';
|
|
26
27
|
export * from './augments/truncate-number';
|
|
27
28
|
export * from './augments/tuple';
|
|
28
29
|
export * from './augments/type';
|
package/dist/cjs/index.js
CHANGED
|
@@ -39,6 +39,7 @@ __exportStar(require("./augments/promise"), exports);
|
|
|
39
39
|
__exportStar(require("./augments/regexp"), exports);
|
|
40
40
|
__exportStar(require("./augments/runtime-type-of"), exports);
|
|
41
41
|
__exportStar(require("./augments/string/url"), exports);
|
|
42
|
+
__exportStar(require("./augments/string/uuid"), exports);
|
|
42
43
|
__exportStar(require("./augments/truncate-number"), exports);
|
|
43
44
|
__exportStar(require("./augments/tuple"), exports);
|
|
44
45
|
__exportStar(require("./augments/type"), exports);
|
|
@@ -12,4 +12,15 @@ export declare function clamp(
|
|
|
12
12
|
}): number;
|
|
13
13
|
export declare function convertIntoNumber(input: unknown): number;
|
|
14
14
|
export declare function doesRequireScientificNotation(input: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
|
|
17
|
+
* that is not the case, the returned value is the given min and max values swapped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ensureMinAndMax({ min, max }: {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
}): {
|
|
23
|
+
min: number;
|
|
24
|
+
max: number;
|
|
25
|
+
};
|
|
15
26
|
//# sourceMappingURL=common-number.d.ts.map
|
|
@@ -36,3 +36,15 @@ export function convertIntoNumber(input) {
|
|
|
36
36
|
export function doesRequireScientificNotation(input) {
|
|
37
37
|
return String(input).includes('e');
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
|
|
41
|
+
* that is not the case, the returned value is the given min and max values swapped.
|
|
42
|
+
*/
|
|
43
|
+
export function ensureMinAndMax({ min, max }) {
|
|
44
|
+
if (min > max) {
|
|
45
|
+
return { min: max, max: min };
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return { min, max };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { NoInputsFunction } from '
|
|
2
|
-
import { AtLeastTuple } from './tuple';
|
|
3
|
-
import { UnPromise } from './type';
|
|
1
|
+
import { AtLeastTuple, NoInputsFunction, UnPromise } from '..';
|
|
4
2
|
export declare function combineErrors(errors: AtLeastTuple<Error, 1>): Error;
|
|
5
3
|
export declare function combineErrors(errors: ReadonlyArray<never>): undefined;
|
|
6
4
|
export declare function combineErrors(errors: ReadonlyArray<Error>): Error | undefined;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { UnPromise } from '
|
|
2
|
-
import { PropertyValueType } from './object';
|
|
1
|
+
import { PropertyValueType, UnPromise } from '../..';
|
|
3
2
|
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
|
|
4
3
|
[MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
|
|
5
4
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getObjectTypedKeys } from '
|
|
1
|
+
import { getObjectTypedKeys } from '../..';
|
|
2
2
|
/**
|
|
3
3
|
* Map an object's keys to new values synchronously. This is different from plain mapObjectValues in
|
|
4
4
|
* that this will not wrap the return value in a promise if any of the new object values are
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare function wait(delayMs: number): Promise<void>;
|
|
2
2
|
export declare function waitValue<ResolutionValue>(delayMs: number, returnValue: ResolutionValue): Promise<ResolutionValue>;
|
|
3
3
|
export declare function isPromiseLike<T>(input: T | unknown): input is T extends PromiseLike<infer ValueType> ? PromiseLike<ValueType> : PromiseLike<unknown>;
|
|
4
|
+
export type UnPromise<T> = T extends PromiseLike<infer PromiseType> ? Awaited<PromiseType> : T;
|
|
5
|
+
export type MaybePromise<T> = Promise<UnPromise<T>> | UnPromise<T>;
|
|
4
6
|
export declare class PromiseTimeoutError extends Error {
|
|
5
7
|
readonly durationMs: number;
|
|
6
8
|
readonly message: string;
|
|
@@ -34,7 +34,6 @@ export type RequiredAndNotNullBy<T, K extends keyof T> = Omit<T, K> & Required<{
|
|
|
34
34
|
}>;
|
|
35
35
|
/** If type T = type U, then type Y. Else type N. */
|
|
36
36
|
export type IfEquals<T, U, Y = unknown, N = never> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? Y : N;
|
|
37
|
-
export type UnPromise<T> = T extends PromiseLike<infer PromiseType> ? Awaited<PromiseType> : T;
|
|
38
37
|
/**
|
|
39
38
|
* This function returns another function that simply returns whatever input it's given. However, it
|
|
40
39
|
* also checks that the input matches the original wrapNarrowTypeWithTypeCheck's generic, while
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export * from './augments/promise';
|
|
|
23
23
|
export * from './augments/regexp';
|
|
24
24
|
export * from './augments/runtime-type-of';
|
|
25
25
|
export * from './augments/string/url';
|
|
26
|
+
export * from './augments/string/uuid';
|
|
26
27
|
export * from './augments/truncate-number';
|
|
27
28
|
export * from './augments/tuple';
|
|
28
29
|
export * from './augments/type';
|
package/dist/esm/index.js
CHANGED
|
@@ -23,6 +23,7 @@ export * from './augments/promise';
|
|
|
23
23
|
export * from './augments/regexp';
|
|
24
24
|
export * from './augments/runtime-type-of';
|
|
25
25
|
export * from './augments/string/url';
|
|
26
|
+
export * from './augments/string/uuid';
|
|
26
27
|
export * from './augments/truncate-number';
|
|
27
28
|
export * from './augments/tuple';
|
|
28
29
|
export * from './augments/type';
|
|
@@ -12,4 +12,15 @@ export declare function clamp(
|
|
|
12
12
|
}): number;
|
|
13
13
|
export declare function convertIntoNumber(input: unknown): number;
|
|
14
14
|
export declare function doesRequireScientificNotation(input: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Given a min and max, ensures that they are in correct order. Meaning, min is less than max. If
|
|
17
|
+
* that is not the case, the returned value is the given min and max values swapped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ensureMinAndMax({ min, max }: {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
}): {
|
|
23
|
+
min: number;
|
|
24
|
+
max: number;
|
|
25
|
+
};
|
|
15
26
|
//# sourceMappingURL=common-number.d.ts.map
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { NoInputsFunction } from '
|
|
2
|
-
import { AtLeastTuple } from './tuple';
|
|
3
|
-
import { UnPromise } from './type';
|
|
1
|
+
import { AtLeastTuple, NoInputsFunction, UnPromise } from '..';
|
|
4
2
|
export declare function combineErrors(errors: AtLeastTuple<Error, 1>): Error;
|
|
5
3
|
export declare function combineErrors(errors: ReadonlyArray<never>): undefined;
|
|
6
4
|
export declare function combineErrors(errors: ReadonlyArray<Error>): Error | undefined;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { UnPromise } from '
|
|
2
|
-
import { PropertyValueType } from './object';
|
|
1
|
+
import { PropertyValueType, UnPromise } from '../..';
|
|
3
2
|
export type InnerMappedValues<EntireInputGeneric extends object, MappedValueGeneric> = {
|
|
4
3
|
[MappedProp in keyof EntireInputGeneric]: MappedValueGeneric;
|
|
5
4
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare function wait(delayMs: number): Promise<void>;
|
|
2
2
|
export declare function waitValue<ResolutionValue>(delayMs: number, returnValue: ResolutionValue): Promise<ResolutionValue>;
|
|
3
3
|
export declare function isPromiseLike<T>(input: T | unknown): input is T extends PromiseLike<infer ValueType> ? PromiseLike<ValueType> : PromiseLike<unknown>;
|
|
4
|
+
export type UnPromise<T> = T extends PromiseLike<infer PromiseType> ? Awaited<PromiseType> : T;
|
|
5
|
+
export type MaybePromise<T> = Promise<UnPromise<T>> | UnPromise<T>;
|
|
4
6
|
export declare class PromiseTimeoutError extends Error {
|
|
5
7
|
readonly durationMs: number;
|
|
6
8
|
readonly message: string;
|
|
@@ -34,7 +34,6 @@ export type RequiredAndNotNullBy<T, K extends keyof T> = Omit<T, K> & Required<{
|
|
|
34
34
|
}>;
|
|
35
35
|
/** If type T = type U, then type Y. Else type N. */
|
|
36
36
|
export type IfEquals<T, U, Y = unknown, N = never> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? Y : N;
|
|
37
|
-
export type UnPromise<T> = T extends PromiseLike<infer PromiseType> ? Awaited<PromiseType> : T;
|
|
38
37
|
/**
|
|
39
38
|
* This function returns another function that simply returns whatever input it's given. However, it
|
|
40
39
|
* also checks that the input matches the original wrapNarrowTypeWithTypeCheck's generic, while
|
package/dist/types/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export * from './augments/promise';
|
|
|
23
23
|
export * from './augments/regexp';
|
|
24
24
|
export * from './augments/runtime-type-of';
|
|
25
25
|
export * from './augments/string/url';
|
|
26
|
+
export * from './augments/string/uuid';
|
|
26
27
|
export * from './augments/truncate-number';
|
|
27
28
|
export * from './augments/tuple';
|
|
28
29
|
export * from './augments/type';
|