@augment-vir/common 4.2.1 → 4.3.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.
@@ -1,9 +1,9 @@
1
1
  import { AtLeastTuple } from './tuple';
2
2
  import { ArrayElement } from './type';
3
- export declare function filterOutIndexes<T>(array: Readonly<T[]>, indexes: Readonly<number[]>): T[];
4
- export declare function flatten2dArray<T>(array2d: T[][]): T[];
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
5
  export declare type AtLeastOneEntryArray<ArrayGeneric extends ReadonlyArray<any>> = AtLeastTuple<ArrayElement<ArrayGeneric>, 1>;
6
- export declare function trimArrayStrings(input: string[]): string[];
6
+ export declare function trimArrayStrings(input: ReadonlyArray<string>): string[];
7
7
  /**
8
8
  * Acts like calling Array.prototype.forEach in that all elements are executed upon in order, and
9
9
  * each execution is blocking. Meaning, the callback won't be called on element 2 until the callback
@@ -11,7 +11,7 @@ export declare function trimArrayStrings(input: string[]): string[];
11
11
  */
12
12
  export declare function awaitedForEach<OriginalGeneric>(input: ReadonlyArray<OriginalGeneric>, callback: (arrayElement: OriginalGeneric, index: number, wholeArray: ReadonlyArray<OriginalGeneric>) => void | PromiseLike<void>): Promise<void>;
13
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: T[], input: any): input is T;
14
+ export declare function isInTypedArray<T>(array: ReadonlyArray<T>, input: any): input is T;
15
15
  declare type MapCallbackType<ArrayType extends ReadonlyArray<any>, OutputType> = (value: ArrayElement<ArrayType>, index: number, array: ArrayType) => OutputType;
16
16
  /** Preserves tuple types. */
17
17
  export declare function typedMap<InputArrayGeneric extends ReadonlyArray<any>, OutputType>(arrayToMap: InputArrayGeneric, mapCallback: MapCallbackType<InputArrayGeneric, OutputType>): {
@@ -1,4 +1,4 @@
1
- export declare const englishFullMonthNames: string[];
1
+ export declare const englishFullMonthNames: readonly ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];
2
2
  export declare const englishShortMonthNames: string[];
