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.
@@ -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 var random = function random(n) {
8
- if (n === void 0) {
9
- n = 8;
10
- }
11
- var ra = function ra(x) {
12
- return Math.random().toString(32).slice(2, 2 + x);
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
- return res;
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 var randomRangeNum = function randomRangeNum(range) {
34
- var size = Math.abs(range[1] - range[0]);
35
- return Math.random() * size + Math.min.apply(Math, range);
36
- };
31
+ export const randomRangeNum = (range) => {
32
+ const size = Math.abs(range[1] - range[0]);
33
+ return Math.random() * size + Math.min(...range);
34
+ };
@@ -1,21 +1,17 @@
1
- export var RegExpList = /*#__PURE__*/function () {
2
- function RegExpList(list) {
3
- this.list = void 0;
4
- this._RegExpList = null;
5
- this.list = list;
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
- return this._RegExpList.some(function (item) {
17
- return item.test(value);
18
- });
19
- };
20
- return RegExpList;
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
- function _empty() {}
9
- function _awaitIgnored(value, direct) {
10
- if (!direct) {
11
- return value && value.then ? value.then(_empty) : Promise.resolve();
12
- }
13
- }
14
- function _async(f) {
15
- return function () {
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
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
2
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
3
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
4
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
- export var HistoryStack = /*#__PURE__*/function () {
6
- function HistoryStack(len) {
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
- this.stack = [];
11
- this.len = 10;
12
- this.point = 0;
13
- this.len = len;
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
- this.stack.unshift(item);
26
- if (this.stack.length > this.len) {
27
- this.stack.pop();
14
+ clear() {
15
+ this.stack.length = 0;
16
+ this.point = 0;
28
17
  }
29
- };
30
- _proto.undo = function undo() {
31
- if (this.point < this.stack.length - 1) {
32
- this.point += 1;
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
- return this.current;
35
- };
36
- _proto.redo = function redo() {
37
- if (this.point > 0) {
38
- this.point -= 1;
28
+ undo() {
29
+ if (this.point < this.stack.length - 1) {
30
+ this.point += 1;
31
+ }
32
+ return this.current;
39
33
  }
40
- return this.current;
41
- };
42
- _createClass(HistoryStack, [{
43
- key: "current",
44
- get: function get() {
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 var lower2camel = function lower2camel(str) {
3
- return str.split('_').map(function (item, i) {
4
- return i > 0 ? item.slice(0, 1).toUpperCase() + item.slice(1) : item;
5
- }).join('');
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
+ };
@@ -1,21 +1,18 @@
1
1
  export function throttle(cb, time) {
2
- var t;
3
- var onOff = true;
4
- return function () {
5
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
6
- args[_key] = arguments[_key];
7
- }
8
- if (!t) {
9
- t = setTimeout(function () {
10
- clearTimeout(t);
11
- onOff = true;
12
- t = null;
13
- }, time);
14
- }
15
- if (onOff) {
16
- onOff = false;
17
- cb.apply(void 0, args);
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
+ }
@@ -1,36 +1,24 @@
1
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
2
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
3
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
4
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
- export var ContinuousTrigger = /*#__PURE__*/function () {
6
- function ContinuousTrigger(props) {
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
- _proto.clear = function clear() {
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
- return ContinuousTrigger;
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
+ }
@@ -1,36 +1,30 @@
1
- export var WatchDog = /*#__PURE__*/function () {
2
- function WatchDog(_ref) {
3
- var _this = this;
4
- var _ref$limit = _ref.limit,
5
- limit = _ref$limit === void 0 ? 10 : _ref$limit,
6
- onTimeout = _ref.onTimeout;
7
- this.onTimeout = void 0;
8
- this.timeout = null;
9
- this._time = void 0;
10
- this._time = limit * 1000;
11
- this.onTimeout = function () {
12
- if (_this.timeout) {
13
- clearTimeout(_this.timeout);
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
- delete this.timeout;
34
- };
35
- return WatchDog;
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.lower2camel = exports.StringSplit = exports.SensorDataFilter = exports.RegExpList = 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;
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.149",
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": "2fb3948cc5dc5030739ce34928e4ec8195b55c1b",
21
+ "gitHead": "600ac18384c1b657522eee9f2c80dba805443de3",
22
22
  "devDependencies": {
23
23
  "@babel/cli": "^7.10.1",
24
24
  "@babel/core": "^7.10.2",