utils-lib-js 1.7.18 → 1.7.19

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.
Files changed (52) hide show
  1. package/README.en.md +337 -319
  2. package/README.md +23 -1
  3. package/dist/bundle/animate.d.ts +25 -0
  4. package/dist/bundle/array.d.ts +1 -1
  5. package/dist/bundle/base.d.ts +2 -1
  6. package/dist/bundle/element.d.ts +1 -1
  7. package/dist/bundle/event.d.ts +1 -1
  8. package/dist/bundle/function.d.ts +1 -1
  9. package/dist/bundle/index.d.ts +7 -0
  10. package/dist/bundle/index.js +1 -1
  11. package/dist/bundle/log.d.ts +1 -1
  12. package/dist/bundle/object.d.ts +1 -1
  13. package/dist/bundle/request.d.ts +1 -1
  14. package/dist/bundle/types.d.ts +9 -0
  15. package/dist/cjs/animate.d.ts +25 -0
  16. package/dist/cjs/array.d.ts +1 -1
  17. package/dist/cjs/base.d.ts +2 -1
  18. package/dist/cjs/element.d.ts +1 -1
  19. package/dist/cjs/event.d.ts +1 -1
  20. package/dist/cjs/function.d.ts +1 -1
  21. package/dist/cjs/index.d.ts +7 -0
  22. package/dist/cjs/index.js +143 -64
  23. package/dist/cjs/log.d.ts +1 -1
  24. package/dist/cjs/object.d.ts +1 -1
  25. package/dist/cjs/request.d.ts +1 -1
  26. package/dist/cjs/types.d.ts +9 -0
  27. package/dist/esm/animate.d.ts +25 -0
  28. package/dist/esm/array.d.ts +1 -1
  29. package/dist/esm/base.d.ts +2 -1
  30. package/dist/esm/element.d.ts +1 -1
  31. package/dist/esm/event.d.ts +1 -1
  32. package/dist/esm/function.d.ts +1 -1
  33. package/dist/esm/index.d.ts +7 -0
  34. package/dist/esm/index.js +138 -65
  35. package/dist/esm/log.d.ts +1 -1
  36. package/dist/esm/object.d.ts +1 -1
  37. package/dist/esm/request.d.ts +1 -1
  38. package/dist/esm/types.d.ts +9 -0
  39. package/dist/umd/animate.d.ts +25 -0
  40. package/dist/umd/array.d.ts +1 -1
  41. package/dist/umd/base.d.ts +2 -1
  42. package/dist/umd/element.d.ts +1 -1
  43. package/dist/umd/event.d.ts +1 -1
  44. package/dist/umd/function.d.ts +1 -1
  45. package/dist/umd/index.d.ts +7 -0
  46. package/dist/umd/index.js +143 -64
  47. package/dist/umd/log.d.ts +1 -1
  48. package/dist/umd/object.d.ts +1 -1
  49. package/dist/umd/request.d.ts +1 -1
  50. package/dist/umd/types.d.ts +9 -0
  51. package/package.json +49 -49
  52. package/pnpm-lock.yaml +0 -423
package/dist/umd/index.js CHANGED
@@ -68,6 +68,69 @@
68
68
  return to.concat(ar || Array.prototype.slice.call(from));
69
69
  }
70
70
 