3
3
  export declare class InvalidDateError extends Error {
4
4
  readonly name = "InvalidDateError";
@@ -1,8 +1,8 @@
1
1
  import { AtLeastTuple } from './tuple';
2
2
  export declare function combineErrors(errors: AtLeastTuple<Error, 1>): Error;
3
- export declare function combineErrors(errors: never[]): undefined;
4
- export declare function combineErrors(errors: Error[]): Error | undefined;
3
+ export declare function combineErrors(errors: ReadonlyArray<never>): undefined;
4
+ export declare function combineErrors(errors: ReadonlyArray<Error>): Error | undefined;
5
5
  export declare function combineErrors(errors?: undefined): undefined;
6
- export declare function combineErrorMessages(errors?: (Error | string | undefined)[] | undefined): string;
6
+ export declare function combineErrorMessages(errors?: ReadonlyArray<Error | string | undefined> | undefined): string;
7
7
  export declare function extractErrorMessage(error: unknown): string;
8
8
  export declare function ensureError(input: unknown): Error;
@@ -24,4 +24,4 @@ export declare function clamp(
24
24
  * 'Z', // zetta- sextillion
25
25
  * 'Y', // yotta- septillion
26
26
  */
27
- export declare function truncateNumber(originalValue: unknown, suffixes?: readonly string[]): string;
27
+ export declare function truncateNumber(originalValue: unknown, suffixes?: ReadonlyArray<string>): string;
@@ -4,14 +4,14 @@ export declare function getEnumTypedKeys<T extends object>(input: T): (keyof T)[
4
4
  export declare function getEnumTypedValues<T extends object>(input: T): T[keyof T][];
5
5
  export declare function isEnumValue<T extends object>(input: unknown, checkEnum: T): input is T[keyof T];
6
6
  export declare function isKeyof<ObjectGeneric>(key: PropertyKey, object: ObjectGeneric): key is keyof object;
7
- export declare function filterToEnumValues<T extends object>(inputs: unknown[], checkEnum: T, caseInsensitive?: boolean): T[keyof T][];
7
+ export declare function filterToEnumValues<T extends object>(inputs: ReadonlyArray<unknown>, checkEnum: T, caseInsensitive?: boolean): T[keyof T][];
8
8
  export declare function getObjectTypedKeys<ObjectGeneric extends unknown>(input: ObjectGeneric): ReadonlyArray<keyof ObjectGeneric>;
9
9
  export declare function getObjectTypedValues<ObjectGeneric extends unknown>(input: ObjectGeneric): ObjectGeneric[keyof ObjectGeneric][];
10
10
  declare type ExtractValue<KeyGeneric extends PropertyKey, ParentGeneric> = KeyGeneric extends keyof ParentGeneric ? RequiredBy<ParentGeneric, KeyGeneric>[KeyGeneric] : KeyGeneric extends keyof Extract<ParentGeneric, Record<KeyGeneric, any>> ? RequiredBy<Extract<ParentGeneric, Record<KeyGeneric, any>>, KeyGeneric>[KeyGeneric] : never;
11
11
  declare type CombinedParentValue<KeyGeneric extends PropertyKey, ParentGeneric> = ExtractValue<KeyGeneric, ParentGeneric> extends never ? unknown : ExtractValue<KeyGeneric, ParentGeneric>;
12
12
  declare type CombineTypeWithKey<KeyGeneric extends PropertyKey, ParentGeneric> = ParentGeneric & Record<KeyGeneric, CombinedParentValue<KeyGeneric, ParentGeneric>>;
13
13
  export declare function typedHasProperty<KeyGeneric extends PropertyKey, ParentGeneric>(inputObject: ParentGeneric, inputKey: KeyGeneric): inputObject is CombineTypeWithKey<KeyGeneric, ParentGeneric>;
14
- export declare function typedHasProperties<KeyGeneric extends PropertyKey, ParentGeneric>(inputObject: ParentGeneric, inputKeys: KeyGeneric[]): inputObject is CombineTypeWithKey<KeyGeneric, ParentGeneric>;
14
+ export declare function typedHasProperties<KeyGeneric extends PropertyKey, ParentGeneric>(inputObject: ParentGeneric, inputKeys: ReadonlyArray<KeyGeneric>): inputObject is CombineTypeWithKey<KeyGeneric, ParentGeneric>;
15
15
  export declare function isObject(input: any): input is NonNullable<object>;
16
16
  export declare function getEntriesSortedByKey(input: object): [string, unknown][];
17
17
  export declare function areJsonEqual(a: object, b: object): boolean;
@@ -7,14 +7,14 @@
7
7
  * to begin with.
8
8
  * @param conjunction Defaults to 'and'. The conjunction to be used before the final element.
9
9
  */
10
- export declare function joinWithFinalConjunction<T>(list: T[], conjunction?: string): string;
10
+ export declare function joinWithFinalConjunction(list: ReadonlyArray<any>, conjunction?: string): string;
11
11
  export declare function removeAnsiEscapeCodes(input: string): string;
12
12
  export declare const removeColor: typeof removeAnsiEscapeCodes;
13
13
  export declare function removeCommasFromNumberString(numberString: string): string;
14
14
  /** Collapse all consecutive white space into just one space and trim surrounding whitespace. */
15
15
  export declare function collapseWhiteSpace(input: string): string;
16
16
  /** Same as String.prototype.split but includes the delimiter to split by in the output array. */
17
- export declare function splitIncludeSplit(original: string, splitterInput: string | RegExp, caseSensitive: boolean): string[];
17
+ export declare function splitIncludeSplit(original: string, splitterInput: string | RegExp, caseSensitive: boolean): readonly string[];
18
18
  export declare type CasingOptions = {
19
19
  capitalizeFirstLetter: boolean;
20
20
  };
@@ -0,0 +1,17 @@
1
+ declare function getTypeOf(x: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
2
+ export declare type TypeOf = ReturnType<typeof getTypeOf>;
3
+ export declare type TypeOfWithArray = TypeOf | 'array';
4
+ export declare type TypeOfMapping = {
5
+ array: any[];
6
+ bigint: bigint;
7
+ boolean: boolean;
8
+ function: (...args: any[]) => any;
9
+ number: number;
10
+ object: object;
11
+ string: string;
12
+ symbol: symbol;
13
+ undefined: undefined;
14
+ };
15
+ export declare function typeOfWithArray(input: unknown): TypeOfWithArray;
16
+ export declare function isTypeOfWithArray<T extends TypeOfWithArray>(input: unknown, testType: T): input is TypeOfMapping[T];
17
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTypeOfWithArray = exports.typeOfWithArray = void 0;
4
+ function getTypeOf(x) {
5
+ return typeof x;
6
+ }
7
+ function typeOfWithArray(input) {
8
+ return Array.isArray(input) ? 'array' : typeof input;
9
+ }
10
+ exports.typeOfWithArray = typeOfWithArray;
11
+ function isTypeOfWithArray(input, testType) {
12
+ const inputType = typeOfWithArray(input);
13
+ return inputType === testType;
14
+ }
15
+ exports.isTypeOfWithArray = isTypeOfWithArray;
package/dist/index.d.ts CHANGED
@@ -10,4 +10,5 @@ export * from './augments/regexp';
10
10
  export * from './augments/string';
11
11
  export * from './augments/tuple';
12
12
  export * from './augments/type';
13
+ export * from './augments/type-of';
13
14
  export * from './augments/type-test';
package/dist/index.js CHANGED
@@ -26,4 +26,5 @@ __exportStar(require("./augments/regexp"), exports);
26
26
  __exportStar(require("./augments/string"), exports);
27
27
  __exportStar(require("./augments/tuple"), exports);
28
28
  __exportStar(require("./augments/type"), exports);
29
+ __exportStar(require("./augments/type-of"), exports);
29
30
  __exportStar(require("./augments/type-test"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "4.2.1",
3
+ "version": "4.3.0",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"
@@ -22,7 +22,8 @@
22
22
  "test": "echo \"use common-test to run tests\" && exit 0"
23
23
  },
24
24
  "dependencies": {
25
- "@type-challenges/utils": "^0.1.1"
25
+ "@type-challenges/utils": "^0.1.1",
26
+ "type-fest": "^3.2.0"
26
27
  },
27
28
  "devDependencies": {
28
29
  "prettier": "^2.7.1",