@vope/utils 1.3.1 → 1.4.1

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 (55) hide show
  1. package/cjs/clamp.js +29 -12
  2. package/cjs/classnames.js +34 -20
  3. package/cjs/compare/version.js +35 -18
  4. package/cjs/compare/weak-equal.js +49 -36
  5. package/cjs/convert/json.js +25 -15
  6. package/cjs/convert/object.js +26 -16
  7. package/cjs/convert/strings.js +25 -9
  8. package/cjs/encoding.js +64 -51
  9. package/cjs/index.js +76 -53
  10. package/cjs/input-regex.js +24 -5
  11. package/cjs/is/class.js +40 -23
  12. package/cjs/is/empty.js +34 -10
  13. package/cjs/is/null.js +24 -7
  14. package/cjs/memory/basic.js +159 -139
  15. package/cjs/memory/list.js +39 -17
  16. package/cjs/memory/power.js +40 -16
  17. package/cjs/memory/type.d.js +16 -0
  18. package/cjs/once.js +26 -13
  19. package/cjs/power/decon.js +38 -26
  20. package/cjs/rotate/angle.js +34 -12
  21. package/cjs/rotate/rad.js +29 -14
  22. package/cjs/union.js +41 -26
  23. package/cjs/url/join.js +27 -11
  24. package/cjs/url/params.js +41 -33
  25. package/cjs/wait.js +23 -5
  26. package/lib/clamp.js +7 -10
  27. package/lib/classnames.js +12 -18
  28. package/lib/compare/version.js +13 -16
  29. package/lib/compare/weak-equal.js +27 -34
  30. package/lib/convert/json.js +3 -13
  31. package/lib/convert/object.js +4 -14
  32. package/lib/convert/strings.js +3 -7
  33. package/lib/encoding.js +42 -49
  34. package/lib/index.js +24 -24
  35. package/lib/input-regex.js +2 -3
  36. package/lib/is/class.js +18 -21
  37. package/lib/is/empty.js +3 -6
  38. package/lib/is/null.js +2 -5
  39. package/lib/memory/basic.js +129 -135
  40. package/lib/memory/list.js +8 -12
  41. package/lib/memory/power.js +9 -11
  42. package/lib/memory/type.d.js +1 -0
  43. package/lib/once.js +4 -11
  44. package/lib/power/decon.js +16 -24
  45. package/lib/rotate/angle.js +2 -7
  46. package/lib/rotate/rad.js +7 -12
  47. package/lib/union.js +20 -24
  48. package/lib/url/join.js +5 -9
  49. package/lib/url/params.js +19 -31
  50. package/lib/wait.js +1 -3
  51. package/package.json +6 -8
  52. package/types/index.d.ts +0 -1
  53. package/cjs/api.js +0 -56
  54. package/lib/api.js +0 -48
  55. package/types/api.d.ts +0 -19