71
+ exports.types = void 0;
72
+ (function (types) {
73
+ types["[object Array]"] = "array";
74
+ types["[object Object]"] = "object";
75
+ types["[object Function]"] = "function";
76
+ types["[object Set]"] = "set";
77
+ types["[object Map]"] = "map";
78
+ types["[object WeakMap]"] = "weakMap";
79
+ types["[object WeakSet]"] = "weakSet";
80
+ types["[object Date]"] = "date";
81
+ types["[object RegExp]"] = "regExp";
82
+ types["[object Math]"] = "math";
83
+ })(exports.types || (exports.types = {}));
84
+ var __static = { types: exports.types };
85
+
86
+ var randomNum = function (min, max, bool) {
87
+ if (bool === void 0) { bool = false; }
88
+ return Math.floor(Math.random() * (max - min + (bool ? 1 : 0)) + min);
89
+ };
90
+ var urlSplit = function (url) {
91
+ var result = {};
92
+ if (!url.includes("?")) {
93
+ return result;
94
+ }
95
+ var params = url.split("?")[1].split("&");
96
+ params.forEach(function (i) {
97
+ var key = i.split("=")[0];
98
+ result[key] = i.split("=")[1];
99
+ });
100
+ return result;
101
+ };
102
+ var urlJoin = function (url, query) {
103
+ if (query === void 0) { query = {}; }
104
+ var queryObject = Object.keys(query);
105
+ if (queryObject.length === 0)
106
+ return url;
107
+ var params = queryObject.map(function (i) { return "".concat(i, "=").concat(query[i]); });
108
+ return "".concat(url).concat(url.includes("?") ? "&" : '?').concat(params.join("&"));
109
+ };
110
+ var getType = function (data) {
111
+ var type = typeof data;
112
+ if (data === null) {
113
+ return "null";
114
+ }
115
+ else if (type === "object") {
116
+ var key = Object.prototype.toString.call(data);
117
+ return exports.types[key];
118
+ }
119
+ return type;
120
+ };
121
+ var getTypeByList = function (data, whiteList) {
122
+ if (whiteList === void 0) { whiteList = []; }
123
+ var __type = getType(data);
124
+ return whiteList.indexOf(__type) > 0;
125
+ };
126
+ var base = {
127
+ randomNum: randomNum,
128
+ urlSplit: urlSplit,
129
+ urlJoin: urlJoin,
130
+ getType: getType,
131
+ getTypeByList: getTypeByList,
132
+ };
133
+
71
134
  var getValue = function (object, key, defaultValue) {
72
135
  if (defaultValue === void 0) { defaultValue = ''; }
73
136
  var paths = key.split('.');
@@ -237,54 +300,6 @@
237
300
  isWindow: isWindow,
238
301
  };
239
302
 
240
- var randomNum = function (min, max, bool) {
241
- if (bool === void 0) { bool = false; }
242
- return Math.floor(Math.random() * (max - min + (bool ? 1 : 0)) + min);
243
- };
244
- var urlSplit = function (url) {
245
- var result = {};
246
- if (!url.includes("?")) {
247
- return result;
248
- }
249
- var params = url.split("?")[1].split("&");
250
- params.forEach(function (i) {
251
- var key = i.split("=")[0];
252
- result[key] = i.split("=")[1];
253
- });
254
- return result;
255
- };
256
- var urlJoin = function (url, query) {
257
- if (query === void 0) { query = {}; }
258
- var queryObject = Object.keys(query);
259
- if (queryObject.length === 0)
260
- return url;
261
- var params = queryObject.map(function (i) { return "".concat(i, "=").concat(query[i]); });
262
- return "".concat(url).concat(url.includes("?") ? "&" : '?').concat(params.join("&"));
263
- };
264
- var getType = function (data) {
265
- var type = typeof data;
266
- if (data === null) {
267
- return "null";
268
- }
269
- else if (type === "object") {
270
- var key = Object.prototype.toString.call(data);
271
- return exports.types[key];
272
- }
273
- return type;
274
- };
275
- var getTypeByList = function (data, whiteList) {
276
- if (whiteList === void 0) { whiteList = []; }
277
- var __type = getType(data);
278
- return whiteList.indexOf(__type) > 0;
279
- };
280
- var base = {
281
- randomNum: randomNum,
282
- urlSplit: urlSplit,
283
- urlJoin: urlJoin,
284
- getType: getType,
285
- getTypeByList: getTypeByList,
286
- };
287
-
288
303
  var arrayRandom = function (arr) { return arr.sort(function () { return Math.random() - 0.5; }); };
289
304
  var arrayUniq = function (arr) { return Array.from(new Set(arr)); };
290
305
  var arrayDemote = function (arr, result) {
@@ -365,21 +380,6 @@
365
380
  createElement: createElement
366
381
  };
367
382
 
