@infra-blocks/types 0.2.0 → 0.3.0-alpha.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/README.md +8 -5
- package/lib/cjs/index.js +61 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/esm/index.d.ts +95 -0
- package/lib/esm/index.js.map +1 -0
- package/package.json +21 -14
- package/lib/index.js.map +0 -1
- /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/lib/{index.js → esm/index.js} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# ts-types
|
|
2
|
+
[](https://github.com/infrastructure-blocks/ts-types/actions/workflows/build.yml)
|
|
3
|
+
[](https://github.com/infrastructure-blocks/ts-types/actions/workflows/npm-publish-release-from-label.yml)
|
|
4
|
+
[](https://github.com/infrastructure-blocks/ts-types/actions/workflows/update-from-template.yml)
|
|
5
|
+
[](https://codecov.io/gh/infrastructure-blocks/ts-types)
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
Types utility library for Typescript.
|
|
4
8
|
|
|
5
9
|
## Development
|
|
6
10
|
|
|
@@ -21,7 +25,6 @@ npm run test
|
|
|
21
25
|
|
|
22
26
|
### Package publication
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Packages should therefore not be published manually, as these tasks are automated by the CI.
|
|
28
|
+
Package publication is fully automated at the CI level. This repository leverages the
|
|
29
|
+
[npm-publish-from-label-workflow](https://github.com/infrastructure-blocks/npm-publish-from-label-workflow)
|
|
30
|
+
workflow as a turnkey, automated mechanism for publishing packages. Refer to its documentation for usage information.
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFunction = exports.isNumber = exports.isSymbol = exports.isString = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A convenient Typescript type guard function to assess that a value is a string.
|
|
6
|
+
*
|
|
7
|
+
* @remark
|
|
8
|
+
* This function is mostly meant as a Typescript type guard. See:
|
|
9
|
+
* https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
10
|
+
*
|
|
11
|
+
* @param value - The value to test.
|
|
12
|
+
* @returns Whether or not the value is a string.
|
|
13
|
+
*/
|
|
14
|
+
function isString(value) {
|
|
15
|
+
return typeof value === "string";
|
|
16
|
+
}
|
|
17
|
+
exports.isString = isString;
|
|
18
|
+
/**
|
|
19
|
+
* A convenient Typescript type guard function to assess that a value is a symbol.
|
|
20
|
+
*
|
|
21
|
+
* @remark
|
|
22
|
+
* This function is mostly meant as a Typescript type guard. See:
|
|
23
|
+
* https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
24
|
+
*
|
|
25
|
+
* @param value - The value to test.
|
|
26
|
+
* @returns Whether or not the value is a symbol.
|
|
27
|
+
*/
|
|
28
|
+
function isSymbol(value) {
|
|
29
|
+
return typeof value === "symbol";
|
|
30
|
+
}
|
|
31
|
+
exports.isSymbol = isSymbol;
|
|
32
|
+
/**
|
|
33
|
+
* A convenient Typescript type guard function to assess that a value is a number.
|
|
34
|
+
*
|
|
35
|
+
* @remark
|
|
36
|
+
* This function is mostly meant as a Typescript type guard. See:
|
|
37
|
+
* https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
38
|
+
*
|
|
39
|
+
* @param value - The value to test.
|
|
40
|
+
* @returns Whether or not the value is a number.
|
|
41
|
+
*/
|
|
42
|
+
function isNumber(value) {
|
|
43
|
+
return typeof value === "number";
|
|
44
|
+
}
|
|
45
|
+
exports.isNumber = isNumber;
|
|
46
|
+
/**
|
|
47
|
+
* A convenient Typescript type guard function to assess that a value is a function.
|
|
48
|
+
*
|
|
49
|
+
* @remark
|
|
50
|
+
* * This function is mostly meant as a Typescript type guard. See:
|
|
51
|
+
* https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
52
|
+
*
|
|
53
|
+
* @param value - The value to test.
|
|
54
|
+
* @returns Whether or not the value is a function.
|
|
55
|
+
*/
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
57
|
+
function isFunction(value) {
|
|
58
|
+
return typeof value === "function";
|
|
59
|
+
}
|
|
60
|
+
exports.isFunction = isFunction;
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AA2DA;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAFD,4BAEC;AAED;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAFD,4BAEC;AAED;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAFD,4BAEC;AAED;;;;;;;;;GASG;AACH,wDAAwD;AACxD,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAFD,gCAEC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convenient type alias to regroup a type that can be T, null or undefined.
|
|
3
|
+
*
|
|
4
|
+
* Semantically the opposite of {@link NonNullable}.
|
|
5
|
+
*/
|
|
6
|
+
export type Nullable<T> = T | null | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* A type alias for single element predicate functions.
|
|
9
|
+
*/
|
|
10
|
+
export type Predicate<T> = (item: T) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* A type alias for functions that return a value of a given type without arguments.
|
|
13
|
+
*/
|
|
14
|
+
export type Provider<T> = () => T;
|
|
15
|
+
/**
|
|
16
|
+
* A convenient type declaration for handlers used to resolve "error" type events.
|
|
17
|
+
*/
|
|
18
|
+
export type ErrorHandler<T extends Error = Error> = (err: T) => void;
|
|
19
|
+
/**
|
|
20
|
+
* A convenience type extractor to get the inner type of an array.
|
|
21
|
+
*
|
|
22
|
+
* It will cause compilation errors if T isn't an array.
|
|
23
|
+
*
|
|
24
|
+
* See here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
|
|
25
|
+
*/
|
|
26
|
+
export type UnpackedArray<T> = T extends (infer U)[] ? U : never;
|
|
27
|
+
/**
|
|
28
|
+
* A convenience type extractor to get the inner type of a promise.
|
|
29
|
+
*
|
|
30
|
+
* It will cause compilation errors if T isn't a promise.
|
|
31
|
+
*
|
|
32
|
+
* See here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
|
|
33
|
+
*/
|
|
34
|
+
export type UnpackedPromise<T> = T extends Promise<infer U> ? U : never;
|
|
35
|
+
/**
|
|
36
|
+
* A convenience type mapping that transitively make partial fields optional.
|
|
37
|
+
*
|
|
38
|
+
* The built-in Partial type doesn't cover nested objects, this one does.
|
|
39
|
+
*/
|
|
40
|
+
export type TransitivePartial<T> = {
|
|
41
|
+
[K in keyof T]?: T[K] extends object ? TransitivePartial<T[K]> : T[K];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A convenience type mapping to extract keys of a type that are of a given type.
|
|
45
|
+
*
|
|
46
|
+
* For example, if you would like all the types of an object that are numbers, you could do
|
|
47
|
+
* KeyOfType<TheType, number>
|
|
48
|
+
*/
|
|
49
|
+
export type KeyOfType<T, U> = {
|
|
50
|
+
[P in keyof T]: T[P] extends U ? P : never;
|
|
51
|
+
}[keyof T];
|
|
52
|
+
/**
|
|
53
|
+
* A convenient Typescript type guard function to assess that a value is a string.
|
|
54
|
+
*
|
|
55
|
+
* @remark
|
|
56
|
+
* This function is mostly meant as a Typescript type guard. See:
|
|
57
|
+
* https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
58
|
+
*
|
|
59
|
+
* @param value - The value to test.
|
|
60
|
+
* @returns Whether or not the value is a string.
|
|
61
|
+
*/
|
|
62
|
+
export declare function isString(value: unknown): value is string;
|
|
63
|
+
/**
|
|
64
|
+
* A convenient Typescript type guard function to assess that a value is a symbol.
|
|
65
|
+
*
|
|
66
|
+
* @remark
|
|
67
|
+
* This function is mostly meant as a Typescript type guard. See:
|
|
68
|
+
* https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
69
|
+
*
|
|
70
|
+
* @param value - The value to test.
|
|
71
|
+
* @returns Whether or not the value is a symbol.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isSymbol(value: unknown): value is symbol;
|
|
74
|
+
/**
|
|
75
|
+
* A convenient Typescript type guard function to assess that a value is a number.
|
|
76
|
+
*
|
|
77
|
+
* @remark
|
|
78
|
+
* This function is mostly meant as a Typescript type guard. See:
|
|
79
|
+
* https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
80
|
+
*
|
|
81
|
+
* @param value - The value to test.
|
|
82
|
+
* @returns Whether or not the value is a number.
|
|
83
|
+
*/
|
|
84
|
+
export declare function isNumber(value: unknown): value is number;
|
|
85
|
+
/**
|
|
86
|
+
* A convenient Typescript type guard function to assess that a value is a function.
|
|
87
|
+
*
|
|
88
|
+
* @remark
|
|
89
|
+
* * This function is mostly meant as a Typescript type guard. See:
|
|
90
|
+
* https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
91
|
+
*
|
|
92
|
+
* @param value - The value to test.
|
|
93
|
+
* @returns Whether or not the value is a function.
|
|
94
|
+
*/
|
|
95
|
+
export declare function isFunction(value: unknown): value is Function;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AA2DA;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;GASG;AACH,wDAAwD;AACxD,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infra-blocks/types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha.0",
|
|
4
4
|
"description": "Typescript types utility package.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
"import": "./lib/esm/index.js",
|
|
10
|
+
"require": "./lib/cjs/index.js",
|
|
11
|
+
"default": "./lib/esm/index.js"
|
|
8
12
|
},
|
|
9
13
|
"files": [
|
|
10
|
-
"lib/**/*.{js,d.ts,map}"
|
|
14
|
+
"lib/**/*.{js,cjs,mjs,json,d.ts,map}"
|
|
11
15
|
],
|
|
12
|
-
"type": "module",
|
|
13
16
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
-
"build": "
|
|
16
|
-
"
|
|
17
|
+
"prebuild": "npm run clean",
|
|
18
|
+
"build": "tsc -b tsconfig.build.json tsconfig.build.cjs.json",
|
|
19
|
+
"postbuild": "scripts/post-build.sh",
|
|
17
20
|
"clean": "rm -rf lib && rm -f infra-blocks-*.tgz",
|
|
18
|
-
"
|
|
21
|
+
"compile": "tsc",
|
|
22
|
+
"lint": "eslint --ext .js,.cjs,.mjs,.json,.ts --max-warnings 0 .",
|
|
23
|
+
"prepack": "npm run build",
|
|
19
24
|
"test": "npm run test:unit",
|
|
20
25
|
"test:coverage": "c8 npm run test",
|
|
21
26
|
"test:coverage:lcov": "c8 --reporter=lcov npm run test",
|
|
22
|
-
"test:
|
|
23
|
-
"test:
|
|
27
|
+
"test:integration": "mocha --config test/integration/.mocharc.js 'test/integration/**/*.spec.ts'",
|
|
28
|
+
"test:unit": "mocha --config test/unit/.mocharc.cjs 'test/unit/**/*.spec.ts'"
|
|
24
29
|
},
|
|
25
30
|
"devDependencies": {
|
|
26
31
|
"@infra-blocks/test": "^0.1.1",
|
|
@@ -31,12 +36,14 @@
|
|
|
31
36
|
"c8": "^8.0.0",
|
|
32
37
|
"eslint": "^8.41.0",
|
|
33
38
|
"eslint-config-prettier": "^8.8.0",
|
|
39
|
+
"eslint-plugin-json-format": "^2.0.1",
|
|
34
40
|
"eslint-plugin-prettier": "^4.2.1",
|
|
35
41
|
"mocha": "^10.2.0",
|
|
36
42
|
"prettier": "^2.8.8",
|
|
37
43
|
"ts-node": "^10.9.1",
|
|
38
44
|
"typescript": "^5.0.4"
|
|
39
45
|
},
|
|
40
|
-
"
|
|
41
|
-
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18.0.0"
|
|
48
|
+
}
|
|
42
49
|
}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA2DA;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;GASG;AACH,wDAAwD;AACxD,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC"}
|
|
File without changes
|
|
File without changes
|