package/cjs/clamp.js CHANGED
@@ -1,14 +1,31 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * 获取中间数
5
- */
6
- exports.default = (value, min, max) => {
7
- if (min > max) {
8
- // js位运算的范围为(-2^32,2^32),超出会产生溢出
9
- const swap = max;
10
- max = min;
11
- min = swap;
12
- }
13
- return Math.min(max, Math.max(min, value));
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var clamp_exports = {};
20
+ __export(clamp_exports, {
21
+ default: () => clamp_default
22
+ });
23
+ module.exports = __toCommonJS(clamp_exports);
24
+ var clamp_default = (value, min, max) => {
25
+ if (min > max) {
26
+ const swap = max;
27
+ max = min;
28
+ min = swap;
29
+ }
30
+ return Math.min(max, Math.max(min, value));
14
31
  };
package/cjs/classnames.js CHANGED
@@ -1,22 +1,36 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const add = (a, b) => a
4
- ? a + '\u0020' + b
5
- : b;
6
- /**
7
- * 拼接多个class
8
- */
9
- exports.default = (...list) => list.reduce((caches, data) => {
10
- if (typeof data === 'string') {
11
- data && (caches = add(caches, data));
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var classnames_exports = {};
20
+ __export(classnames_exports, {
21
+ default: () => classnames_default
22
+ });
23
+ module.exports = __toCommonJS(classnames_exports);
24
+ const add = (a, b) => a ? a + " " + b : b;
25
+ var classnames_default = (...list) => list.reduce((caches, data) => {
26
+ if (typeof data === "string") {
27
+ data && (caches = add(caches, data));
28
+ } else if (Array.isArray(data)) {
29
+ data.forEach((value) => value && (caches = add(caches, value)));
30
+ } else if (data) {
31
+ for (const key in data) {
32
+ key && data[key] && (caches = add(caches, key));
12
33
  }
13
- else if (Array.isArray(data)) {
14
- data.forEach((value) => value && (caches = add(caches, value)));
15
- }
16
- else if (data) {
17
- for (const key in data) {
18
- key && data[key] && (caches = add(caches, key));
19
- }
20
- }
21
- return caches;
22
- }, '');
34
+ }
35
+ return caches;
36
+ }, "");
@@ -1,21 +1,38 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const CHAR = '.';
4
- /**
5
- * 版本号大小比较
6
- * @description from < to = 1,from === to = 0,from > to = -1
7
- */
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var version_exports = {};
20
+ __export(version_exports, {
21
+ default: () => version_default
22
+ });
23
+ module.exports = __toCommonJS(version_exports);
24
+ const CHAR = ".";
8
25
  const compareVersion = (from, to) => {
9
- const froms = from.split(CHAR);
10
- const tos = to.split(CHAR);
11
- for (let i = 0, max = Math.max(froms.length, tos.length); i < max; i++) {
12
- const fromV = +froms[i] || 0;
13
- const toV = +tos[i] || 0;
14
- if (fromV > toV)
15
- return -1;
16
- if (fromV < toV)
17
- return 1;
18
- }
19
- return 0;
26
+ const froms = from.split(CHAR);
27
+ const tos = to.split(CHAR);
28
+ for (let i = 0, max = Math.max(froms.length, tos.length); i < max; i++) {
29
+ const fromV = +froms[i] || 0;
30
+ const toV = +tos[i] || 0;
31
+ if (fromV > toV)
32
+ return -1;
33
+ if (fromV < toV)
34
+ return 1;
35
+ }
36
+ return 0;
20
37
  };
21
- exports.default = compareVersion;
38
+ var version_default = compareVersion;
@@ -1,41 +1,54 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * 深度相等性比较(弱比较)
5
- */
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var weak_equal_exports = {};
20
+ __export(weak_equal_exports, {
21
+ default: () => weak_equal_default
22
+ });
23
+ module.exports = __toCommonJS(weak_equal_exports);
6
24
  const deepWeakEqual = (from, to) => {
7
- if (typeof from !== 'object'
8
- || from === null
9
- || typeof to !== 'object'
10
- || to === null)
11
- return from === to;
12
- if (Array.isArray(from) && Array.isArray(to)) {
13
- if (from.length !== to.length)
14
- return false;
15
- return !from.some((t1, index) => {
16
- if (!deepWeakEqual(t1, to[index])) {
17
- return true;
18
- }
19
- });
25
+ if (typeof from !== "object" || from === null || typeof to !== "object" || to === null)
26
+ return from === to;
27
+ if (Array.isArray(from) && Array.isArray(to)) {
28
+ if (from.length !== to.length)
29
+ return false;
30
+ return !from.some((t1, index) => {
31
+ if (!deepWeakEqual(t1, to[index])) {
32
+ return true;
33
+ }
34
+ });
35
+ } else {
36
+ const caches = {};
37
+ for (const key in from) {
38
+ if (!deepWeakEqual(from[key], to[key])) {
39
+ return false;
40
+ } else {
41
+ caches[key] = key;
42
+ }
20
43
  }
21
- else {
22
- const caches = {};
23
- for (const key in from) {
24
- if (!deepWeakEqual(from[key], to[key])) {
25
- return false;
26
- }
27
- else {
28
- caches[key] = key;
29
- }
30
- }
31
- for (const key in to) {
32
- if (key in caches)
33
- continue;
34
- if (!deepWeakEqual(from[key], to[key])) {
35
- return false;
36
- }
37
- }
44
+ for (const key in to) {
45
+ if (key in caches)
46
+ continue;
47
+ if (!deepWeakEqual(from[key], to[key])) {
48
+ return false;
49
+ }
38
50
  }
39
- return true;
51
+ }
52
+ return true;
40
53
  };
41
- exports.default = deepWeakEqual;
54
+ var weak_equal_default = deepWeakEqual;
@@ -1,18 +1,28 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * 对象数组转hash(要求主键值为string|number类型)
5
- * @example
6
- * hash8json(
7
- * [
8
- * { key: 'a', value: 1 },
9
- * { key: 'b', value: 2 }
10
- * ],
11
- * 'key'
12
- * ).a.value // 1
13
- */
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var json_exports = {};
20
+ __export(json_exports, {
21
+ default: () => json_default
22
+ });
23
+ module.exports = __toCommonJS(json_exports);
14
24
  const hash8json = (list, key) => list.reduce((caches, data) => {
15
- caches[data[key]] = data;
16
- return caches;
25
+ caches[data[key]] = data;
26
+ return caches;
17
27
  }, {});
18
- exports.default = hash8json;
28
+ var json_default = hash8json;
@@ -1,18 +1,28 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * 对象数组转hash
5
- * @example
6
- * hash8object(
7
- * [
8
- * { key: String, value: 1 },
9
- * { key: Object, value: 2 }
10
- * ],
11
- * 'key'
12
- * ).get(Object).value // 2
13
- */
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var object_exports = {};
20
+ __export(object_exports, {
21
+ default: () => object_default
22
+ });
23
+ module.exports = __toCommonJS(object_exports);
14
24
  const hash8object = (list, key) => list.reduce((caches, data) => {
15
- caches.set(data[key], data);
16
- return caches;
17
- }, new Map());
18
- exports.default = hash8object;
25
+ caches.set(data[key], data);
26
+ return caches;
27
+ }, /* @__PURE__ */ new Map());
28
+ var object_default = hash8object;
@@ -1,12 +1,28 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * 字符数组转hash
5
- * @example
6
- * hash8strings(['a', 'b']).a // 0
7
- */
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var strings_exports = {};
20
+ __export(strings_exports, {
21
+ default: () => strings_default
22
+ });
23
+ module.exports = __toCommonJS(strings_exports);
8
24
  const hash8strings = (list) => list.reduce((caches, data, index) => {
9
- caches[data] = index;
10
- return caches;
25
+ caches[data] = index;
26
+ return caches;
11
27
  }, {});
12
- exports.default = hash8strings;
28
+ var strings_default = hash8strings;
package/cjs/encoding.js CHANGED
@@ -1,64 +1,77 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var encoding_exports = {};
20
+ __export(encoding_exports, {
21
+ default: () => encoding_default
22
+ });
23
+ module.exports = __toCommonJS(encoding_exports);
3
24
  const utf8_first_prefix = /^1{2,}/g;
4
25
  const utf8_other_prefix = /^10/;
5
26
  const Encodes = {
6
- UTF_8: 'utf-8',
7
- UTF_16LE: 'utf-16le',
8
- UTF_16BE: 'utf-16be',
9
- GBK: 'gbk'
27
+ UTF_8: "utf-8",
28
+ UTF_16LE: "utf-16le",
29
+ UTF_16BE: "utf-16be",
30
+ GBK: "gbk"
10
31
  };
11
32
  const defaults = {
12
- utf8: [0xef, 0xbb, 0xbf],
33
+ utf8: [239, 187, 191]
13
34
  };
14
35
  const equal = (uint, list) => {
15
- if (uint.length !== list.length)
16
- return false;
17
- return !uint.some((value, index) => value !== list[index]);
36
+ if (uint.length !== list.length)
37
+ return false;
38
+ return !uint.some((value, index) => value !== list[index]);
18
39
  };
19
- /**
20
- * 根据文件内容判断文件的编码
21
- * @param uint 文件内容Uint8Array格式
22
- * @param limit 用于约束GBK和utf_8的判定上限
23
- */
24
40
  const getEncoding = (uint, limit = 1024) => {
25
- let encoding;
26
- let offset = 0;
27
- if (equal(uint.slice(0, 3), defaults.utf8)) {
28
- offset = defaults.utf8.length;
29
- encoding = Encodes.UTF_8;
30
- }
31
- else if (equal(uint.slice(0, 2), [0xff, 0xfe])) {
32
- encoding = Encodes.UTF_16LE;
33
- }
34
- else if (equal(uint.slice(0, 2), [0xfe, 0xff])) {
35
- encoding = Encodes.UTF_16BE;
36
- }
37
- else {
38
- let isBreak = false;
39
- top: for (let i = 0; i < Math.min(uint.length, limit); i++) {
40
- const data = uint[i];
41
- if (data < 128)
42
- continue;
43
- const match = data.toString(2).match(utf8_first_prefix);
44
- if (match) {
45
- for (let m = 0; m < match[0].length - 1; m++) {
46
- const target = uint[++i];
47
- if (target == void 0 || !utf8_other_prefix.test(target.toString(2))) {
48
- encoding = Encodes.GBK;
49
- isBreak = true;
50
- break top;
51
- }
52
- }
53
- }
54
- else {
55
- encoding = Encodes.GBK;
56
- isBreak = true;
57
- break;
41
+ let encoding;
42
+ let offset = 0;
43
+ if (equal(uint.slice(0, 3), defaults.utf8)) {
44
+ offset = defaults.utf8.length;
45
+ encoding = Encodes.UTF_8;
46
+ } else if (equal(uint.slice(0, 2), [255, 254])) {
47
+ encoding = Encodes.UTF_16LE;
48
+ } else if (equal(uint.slice(0, 2), [254, 255])) {
49
+ encoding = Encodes.UTF_16BE;
50
+ } else {
51
+ let isBreak = false;
52
+ top:
53
+ for (let i = 0; i < Math.min(uint.length, limit); i++) {
54
+ const data = uint[i];
55
+ if (data < 128)
56
+ continue;
57
+ const match = data.toString(2).match(utf8_first_prefix);
58
+ if (match) {
59
+ for (let m = 0; m < match[0].length - 1; m++) {
60
+ const target = uint[++i];
61
+ if (target == void 0 || !utf8_other_prefix.test(target.toString(2))) {
62
+ encoding = Encodes.GBK;
63
+ isBreak = true;
64
+ break top;
58
65
  }
66
+ }
67
+ } else {
68
+ encoding = Encodes.GBK;
69
+ isBreak = true;
70
+ break;
59
71
  }
60
- isBreak || (encoding = Encodes.UTF_8);
61
- }
62
- return { encoding, offset };
72
+ }
73
+ isBreak || (encoding = Encodes.UTF_8);
74
+ }
75
+ return { encoding, offset };
63
76
  };
64
- exports.default = getEncoding;
77
+ var encoding_default = getEncoding;