pubo-utils 1.0.157 → 1.0.159
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/pubo-utils.js +1 -1
- package/es/base64/index.js +6 -7
- package/es/color/utils.d.ts +1 -10
- package/es/color/utils.js +17 -12
- package/es/debounce/index.js +6 -7
- package/es/emitter/index.js +15 -5
- package/es/factory/index.js +3 -4
- package/es/filter/sensor.js +15 -17
- package/es/index.js +1 -1
- package/es/level/index.js +2 -2
- package/es/loop/index.d.ts +2 -2
- package/es/loop/index.js +9 -13
- package/es/math/geometry.js +45 -25
- package/es/promise/index.js +15 -14
- package/es/queue/index.js +10 -6
- package/es/random/index.js +5 -10
- package/es/regexp-list/index.js +2 -2
- package/es/sleep/index.js +3 -4
- package/es/stack/index.js +1 -1
- package/es/str.js +2 -5
- package/es/throttle/index.d.ts +1 -1
- package/es/throttle/index.js +13 -14
- package/es/trigger/index.js +2 -2
- package/es/watch-dog/index.js +2 -2
- package/lib/base64/index.js +23 -15
- package/lib/color/utils.d.ts +1 -10
- package/lib/color/utils.js +40 -20
- package/lib/debounce/index.js +15 -10
- package/lib/emitter/index.js +34 -11
- package/lib/factory/index.js +12 -12
- package/lib/filter/sensor.js +32 -26
- package/lib/index.js +165 -73
- package/lib/level/index.js +11 -5
- package/lib/loop/index.d.ts +2 -2
- package/lib/loop/index.js +28 -33
- package/lib/math/geometry.js +94 -54
- package/lib/promise/index.js +25 -18
- package/lib/queue/index.js +19 -9
- package/lib/random/index.js +23 -20
- package/lib/regexp-list/index.js +11 -5
- package/lib/sleep/index.js +13 -8
- package/lib/stack/index.js +10 -4
- package/lib/str.js +12 -9
- package/lib/throttle/index.d.ts +1 -1
- package/lib/throttle/index.js +22 -17
- package/lib/trigger/index.js +11 -5
- package/lib/watch-dog/index.js +11 -5
- package/package.json +2 -14
package/lib/queue/index.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "SyncQueue", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return SyncQueue;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
4
11
|
class SyncQueue {
|
|
5
12
|
cache = [];
|
|
6
13
|
running = false;
|
|
@@ -9,8 +16,7 @@ class SyncQueue {
|
|
|
9
16
|
try {
|
|
10
17
|
const res = await fn();
|
|
11
18
|
promise.resolve(res);
|
|
12
|
-
}
|
|
13
|
-
catch (err) {
|
|
19
|
+
} catch (err) {
|
|
14
20
|
promise.reject(err);
|
|
15
21
|
}
|
|
16
22
|
fn = null;
|
|
@@ -20,8 +26,7 @@ class SyncQueue {
|
|
|
20
26
|
if (this.cache.length < 1) {
|
|
21
27
|
this.running = false;
|
|
22
28
|
return;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
29
|
+
} else {
|
|
25
30
|
this.running = true;
|
|
26
31
|
}
|
|
27
32
|
const item = this.cache.shift();
|
|
@@ -33,8 +38,14 @@ class SyncQueue {
|
|
|
33
38
|
}
|
|
34
39
|
push(fn) {
|
|
35
40
|
this.len += 1;
|
|
36
|
-
return new Promise((resolve, reject)
|
|
37
|
-
this.cache.push({
|
|
41
|
+
return new Promise((resolve, reject)=>{
|
|
42
|
+
this.cache.push({
|
|
43
|
+
fn,
|
|
44
|
+
promise: {
|
|
45
|
+
resolve,
|
|
46
|
+
reject
|
|
47
|
+
}
|
|
48
|
+
});
|
|
38
49
|
if (!this.running) {
|
|
39
50
|
this.run();
|
|
40
51
|
}
|
|
@@ -44,4 +55,3 @@ class SyncQueue {
|
|
|
44
55
|
return this.len;
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
|
-
exports.SyncQueue = SyncQueue;
|
package/lib/random/index.js
CHANGED
|
@@ -1,39 +1,42 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Generates a random string of specified length.
|
|
4
3
|
*
|
|
5
4
|
* @param {number} n - The length of the random string to generate
|
|
6
5
|
* @return {string} The randomly generated string
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
*/ "use strict";
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
function _export(target, all) {
|
|
11
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: all[name]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_export(exports, {
|
|
17
|
+
random: function() {
|
|
18
|
+
return random;
|
|
19
|
+
},
|
|
20
|
+
randomRangeNum: function() {
|
|
21
|
+
return randomRangeNum;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const random = (n = 8)=>{
|
|
25
|
+
const ra = (x)=>Math.random().toString(32).slice(2, 2 + x);
|
|
14
26
|
if (n <= 8) {
|
|
15
27
|
return ra(n);
|
|
16
28
|
}
|
|
17
29
|
let res = '';
|
|
18
|
-
for
|
|
30
|
+
for(let a = 0; a <= n; a += 8){
|
|
19
31
|
if (n - a > 8) {
|
|
20
32
|
res += ra(8);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
33
|
+
} else {
|
|
23
34
|
res += ra(n - a);
|
|
24
35
|
}
|
|
25
36
|
}
|
|
26
37
|
return res;
|
|
27
38
|
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Generates a random number within the specified range.
|
|
31
|
-
*
|
|
32
|
-
* @param {number[]} range - The range within which to generate the random number.
|
|
33
|
-
* @return {number} The randomly generated number within the specified range.
|
|
34
|
-
*/
|
|
35
|
-
const randomRangeNum = (range) => {
|
|
39
|
+
const randomRangeNum = (range)=>{
|
|
36
40
|
const size = Math.abs(range[1] - range[0]);
|
|
37
41
|
return Math.random() * size + Math.min(...range);
|
|
38
42
|
};
|
|
39
|
-
exports.randomRangeNum = randomRangeNum;
|
package/lib/regexp-list/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "RegExpList", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return RegExpList;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
4
11
|
class RegExpList {
|
|
5
12
|
list;
|
|
6
13
|
_RegExpList = null;
|
|
7
|
-
constructor(list)
|
|
14
|
+
constructor(list){
|
|
8
15
|
this.list = list;
|
|
9
16
|
}
|
|
10
17
|
getRegEXP(item) {
|
|
@@ -15,7 +22,6 @@ class RegExpList {
|
|
|
15
22
|
if (!this._RegExpList) {
|
|
16
23
|
this._RegExpList = this.list.map(this.getRegEXP);
|
|
17
24
|
}
|
|
18
|
-
return this._RegExpList.some((item)
|
|
25
|
+
return this._RegExpList.some((item)=>item.test(value));
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
|
-
exports.RegExpList = RegExpList;
|
package/lib/sleep/index.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Asynchronous function to sleep for a specified amount of time.
|
|
4
3
|
*
|
|
5
4
|
* @param {number} time - The duration in milliseconds to sleep
|
|
6
5
|
* @return {Promise<void>} A promise that resolves after the specified time
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
*/ "use strict";
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(exports, "sleep", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return sleep;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const sleep = async (time)=>{
|
|
17
|
+
await new Promise((resolve)=>{
|
|
18
|
+
let timeout = setTimeout(()=>{
|
|
13
19
|
resolve();
|
|
14
20
|
clearTimeout(timeout);
|
|
15
21
|
timeout = null;
|
|
16
22
|
}, time);
|
|
17
23
|
});
|
|
18
24
|
};
|
|
19
|
-
exports.sleep = sleep;
|
package/lib/stack/index.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "HistoryStack", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return HistoryStack;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
4
11
|
class HistoryStack {
|
|
5
12
|
stack = [];
|
|
6
13
|
len = 10;
|
|
7
14
|
point = 0;
|
|
8
|
-
constructor(len = 10)
|
|
15
|
+
constructor(len = 10){
|
|
9
16
|
this.len = len;
|
|
10
17
|
}
|
|
11
18
|
get current() {
|
|
@@ -41,4 +48,3 @@ class HistoryStack {
|
|
|
41
48
|
return this.current;
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
|
-
exports.HistoryStack = HistoryStack;
|
package/lib/str.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lower2camel = void 0;
|
|
4
1
|
// 下划线转驼峰
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "lower2camel", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return lower2camel;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
const lower2camel = (str)=>{
|
|
13
|
+
return str.split('_').map((item, i)=>i > 0 ? item.slice(0, 1).toUpperCase() + item.slice(1) : item).join('');
|
|
10
14
|
};
|
|
11
|
-
exports.lower2camel = lower2camel;
|
package/lib/throttle/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function throttle(cb: any, time: number): (...args: any[]) =>
|
|
1
|
+
export declare function throttle(cb: any, time: number): (...args: any[]) => Promise<unknown> | undefined;
|
package/lib/throttle/index.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "throttle", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return throttle;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _queue = require("../queue");
|
|
12
|
+
const _sleep = require("../sleep");
|
|
4
13
|
function throttle(cb, time) {
|
|
5
|
-
|
|
6
|
-
let
|
|
7
|
-
return (...args)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
onOff = true;
|
|
12
|
-
t = null;
|
|
13
|
-
}, time);
|
|
14
|
+
const queue = new _queue.SyncQueue();
|
|
15
|
+
let payload;
|
|
16
|
+
return (...args)=>{
|
|
17
|
+
payload = args;
|
|
18
|
+
if (queue.length > 0) {
|
|
19
|
+
return;
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
cb(...
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
return queue.push(async ()=>{
|
|
22
|
+
await (0, _sleep.sleep)(time);
|
|
23
|
+
await cb(...payload);
|
|
24
|
+
payload = null;
|
|
25
|
+
});
|
|
20
26
|
};
|
|
21
27
|
}
|
|
22
|
-
exports.throttle = throttle;
|
package/lib/trigger/index.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ContinuousTrigger", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ContinuousTrigger;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
4
11
|
class ContinuousTrigger {
|
|
5
12
|
timeout;
|
|
6
13
|
_count = 0;
|
|
7
14
|
props;
|
|
8
|
-
constructor(props)
|
|
15
|
+
constructor(props){
|
|
9
16
|
this.props = props;
|
|
10
17
|
}
|
|
11
18
|
get count() {
|
|
@@ -13,7 +20,7 @@ class ContinuousTrigger {
|
|
|
13
20
|
}
|
|
14
21
|
increment() {
|
|
15
22
|
clearTimeout(this.timeout);
|
|
16
|
-
this.timeout = setTimeout(()
|
|
23
|
+
this.timeout = setTimeout(()=>this.clear(), this.props.resetTime);
|
|
17
24
|
this._count = this._count + 1;
|
|
18
25
|
if (this._count > this.props.count) {
|
|
19
26
|
this.props.cb();
|
|
@@ -25,4 +32,3 @@ class ContinuousTrigger {
|
|
|
25
32
|
this.timeout = 0;
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
|
-
exports.ContinuousTrigger = ContinuousTrigger;
|
package/lib/watch-dog/index.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "WatchDog", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return WatchDog;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
4
11
|
class WatchDog {
|
|
5
12
|
onTimeout;
|
|
6
13
|
timeout = null;
|
|
7
14
|
_time;
|
|
8
|
-
constructor({ limit = 10, onTimeout })
|
|
15
|
+
constructor({ limit = 10, onTimeout }){
|
|
9
16
|
this._time = limit * 1000;
|
|
10
|
-
this.onTimeout = ()
|
|
17
|
+
this.onTimeout = ()=>{
|
|
11
18
|
if (this.timeout) {
|
|
12
19
|
clearTimeout(this.timeout);
|
|
13
20
|
this.timeout = null;
|
|
@@ -31,4 +38,3 @@ class WatchDog {
|
|
|
31
38
|
delete this.timeout;
|
|
32
39
|
}
|
|
33
40
|
}
|
|
34
|
-
exports.WatchDog = WatchDog;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.159",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,27 +18,15 @@
|
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=8.0.0"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "60fbd625f83fd092f347303a76b0e2333af55a6a",
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@babel/cli": "^7.10.1",
|
|
24
|
-
"@babel/core": "^7.10.2",
|
|
25
|
-
"@babel/preset-env": "^7.20.2",
|
|
26
|
-
"babel-loader": "^8.1.0",
|
|
27
|
-
"babel-plugin-import": "^1.12.0",
|
|
28
|
-
"babel-plugin-transform-async-to-promises": "^0.8.15",
|
|
29
23
|
"del": "^5.1.0",
|
|
30
24
|
"eslint": "^8.42.0",
|
|
31
25
|
"eslint-plugin-react-hooks": "^4.0.8",
|
|
32
26
|
"gulp": "^4.0.2",
|
|
33
|
-
"gulp-babel": "^8.0.0",
|
|
34
27
|
"gulp-typescript": "^6.0.0-alpha.1",
|
|
35
|
-
"jest": "^26.0.1",
|
|
36
|
-
"jest-fetch-mock": "^3.0.3",
|
|
37
|
-
"jest-localstorage-mock": "^2.4.18",
|
|
38
28
|
"prettier": "^2.8.8",
|
|
39
29
|
"pretty-quick": "^2.0.1",
|
|
40
|
-
"surge": "^0.21.3",
|
|
41
|
-
"ts-jest": "^26.1.0",
|
|
42
30
|
"typescript": "^4.9.5",
|
|
43
31
|
"webpack": "^5.75.0",
|
|
44
32
|
"webpack-cli": "^5.0.1",
|