368
- exports.types = void 0;
369
- (function (types) {
370
- types["[object Array]"] = "array";
371
- types["[object Object]"] = "object";
372
- types["[object Function]"] = "function";
373
- types["[object Set]"] = "set";
374
- types["[object Map]"] = "map";
375
- types["[object WeakMap]"] = "weakMap";
376
- types["[object WeakSet]"] = "weakSet";
377
- types["[object Date]"] = "date";
378
- types["[object RegExp]"] = "regExp";
379
- types["[object Math]"] = "math";
380
- })(exports.types || (exports.types = {}));
381
- var __static = { types: exports.types };
382
-
383
383
  var httpRequest, httpsRequest, parse, CustomAbortController;
384
384
  if (typeof require !== "undefined") {
385
385
  CustomAbortController = require("abort-controller");
@@ -699,6 +699,79 @@
699
699
  logLoop: logLoop
700
700
  };
701
701
 
702
+ var AnimateFrame = (function () {
703
+ function AnimateFrame(fn) {
704
+ this.fn = fn;
705
+ this.id = null;
706
+ this.duration = Infinity;
707
+ this.isActive = false;
708
+ }
709
+ AnimateFrame.prototype.start = function (duration) {
710
+ if (this.isActive)
711
+ return;
712
+ this.duration = duration !== null && duration !== void 0 ? duration : Infinity;
713
+ this.isActive = true;
714
+ this.animate();
715
+ };
716
+ AnimateFrame.prototype.stop = function () {
717
+ this.isActive = false;
718
+ cancelAnimationFrame(this.id);
719
+ };
720
+ AnimateFrame.prototype.animate = function (timer) {
721
+ if (timer === void 0) { timer = 0; }
722
+ if (this.isActive && this.duration-- > 0) {
723
+ this.fn(timer);
724
+ this.id = requestAnimationFrame(this.animate.bind(this));
725
+ }
726
+ };
727
+ return AnimateFrame;
728
+ }());
729
+ function quadraticBezier(_x, _y, t) {
730
+ var mt = 1 - t;
731
+ var t2 = t * t;
732
+ var x = 2 * mt * t * _x + t2;
733
+ var y = 2 * mt * t * _y + t2;
734
+ return [x, y];
735
+ }
736
+ function cubicBezier(_x1, _y1, _x2, _y2, t) {
737
+ var cx = 3 * _x1;
738
+ var cy = 3 * _y1;
739
+ var bx = 3 * (_x2 - _x1) - cx;
740
+ var by = 3 * (_y2 - _y1) - cy;
741
+ var ax = 1 - cx - bx;
742
+ var ay = 1 - cy - by;
743
+ var x = ax * Math.pow(t, 3) + bx * Math.pow(t, 2) + cx * t;
744
+ var y = ay * Math.pow(t, 3) + by * Math.pow(t, 2) + cy * t;
745
+ return [x, y];
746
+ }
747
+ function factorial(n) {
748
+ if (n === 0 || n === 1) {
749
+ return 1;
750
+ }
751
+ return n * factorial(n - 1);
752
+ }
753
+ function combination(n, k) {
754
+ return factorial(n) / (factorial(k) * factorial(n - k));
755
+ }
756
+ function NBezier(points, t) {
757
+ var n = points.length - 1;
758
+ var result = [0, 0];
759
+ for (var i = 0; i <= n; i++) {
760
+ var coefficient = combination(n, i) * Math.pow(1 - t, n - i) * Math.pow(t, i);
761
+ result[0] += coefficient * points[i][0];
762
+ result[1] += coefficient * points[i][1];
763
+ }
764
+ return result;
765
+ }
766
+ var animate = {
767
+ AnimateFrame: AnimateFrame,
768
+ quadraticBezier: quadraticBezier,
769
+ cubicBezier: cubicBezier,
770
+ factorial: factorial,
771
+ combination: combination,
772
+ NBezier: NBezier,
773
+ };
774
+
702
775
  var MessageCenter = (function () {
703
776
  function MessageCenter(options) {
704
777
  if (options === void 0) { options = {}; }
@@ -1021,9 +1094,11 @@
1021
1094
  };
1022
1095
  };
1023
1096
 
1024
- var index = __assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1({}, object), base), array), __function), element), __static), request), event), storage), log), { eventMessageCenter: MessageCenter, taskQueueLib: TaskQueue });
1097
+ var index = __assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1({}, object), base), array), __function), element), __static), request), event), storage), log), animate), { eventMessageCenter: MessageCenter, taskQueueLib: TaskQueue });
1025
1098
 
