@battis/typescript-tricks 0.5.0 → 0.5.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/CHANGELOG.md +7 -0
- package/package.json +10 -25
- package/dist/Constructor.d.ts +0 -21
- package/dist/Constructor.js +0 -29
- package/dist/EnumeratedTypes.d.ts +0 -11
- package/dist/EnumeratedTypes.js +0 -12
- package/dist/JSONValue.d.ts +0 -9
- package/dist/JSONValue.js +0 -2
- package/dist/MethodNames.d.ts +0 -13
- package/dist/MethodNames.js +0 -2
- package/dist/Mixin.d.ts +0 -2
- package/dist/Mixin.js +0 -2
- package/dist/PropertyRequirements.d.ts +0 -40
- package/dist/PropertyRequirements.js +0 -2
- package/dist/Shorthand.d.ts +0 -11
- package/dist/Shorthand.js +0 -2
- package/dist/StaticImplements.d.ts +0 -23
- package/dist/StaticImplements.js +0 -2
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -24
package/CHANGELOG.md
ADDED
package/package.json
CHANGED
|
@@ -1,47 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@battis/typescript-tricks",
|
|
3
3
|
"description": "A handful of useful types and operators",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"author": "Seth Battis <seth@battis.net>",
|
|
6
6
|
"license": "GPL-3.0",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"homepage": "https://github.com/battis/typescript-tricks#readme",
|
|
9
|
+
"homepage": "https://github.com/battis/typescript-config/tree/main/packages/tricks#readme",
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": "*"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "
|
|
15
|
+
"url": "https://github.com/battis/typescript-config.git",
|
|
16
|
+
"directory": "packages/tricks"
|
|
16
17
|
},
|
|
17
18
|
"bugs": {
|
|
18
|
-
"url": "https://github.com/battis/typescript-
|
|
19
|
-
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "run-s build:*",
|
|
22
|
-
"build:clean": "shx rm -rf dist",
|
|
23
|
-
"build:compile": "tsc",
|
|
24
|
-
"release": "run-s release:*",
|
|
25
|
-
"release:build": "npm run build",
|
|
26
|
-
"release:publish": "np --yolo --no-release-draft"
|
|
19
|
+
"url": "https://github.com/battis/typescript-config/issues"
|
|
27
20
|
},
|
|
28
21
|
"devDependencies": {
|
|
29
|
-
"@battis/eslint-config": "github:battis/eslint-config",
|
|
30
|
-
"@battis/prettier-config": "github:battis/prettier-config",
|
|
31
22
|
"@tsconfig/recommended": "^1.0.3",
|
|
32
|
-
"np": "^8.0.4",
|
|
33
23
|
"npm-run-all": "^4.1.5",
|
|
34
24
|
"shx": "^0.3.4",
|
|
35
25
|
"typescript": "^4.9.5"
|
|
36
26
|
},
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
]
|
|
42
|
-
},
|
|
43
|
-
"np": {
|
|
44
|
-
"cleanup": false,
|
|
45
|
-
"tests": false
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "run-s build:*",
|
|
29
|
+
"build:clean": "shx rm -rf dist",
|
|
30
|
+
"build:compile": "tsc"
|
|
46
31
|
}
|
|
47
|
-
}
|
|
32
|
+
}
|
package/dist/Constructor.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export type Constructor<T = object> = new (...args: any[]) => T;
|
|
2
|
-
export declare const isConstructor: (value: any) => value is Constructor<any>;
|
|
3
|
-
/**
|
|
4
|
-
* ```ts
|
|
5
|
-
* class A {}
|
|
6
|
-
* class B {}
|
|
7
|
-
* class C extends A {}
|
|
8
|
-
*
|
|
9
|
-
* const a = new A();
|
|
10
|
-
* const b = new B();
|
|
11
|
-
* const c = new C();
|
|
12
|
-
*
|
|
13
|
-
* const list = [a, b, c];
|
|
14
|
-
* const filteredList = instanceOf(list, A);
|
|
15
|
-
* // filteredList = [a, c]
|
|
16
|
-
* ```
|
|
17
|
-
* @ see https://stackoverflow.com/a/65152869/294171
|
|
18
|
-
*/
|
|
19
|
-
export declare function filterByType<Elements, Filter extends Elements>(array: Elements[], filterType: Constructor<Filter>): Filter[];
|
|
20
|
-
/** @deprecated use {@link filterByType} */
|
|
21
|
-
export declare const instanceOf: typeof filterByType;
|
package/dist/Constructor.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.instanceOf = exports.filterByType = exports.isConstructor = void 0;
|
|
4
|
-
const isConstructor = (value) => {
|
|
5
|
-
return !!value && !!value.prototype && !!value.prototype.constructor;
|
|
6
|
-
};
|
|
7
|
-
exports.isConstructor = isConstructor;
|
|
8
|
-
/**
|
|
9
|
-
* ```ts
|
|
10
|
-
* class A {}
|
|
11
|
-
* class B {}
|
|
12
|
-
* class C extends A {}
|
|
13
|
-
*
|
|
14
|
-
* const a = new A();
|
|
15
|
-
* const b = new B();
|
|
16
|
-
* const c = new C();
|
|
17
|
-
*
|
|
18
|
-
* const list = [a, b, c];
|
|
19
|
-
* const filteredList = instanceOf(list, A);
|
|
20
|
-
* // filteredList = [a, c]
|
|
21
|
-
* ```
|
|
22
|
-
* @ see https://stackoverflow.com/a/65152869/294171
|
|
23
|
-
*/
|
|
24
|
-
function filterByType(array, filterType) {
|
|
25
|
-
return array.filter((e) => e instanceof filterType);
|
|
26
|
-
}
|
|
27
|
-
exports.filterByType = filterByType;
|
|
28
|
-
/** @deprecated use {@link filterByType} */
|
|
29
|
-
exports.instanceOf = filterByType;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type EnumObject = {
|
|
2
|
-
[key: string]: number | string;
|
|
3
|
-
};
|
|
4
|
-
type EnumObjectEnum<E extends EnumObject> = E extends {
|
|
5
|
-
[key: string]: infer ET | string;
|
|
6
|
-
} ? ET : never;
|
|
7
|
-
/**
|
|
8
|
-
* @see {@link https://blog.oyam.dev/typescript-enum-values/ How to get an array of enum values in TypeScript}
|
|
9
|
-
*/
|
|
10
|
-
export declare function getEnumValues<E extends EnumObject>(enumObject: E): EnumObjectEnum<E>[];
|
|
11
|
-
export {};
|
package/dist/EnumeratedTypes.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEnumValues = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @see {@link https://blog.oyam.dev/typescript-enum-values/ How to get an array of enum values in TypeScript}
|
|
6
|
-
*/
|
|
7
|
-
function getEnumValues(enumObject) {
|
|
8
|
-
return Object.keys(enumObject)
|
|
9
|
-
.filter((key) => Number.isNaN(Number(key)))
|
|
10
|
-
.map((key) => enumObject[key]);
|
|
11
|
-
}
|
|
12
|
-
exports.getEnumValues = getEnumValues;
|
package/dist/JSONValue.d.ts
DELETED
package/dist/JSONValue.js
DELETED
package/dist/MethodNames.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://stackoverflow.com/a/61940388
|
|
3
|
-
*/
|
|
4
|
-
export type MethodNames<T extends {
|
|
5
|
-
[K in keyof T]: any;
|
|
6
|
-
}> = {
|
|
7
|
-
[K in keyof T]: T[K] extends Function ? K : never;
|
|
8
|
-
}[keyof T];
|
|
9
|
-
export type MethodNamesMatching<T extends {
|
|
10
|
-
[K in keyof T]: any;
|
|
11
|
-
}, P extends Function = Function> = {
|
|
12
|
-
[K in keyof T]: T[K] extends Function ? P extends T[K] ? K : never : never;
|
|
13
|
-
}[keyof T];
|
package/dist/MethodNames.js
DELETED
package/dist/Mixin.d.ts
DELETED
package/dist/Mixin.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see {@link https://stackoverflow.com/a/49725198/294171 StackOverflow response} on requiring at least one property
|
|
3
|
-
*/
|
|
4
|
-
export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
|
5
|
-
[K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
|
|
6
|
-
}[Keys];
|
|
7
|
-
/**
|
|
8
|
-
* @see {@link https://stackoverflow.com/a/49725198/294171 StackOverflow response} on requiring only one property
|
|
9
|
-
*/
|
|
10
|
-
export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
|
11
|
-
[K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>;
|
|
12
|
-
}[Keys];
|
|
13
|
-
/** @see {@link https://stackoverflow.com/a/51365037 StackOverflow response} */
|
|
14
|
-
export type RecursivePartial<T> = {
|
|
15
|
-
[P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial<U>[] : T[P] extends object | undefined ? RecursivePartial<T[P]> : T[P];
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* ```ts
|
|
19
|
-
* type A = {
|
|
20
|
-
* d: number,
|
|
21
|
-
* e: string
|
|
22
|
-
* f: boolean
|
|
23
|
-
* }
|
|
24
|
-
*
|
|
25
|
-
* type B = ReplaceProperty<A, 'e', number[]>;
|
|
26
|
-
* // type B = {
|
|
27
|
-
* // d: number,
|
|
28
|
-
* // e: number[],
|
|
29
|
-
* // f: boolean
|
|
30
|
-
* // }
|
|
31
|
-
* ```
|
|
32
|
-
* @see {@link https://stackoverflow.com/a/51599774 StackOverflow response}
|
|
33
|
-
*/
|
|
34
|
-
export type ReplaceProperty<T, K extends keyof T, TReplace> = Identity<Pick<T, Exclude<keyof T, K>> & {
|
|
35
|
-
[P in K]: TReplace;
|
|
36
|
-
}>;
|
|
37
|
-
type Identity<T> = {
|
|
38
|
-
[P in keyof T]: T[P];
|
|
39
|
-
};
|
|
40
|
-
export {};
|
package/dist/Shorthand.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type AsynchronousFunction = () => Promise<any>;
|
|
2
|
-
/** @deprecated `null` is part of type unless using utility type `Nonnullable` */
|
|
3
|
-
export type Nullable<T> = T | null;
|
|
4
|
-
/** @deprecated use `?` */
|
|
5
|
-
export type Optional<T> = T | undefined;
|
|
6
|
-
export type Subset<T, U extends T> = T;
|
|
7
|
-
/** @deprecated use `Record<string,T>` */
|
|
8
|
-
export type AssociativeArray<T> = {
|
|
9
|
-
[key: string]: T;
|
|
10
|
-
};
|
|
11
|
-
export type JSONPrimitiveTypes = string | number | boolean | null;
|
package/dist/Shorthand.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
@see {@link https://stackoverflow.com/a/69571314/294171 StackOverflow response} on static interfaces
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
interface InstanceInterface {
|
|
7
|
-
instanceMethod();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface StaticInterface {
|
|
11
|
-
new(...args: any[]): InstanceInterface;
|
|
12
|
-
staticMethod();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
class MyClass implements StaticImplements<StaticInterface, typeof MyClass> {
|
|
16
|
-
static staticMethod() { }
|
|
17
|
-
static ownStaticMethod() { }
|
|
18
|
-
instanceMethod() { }
|
|
19
|
-
ownInstanceMethod() { }
|
|
20
|
-
}
|
|
21
|
-
```
|
|
22
|
-
*/
|
|
23
|
-
export type StaticImplements<I extends new (...args: any[]) => any, C extends I> = InstanceType<C>;
|
package/dist/StaticImplements.js
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './Constructor';
|
|
2
|
-
export * from './EnumeratedTypes';
|
|
3
|
-
export * from './Mixin';
|
|
4
|
-
export * from './PropertyRequirements';
|
|
5
|
-
export * from './Shorthand';
|
|
6
|
-
export * from './StaticImplements';
|
|
7
|
-
export * from './JSONValue';
|
|
8
|
-
export * from './MethodNames';
|
package/dist/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Constructor"), exports);
|
|
18
|
-
__exportStar(require("./EnumeratedTypes"), exports);
|
|
19
|
-
__exportStar(require("./Mixin"), exports);
|
|
20
|
-
__exportStar(require("./PropertyRequirements"), exports);
|
|
21
|
-
__exportStar(require("./Shorthand"), exports);
|
|
22
|
-
__exportStar(require("./StaticImplements"), exports);
|
|
23
|
-
__exportStar(require("./JSONValue"), exports);
|
|
24
|
-
__exportStar(require("./MethodNames"), exports);
|