@gershy/clearing 0.0.16 → 0.0.17
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/cmp/cjs/main.d.ts +10 -0
- package/cmp/cjs/main.js +25 -1
- package/cmp/mjs/main.d.ts +10 -0
- package/cmp/mjs/main.js +22 -0
- package/package.json +4 -4
package/cmp/cjs/main.d.ts
CHANGED
|
@@ -16,5 +16,15 @@ export declare const getCls: (i: any) => any;
|
|
|
16
16
|
export declare const isCls: ClsCheck;
|
|
17
17
|
export declare const inCls: ClsCheck;
|
|
18
18
|
export declare const skip: undefined;
|
|
19
|
+
type Then = {
|
|
20
|
+
<V, R0 = V, R1 = never>(val: Promise<V>, rsv?: (v: V) => R0, rjc?: (e: any) => R1): Promise<R0 | R1>;
|
|
21
|
+
<V, R0 = V, R1 = never>(val: V, rsv?: (v: V) => R0, rjc?: (e: any) => R1): R0 | R1;
|
|
22
|
+
};
|
|
23
|
+
export declare const then: Then;
|
|
24
|
+
type Safe = {
|
|
25
|
+
<V, R0 = never>(fn: () => Promise<V>, rjc?: (e: any) => R0): Promise<V | R0>;
|
|
26
|
+
<V, R0 = never>(fn: () => V, rjc?: (e: any) => R0): Promise<V | R0>;
|
|
27
|
+
};
|
|
28
|
+
export declare const safe: Safe;
|
|
19
29
|
declare const applyClearing: () => void;
|
|
20
30
|
export default applyClearing;
|
package/cmp/cjs/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.skip = exports.inCls = exports.isCls = exports.getCls = exports.getClsName = void 0;
|
|
3
|
+
exports.safe = exports.then = exports.skip = exports.inCls = exports.isCls = exports.getCls = exports.getClsName = void 0;
|
|
4
4
|
const getClsName = i => {
|
|
5
5
|
if (i === null)
|
|
6
6
|
return 'Null';
|
|
@@ -27,6 +27,30 @@ exports.isCls = isCls;
|
|
|
27
27
|
const inCls = (i, C) => i instanceof C;
|
|
28
28
|
exports.inCls = inCls;
|
|
29
29
|
exports.skip = undefined;
|
|
30
|
+
const then = (val, rsv = (v => v), rjc = ((e) => { throw e; })) => {
|
|
31
|
+
// Act on `val` regardless of whether it's a Promise or immediate value; return `rsv(val)`
|
|
32
|
+
// either immediately or as a Promise
|
|
33
|
+
if ((0, exports.inCls)(val, Promise))
|
|
34
|
+
return val.then(rsv).catch(rjc);
|
|
35
|
+
try {
|
|
36
|
+
return rsv(val);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
return rjc(err);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.then = then;
|
|
43
|
+
const safe = (fn, rjc = e => { throw e; }) => {
|
|
44
|
+
// Execute a function which returns a value either synchronously or asynchronously; in both cases
|
|
45
|
+
// allows errors occurring from function execution to be handled
|
|
46
|
+
try {
|
|
47
|
+
return (0, exports.then)(fn(), v => v, rjc);
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
return rjc(err);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.safe = safe;
|
|
30
54
|
const applyClearing = (() => {
|
|
31
55
|
const global = globalThis;
|
|
32
56
|
// Prevent multiple installations...
|
package/cmp/mjs/main.d.ts
CHANGED
|
@@ -16,5 +16,15 @@ export declare const getCls: (i: any) => any;
|
|
|
16
16
|
export declare const isCls: ClsCheck;
|
|
17
17
|
export declare const inCls: ClsCheck;
|
|
18
18
|
export declare const skip: undefined;
|
|
19
|
+
type Then = {
|
|
20
|
+
<V, R0 = V, R1 = never>(val: Promise<V>, rsv?: (v: V) => R0, rjc?: (e: any) => R1): Promise<R0 | R1>;
|
|
21
|
+
<V, R0 = V, R1 = never>(val: V, rsv?: (v: V) => R0, rjc?: (e: any) => R1): R0 | R1;
|
|
22
|
+
};
|
|
23
|
+
export declare const then: Then;
|
|
24
|
+
type Safe = {
|
|
25
|
+
<V, R0 = never>(fn: () => Promise<V>, rjc?: (e: any) => R0): Promise<V | R0>;
|
|
26
|
+
<V, R0 = never>(fn: () => V, rjc?: (e: any) => R0): Promise<V | R0>;
|
|
27
|
+
};
|
|
28
|
+
export declare const safe: Safe;
|
|
19
29
|
declare const applyClearing: () => void;
|
|
20
30
|
export default applyClearing;
|
package/cmp/mjs/main.js
CHANGED
|
@@ -20,6 +20,28 @@ export const isCls = (i, C) => {
|
|
|
20
20
|
};
|
|
21
21
|
export const inCls = (i, C) => i instanceof C;
|
|
22
22
|
export const skip = undefined;
|
|
23
|
+
export const then = (val, rsv = (v => v), rjc = ((e) => { throw e; })) => {
|
|
24
|
+
// Act on `val` regardless of whether it's a Promise or immediate value; return `rsv(val)`
|
|
25
|
+
// either immediately or as a Promise
|
|
26
|
+
if (inCls(val, Promise))
|
|
27
|
+
return val.then(rsv).catch(rjc);
|
|
28
|
+
try {
|
|
29
|
+
return rsv(val);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
return rjc(err);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export const safe = (fn, rjc = e => { throw e; }) => {
|
|
36
|
+
// Execute a function which returns a value either synchronously or asynchronously; in both cases
|
|
37
|
+
// allows errors occurring from function execution to be handled
|
|
38
|
+
try {
|
|
39
|
+
return then(fn(), v => v, rjc);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
return rjc(err);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
23
45
|
const applyClearing = (() => {
|
|
24
46
|
const global = globalThis;
|
|
25
47
|
// Prevent multiple installations...
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gershy/clearing",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "Adds the features you always wish javascript had!",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"clearing",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"scripts": {
|
|
39
39
|
"test": "npm run ts.check && npx tsx ./src/main.test.ts",
|
|
40
40
|
"ts.check": "npx tsc --noEmit",
|
|
41
|
-
"build.cjs": "tsc -p
|
|
42
|
-
"build.mjs": "tsc -p
|
|
43
|
-
"build": "node ./build.js removeCmp && npm run build.cjs && npm run build.mjs && node ./build.js finalizeExportVariants",
|
|
41
|
+
"build.cjs": "tsc -p build/tsconfig.cjs.json",
|
|
42
|
+
"build.mjs": "tsc -p build/tsconfig.mjs.json",
|
|
43
|
+
"build": "node ./build/act.js removeCmp && npm run build.cjs && npm run build.mjs && node ./build/act.js finalizeExportVariants",
|
|
44
44
|
"git.pub": "npm run test && git add --all && git commit -m \"automated\" && git push",
|
|
45
45
|
"npm.login": "npm login",
|
|
46
46
|
"npm.pub": "npm run test && npm run build && npm publish --access public"
|