1099
+ exports.AnimateFrame = AnimateFrame;
1026
1100
  exports.MessageCenter = MessageCenter;
1101
+ exports.NBezier = NBezier;
1027
1102
  exports.Request = Request;
1028
1103
  exports.TaskQueue = TaskQueue;
1029
1104
  exports.addHandler = addHandler;
@@ -1034,9 +1109,11 @@
1034
1109
  exports.classDecorator = classDecorator;
1035
1110
  exports.clearStorage = clearStorage;
1036
1111
  exports.cloneDeep = cloneDeep;
1112
+ exports.combination = combination;
1037
1113
  exports.createElement = createElement;
1038
1114
  exports.createObject = createObject;
1039
1115
  exports.createObjectVariable = createObjectVariable;
1116
+ exports.cubicBezier = cubicBezier;
1040
1117
  exports.debounce = debounce;
1041
1118
  exports.decoratorMessageCenter = decoratorMessageCenter;
1042
1119
  exports.decoratorTaskQueue = decoratorTaskQueue;
@@ -1044,6 +1121,7 @@
1044
1121
  exports.defer = defer;
1045
1122
  exports.dispatchEvent = dispatchEvent;
1046
1123
  exports.enumInversion = enumInversion;
1124
+ exports.factorial = factorial;
1047
1125
  exports.getInstance = getInstance;
1048
1126
  exports.getStorage = getStorage;
1049
1127
  exports.getType = getType;
@@ -1057,6 +1135,7 @@
1057
1135
  exports.logOneLine = logOneLine;
1058
1136
  exports.messageCenter = messageCenter;
1059
1137
  exports.mixIn = mixIn;
1138
+ exports.quadraticBezier = quadraticBezier;
1060
1139
  exports.randomNum = randomNum;
1061
1140
  exports.removeHandler = removeHandler;
1062
1141
  exports.setStorage = setStorage;
package/dist/umd/log.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILogOneLine, ILogLoop } from "./index";
1
+ import { ILogOneLine, ILogLoop } from "./types";
2
2
  export declare const logOneLine: ILogOneLine;
3
3
  export declare const logLoop: ILogLoop;
