@infra-blocks/types 0.12.0 → 0.13.0-alpha.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/lib/cjs/guard.d.ts +23 -0
- package/lib/cjs/guard.js +32 -1
- package/lib/cjs/guard.js.map +1 -1
- package/lib/cjs/index.d.ts +1 -45
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/predicates.js +2 -1
- package/lib/cjs/predicates.js.map +1 -1
- package/lib/cjs/types.d.ts +49 -0
- package/lib/cjs/types.js +3 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/esm/guard.d.ts +23 -0
- package/lib/esm/guard.js +30 -0
- package/lib/esm/guard.js.map +1 -1
- package/lib/esm/index.d.ts +1 -45
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/predicates.js +2 -1
- package/lib/esm/predicates.js.map +1 -1
- package/lib/esm/types.d.ts +49 -0
- package/lib/esm/types.js +2 -0
- package/lib/esm/types.js.map +1 -0
- package/package.json +1 -1
package/lib/cjs/guard.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Primitive } from "./types.js";
|
|
1
2
|
/**
|
|
2
3
|
* A type guard to assess that a value is a bigint.
|
|
3
4
|
*
|
|
@@ -85,6 +86,28 @@ export declare function isObject(value: unknown): value is object | null;
|
|
|
85
86
|
* @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
86
87
|
*/
|
|
87
88
|
export declare function isObjectNotNull(value: unknown): value is object;
|
|
89
|
+
/**
|
|
90
|
+
* A type guard to assess that a value is a primitive.
|
|
91
|
+
*
|
|
92
|
+
* This function checks if the value is one of the primitive types:
|
|
93
|
+
* bigint, boolean, null, number, string, symbol, or undefined.
|
|
94
|
+
*
|
|
95
|
+
* Sometimes those checks are made with the `typeof` operator, sometimes with strict equality checks.
|
|
96
|
+
*
|
|
97
|
+
* @param value - The value to test.
|
|
98
|
+
*
|
|
99
|
+
* @returns Whether or not the value is a primitive.
|
|
100
|
+
*
|
|
101
|
+
* @see isBigint
|
|
102
|
+
* @see isBoolean
|
|
103
|
+
* @see isNull
|
|
104
|
+
* @see isNumber
|
|
105
|
+
* @see isString
|
|
106
|
+
* @see isSymbol
|
|
107
|
+
* @see isUndefined
|
|
108
|
+
* @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
109
|
+
*/
|
|
110
|
+
export declare function isPrimitive(value: unknown): value is Primitive;
|
|
88
111
|
/**
|
|
89
112
|
* A type guard to assess that a value is a string.
|
|
90
113
|
*
|
package/lib/cjs/guard.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUndefined = exports.isSymbol = exports.isString = exports.isObjectNotNull = exports.isObject = exports.isNull = exports.isNumber = exports.isFunction = exports.isBoolean = exports.isBigint = void 0;
|
|
3
|
+
exports.isUndefined = exports.isSymbol = exports.isString = exports.isPrimitive = exports.isObjectNotNull = exports.isObject = exports.isNull = exports.isNumber = exports.isFunction = exports.isBoolean = exports.isBigint = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* A type guard to assess that a value is a bigint.
|
|
6
6
|
*
|
|
@@ -110,6 +110,37 @@ function isObjectNotNull(value) {
|
|
|
110
110
|
return !isNull(value) && typeof value === "object";
|
|
111
111
|
}
|
|
112
112
|
exports.isObjectNotNull = isObjectNotNull;
|
|
113
|
+
/**
|
|
114
|
+
* A type guard to assess that a value is a primitive.
|
|
115
|
+
*
|
|
116
|
+
* This function checks if the value is one of the primitive types:
|
|
117
|
+
* bigint, boolean, null, number, string, symbol, or undefined.
|
|
118
|
+
*
|
|
119
|
+
* Sometimes those checks are made with the `typeof` operator, sometimes with strict equality checks.
|
|
120
|
+
*
|
|
121
|
+
* @param value - The value to test.
|
|
122
|
+
*
|
|
123
|
+
* @returns Whether or not the value is a primitive.
|
|
124
|
+
*
|
|
125
|
+
* @see isBigint
|
|
126
|
+
* @see isBoolean
|
|
127
|
+
* @see isNull
|
|
128
|
+
* @see isNumber
|
|
129
|
+
* @see isString
|
|
130
|
+
* @see isSymbol
|
|
131
|
+
* @see isUndefined
|
|
132
|
+
* @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
133
|
+
*/
|
|
134
|
+
function isPrimitive(value) {
|
|
135
|
+
return (isBigint(value) ||
|
|
136
|
+
isBoolean(value) ||
|
|
137
|
+
isNull(value) ||
|
|
138
|
+
isNumber(value) ||
|
|
139
|
+
isString(value) ||
|
|
140
|
+
isSymbol(value) ||
|
|
141
|
+
isUndefined(value));
|
|
142
|
+
}
|
|
143
|
+
exports.isPrimitive = isPrimitive;
|
|
113
144
|
/**
|
|
114
145
|
* A type guard to assess that a value is a string.
|
|
115
146
|
*
|
package/lib/cjs/guard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/guard.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/guard.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;GAUG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAFD,4BAEC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,SAAS,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC;AACpC,CAAC;AAFD,8BAEC;AAED;;;;;;;;;;GAUG;AACH,wDAAwD;AACxD,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAFD,gCAEC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAFD,4BAEC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,MAAM,CAAC,KAAc;IACnC,OAAO,KAAK,KAAK,IAAI,CAAC;AACxB,CAAC;AAFD,wBAEC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAFD,4BAEC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AACrD,CAAC;AAFD,0CAEC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,WAAW,CAAC,KAAc;IACxC,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC;QACf,SAAS,CAAC,KAAK,CAAC;QAChB,MAAM,CAAC,KAAK,CAAC;QACb,QAAQ,CAAC,KAAK,CAAC;QACf,QAAQ,CAAC,KAAK,CAAC;QACf,QAAQ,CAAC,KAAK,CAAC;QACf,WAAW,CAAC,KAAK,CAAC,CACnB,CAAC;AACJ,CAAC;AAVD,kCAUC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAFD,4BAEC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAFD,4BAEC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,WAAW,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,WAAW,CAAC;AACtC,CAAC;AAFD,kCAEC"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -2,51 +2,7 @@ export * from "./func.js";
|
|
|
2
2
|
export * from "./guard.js";
|
|
3
3
|
export * from "./events.js";
|
|
4
4
|
export * from "./predicates.js";
|
|
5
|
-
|
|
6
|
-
* Convenience type to represent environment variables.
|
|
7
|
-
*/
|
|
8
|
-
export type EnvironmentVariables = Record<string, string | undefined>;
|
|
9
|
-
/**
|
|
10
|
-
* Just aliasing {@link EnvironmentVariables} for brevity.
|
|
11
|
-
*/
|
|
12
|
-
export type EnvVars = EnvironmentVariables;
|
|
13
|
-
/**
|
|
14
|
-
* Convenient type alias to regroup a type that can be T, null or undefined.
|
|
15
|
-
*
|
|
16
|
-
* Semantically the opposite of {@link NonNullable}.
|
|
17
|
-
*/
|
|
18
|
-
export type Nullable<T> = T | null | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Convenient mapped type to selectively make some fields of a type optional.
|
|
21
|
-
*
|
|
22
|
-
* This is in contrast to the built-in `Partial` type which makes all fields optional.
|
|
23
|
-
*/
|
|
24
|
-
export type Optional<T, K extends keyof T = keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
|
|
25
|
-
/**
|
|
26
|
-
* A convenience type extractor to get the inner type of an array.
|
|
27
|
-
*
|
|
28
|
-
* It will cause compilation errors if T isn't an array.
|
|
29
|
-
*
|
|
30
|
-
* See here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
|
|
31
|
-
*/
|
|
32
|
-
export type UnpackedArray<T> = T extends (infer U)[] ? U : never;
|
|
33
|
-
/**
|
|
34
|
-
* A convenience type mapping that transitively make partial fields optional.
|
|
35
|
-
*
|
|
36
|
-
* The built-in Partial type doesn't cover nested objects, this one does.
|
|
37
|
-
*/
|
|
38
|
-
export type TransitivePartial<T> = {
|
|
39
|
-
[K in keyof T]?: T[K] extends object ? TransitivePartial<T[K]> : T[K];
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* A convenience type mapping to extract keys of a type that are of a given type.
|
|
43
|
-
*
|
|
44
|
-
* For example, if you would like all the types of an object that are numbers, you could do
|
|
45
|
-
* KeyOfType<TheType, number>
|
|
46
|
-
*/
|
|
47
|
-
export type KeyOfType<T, U> = {
|
|
48
|
-
[P in keyof T]: T[P] extends U ? P : never;
|
|
49
|
-
}[keyof T];
|
|
5
|
+
export * from "./types.js";
|
|
50
6
|
/**
|
|
51
7
|
* A function for forcing exhaustiveness in switch statements or if-else chains.
|
|
52
8
|
*
|
package/lib/cjs/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __exportStar(require("./func.js"), exports);
|
|
|
19
19
|
__exportStar(require("./guard.js"), exports);
|
|
20
20
|
__exportStar(require("./events.js"), exports);
|
|
21
21
|
__exportStar(require("./predicates.js"), exports);
|
|
22
|
+
__exportStar(require("./types.js"), exports);
|
|
22
23
|
/**
|
|
23
24
|
* A function for forcing exhaustiveness in switch statements or if-else chains.
|
|
24
25
|
*
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,8CAA4B;AAC5B,kDAAgC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,8CAA4B;AAC5B,kDAAgC;AAChC,6CAA2B;AAE3B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,WAAW,CAAC,KAAY;IACtC,OAAO,KAAK,CAAC;AACf,CAAC;AAFD,kCAEC"}
|
package/lib/cjs/predicates.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isPlainObject = void 0;
|
|
4
|
+
const guard_js_1 = require("./guard.js");
|
|
4
5
|
/**
|
|
5
6
|
* A type predicate to determine if a value is a plain object.
|
|
6
7
|
*
|
|
@@ -12,7 +13,7 @@ exports.isPlainObject = void 0;
|
|
|
12
13
|
* @returns Whether or not the value is a plain object.
|
|
13
14
|
*/
|
|
14
15
|
function isPlainObject(value) {
|
|
15
|
-
return (
|
|
16
|
+
return (0, guard_js_1.isObjectNotNull)(value) && value.constructor === Object;
|
|
16
17
|
}
|
|
17
18
|
exports.isPlainObject = isPlainObject;
|
|
18
19
|
//# sourceMappingURL=predicates.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predicates.js","sourceRoot":"","sources":["../../src/predicates.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"predicates.js","sourceRoot":"","sources":["../../src/predicates.ts"],"names":[],"mappings":";;;AAAA,yCAA6C;AAE7C;;;;;;;;;GASG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,IAAA,0BAAe,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,WAAW,KAAK,MAAM,CAAC;AAChE,CAAC;AAFD,sCAEC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convenience type to represent environment variables.
|
|
3
|
+
*/
|
|
4
|
+
export type EnvironmentVariables = Record<string, string | undefined>;
|
|
5
|
+
/**
|
|
6
|
+
* Just aliasing {@link EnvironmentVariables} for brevity.
|
|
7
|
+
*/
|
|
8
|
+
export type EnvVars = EnvironmentVariables;
|
|
9
|
+
/**
|
|
10
|
+
* A convenience type mapping to extract keys of a type that are of a given type.
|
|
11
|
+
*
|
|
12
|
+
* For example, if you would like all the types of an object that are numbers, you could do
|
|
13
|
+
* KeyOfType<TheType, number>
|
|
14
|
+
*/
|
|
15
|
+
export type KeyOfType<T, U> = {
|
|
16
|
+
[P in keyof T]: T[P] extends U ? P : never;
|
|
17
|
+
}[keyof T];
|
|
18
|
+
/**
|
|
19
|
+
* Convenient type alias to regroup a type that can be T, null or undefined.
|
|
20
|
+
*
|
|
21
|
+
* Semantically the opposite of {@link NonNullable}.
|
|
22
|
+
*/
|
|
23
|
+
export type Nullable<T> = T | null | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Convenient mapped type to selectively make some fields of a type optional.
|
|
26
|
+
*
|
|
27
|
+
* This is in contrast to the built-in `Partial` type which makes all fields optional.
|
|
28
|
+
*/
|
|
29
|
+
export type Optional<T, K extends keyof T = keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
|
|
30
|
+
/**
|
|
31
|
+
* A union type that includes all primitive types.
|
|
32
|
+
*/
|
|
33
|
+
export type Primitive = bigint | boolean | null | number | string | symbol | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* A convenience type mapping that transitively make partial fields optional.
|
|
36
|
+
*
|
|
37
|
+
* The built-in Partial type doesn't cover nested objects, this one does.
|
|
38
|
+
*/
|
|
39
|
+
export type TransitivePartial<T> = {
|
|
40
|
+
[K in keyof T]?: T[K] extends object ? TransitivePartial<T[K]> : T[K];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* A convenience type extractor to get the inner type of an array.
|
|
44
|
+
*
|
|
45
|
+
* It will cause compilation errors if T isn't an array.
|
|
46
|
+
*
|
|
47
|
+
* See here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
|
|
48
|
+
*/
|
|
49
|
+
export type UnpackedArray<T> = T extends (infer U)[] ? U : never;
|
package/lib/cjs/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/lib/esm/guard.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Primitive } from "./types.js";
|
|
1
2
|
/**
|
|
2
3
|
* A type guard to assess that a value is a bigint.
|
|
3
4
|
*
|
|
@@ -85,6 +86,28 @@ export declare function isObject(value: unknown): value is object | null;
|
|
|
85
86
|
* @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
86
87
|
*/
|
|
87
88
|
export declare function isObjectNotNull(value: unknown): value is object;
|
|
89
|
+
/**
|
|
90
|
+
* A type guard to assess that a value is a primitive.
|
|
91
|
+
*
|
|
92
|
+
* This function checks if the value is one of the primitive types:
|
|
93
|
+
* bigint, boolean, null, number, string, symbol, or undefined.
|
|
94
|
+
*
|
|
95
|
+
* Sometimes those checks are made with the `typeof` operator, sometimes with strict equality checks.
|
|
96
|
+
*
|
|
97
|
+
* @param value - The value to test.
|
|
98
|
+
*
|
|
99
|
+
* @returns Whether or not the value is a primitive.
|
|
100
|
+
*
|
|
101
|
+
* @see isBigint
|
|
102
|
+
* @see isBoolean
|
|
103
|
+
* @see isNull
|
|
104
|
+
* @see isNumber
|
|
105
|
+
* @see isString
|
|
106
|
+
* @see isSymbol
|
|
107
|
+
* @see isUndefined
|
|
108
|
+
* @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
109
|
+
*/
|
|
110
|
+
export declare function isPrimitive(value: unknown): value is Primitive;
|
|
88
111
|
/**
|
|
89
112
|
* A type guard to assess that a value is a string.
|
|
90
113
|
*
|
package/lib/esm/guard.js
CHANGED
|
@@ -100,6 +100,36 @@ export function isObject(value) {
|
|
|
100
100
|
export function isObjectNotNull(value) {
|
|
101
101
|
return !isNull(value) && typeof value === "object";
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* A type guard to assess that a value is a primitive.
|
|
105
|
+
*
|
|
106
|
+
* This function checks if the value is one of the primitive types:
|
|
107
|
+
* bigint, boolean, null, number, string, symbol, or undefined.
|
|
108
|
+
*
|
|
109
|
+
* Sometimes those checks are made with the `typeof` operator, sometimes with strict equality checks.
|
|
110
|
+
*
|
|
111
|
+
* @param value - The value to test.
|
|
112
|
+
*
|
|
113
|
+
* @returns Whether or not the value is a primitive.
|
|
114
|
+
*
|
|
115
|
+
* @see isBigint
|
|
116
|
+
* @see isBoolean
|
|
117
|
+
* @see isNull
|
|
118
|
+
* @see isNumber
|
|
119
|
+
* @see isString
|
|
120
|
+
* @see isSymbol
|
|
121
|
+
* @see isUndefined
|
|
122
|
+
* @see https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards
|
|
123
|
+
*/
|
|
124
|
+
export function isPrimitive(value) {
|
|
125
|
+
return (isBigint(value) ||
|
|
126
|
+
isBoolean(value) ||
|
|
127
|
+
isNull(value) ||
|
|
128
|
+
isNumber(value) ||
|
|
129
|
+
isString(value) ||
|
|
130
|
+
isSymbol(value) ||
|
|
131
|
+
isUndefined(value));
|
|
132
|
+
}
|
|
103
133
|
/**
|
|
104
134
|
* A type guard to assess that a value is a string.
|
|
105
135
|
*
|
package/lib/esm/guard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/guard.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/guard.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC;AACpC,CAAC;AAED;;;;;;;;;;GAUG;AACH,wDAAwD;AACxD,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,OAAO,KAAK,KAAK,IAAI,CAAC;AACxB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AACrD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC;QACf,SAAS,CAAC,KAAK,CAAC;QAChB,MAAM,CAAC,KAAK,CAAC;QACb,QAAQ,CAAC,KAAK,CAAC;QACf,QAAQ,CAAC,KAAK,CAAC;QACf,QAAQ,CAAC,KAAK,CAAC;QACf,WAAW,CAAC,KAAK,CAAC,CACnB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,WAAW,CAAC;AACtC,CAAC"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -2,51 +2,7 @@ export * from "./func.js";
|
|
|
2
2
|
export * from "./guard.js";
|
|
3
3
|
export * from "./events.js";
|
|
4
4
|
export * from "./predicates.js";
|
|
5
|
-
|
|
6
|
-
* Convenience type to represent environment variables.
|
|
7
|
-
*/
|
|
8
|
-
export type EnvironmentVariables = Record<string, string | undefined>;
|
|
9
|
-
/**
|
|
10
|
-
* Just aliasing {@link EnvironmentVariables} for brevity.
|
|
11
|
-
*/
|
|
12
|
-
export type EnvVars = EnvironmentVariables;
|
|
13
|
-
/**
|
|
14
|
-
* Convenient type alias to regroup a type that can be T, null or undefined.
|
|
15
|
-
*
|
|
16
|
-
* Semantically the opposite of {@link NonNullable}.
|
|
17
|
-
*/
|
|
18
|
-
export type Nullable<T> = T | null | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Convenient mapped type to selectively make some fields of a type optional.
|
|
21
|
-
*
|
|
22
|
-
* This is in contrast to the built-in `Partial` type which makes all fields optional.
|
|
23
|
-
*/
|
|
24
|
-
export type Optional<T, K extends keyof T = keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
|
|
25
|
-
/**
|
|
26
|
-
* A convenience type extractor to get the inner type of an array.
|
|
27
|
-
*
|
|
28
|
-
* It will cause compilation errors if T isn't an array.
|
|
29
|
-
*
|
|
30
|
-
* See here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
|
|
31
|
-
*/
|
|
32
|
-
export type UnpackedArray<T> = T extends (infer U)[] ? U : never;
|
|
33
|
-
/**
|
|
34
|
-
* A convenience type mapping that transitively make partial fields optional.
|
|
35
|
-
*
|
|
36
|
-
* The built-in Partial type doesn't cover nested objects, this one does.
|
|
37
|
-
*/
|
|
38
|
-
export type TransitivePartial<T> = {
|
|
39
|
-
[K in keyof T]?: T[K] extends object ? TransitivePartial<T[K]> : T[K];
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* A convenience type mapping to extract keys of a type that are of a given type.
|
|
43
|
-
*
|
|
44
|
-
* For example, if you would like all the types of an object that are numbers, you could do
|
|
45
|
-
* KeyOfType<TheType, number>
|
|
46
|
-
*/
|
|
47
|
-
export type KeyOfType<T, U> = {
|
|
48
|
-
[P in keyof T]: T[P] extends U ? P : never;
|
|
49
|
-
}[keyof T];
|
|
5
|
+
export * from "./types.js";
|
|
50
6
|
/**
|
|
51
7
|
* A function for forcing exhaustiveness in switch statements or if-else chains.
|
|
52
8
|
*
|
package/lib/esm/index.js
CHANGED
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,WAAW,CAAC,KAAY;IACtC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/lib/esm/predicates.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isObjectNotNull } from "./guard.js";
|
|
1
2
|
/**
|
|
2
3
|
* A type predicate to determine if a value is a plain object.
|
|
3
4
|
*
|
|
@@ -9,6 +10,6 @@
|
|
|
9
10
|
* @returns Whether or not the value is a plain object.
|
|
10
11
|
*/
|
|
11
12
|
export function isPlainObject(value) {
|
|
12
|
-
return (
|
|
13
|
+
return isObjectNotNull(value) && value.constructor === Object;
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=predicates.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predicates.js","sourceRoot":"","sources":["../../src/predicates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"predicates.js","sourceRoot":"","sources":["../../src/predicates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,WAAW,KAAK,MAAM,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convenience type to represent environment variables.
|
|
3
|
+
*/
|
|
4
|
+
export type EnvironmentVariables = Record<string, string | undefined>;
|
|
5
|
+
/**
|
|
6
|
+
* Just aliasing {@link EnvironmentVariables} for brevity.
|
|
7
|
+
*/
|
|
8
|
+
export type EnvVars = EnvironmentVariables;
|
|
9
|
+
/**
|
|
10
|
+
* A convenience type mapping to extract keys of a type that are of a given type.
|
|
11
|
+
*
|
|
12
|
+
* For example, if you would like all the types of an object that are numbers, you could do
|
|
13
|
+
* KeyOfType<TheType, number>
|
|
14
|
+
*/
|
|
15
|
+
export type KeyOfType<T, U> = {
|
|
16
|
+
[P in keyof T]: T[P] extends U ? P : never;
|
|
17
|
+
}[keyof T];
|
|
18
|
+
/**
|
|
19
|
+
* Convenient type alias to regroup a type that can be T, null or undefined.
|
|
20
|
+
*
|
|
21
|
+
* Semantically the opposite of {@link NonNullable}.
|
|
22
|
+
*/
|
|
23
|
+
export type Nullable<T> = T | null | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Convenient mapped type to selectively make some fields of a type optional.
|
|
26
|
+
*
|
|
27
|
+
* This is in contrast to the built-in `Partial` type which makes all fields optional.
|
|
28
|
+
*/
|
|
29
|
+
export type Optional<T, K extends keyof T = keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
|
|
30
|
+
/**
|
|
31
|
+
* A union type that includes all primitive types.
|
|
32
|
+
*/
|
|
33
|
+
export type Primitive = bigint | boolean | null | number | string | symbol | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* A convenience type mapping that transitively make partial fields optional.
|
|
36
|
+
*
|
|
37
|
+
* The built-in Partial type doesn't cover nested objects, this one does.
|
|
38
|
+
*/
|
|
39
|
+
export type TransitivePartial<T> = {
|
|
40
|
+
[K in keyof T]?: T[K] extends object ? TransitivePartial<T[K]> : T[K];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* A convenience type extractor to get the inner type of an array.
|
|
44
|
+
*
|
|
45
|
+
* It will cause compilation errors if T isn't an array.
|
|
46
|
+
*
|
|
47
|
+
* See here: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
|
|
48
|
+
*/
|
|
49
|
+
export type UnpackedArray<T> = T extends (infer U)[] ? U : never;
|
package/lib/esm/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|