utils-lib-js 1.6.0 → 1.6.2

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.
@@ -1,39 +1,41 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.clearStorage = exports.getStorage = exports.setStorage = void 0;
5
- var setStorage = function (key, val) {
6
- try {
7
- localStorage.setItem(key, JSON.stringify(val));
8
- } catch (error) {
9
- console.error(error);
10
- }
11
- };
12
- exports.setStorage = setStorage;
13
- var getStorage = function (key) {
14
- try {
15
- var str = localStorage.getItem(key);
16
- if (str === null || str === undefined) {
17
- return null;
18
- }
19
- return JSON.parse(str);
20
- } catch (error) {
21
- console.error(error);
22
- return null;
23
- }
24
- };
25
- exports.getStorage = getStorage;
26
- var clearStorage = function (key) {
27
- try {
28
- key && localStorage.removeItem(key);
29
- !key && localStorage.clear();
30
- } catch (error) {
31
- console.error(error);
32
- }
33
- };
34
- exports.clearStorage = clearStorage;
35
- exports.default = {
36
- setStorage: exports.setStorage,
37
- getStorage: exports.getStorage,
38
- clearStorage: exports.clearStorage
39
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clearStorage = exports.getStorage = exports.setStorage = void 0;
4
+ var setStorage = function (key, val) {
5
+ try {
6
+ localStorage.setItem(key, JSON.stringify(val));
7
+ }
8
+ catch (error) {
9
+ console.error(error);
10
+ }
11
+ };
12
+ exports.setStorage = setStorage;
13
+ var getStorage = function (key) {
14
+ try {
15
+ var str = localStorage.getItem(key);
16
+ if (str === null || str === undefined) {
17
+ return null;
18
+ }
19
+ return JSON.parse(str);
20
+ }
21
+ catch (error) {
22
+ console.error(error);
23
+ return null;
24
+ }
25
+ };
26
+ exports.getStorage = getStorage;
27
+ var clearStorage = function (key) {
28
+ try {
29
+ key && localStorage.removeItem(key);
30
+ !key && localStorage.clear();
31
+ }
32
+ catch (error) {
33
+ console.error(error);
34
+ }
35
+ };
36
+ exports.clearStorage = clearStorage;
37
+ exports.default = {
38
+ setStorage: exports.setStorage,
39
+ getStorage: exports.getStorage,
40
+ clearStorage: exports.clearStorage
41
+ };
package/dist/cjs/types.js CHANGED
@@ -1,3 +1,2 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/esm/array.js CHANGED
@@ -1,23 +1,13 @@
1
- import { getType } from "./index.js";
2
- export var arrayRandom = function (arr) {
3
- return arr.sort(function () {
4
- return Math.random() - 0.5;
5
- });
6
- };
7
- export var arrayUniq = function (arr) {
8
- return Array.from(new Set(arr));
9
- };
10
- export var arrayDemote = function (arr, result) {
11
- if (result === void 0) {
12
- result = [];
13
- }
14
- arr.forEach(function (i) {
15
- return getType(i) === "array" ? arrayDemote(i, result) : result.push(i);
16
- });
17
- return result;
18
- };
19
- export default {
20
- arrayRandom: arrayRandom,
21
- arrayUniq: arrayUniq,
22
- arrayDemote: arrayDemote
23
- };
1
+ import { getType } from "./index.js";
2
+ export var arrayRandom = function (arr) { return arr.sort(function () { return Math.random() - 0.5; }); };
3
+ export var arrayUniq = function (arr) { return Array.from(new Set(arr)); };
4
+ export var arrayDemote = function (arr, result) {
5
+ if (result === void 0) { result = []; }
6
+ arr.forEach(function (i) { return getType(i) === "array" ? arrayDemote(i, result) : result.push(i); });
7
+ return result;
8
+ };
9
+ export default {
10
+ arrayRandom: arrayRandom,
11
+ arrayUniq: arrayUniq,
12
+ arrayDemote: arrayDemote
13
+ };
package/dist/esm/base.js CHANGED
@@ -1,54 +1,48 @@
1
- import { types } from "./index.js";
2
- export var randomNum = function (min, max, bool) {
3
- if (bool === void 0) {
4
- bool = false;
5
- }
6
- return Math.floor(Math.random() * (max - min + (bool ? 1 : 0)) + min);
7
- };
8
- export var urlSplit = function (url) {
9
- var result = {};
10
- if (!url.includes("?")) {
11
- return result;
12
- }
13
- var params = url.split("?")[1].split("&");
14
- params.forEach(function (i) {
15
- var key = i.split("=")[0];
16
- result[key] = i.split("=")[1];
17
- });
18
- return result;
19
- };
20
- export var urlJoin = function (url, query) {
21
- if (query === void 0) {
22
- query = {};
23
- }
24
- var queryObject = Object.keys(query);
25
- if (queryObject.length === 0) return url;
26
- var params = queryObject.map(function (i) {
27
- return "".concat(i, "=").concat(query[i]);
28
- });
29
- return "".concat(url).concat(url.includes("?") ? "&" : '?').concat(params.join("&"));
30
- };
31
- export var getType = function (data) {
32
- var type = typeof data;
33
- if (data === null) {
34
- return "null";
35
- } else if (type === "object") {
36
- var key = Object.prototype.toString.call(data);
37
- return types[key];
38
- }
39
- return type;
40
- };
41
- export var getTypeByList = function (data, whiteList) {
42
- if (whiteList === void 0) {
43
- whiteList = [];
44
- }
45
- var __type = getType(data);
46
- return whiteList.indexOf(__type) > 0;
47
- };
48
- export default {
49
- randomNum: randomNum,
50
- urlSplit: urlSplit,
51
- urlJoin: urlJoin,
52
- getType: getType,
53
- getTypeByList: getTypeByList
54
- };
1
+ import { types } from "./index.js";
2
+ export var randomNum = function (min, max, bool) {
3
+ if (bool === void 0) { bool = false; }
4
+ return Math.floor(Math.random() * (max - min + (bool ? 1 : 0)) + min);
5
+ };
6
+ export var urlSplit = function (url) {
7
+ var result = {};
8
+ if (!url.includes("?")) {
9
+ return result;
10
+ }
11
+ var params = url.split("?")[1].split("&");
12
+ params.forEach(function (i) {
13
+ var key = i.split("=")[0];
14
+ result[key] = i.split("=")[1];
15
+ });
16
+ return result;
17
+ };
18
+ export var urlJoin = function (url, query) {
19
+ if (query === void 0) { query = {}; }
20
+ var queryObject = Object.keys(query);
21
+ if (queryObject.length === 0)
22
+ return url;
23
+ var params = queryObject.map(function (i) { return "".concat(i, "=").concat(query[i]); });
24
+ return "".concat(url).concat(url.includes("?") ? "&" : '?').concat(params.join("&"));
25
+ };
26
+ export var getType = function (data) {
27
+ var type = typeof data;
28
+ if (data === null) {
29
+ return "null";
30
+ }
31
+ else if (type === "object") {
32
+ var key = Object.prototype.toString.call(data);
33
+ return types[key];
34
+ }
35
+ return type;
36
+ };
37
+ export var getTypeByList = function (data, whiteList) {
38
+ if (whiteList === void 0) { whiteList = []; }
39
+ var __type = getType(data);
40
+ return whiteList.indexOf(__type) > 0;
41
+ };
42
+ export default {
43
+ randomNum: randomNum,
44
+ urlSplit: urlSplit,
45
+ urlJoin: urlJoin,
46
+ getType: getType,
47
+ getTypeByList: getTypeByList,
48
+ };
@@ -1,19 +1,12 @@
1
- export var createElement = function (_a) {
2
- var _b, _c;
3
- var ele = _a.ele,
4
- style = _a.style,
5
- attr = _a.attr,
6
- parent = _a.parent;
7
- var element = ele instanceof HTMLElement ? ele : document.createElement(ele !== null && ele !== void 0 ? ele : 'div');
8
- style && ((_b = Object.keys(style)) === null || _b === void 0 ? void 0 : _b.forEach(function (key) {
9
- return element.style[key] = style[key];
10
- }));
11
- attr && ((_c = Object.keys(style)) === null || _c === void 0 ? void 0 : _c.forEach(function (key) {
12
- return element[key] = attr[key];
13
- }));
14
- parent && parent.appendChild(element);
15
- return element;
16
- };
17
- export default {
18
- createElement: createElement
19
- };
1
+ export var createElement = function (_a) {
2
+ var _b, _c;
3
+ var ele = _a.ele, style = _a.style, attr = _a.attr, parent = _a.parent;
4
+ var element = ele instanceof HTMLElement ? ele : document.createElement(ele !== null && ele !== void 0 ? ele : 'div');
5
+ style && ((_b = Object.keys(style)) === null || _b === void 0 ? void 0 : _b.forEach(function (key) { return element.style[key] = style[key]; }));
6
+ attr && ((_c = Object.keys(style)) === null || _c === void 0 ? void 0 : _c.forEach(function (key) { return element[key] = attr[key]; }));
7
+ parent && parent.appendChild(element);
8
+ return element;
9
+ };
10
+ export default {
11
+ createElement: createElement
12
+ };
package/dist/esm/event.js CHANGED
@@ -1,41 +1,45 @@
1
- export var addHandler = function (ele, type, handler) {
2
- if (ele.addEventListener) {
3
- ele.addEventListener(type, handler, false);
4
- } else {
5
- ele["on" + type] = handler;
6
- }
7
- };
8
- export var stopBubble = function (event) {
9
- event = event || window.event;
10
- if (event.stopPropagation) {
11
- event.stopPropagation();
12
- } else {
13
- event.cancelBubble = false;
14
- }
15
- };
16
- export var stopDefault = function (event) {
17
- event = event || window.event;
18
- if (event.preventDefault) {
19
- event.preventDefault();
20
- } else {
21
- event.returnValue = false;
22
- }
23
- };
24
- export var removeHandler = function (ele, type, handler) {
25
- if (ele.removeEventListener) {
26
- ele.removeEventListener(type, handler, false);
27
- } else {
28
- ele["on" + type] = null;
29
- }
30
- };
31
- export var dispatchEvent = function (ele, data) {
32
- var evts = new Event(data);
33
- ele.dispatchEvent(evts);
34
- };
35
- export default {
36
- addHandler: addHandler,
37
- stopBubble: stopBubble,
38
- stopDefault: stopDefault,
39
- removeHandler: removeHandler,
40
- dispatchEvent: dispatchEvent
41
- };
1
+ export var addHandler = function (ele, type, handler) {
2
+ if (ele.addEventListener) {
3
+ ele.addEventListener(type, handler, false);
4
+ }
5
+ else {
6
+ ele["on" + type] = handler;
7
+ }
8
+ };
9
+ export var stopBubble = function (event) {
10
+ event = event || window.event;
11
+ if (event.stopPropagation) {
12
+ event.stopPropagation();
13
+ }
14
+ else {
15
+ event.cancelBubble = false;
16
+ }
17
+ };
18
+ export var stopDefault = function (event) {
19
+ event = event || window.event;
20
+ if (event.preventDefault) {
21
+ event.preventDefault();
22
+ }
23
+ else {
24
+ event.returnValue = false;
25
+ }
26
+ };
27
+ export var removeHandler = function (ele, type, handler) {
28
+ if (ele.removeEventListener) {
29
+ ele.removeEventListener(type, handler, false);
30
+ }
31
+ else {
32
+ ele["on" + type] = null;
33
+ }
34
+ };
35
+ export var dispatchEvent = function (ele, data) {
36
+ var evts = new Event(data);
37
+ ele.dispatchEvent(evts);
38
+ };
39
+ export default {
40
+ addHandler: addHandler,
41
+ stopBubble: stopBubble,
42
+ stopDefault: stopDefault,
43
+ removeHandler: removeHandler,
44
+ dispatchEvent: dispatchEvent,
45
+ };
@@ -1,64 +1,59 @@
1
- var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
2
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
- if (ar || !(i in from)) {
4
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
- ar[i] = from[i];
6
- }
7
- }
8
- return to.concat(ar || Array.prototype.slice.call(from));
9
- };
10
- var _this = this;
11
- export var throttle = function (fn, time) {
12
- var _timer = null;
13
- return function () {
14
- var args = [];
15
- for (var _i = 0; _i < arguments.length; _i++) {
16
- args[_i] = arguments[_i];
17
- }
18
- if (_timer) return;
19
- _timer = setTimeout(function () {
20
- fn.call.apply(fn, __spreadArray([_this], args, false));
21
- _timer = null;
22
- }, time);
23
- };
24
- };
25
- export var debounce = function (fn, time) {
26
- var _timer = null;
27
- return function () {
28
- var args = [];
29
- for (var _i = 0; _i < arguments.length; _i++) {
30
- args[_i] = arguments[_i];
31
- }
32
- if (_timer) {
33
- clearTimeout(_timer);
34
- _timer = null;
35
- }
36
- _timer = setTimeout(function () {
37
- fn.call.apply(fn, __spreadArray([_this], args, false));
38
- }, time);
39
- };
40
- };
41
- export var defer = function () {
42
- var resolve, reject;
43
- return {
44
- promise: new Promise(function (_resolve, _reject) {
45
- resolve = _resolve;
46
- reject = _reject;
47
- }),
48
- resolve: resolve,
49
- reject: reject
50
- };
51
- };
52
- export var catchAwait = function (defer) {
53
- return defer.then(function (res) {
54
- return [null, res];
55
- }).catch(function (err) {
56
- return [err];
57
- });
58
- };
59
- export default {
60
- throttle: throttle,
61
- debounce: debounce,
62
- defer: defer,
63
- catchAwait: catchAwait
64
- };
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ var _this = this;
11
+ export var throttle = function (fn, time) {
12
+ var _timer = null;
13
+ return function () {
14
+ var args = [];
15
+ for (var _i = 0; _i < arguments.length; _i++) {
16
+ args[_i] = arguments[_i];
17
+ }
18
+ if (_timer)
19
+ return;
20
+ _timer = setTimeout(function () {
21
+ fn.call.apply(fn, __spreadArray([_this], args, false));
22
+ _timer = null;
23
+ }, time);
24
+ };
25
+ };
26
+ export var debounce = function (fn, time) {
27
+ var _timer = null;
28
+ return function () {
29
+ var args = [];
30
+ for (var _i = 0; _i < arguments.length; _i++) {
31
+ args[_i] = arguments[_i];
32
+ }
33
+ if (_timer) {
34
+ clearTimeout(_timer);
35
+ _timer = null;
36
+ }
37
+ _timer = setTimeout(function () {
38
+ fn.call.apply(fn, __spreadArray([_this], args, false));
39
+ }, time);
40
+ };
41
+ };
42
+ export var defer = function () {
43
+ var resolve, reject;
44
+ return {
45
+ promise: new Promise(function (_resolve, _reject) {
46
+ resolve = _resolve;
47
+ reject = _reject;
48
+ }),
49
+ resolve: resolve,
50
+ reject: reject
51
+ };
52
+ };
53
+ export var catchAwait = function (defer) { return defer.then(function (res) { return [null, res]; }).catch(function (err) { return [err]; }); };
54
+ export default {
55
+ throttle: throttle,
56
+ debounce: debounce,
57
+ defer: defer,
58
+ catchAwait: catchAwait,
59
+ };
@@ -8,6 +8,8 @@ export * from "./types.js";
8
8
  export * from "./request.js";
