@augment-vir/common 7.1.0 → 8.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.
@@ -0,0 +1,20 @@
1
+ import { AnyFunction } from './function';
2
+ declare function rawGetTypeOf(x: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
3
+ type RawTypeOf = ReturnType<typeof rawGetTypeOf>;
4
+ export type RuntimeTypeOf = RawTypeOf | 'array';
5
+ export type RuntimeTypeOfMapping = {
6
+ array: any[];
7
+ bigint: bigint;
8
+ boolean: boolean;
9
+ function: AnyFunction;
10
+ number: number;
11
+ object: Record<PropertyKey, unknown>;
12
+ string: string;
13
+ symbol: symbol;
14
+ undefined: undefined;
15
+ };
16
+ export declare function getRuntimeTypeOf(input: unknown): RuntimeTypeOf;
17
+ export declare function isRuntimeTypeOf<T extends RuntimeTypeOf>(input: unknown, testType: T): input is RuntimeTypeOfMapping[T];
18
+ export declare function assertRuntimeTypeOf<T extends RuntimeTypeOf>(input: unknown, testType: T): asserts input is RuntimeTypeOfMapping[T];
19
+ export {};
20
+ //# sourceMappingURL=runtime-type-of.d.ts.map
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertRuntimeTypeOf = exports.isRuntimeTypeOf = exports.getRuntimeTypeOf = void 0;
4
+ // this function is not used at run time, it's only here for types
5
+ // istanbul ignore next
6
+ function rawGetTypeOf(x) {
7
+ return typeof x;
8
+ }
9
+ function getRuntimeTypeOf(input) {
10
+ return Array.isArray(input) ? 'array' : typeof input;
11
+ }
12
+ exports.getRuntimeTypeOf = getRuntimeTypeOf;
13
+ function isRuntimeTypeOf(input, testType) {
14
+ const inputType = getRuntimeTypeOf(input);
15
+ return inputType === testType;
16
+ }
17
+ exports.isRuntimeTypeOf = isRuntimeTypeOf;
18
+ function assertRuntimeTypeOf(input, testType) {
19
+ if (!isRuntimeTypeOf(input, testType)) {
20
+ throw new TypeError(`'${input}' is not of type '${testType}'`);
21
+ }
22
+ }
23
+ exports.assertRuntimeTypeOf = assertRuntimeTypeOf;
@@ -12,8 +12,8 @@ export * from './augments/object';
12
12
  export * from './augments/pick-deep';
13
13
  export * from './augments/promise';
14
14
  export * from './augments/regexp';
15
+ export * from './augments/runtime-type-of';
15
16
  export * from './augments/truncate-number';
16
17
  export * from './augments/tuple';
17
18
  export * from './augments/type';
18
- export * from './augments/type-of';
19
19
  //# sourceMappingURL=index.d.ts.map
package/dist/cjs/index.js CHANGED
@@ -28,7 +28,7 @@ __exportStar(require("./augments/object"), exports);
28
28
  __exportStar(require("./augments/pick-deep"), exports);
29
29
  __exportStar(require("./augments/promise"), exports);
30
30
  __exportStar(require("./augments/regexp"), exports);
31
+ __exportStar(require("./augments/runtime-type-of"), exports);
31
32
  __exportStar(require("./augments/truncate-number"), exports);
32
33
  __exportStar(require("./augments/tuple"), exports);
33
34
  __exportStar(require("./augments/type"), exports);
34
- __exportStar(require("./augments/type-of"), exports);
@@ -0,0 +1,20 @@
1
+ import { AnyFunction } from './function';
2
+ declare function rawGetTypeOf(x: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
3
+ type RawTypeOf = ReturnType<typeof rawGetTypeOf>;
4
+ export type RuntimeTypeOf = RawTypeOf | 'array';
5
+ export type RuntimeTypeOfMapping = {
6
+ array: any[];
7
+ bigint: bigint;
8
+ boolean: boolean;
9
+ function: AnyFunction;
10
+ number: number;
11
+ object: Record<PropertyKey, unknown>;
12
+ string: string;
13
+ symbol: symbol;
14
+ undefined: undefined;
15
+ };
16
+ export declare function getRuntimeTypeOf(input: unknown): RuntimeTypeOf;
17
+ export declare function isRuntimeTypeOf<T extends RuntimeTypeOf>(input: unknown, testType: T): input is RuntimeTypeOfMapping[T];
18
+ export declare function assertRuntimeTypeOf<T extends RuntimeTypeOf>(input: unknown, testType: T): asserts input is RuntimeTypeOfMapping[T];
19
+ export {};
20
+ //# sourceMappingURL=runtime-type-of.d.ts.map
@@ -0,0 +1,17 @@
1
+ // this function is not used at run time, it's only here for types
2
+ // istanbul ignore next
3
+ function rawGetTypeOf(x) {
4
+ return typeof x;
5
+ }
6
+ export function getRuntimeTypeOf(input) {
7
+ return Array.isArray(input) ? 'array' : typeof input;
8
+ }
9
+ export function isRuntimeTypeOf(input, testType) {
10
+ const inputType = getRuntimeTypeOf(input);
11
+ return inputType === testType;
12
+ }
13
+ export function assertRuntimeTypeOf(input, testType) {
14
+ if (!isRuntimeTypeOf(input, testType)) {
15
+ throw new TypeError(`'${input}' is not of type '${testType}'`);
16
+ }
17
+ }
@@ -12,8 +12,8 @@ export * from './augments/object';
12
12
  export * from './augments/pick-deep';
13
13
  export * from './augments/promise';
14
14
  export * from './augments/regexp';
15
+ export * from './augments/runtime-type-of';
15
16
  export * from './augments/truncate-number';
16
17
  export * from './augments/tuple';
17
18
  export * from './augments/type';
18
- export * from './augments/type-of';
19
19
  //# sourceMappingURL=index.d.ts.map
package/dist/esm/index.js CHANGED
@@ -12,7 +12,7 @@ export * from './augments/object';
12
12
  export * from './augments/pick-deep';
13
13
  export * from './augments/promise';
14
14
  export * from './augments/regexp';
15
+ export * from './augments/runtime-type-of';
15
16
  export * from './augments/truncate-number';
16
17
  export * from './augments/tuple';
17
18
  export * from './augments/type';
18
- export * from './augments/type-of';
@@ -0,0 +1,20 @@
1
+ import { AnyFunction } from './function';
2
+ declare function rawGetTypeOf(x: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
3
+ type RawTypeOf = ReturnType<typeof rawGetTypeOf>;
4
+ export type RuntimeTypeOf = RawTypeOf | 'array';
5
+ export type RuntimeTypeOfMapping = {
6
+ array: any[];
7
+ bigint: bigint;
8
+ boolean: boolean;
9
+ function: AnyFunction;
10
+ number: number;
11
+ object: Record<PropertyKey, unknown>;
12
+ string: string;
13
+ symbol: symbol;
14
+ undefined: undefined;
15
+ };
16
+ export declare function getRuntimeTypeOf(input: unknown): RuntimeTypeOf;
17
+ export declare function isRuntimeTypeOf<T extends RuntimeTypeOf>(input: unknown, testType: T): input is RuntimeTypeOfMapping[T];
18
+ export declare function assertRuntimeTypeOf<T extends RuntimeTypeOf>(input: unknown, testType: T): asserts input is RuntimeTypeOfMapping[T];
19
+ export {};
20
+ //# sourceMappingURL=runtime-type-of.d.ts.map
@@ -12,8 +12,8 @@ export * from './augments/object';
12
12
  export * from './augments/pick-deep';
13
13
  export * from './augments/promise';
14
14
  export * from './augments/regexp';
15
+ export * from './augments/runtime-type-of';
15
16
  export * from './augments/truncate-number';
16
17
  export * from './augments/tuple';
17
18
  export * from './augments/type';
18
- export * from './augments/type-of';
19
19
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "7.1.0",
3
+ "version": "8.0.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"