@battis/typescript-tricks 0.5.6 → 0.6.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/CHANGELOG.md +6 -0
- package/dist/Coerce/Coerce.d.ts +1 -0
- package/dist/Coerce/Coerce.js +13 -0
- package/dist/Coerce/Error.d.ts +1 -0
- package/dist/Coerce/Error.js +16 -0
- package/dist/Coerce.d.ts +2 -0
- package/dist/Coerce.js +18 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Coerce<T>(u: unknown, isT: (u: unknown) => u is T, toT?: (u: unknown) => T): T;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Coerce = void 0;
|
|
4
|
+
function FailedCoercion(u) {
|
|
5
|
+
throw new TypeError('Attempted coercion to a non-matching type');
|
|
6
|
+
}
|
|
7
|
+
function Coerce(u, isT, toT = (FailedCoercion)) {
|
|
8
|
+
if (isT(u)) {
|
|
9
|
+
return u;
|
|
10
|
+
}
|
|
11
|
+
return toT(u);
|
|
12
|
+
}
|
|
13
|
+
exports.Coerce = Coerce;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function coerceError(error: unknown): Error;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.coerceError = void 0;
|
|
4
|
+
const Coerce_js_1 = require("./Coerce.js");
|
|
5
|
+
function isError(error) {
|
|
6
|
+
return (typeof error === 'object' &&
|
|
7
|
+
error !== null &&
|
|
8
|
+
'message' in error &&
|
|
9
|
+
'name' in error &&
|
|
10
|
+
typeof error.name === 'string' &&
|
|
11
|
+
typeof error.message === 'string');
|
|
12
|
+
}
|
|
13
|
+
function coerceError(error) {
|
|
14
|
+
return (0, Coerce_js_1.Coerce)(error, isError, (e) => new Error(String(e)));
|
|
15
|
+
}
|
|
16
|
+
exports.coerceError = coerceError;
|
package/dist/Coerce.d.ts
ADDED
package/dist/Coerce.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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("./Coerce/Coerce"), exports);
|
|
18
|
+
__exportStar(require("./Coerce/Error"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
export * from './Coerce';
|
|
1
2
|
export * from './Constructor';
|
|
2
3
|
export * from './EnumeratedTypes';
|
|
4
|
+
export * from './Forms';
|
|
5
|
+
export * from './JSONValue';
|
|
6
|
+
export * from './MethodNames';
|
|
3
7
|
export * from './Mixin';
|
|
4
8
|
export * from './PropertyRequirements';
|
|
5
9
|
export * from './Shorthand';
|
|
6
10
|
export * from './StaticImplements';
|
|
7
|
-
export * from './JSONValue';
|
|
8
|
-
export * from './MethodNames';
|
|
9
|
-
export * from './Forms';
|
package/dist/index.js
CHANGED
|
@@ -14,12 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Coerce"), exports);
|
|
17
18
|
__exportStar(require("./Constructor"), exports);
|
|
18
19
|
__exportStar(require("./EnumeratedTypes"), exports);
|
|
20
|
+
__exportStar(require("./Forms"), exports);
|
|
21
|
+
__exportStar(require("./JSONValue"), exports);
|
|
22
|
+
__exportStar(require("./MethodNames"), exports);
|
|
19
23
|
__exportStar(require("./Mixin"), exports);
|
|
20
24
|
__exportStar(require("./PropertyRequirements"), exports);
|
|
21
25
|
__exportStar(require("./Shorthand"), exports);
|
|
22
26
|
__exportStar(require("./StaticImplements"), exports);
|
|
23
|
-
__exportStar(require("./JSONValue"), exports);
|
|
24
|
-
__exportStar(require("./MethodNames"), exports);
|
|
25
|
-
__exportStar(require("./Forms"), exports);
|
package/package.json
CHANGED