pepka 1.9.4 → 1.10.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/dist/bundle.cjs +10 -15
- package/dist/bundle.d.ts +0 -1
- package/dist/bundle.mjs +10 -15
- package/package.json +1 -1
- package/src/common.ts +2 -0
- package/src/utils.ts +2 -3
package/dist/bundle.cjs
CHANGED
|
@@ -86,6 +86,7 @@ const startsWithWith = (comparator) => curry2((start, s) => {
|
|
|
86
86
|
const undef = undefined;
|
|
87
87
|
const nul = null;
|
|
88
88
|
const inf = Infinity;
|
|
89
|
+
const not_assigned = Symbol();
|
|
89
90
|
const to = (s) => typeof s;
|
|
90
91
|
const isNull = (s) => (s === nul);
|
|
91
92
|
const isUndef = (s) => (s === undef);
|
|
@@ -95,37 +96,30 @@ function isFunc(s) { return to(s) === 'function'; }
|
|
|
95
96
|
const isStr = (s) => (to(s) === 'string');
|
|
96
97
|
const isObj = (s) => (!isNull(s) && to(s) === 'object');
|
|
97
98
|
const isNil = (s) => (isNull(s) || isUndef(s));
|
|
99
|
+
// TODO: add .then(), .finally() and .catch() to return QPromise.
|
|
98
100
|
class QPromise extends Promise {
|
|
99
101
|
oncancel;
|
|
100
102
|
ff;
|
|
101
|
-
rj;
|
|
102
103
|
_cancel_data;
|
|
103
104
|
cancel(resolve = false) {
|
|
104
105
|
if (resolve)
|
|
105
106
|
this.ff();
|
|
106
|
-
|
|
107
|
-
super.catch(noop);
|
|
108
|
-
this.rj('canceled');
|
|
109
|
-
this.oncancel(this._cancel_data);
|
|
110
|
-
}
|
|
107
|
+
this.oncancel(this._cancel_data);
|
|
111
108
|
}
|
|
112
109
|
constructor(fn, oncancel = noop) {
|
|
113
|
-
let
|
|
114
|
-
super((ff, rj) =>
|
|
115
|
-
_ff = ff;
|
|
116
|
-
_rj = rj;
|
|
117
|
-
_cancel_data = fn(ff, rj);
|
|
118
|
-
});
|
|
110
|
+
let _cancel_data = not_assigned;
|
|
111
|
+
super((ff, rj) => _cancel_data = fn(ff, rj));
|
|
119
112
|
this.oncancel = oncancel;
|
|
120
|
-
const set_cb = () =>
|
|
113
|
+
const set_cb = () => this._cancel_data = _cancel_data;
|
|
121
114
|
// @ts-ignore-next
|
|
122
|
-
if (
|
|
115
|
+
if (_cancel_data !== not_assigned)
|
|
123
116
|
set_cb();
|
|
124
117
|
else
|
|
125
118
|
setTimeout(set_cb);
|
|
126
119
|
}
|
|
127
120
|
}
|
|
128
121
|
|
|
122
|
+
const { isNaN } = Number;
|
|
129
123
|
// It's faster that toUpperCase() !
|
|
130
124
|
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F', o: 'O' };
|
|
131
125
|
const symbol = Symbol();
|
|
@@ -136,7 +130,8 @@ const type = (s) => {
|
|
|
136
130
|
const t = to(s);
|
|
137
131
|
return t === 'object'
|
|
138
132
|
? isNull(s) ? 'Null' : (s.constructor?.name || cap_type(t))
|
|
139
|
-
:
|
|
133
|
+
: t === 'number' && isNaN(s) ? 'NaN'
|
|
134
|
+
: cap_type(t);
|
|
140
135
|
};
|
|
141
136
|
const typeIs = curry2((t, s) => type(s) === t);
|
|
142
137
|
const eq = curry2((a, b) => a === b);
|
package/dist/bundle.d.ts
CHANGED
|
@@ -242,7 +242,6 @@ export declare const isNil: <T extends any>(s: T) => T extends (null | undefined
|
|
|
242
242
|
export declare class QPromise<T> extends Promise<T> {
|
|
243
243
|
private oncancel;
|
|
244
244
|
private ff;
|
|
245
|
-
private rj;
|
|
246
245
|
private _cancel_data;
|
|
247
246
|
cancel(resolve?: boolean): void;
|
|
248
247
|
constructor(fn: AnyFunc<any, [
|
package/dist/bundle.mjs
CHANGED
|
@@ -84,6 +84,7 @@ const startsWithWith = (comparator) => curry2((start, s) => {
|
|
|
84
84
|
const undef = undefined;
|
|
85
85
|
const nul = null;
|
|
86
86
|
const inf = Infinity;
|
|
87
|
+
const not_assigned = Symbol();
|
|
87
88
|
const to = (s) => typeof s;
|
|
88
89
|
const isNull = (s) => (s === nul);
|
|
89
90
|
const isUndef = (s) => (s === undef);
|
|
@@ -93,37 +94,30 @@ function isFunc(s) { return to(s) === 'function'; }
|
|
|
93
94
|
const isStr = (s) => (to(s) === 'string');
|
|
94
95
|
const isObj = (s) => (!isNull(s) && to(s) === 'object');
|
|
95
96
|
const isNil = (s) => (isNull(s) || isUndef(s));
|
|
97
|
+
// TODO: add .then(), .finally() and .catch() to return QPromise.
|
|
96
98
|
class QPromise extends Promise {
|
|
97
99
|
oncancel;
|
|
98
100
|
ff;
|
|
99
|
-
rj;
|
|
100
101
|
_cancel_data;
|
|
101
102
|
cancel(resolve = false) {
|
|
102
103
|
if (resolve)
|
|
103
104
|
this.ff();
|
|
104
|
-
|
|
105
|
-
super.catch(noop);
|
|
106
|
-
this.rj('canceled');
|
|
107
|
-
this.oncancel(this._cancel_data);
|
|
108
|
-
}
|
|
105
|
+
this.oncancel(this._cancel_data);
|
|
109
106
|
}
|
|
110
107
|
constructor(fn, oncancel = noop) {
|
|
111
|
-
let
|
|
112
|
-
super((ff, rj) =>
|
|
113
|
-
_ff = ff;
|
|
114
|
-
_rj = rj;
|
|
115
|
-
_cancel_data = fn(ff, rj);
|
|
116
|
-
});
|
|
108
|
+
let _cancel_data = not_assigned;
|
|
109
|
+
super((ff, rj) => _cancel_data = fn(ff, rj));
|
|
117
110
|
this.oncancel = oncancel;
|
|
118
|
-
const set_cb = () =>
|
|
111
|
+
const set_cb = () => this._cancel_data = _cancel_data;
|
|
119
112
|
// @ts-ignore-next
|
|
120
|
-
if (
|
|
113
|
+
if (_cancel_data !== not_assigned)
|
|
121
114
|
set_cb();
|
|
122
115
|
else
|
|
123
116
|
setTimeout(set_cb);
|
|
124
117
|
}
|
|
125
118
|
}
|
|
126
119
|
|
|
120
|
+
const { isNaN } = Number;
|
|
127
121
|
// It's faster that toUpperCase() !
|
|
128
122
|
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F', o: 'O' };
|
|
129
123
|
const symbol = Symbol();
|
|
@@ -134,7 +128,8 @@ const type = (s) => {
|
|
|
134
128
|
const t = to(s);
|
|
135
129
|
return t === 'object'
|
|
136
130
|
? isNull(s) ? 'Null' : (s.constructor?.name || cap_type(t))
|
|
137
|
-
:
|
|
131
|
+
: t === 'number' && isNaN(s) ? 'NaN'
|
|
132
|
+
: cap_type(t);
|
|
138
133
|
};
|
|
139
134
|
const typeIs = curry2((t, s) => type(s) === t);
|
|
140
135
|
const eq = curry2((a, b) => a === b);
|
package/package.json
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
|
|
42
42
|
"all": "npm run dev && npm run prod"
|
|
43
43
|
},
|
|
44
|
-
"version": "1.
|
|
44
|
+
"version": "1.10.0",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@rollup/plugin-commonjs": "^29.0.2",
|
|
47
47
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
package/src/common.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { curry2 } from "./curry"
|
|
2
2
|
import { is_typed_arr } from "./internal"
|
|
3
3
|
import { isNull, isStr, to } from "./utils"
|
|
4
|
+
const {isNaN} = Number
|
|
4
5
|
|
|
5
6
|
// It's faster that toUpperCase() !
|
|
6
7
|
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F', o: 'O' }
|
|
@@ -13,6 +14,7 @@ export const type = (s: any): string => {
|
|
|
13
14
|
const t = to(s)
|
|
14
15
|
return t==='object'
|
|
15
16
|
? isNull(s) ? 'Null' : (s.constructor?.name||cap_type(t))
|
|
17
|
+
: t==='number'&&isNaN(s) ? 'NaN'
|
|
16
18
|
: cap_type(t)
|
|
17
19
|
}
|
|
18
20
|
export const typeIs = curry2((t: string, s: any) => type(s)===t)
|
package/src/utils.ts
CHANGED
|
@@ -17,6 +17,7 @@ export const isStr = <T extends any>(s: T) => (to(s)==='string') as T extends st
|
|
|
17
17
|
export const isObj = <T extends any>(s: T) => (!isNull(s) && to(s)==='object') as T extends AnyObject ? true : false
|
|
18
18
|
export const isNil = <T extends any>(s: T) => (isNull(s) || isUndef(s)) as T extends (null|undefined) ? true : false
|
|
19
19
|
|
|
20
|
+
// TODO: add .then(), .finally() and .catch() to return QPromise.
|
|
20
21
|
export class QPromise<T> extends Promise<T> {
|
|
21
22
|
private ff: AnyFunc
|
|
22
23
|
private _cancel_data: any
|
|
@@ -26,9 +27,7 @@ export class QPromise<T> extends Promise<T> {
|
|
|
26
27
|
}
|
|
27
28
|
constructor(fn: AnyFunc<any, [AnyFunc, AnyFunc, AnyFunc?]>, private oncancel = noop) {
|
|
28
29
|
let _cancel_data: any = not_assigned
|
|
29
|
-
super((ff, rj) =>
|
|
30
|
-
_cancel_data = fn(ff, rj)
|
|
31
|
-
})
|
|
30
|
+
super((ff, rj) => _cancel_data = fn(ff, rj))
|
|
32
31
|
const set_cb = () => this._cancel_data=_cancel_data
|
|
33
32
|
// @ts-ignore-next
|
|
34
33
|
if(_cancel_data!==not_assigned) set_cb()
|