9
9
  export * from "./event.js";
10
10
  export * from "./storage.js";
11
+ export * from "event-message-center";
12
+ export * from "task-queue-lib";
11
13
  declare const _default: {
12
14
  setStorage: (key: string, val: any) => void;
13
15
  getStorage: (key: string) => any;
package/dist/esm/index.js CHANGED
@@ -1,30 +1,35 @@
1
- var __assign = this && this.__assign || function () {
2
- __assign = Object.assign || function (t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
6
- }
7
- return t;
8
- };
9
- return __assign.apply(this, arguments);
10
- };
11
- export * from "./object.js";
12
- export * from "./base.js";
13
- export * from "./array.js";
14
- export * from "./function.js";
15
- export * from "./element.js";
16
- export * from "./static.js";
17
- export * from "./types.js";
18
- export * from "./request.js";
19
- export * from "./event.js";
20
- export * from "./storage.js";
21
- import object from "./object.js";
22
- import base from "./base.js";
23
- import array from "./array.js";
24
- import __function from "./function.js";
25
- import element from "./element.js";
26
- import __static from "./static.js";
27
- import request from "./request.js";
28
- import event from "./event.js";
29
- import storage from "./storage.js";
30
- export default __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, object), base), array), __function), element), __static), request), event), storage);
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ export * from "./object.js";
13
+ export * from "./base.js";
14
+ export * from "./array.js";
15
+ export * from "./function.js";
16
+ export * from "./element.js";
17
+ export * from "./static.js";
18
+ export * from "./types.js";
19
+ export * from "./request.js";
20
+ export * from "./event.js";
21
+ export * from "./storage.js";
22
+ export * from "event-message-center";
23
+ export * from "task-queue-lib";
24
+ import object from "./object.js";
25
+ import base from "./base.js";
26
+ import array from "./array.js";
27
+ import __function from "./function.js";
28
+ import element from "./element.js";
29
+ import __static from "./static.js";
30
+ import request from "./request.js";
31
+ import event from "./event.js";
32
+ import storage from "./storage.js";
33
+ import eventMessageCenter from "event-message-center";
34
+ import taskQueueLib from "task-queue-lib";
35
+ export default __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, object), base), array), __function), element), __static), request), event), storage), eventMessageCenter), taskQueueLib);