pubo-utils 1.0.149 → 1.0.157
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 +33 -33
- package/es/color/utils.js +40 -55
- package/es/debounce/index.js +35 -40
- package/es/emitter/index.js +59 -279
- package/es/factory/index.js +9 -10
- package/es/filter/sensor.js +99 -126
- package/es/index.d.ts +1 -1
- package/es/index.js +3 -4
- package/es/level/index.js +20 -22
- package/es/loop/index.js +68 -123
- package/es/math/geometry.js +69 -98
- package/es/promise/index.js +15 -22
- package/es/queue/index.js +36 -115
- package/es/random/index.js +20 -22
- package/es/regexp-list/index.js +16 -20
- package/es/sleep/index.js +9 -28
- package/es/stack/index.js +34 -46
- package/es/str.js +6 -5
- package/es/throttle/index.js +17 -20
- package/es/trigger/index.js +22 -34
- package/es/watch-dog/index.js +29 -35
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -3
- package/package.json +2 -2
package/es/random/index.js
CHANGED
|
@@ -4,25 +4,23 @@
|
|
|
4
4
|
* @param {number} n - The length of the random string to generate
|
|
5
5
|
* @return {string} The randomly generated string
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
if (n <= 8) {
|
|
15
|
-
return ra(n);
|
|
16
|
-
}
|
|
17
|
-
var res = '';
|
|
18
|
-
for (var a = 0; a <= n; a += 8) {
|
|
19
|
-
if (n - a > 8) {
|
|
20
|
-
res += ra(8);
|
|
21
|
-
} else {
|
|
22
|
-
res += ra(n - a);
|
|
7
|
+
export const random = (n = 8) => {
|
|
8
|
+
const ra = (x) => Math.random()
|
|
9
|
+
.toString(32)
|
|
10
|
+
.slice(2, 2 + x);
|
|
11
|
+
if (n <= 8) {
|
|
12
|
+
return ra(n);
|
|
23
13
|
}
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
let res = '';
|
|
15
|
+
for (let a = 0; a <= n; a += 8) {
|
|
16
|
+
if (n - a > 8) {
|
|
17
|
+
res += ra(8);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
res += ra(n - a);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return res;
|
|
26
24
|
};
|
|
27
25
|
/**
|
|
28
26
|
* Generates a random number within the specified range.
|
|
@@ -30,7 +28,7 @@ export var random = function random(n) {
|
|
|
30
28
|
* @param {number[]} range - The range within which to generate the random number.
|
|
31
29
|
* @return {number} The randomly generated number within the specified range.
|
|
32
30
|
*/
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
31
|
+
export const randomRangeNum = (range) => {
|
|
32
|
+
const size = Math.abs(range[1] - range[0]);
|
|
33
|
+
return Math.random() * size + Math.min(...range);
|
|
34
|
+
};
|
package/es/regexp-list/index.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
var _proto = RegExpList.prototype;
|
|
8
|
-
_proto.getRegEXP = function getRegEXP(item) {
|
|
9
|
-
var str = item.replace('/', '\\/').replace('*', '.*');
|
|
10
|
-
return new RegExp(str);
|
|
11
|
-
};
|
|
12
|
-
_proto.include = function include(value) {
|
|
13
|
-
if (!this._RegExpList) {
|
|
14
|
-
this._RegExpList = this.list.map(this.getRegEXP);
|
|
1
|
+
export class RegExpList {
|
|
2
|
+
list;
|
|
3
|
+
_RegExpList = null;
|
|
4
|
+
constructor(list) {
|
|
5
|
+
this.list = list;
|
|
15
6
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
getRegEXP(item) {
|
|
8
|
+
const str = item.replace('/', '\\/').replace('*', '.*');
|
|
9
|
+
return new RegExp(str);
|
|
10
|
+
}
|
|
11
|
+
include(value) {
|
|
12
|
+
if (!this._RegExpList) {
|
|
13
|
+
this._RegExpList = this.list.map(this.getRegEXP);
|
|
14
|
+
}
|
|
15
|
+
return this._RegExpList.some((item) => item.test(value));
|
|
16
|
+
}
|
|
17
|
+
}
|
package/es/sleep/index.js
CHANGED
|
@@ -4,31 +4,12 @@
|
|
|
4
4
|
* @param {number} time - The duration in milliseconds to sleep
|
|
5
5
|
* @return {Promise<void>} A promise that resolves after the specified time
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
for (var args = [], i = 0; i < arguments.length; i++) {
|
|
17
|
-
args[i] = arguments[i];
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
return Promise.resolve(f.apply(this, args));
|
|
21
|
-
} catch (e) {
|
|
22
|
-
return Promise.reject(e);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export var sleep = _async(function (time) {
|
|
27
|
-
return _awaitIgnored(new Promise(function (resolve) {
|
|
28
|
-
var timeout = setTimeout(function () {
|
|
29
|
-
resolve();
|
|
30
|
-
clearTimeout(timeout);
|
|
31
|
-
timeout = null;
|
|
32
|
-
}, time);
|
|
33
|
-
}));
|
|
34
|
-
});
|
|
7
|
+
export const sleep = async (time) => {
|
|
8
|
+
await new Promise((resolve) => {
|
|
9
|
+
let timeout = setTimeout(() => {
|
|
10
|
+
resolve();
|
|
11
|
+
clearTimeout(timeout);
|
|
12
|
+
timeout = null;
|
|
13
|
+
}, time);
|
|
14
|
+
});
|
|
15
|
+
};
|
package/es/stack/index.js
CHANGED
|
@@ -1,52 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (len === void 0) {
|
|
8
|
-
len = 10;
|
|
1
|
+
export class HistoryStack {
|
|
2
|
+
stack = [];
|
|
3
|
+
len = 10;
|
|
4
|
+
point = 0;
|
|
5
|
+
constructor(len = 10) {
|
|
6
|
+
this.len = len;
|
|
9
7
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _proto = HistoryStack.prototype;
|
|
16
|
-
_proto.clear = function clear() {
|
|
17
|
-
this.stack.length = 0;
|
|
18
|
-
this.point = 0;
|
|
19
|
-
};
|
|
20
|
-
_proto.backup = function backup(item) {
|
|
21
|
-
if (this.point > 0 && this.stack.length > 0) {
|
|
22
|
-
this.stack.splice(0, this.point);
|
|
23
|
-
this.point = 0;
|
|
8
|
+
get current() {
|
|
9
|
+
if (this.point < this.stack.length && this.point > -1) {
|
|
10
|
+
return this.stack[this.point];
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
24
13
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
clear() {
|
|
15
|
+
this.stack.length = 0;
|
|
16
|
+
this.point = 0;
|
|
28
17
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
backup(item) {
|
|
19
|
+
if (this.point > 0 && this.stack.length > 0) {
|
|
20
|
+
this.stack.splice(0, this.point);
|
|
21
|
+
this.point = 0;
|
|
22
|
+
}
|
|
23
|
+
this.stack.unshift(item);
|
|
24
|
+
if (this.stack.length > this.len) {
|
|
25
|
+
this.stack.pop();
|
|
26
|
+
}
|
|
33
27
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
undo() {
|
|
29
|
+
if (this.point < this.stack.length - 1) {
|
|
30
|
+
this.point += 1;
|
|
31
|
+
}
|
|
32
|
+
return this.current;
|
|
39
33
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (this.point < this.stack.length && this.point > -1) {
|
|
46
|
-
return this.stack[this.point];
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
34
|
+
redo() {
|
|
35
|
+
if (this.point > 0) {
|
|
36
|
+
this.point -= 1;
|
|
37
|
+
}
|
|
38
|
+
return this.current;
|
|
49
39
|
}
|
|
50
|
-
|
|
51
|
-
return HistoryStack;
|
|
52
|
-
}();
|
|
40
|
+
}
|
package/es/str.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// 下划线转驼峰
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
export const lower2camel = (str) => {
|
|
3
|
+
return str
|
|
4
|
+
.split('_')
|
|
5
|
+
.map((item, i) => (i > 0 ? item.slice(0, 1).toUpperCase() + item.slice(1) : item))
|
|
6
|
+
.join('');
|
|
7
|
+
};
|
package/es/throttle/index.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
export function throttle(cb, time) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
args = null;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
2
|
+
let t;
|
|
3
|
+
let onOff = true;
|
|
4
|
+
return (...args) => {
|
|
5
|
+
if (!t) {
|
|
6
|
+
t = setTimeout(() => {
|
|
7
|
+
clearTimeout(t);
|
|
8
|
+
onOff = true;
|
|
9
|
+
t = null;
|
|
10
|
+
}, time);
|
|
11
|
+
}
|
|
12
|
+
if (onOff) {
|
|
13
|
+
onOff = false;
|
|
14
|
+
cb(...args);
|
|
15
|
+
}
|
|
16
|
+
args = null;
|
|
17
|
+
};
|
|
18
|
+
}
|
package/es/trigger/index.js
CHANGED
|
@@ -1,36 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.timeout = void 0;
|
|
8
|
-
this._count = 0;
|
|
9
|
-
this.props = void 0;
|
|
10
|
-
this.props = props;
|
|
11
|
-
}
|
|
12
|
-
var _proto = ContinuousTrigger.prototype;
|
|
13
|
-
_proto.increment = function increment() {
|
|
14
|
-
var _this = this;
|
|
15
|
-
clearTimeout(this.timeout);
|
|
16
|
-
this.timeout = setTimeout(function () {
|
|
17
|
-
return _this.clear();
|
|
18
|
-
}, this.props.resetTime);
|
|
19
|
-
this._count = this._count + 1;
|
|
20
|
-
if (this._count > this.props.count) {
|
|
21
|
-
this.props.cb();
|
|
1
|
+
export class ContinuousTrigger {
|
|
2
|
+
timeout;
|
|
3
|
+
_count = 0;
|
|
4
|
+
props;
|
|
5
|
+
constructor(props) {
|
|
6
|
+
this.props = props;
|
|
22
7
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
clearTimeout(this.timeout);
|
|
26
|
-
this._count = 0;
|
|
27
|
-
this.timeout = 0;
|
|
28
|
-
};
|
|
29
|
-
_createClass(ContinuousTrigger, [{
|
|
30
|
-
key: "count",
|
|
31
|
-
get: function get() {
|
|
32
|
-
return this._count;
|
|
8
|
+
get count() {
|
|
9
|
+
return this._count;
|
|
33
10
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
11
|
+
increment() {
|
|
12
|
+
clearTimeout(this.timeout);
|
|
13
|
+
this.timeout = setTimeout(() => this.clear(), this.props.resetTime);
|
|
14
|
+
this._count = this._count + 1;
|
|
15
|
+
if (this._count > this.props.count) {
|
|
16
|
+
this.props.cb();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
clear() {
|
|
20
|
+
clearTimeout(this.timeout);
|
|
21
|
+
this._count = 0;
|
|
22
|
+
this.timeout = 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/es/watch-dog/index.js
CHANGED
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
_this.timeout = null;
|
|
15
|
-
}
|
|
16
|
-
onTimeout();
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
var _proto = WatchDog.prototype;
|
|
20
|
-
_proto.feed = function feed() {
|
|
21
|
-
this.init();
|
|
22
|
-
};
|
|
23
|
-
_proto.init = function init() {
|
|
24
|
-
clearTimeout(this.timeout);
|
|
25
|
-
this.timeout = null;
|
|
26
|
-
delete this.timeout;
|
|
27
|
-
this.timeout = setTimeout(this.onTimeout, this._time);
|
|
28
|
-
};
|
|
29
|
-
_proto.stop = function stop() {
|
|
30
|
-
if (this.timeout) {
|
|
31
|
-
clearTimeout(this.timeout);
|
|
1
|
+
export class WatchDog {
|
|
2
|
+
onTimeout;
|
|
3
|
+
timeout = null;
|
|
4
|
+
_time;
|
|
5
|
+
constructor({ limit = 10, onTimeout }) {
|
|
6
|
+
this._time = limit * 1000;
|
|
7
|
+
this.onTimeout = () => {
|
|
8
|
+
if (this.timeout) {
|
|
9
|
+
clearTimeout(this.timeout);
|
|
10
|
+
this.timeout = null;
|
|
11
|
+
}
|
|
12
|
+
onTimeout();
|
|
13
|
+
};
|
|
32
14
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
15
|
+
feed() {
|
|
16
|
+
this.init();
|
|
17
|
+
}
|
|
18
|
+
init() {
|
|
19
|
+
clearTimeout(this.timeout);
|
|
20
|
+
this.timeout = null;
|
|
21
|
+
delete this.timeout;
|
|
22
|
+
this.timeout = setTimeout(this.onTimeout, this._time);
|
|
23
|
+
}
|
|
24
|
+
stop() {
|
|
25
|
+
if (this.timeout) {
|
|
26
|
+
clearTimeout(this.timeout);
|
|
27
|
+
}
|
|
28
|
+
delete this.timeout;
|
|
29
|
+
}
|
|
30
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ export { WatchDog } from './watch-dog';
|
|
|
14
14
|
export { Level } from './level';
|
|
15
15
|
export { callbackToPromise } from './promise';
|
|
16
16
|
export { getAngle, getDistance, getCenter, degrees, radians, filterKeyPoints, getRotate, getPositionTheta, getBestPointIndex, orderByDistance, getVectorTheta, } from './math/geometry';
|
|
17
|
+
export { lower2camel } from './str';
|
|
17
18
|
export { RegExpList } from './regexp-list';
|
|
18
19
|
export { SensorDataFilter, StringSplit } from './filter/sensor';
|
|
19
|
-
export { lower2camel } from './str';
|
package/lib/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.StringSplit = exports.SensorDataFilter = exports.RegExpList = exports.lower2camel = exports.getVectorTheta = exports.orderByDistance = exports.getBestPointIndex = exports.getPositionTheta = exports.getRotate = exports.filterKeyPoints = exports.radians = exports.degrees = exports.getCenter = exports.getDistance = exports.getAngle = exports.callbackToPromise = exports.Level = exports.WatchDog = exports.HistoryStack = exports.Base64Utils = exports.ContinuousTrigger = exports.throttle = exports.sleep = exports.randomRangeNum = exports.random = exports.SyncQueue = exports.waitFor = exports.loop = exports.superFactory = exports.Emitter = exports.hex2rgb = exports.debounce = void 0;
|
|
27
27
|
var debounce_1 = require("./debounce");
|
|
28
28
|
Object.defineProperty(exports, "debounce", { enumerable: true, get: function () { return debounce_1.debounce; } });
|
|
29
29
|
var utils_1 = require("./color/utils");
|
|
@@ -67,10 +67,10 @@ Object.defineProperty(exports, "getPositionTheta", { enumerable: true, get: func
|
|
|
67
67
|
Object.defineProperty(exports, "getBestPointIndex", { enumerable: true, get: function () { return geometry_1.getBestPointIndex; } });
|
|
68
68
|
Object.defineProperty(exports, "orderByDistance", { enumerable: true, get: function () { return geometry_1.orderByDistance; } });
|
|
69
69
|
Object.defineProperty(exports, "getVectorTheta", { enumerable: true, get: function () { return geometry_1.getVectorTheta; } });
|
|
70
|
+
var str_1 = require("./str");
|
|
71
|
+
Object.defineProperty(exports, "lower2camel", { enumerable: true, get: function () { return str_1.lower2camel; } });
|
|
70
72
|
var regexp_list_1 = require("./regexp-list");
|
|
71
73
|
Object.defineProperty(exports, "RegExpList", { enumerable: true, get: function () { return regexp_list_1.RegExpList; } });
|
|
72
74
|
var sensor_1 = require("./filter/sensor");
|
|
73
75
|
Object.defineProperty(exports, "SensorDataFilter", { enumerable: true, get: function () { return sensor_1.SensorDataFilter; } });
|
|
74
76
|
Object.defineProperty(exports, "StringSplit", { enumerable: true, get: function () { return sensor_1.StringSplit; } });
|
|
75
|
-
var str_1 = require("./str");
|
|
76
|
-
Object.defineProperty(exports, "lower2camel", { enumerable: true, get: function () { return str_1.lower2camel; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pubo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.157",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=8.0.0"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "600ac18384c1b657522eee9f2c80dba805443de3",
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@babel/cli": "^7.10.1",
|
|
24
24
|
"@babel/core": "^7.10.2",
|