4
4
  declare const _default: {
@@ -1,4 +1,4 @@
1
- import { IGetValue, ISetValue, IMixIn, ICloneDeep, ICreateObjectVariable, IEnumInversion, IInherit, ICreateObject, IGetInstance, IClassDecorator, IStringToJson, IJsonToString } from "./index";
1
+ import { IGetValue, ISetValue, IMixIn, ICloneDeep, ICreateObjectVariable, IEnumInversion, IInherit, ICreateObject, IGetInstance, IClassDecorator, IStringToJson, IJsonToString } from "./types";
2
2
  export declare const getValue: IGetValue;
3
3
  export declare const setValue: ISetValue;
4
4
  export declare const mixIn: IMixIn;
@@ -1,4 +1,4 @@
1
- import { IRequest, IRequestBase, IRequestInit, IInterceptors, IUrl, IObject, IRequestBody, IRequestOptions, IRequestBaseFn, IEnv } from "./index";
1
+ import { IRequest, IRequestBase, IRequestInit, IInterceptors, IUrl, IObject, IRequestBody, IRequestOptions, IRequestBaseFn, IEnv } from "./types";
2
2
  declare class Interceptors implements IInterceptors {
3
3
  private requestSuccess;
4
4
  private responseSuccess;
@@ -109,4 +109,13 @@ export type IRequest = {
109
109
  HEAD: IRequestFn;
110
110
  PATCH: IRequestFn;
111
111
  } & IRequestBase;
112
+ export type IAnimateFrame = {
113
+ id: number | null;
114
+ duration: number;
115
+ isActive: boolean;
116
+ fn(timer: number): void;
117
+ start(duration: number): void;
118
+ stop(): void;
119
+ animate(timer: number): void;
120
+ };
112
121
  export {};
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "name": "utils-lib-js",
3
- "version": "1.7.18",
4
- "description": "JavaScript工具函数,封装的一些常用的js函数",
5
- "main": "./dist/cjs/index.js",
6
- "types": "./dist/cjs/index.d.ts",
7
- "module": "./dist/esm/index.js",
8
- "type": "module",
9
- "exports": {
10
- "import": "./dist/esm/index.js",
11
- "require": "./dist/cjs/index.js"
12
- },
13
- "scripts": {
14
- "debug": "start cmd /k pnpm run build:hot & pnpm run node:hot",
15
- "node:hot": "nodemon example.js --watch example.js",
16
- "build:hot": "pnpm rollup -c --watch",
17
- "build": "pnpm run rollup:build && pnpm run commonjs",
18
- "rollup:build": "rm -fr dist && pnpm rollup -c",
19
- "build:publish": "pnpm run build && pnpm run publish",
20
- "commonjs": "cp ./commonjs.json dist/cjs/package.json"
21
- },
22
- "repository": {
23
- "type": "git",
24
- "url": "https://gitee.com/DieHunter/utils-lib-js.git"
25
- },
26
- "keywords": [
27
- "utils",
28
- "tools",
29
- "lib"
30
- ],
31
- "author": "",
32
- "license": "ISC",
33
- "devDependencies": {
34
- "@rollup/plugin-alias": "^4.0.3",
35
- "@rollup/plugin-node-resolve": "^15.0.1",
36
- "@rollup/plugin-typescript": "^11.0.0",
37
- "@types/node": "^18.7.15",
38
- "rollup": "^3.20.2",
39
- "rollup-plugin-terser": "^7.0.2",
40
- "tslib": "^2.5.0",
41
- "typescript": "^4.9.0"
42
- },
43
- "dependencies": {
44
- "abort-controller": "^3.0.0",
45
- "event-message-center": "^1.3.2",
46
- "task-queue-lib": "^1.2.0"
47
- },
48
- "umdModuleName": "UtilsLib"
49
- }
1
+ {
2
+ "name": "utils-lib-js",
3
+ "version": "1.7.19",
4
+ "description": "JavaScript工具函数,封装的一些常用的js函数",
5
+ "main": "./dist/cjs/index.js",
6
+ "types": "./dist/cjs/index.d.ts",
7
+ "module": "./dist/esm/index.js",
8
+ "type": "module",
9
+ "exports": {
10
+ "import": "./dist/esm/index.js",
11
+ "require": "./dist/cjs/index.js"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://gitee.com/DieHunter/utils-lib-js.git"
16
+ },
17
+ "keywords": [
18
+ "utils",
19
+ "tools",
20
+ "lib"
21
+ ],
22
+ "author": "",
23
+ "license": "ISC",
24
+ "devDependencies": {
25
+ "@rollup/plugin-alias": "^4.0.3",
26
+ "@rollup/plugin-node-resolve": "^15.0.1",
27
+ "@rollup/plugin-typescript": "^11.0.0",
28
+ "@types/node": "^18.7.15",
29
+ "rollup": "^3.20.2",
30
+ "rollup-plugin-terser": "^7.0.2",
31
+ "tslib": "^2.5.0",
32
+ "typescript": "^4.9.0"
33
+ },
34
+ "dependencies": {
35
+ "abort-controller": "^3.0.0",
36
+ "event-message-center": "^1.3.2",
37
+ "task-queue-lib": "^1.2.0"
38
+ },
39
+ "umdModuleName": "UtilsLib",
40
+ "scripts": {
41
+ "debug": "start cmd /k pnpm run build:hot & pnpm run node:hot",
42
+ "node:hot": "nodemon example.js --watch example.js",
43
+ "build:hot": "pnpm rollup -c --watch",
44
+ "build": "pnpm run rollup:build && pnpm run commonjs",
45
+ "rollup:build": "rm -fr dist && pnpm rollup -c",
46
+ "build:publish": "pnpm run build && pnpm run publish",
47
+ "commonjs": "cp ./commonjs.json dist/cjs/package.json"
48
+ }
49
+ }