@vope/utils 1.0.2 → 1.2.0

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 (58) hide show
  1. package/README.md +0 -5
  2. package/cjs/clamp.js +14 -0
  3. package/cjs/classnames.js +22 -0
  4. package/cjs/compare/version.js +21 -0
  5. package/cjs/compare/{value.js → weak-equal.js} +6 -6
  6. package/cjs/encoding.js +65 -0
  7. package/cjs/index.js +33 -5
  8. package/cjs/input-regex.js +10 -0
  9. package/cjs/is/class.js +1 -2
  10. package/cjs/memory/basic.js +148 -0
  11. package/cjs/memory/list.js +20 -0
  12. package/cjs/memory/power.js +19 -0
  13. package/cjs/once.js +15 -0
  14. package/cjs/power/decon.js +31 -0
  15. package/cjs/rotate/angle.js +14 -0
  16. package/cjs/rotate/rad.js +17 -0
  17. package/cjs/union.js +25 -0
  18. package/cjs/url/join.js +3 -4
  19. package/cjs/wait.js +6 -0
  20. package/lib/clamp.js +12 -0
  21. package/lib/classnames.js +20 -0
  22. package/lib/compare/version.js +19 -0
  23. package/lib/compare/{value.js → weak-equal.js} +6 -6
  24. package/lib/encoding.js +63 -0
  25. package/lib/index.js +17 -3
  26. package/lib/input-regex.js +8 -0
  27. package/lib/is/class.js +2 -1
  28. package/lib/memory/basic.js +142 -0
  29. package/lib/memory/list.js +14 -0
  30. package/lib/memory/power.js +13 -0
  31. package/lib/once.js +13 -0
  32. package/lib/power/decon.js +29 -0
  33. package/lib/rotate/angle.js +9 -0
  34. package/lib/rotate/rad.js +15 -0
  35. package/lib/union.js +22 -0
  36. package/lib/url/join.js +3 -2
  37. package/lib/wait.js +4 -0
  38. package/package.json +9 -10
  39. package/types/clamp.d.ts +5 -0
  40. package/types/classnames.d.ts +7 -0
  41. package/types/compare/version.d.ts +6 -0
  42. package/types/compare/weak-equal.d.ts +5 -0
  43. package/types/encoding.d.ts +16 -0
  44. package/types/index.d.ts +17 -3
  45. package/types/input-regex.d.ts +13 -0
  46. package/types/is/class.d.ts +2 -1
  47. package/types/memory/basic.d.ts +63 -0
  48. package/types/memory/list.d.ts +8 -0
  49. package/types/memory/power.d.ts +8 -0
  50. package/types/memory/type.d.ts +11 -0
  51. package/types/once.d.ts +7 -0
  52. package/types/power/decon.d.ts +9 -0
  53. package/types/rotate/angle.d.ts +9 -0
  54. package/types/rotate/rad.d.ts +9 -0
  55. package/types/union.d.ts +20 -0
  56. package/types/url/join.d.ts +2 -1
  57. package/types/wait.d.ts +5 -0
  58. package/types/compare/value.d.ts +0 -5
package/README.md CHANGED
@@ -3,11 +3,6 @@
3
3
  发布构建
4
4
  ```
5
5
 
6
- ### init:build
7
- ```
8
- 发布构建(初次需要先构建基本环境)
9
- ```
10
-
11
6
  ### cjs
12
7
  ```
13
8
  构建cjs版本
package/cjs/clamp.js ADDED
@@ -0,0 +1,14 @@
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));
14
+ };
@@ -0,0 +1,22 @@
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));
12
+ }
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
+ }, '');
@@ -0,0 +1,21 @@
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
+ */
8
+ 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;
20
+ };
21
+ exports.default = compareVersion;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
- * 值比较(深度浅比较)
4
+ * 深度相等性比较(弱比较)
5
5
  */
6
- const compareValue = (from, to) => {
6
+ const deepWeakEqual = (from, to) => {
7
7
  if (typeof from !== 'object'
8
8
  || from === null
9
9
  || typeof to !== 'object'
@@ -13,7 +13,7 @@ const compareValue = (from, to) => {
13
13
  if (from.length !== to.length)
14
14
  return false;
15
15
  return !from.some((t1, index) => {
16
- if (!compareValue(t1, to[index])) {
16
+ if (!deepWeakEqual(t1, to[index])) {
17
17
  return true;
18
18
  }
19
19
  });
@@ -21,7 +21,7 @@ const compareValue = (from, to) => {
21
21
  else {
22
22
  const caches = {};
23
23
  for (const key in from) {
24
- if (!compareValue(from[key], to[key])) {
24
+ if (!deepWeakEqual(from[key], to[key])) {
25
25
  return false;
26
26
  }
27
27
  else {
@@ -31,11 +31,11 @@ const compareValue = (from, to) => {
31
31
  for (const key in to) {
32
32
  if (key in caches)
33
33
  continue;
34
- if (!compareValue(from[key], to[key])) {
34
+ if (!deepWeakEqual(from[key], to[key])) {
35
35
  return false;
36
36
  }
37
37
  }
38
38
  }
39
39
  return true;
40
40
  };
41
- exports.default = compareValue;
41
+ exports.default = deepWeakEqual;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utf8_first_prefix = /^1{2,}/g;
4
+ const utf8_other_prefix = /^10/;
5
+ var Encodes;
6
+ (function (Encodes) {
7
+ Encodes["UTF_8"] = "utf-8";
8
+ Encodes["UTF_16LE"] = "utf-16le";
9
+ Encodes["UTF_16BE"] = "utf-16be";
10
+ Encodes["GBK"] = "gbk";
11
+ })(Encodes || (Encodes = {}));
12
+ const defaults = {
13
+ utf8: [0xef, 0xbb, 0xbf],
14
+ };
15
+ const equal = (uint, list) => {
16
+ if (uint.length !== list.length)
17
+ return false;
18
+ return !uint.some((value, index) => value !== list[index]);
19
+ };
20
+ /**
21
+ * 根据文件内容判断文件的编码
22
+ * @param uint 文件内容Uint8Array格式
23
+ * @param limit 用于约束GBK和utf_8的判定上限
24
+ */
25
+ const getEncoding = (uint, limit = 1024) => {
26
+ let encoding;
27
+ let offset = 0;
28
+ if (equal(uint.slice(0, 3), defaults.utf8)) {
29
+ offset = defaults.utf8.length;
30
+ encoding = Encodes.UTF_8;
31
+ }
32
+ else if (equal(uint.slice(0, 2), [0xff, 0xfe])) {
33
+ encoding = Encodes.UTF_16LE;
34
+ }
35
+ else if (equal(uint.slice(0, 2), [0xfe, 0xff])) {
36
+ encoding = Encodes.UTF_16BE;
37
+ }
38
+ else {
39
+ let isBreak = false;
40
+ top: for (let i = 0; i < Math.min(uint.length, limit); i++) {
41
+ const data = uint[i];
42
+ if (data < 128)
43
+ continue;
44
+ const match = data.toString(2).match(utf8_first_prefix);
45
+ if (match) {
46
+ for (let m = 0; m < match[0].length - 1; m++) {
47
+ const target = uint[++i];
48
+ if (target == void 0 || !utf8_other_prefix.test(target.toString(2))) {
49
+ encoding = Encodes.GBK;
50
+ isBreak = true;
51
+ break top;
52
+ }
53
+ }
54
+ }
55
+ else {
56
+ encoding = Encodes.GBK;
57
+ isBreak = true;
58
+ break;
59
+ }
60
+ }
61
+ isBreak || (encoding = Encodes.UTF_8);
62
+ }
63
+ return { encoding, offset };
64
+ };
65
+ exports.default = getEncoding;
package/cjs/index.js CHANGED
@@ -3,25 +3,53 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.connectURLParams = exports.joinURLs = exports.isNull = exports.isEmpty = exports.isClass = exports.hash8strings = exports.hash8object = exports.hash8json = exports.compareValue = exports.apiGet = exports.apiPost = void 0;
6
+ exports.wait = exports.connectURLParams = exports.joinPaths = exports.Union = exports.rotateRad = exports.rotateAngle = exports.deconPowersSum = exports.once = exports.MemoryPower = exports.MemoryList = exports.MemoryBasic = exports.isNull = exports.isEmpty = exports.isClass = exports.inputRegex = exports.getEncoding = exports.hash8strings = exports.hash8object = exports.hash8json = exports.deepWeakEqual = exports.compareVersion = exports.classnames = exports.clamp = exports.apiGet = exports.apiPost = void 0;
7
7
  var api_1 = require("./api");
8
8
  Object.defineProperty(exports, "apiPost", { enumerable: true, get: function () { return api_1.apiPost; } });
9
9
  Object.defineProperty(exports, "apiGet", { enumerable: true, get: function () { return api_1.apiGet; } });
10
- var value_1 = require("./compare/value");
11
- Object.defineProperty(exports, "compareValue", { enumerable: true, get: function () { return __importDefault(value_1).default; } });
10
+ var clamp_1 = require("./clamp");
11
+ Object.defineProperty(exports, "clamp", { enumerable: true, get: function () { return __importDefault(clamp_1).default; } });
12
+ var classnames_1 = require("./classnames");
13
+ Object.defineProperty(exports, "classnames", { enumerable: true, get: function () { return __importDefault(classnames_1).default; } });
14
+ var version_1 = require("./compare/version");
15
+ Object.defineProperty(exports, "compareVersion", { enumerable: true, get: function () { return __importDefault(version_1).default; } });
16
+ var weak_equal_1 = require("./compare/weak-equal");
17
+ Object.defineProperty(exports, "deepWeakEqual", { enumerable: true, get: function () { return __importDefault(weak_equal_1).default; } });
12
18
  var json_1 = require("./convert/json");
13
19
  Object.defineProperty(exports, "hash8json", { enumerable: true, get: function () { return __importDefault(json_1).default; } });
14
20
  var object_1 = require("./convert/object");
15
21
  Object.defineProperty(exports, "hash8object", { enumerable: true, get: function () { return __importDefault(object_1).default; } });
16
22
  var strings_1 = require("./convert/strings");
17
23
  Object.defineProperty(exports, "hash8strings", { enumerable: true, get: function () { return __importDefault(strings_1).default; } });
24
+ var encoding_1 = require("./encoding");
25
+ Object.defineProperty(exports, "getEncoding", { enumerable: true, get: function () { return __importDefault(encoding_1).default; } });
26
+ var input_regex_1 = require("./input-regex");
27
+ Object.defineProperty(exports, "inputRegex", { enumerable: true, get: function () { return __importDefault(input_regex_1).default; } });
18
28
  var class_1 = require("./is/class");
19
- Object.defineProperty(exports, "isClass", { enumerable: true, get: function () { return class_1.isClass; } });
29
+ Object.defineProperty(exports, "isClass", { enumerable: true, get: function () { return __importDefault(class_1).default; } });
20
30
  var empty_1 = require("./is/empty");
21
31
  Object.defineProperty(exports, "isEmpty", { enumerable: true, get: function () { return __importDefault(empty_1).default; } });
22
32
  var null_1 = require("./is/null");
23
33
  Object.defineProperty(exports, "isNull", { enumerable: true, get: function () { return __importDefault(null_1).default; } });
34
+ var basic_1 = require("./memory/basic");
35
+ Object.defineProperty(exports, "MemoryBasic", { enumerable: true, get: function () { return __importDefault(basic_1).default; } });
36
+ var list_1 = require("./memory/list");
37
+ Object.defineProperty(exports, "MemoryList", { enumerable: true, get: function () { return __importDefault(list_1).default; } });
38
+ var power_1 = require("./memory/power");
39
+ Object.defineProperty(exports, "MemoryPower", { enumerable: true, get: function () { return __importDefault(power_1).default; } });
40
+ var once_1 = require("./once");
41
+ Object.defineProperty(exports, "once", { enumerable: true, get: function () { return __importDefault(once_1).default; } });
42
+ var decon_1 = require("./power/decon");
43
+ Object.defineProperty(exports, "deconPowersSum", { enumerable: true, get: function () { return __importDefault(decon_1).default; } });
44
+ var angle_1 = require("./rotate/angle");
45
+ Object.defineProperty(exports, "rotateAngle", { enumerable: true, get: function () { return __importDefault(angle_1).default; } });
46
+ var rad_1 = require("./rotate/rad");
47
+ Object.defineProperty(exports, "rotateRad", { enumerable: true, get: function () { return __importDefault(rad_1).default; } });
48
+ var union_1 = require("./union");
49
+ Object.defineProperty(exports, "Union", { enumerable: true, get: function () { return __importDefault(union_1).default; } });
24
50
  var join_1 = require("./url/join");
25
- Object.defineProperty(exports, "joinURLs", { enumerable: true, get: function () { return join_1.joinURLs; } });
51
+ Object.defineProperty(exports, "joinPaths", { enumerable: true, get: function () { return __importDefault(join_1).default; } });
26
52
  var params_1 = require("./url/params");
27
53
  Object.defineProperty(exports, "connectURLParams", { enumerable: true, get: function () { return __importDefault(params_1).default; } });
54
+ var wait_1 = require("./wait");
55
+ Object.defineProperty(exports, "wait", { enumerable: true, get: function () { return __importDefault(wait_1).default; } });
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const RE_REGEX = /[$()*+.[?\\^{|]/g;
4
+ const RE_STRING = /[$()*+.[?\\^{|-]/g;
5
+ function inputRegex(text, flags) {
6
+ return flags === false
7
+ ? text.replace(RE_STRING, ($0) => '\\' + $0)
8
+ : new RegExp(text.replace(RE_REGEX, ($0) => '\\' + $0), flags);
9
+ }
10
+ exports.default = inputRegex;
package/cjs/is/class.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isClass = void 0;
4
3
  const re_anonymous = /^function\s+\(|^function\s+anonymous\(/;
5
4
  const re_function = /^function\s+[A-Z]/;
6
5
  const re_this = /\b\(this\b|\bthis[\.\[]\b/;
@@ -30,4 +29,4 @@ const isClass = (value, strict = true) => {
30
29
  }
31
30
  return false;
32
31
  };
33
- exports.isClass = isClass;
32
+ exports.default = isClass;
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const strings_1 = __importDefault(require("../convert/strings"));
7
+ /**
8
+ * 分类存储(通过继承,可用于拓展存储方式)
9
+ */
10
+ class MemoryBasic {
11
+ key;
12
+ #mount;
13
+ #reflex;
14
+ list = [];
15
+ memorys = new Map();
16
+ /**
17
+ * 返回存储长度
18
+ */
19
+ get size() {
20
+ return this.list.length;
21
+ }
22
+ /**
23
+ * @param key 用于对数据进行分类的key
24
+ * @param config
25
+ */
26
+ constructor(key, config) {
27
+ this.key = key;
28
+ this.#mount = config.mount;
29
+ this.#reflex = config.reflex;
30
+ }
31
+ getType(data) {
32
+ const { key } = this;
33
+ return typeof key === 'function' ? key(data) : data[key];
34
+ }
35
+ push(...list) {
36
+ const { memorys } = this;
37
+ list.forEach((data) => {
38
+ const type = this.getType(data);
39
+ const memory = memorys.get(type);
40
+ const index = this.list.push(data) - 1;
41
+ const result = this.#mount(index, memory);
42
+ memory === result || memorys.set(type, result);
43
+ });
44
+ return this;
45
+ }
46
+ /**
47
+ * 遍历所有存储数据(按入栈顺序)
48
+ */
49
+ forEach(callback) {
50
+ this.list.forEach(callback);
51
+ return this;
52
+ }
53
+ /**
54
+ * 遍历所有存储类型
55
+ */
56
+ forType(callback) {
57
+ const { memorys, list } = this;
58
+ for (const [type, memory] of memorys) {
59
+ const caches = this.#reflex(memory).map((index) => list[index]);
60
+ callback(caches, type);
61
+ }
62
+ return this;
63
+ }
64
+ /**
65
+ * 检测存储是否包含某种类型
66
+ */
67
+ includes(type) {
68
+ return type in this.memorys;
69
+ }
70
+ /**
71
+ * 获取指定类型存储数据
72
+ */
73
+ get(type) {
74
+ const memory = this.memorys.get(type);
75
+ return memory === void 0
76
+ ? null
77
+ : this.#reflex(memory).map((count) => this.list[count]);
78
+ }
79
+ /**
80
+ * 删除指定存储数据
81
+ */
82
+ delete(data) {
83
+ const { memorys, list } = this;
84
+ let index = -1;
85
+ if (!list.some((value, i) => {
86
+ if (data === value) {
87
+ index = i;
88
+ list.splice(index, 1);
89
+ const type = this.getType(value);
90
+ const memory = this.#reflex(memorys.get(type));
91
+ if (memory.length === 1) {
92
+ memorys.delete(type);
93
+ }
94
+ else {
95
+ memory.some((count, j) => {
96
+ if (count === i) {
97
+ memory.splice(j, 1);
98
+ return true;
99
+ }
100
+ });
101
+ }
102
+ return true;
103
+ }
104
+ }))
105
+ return this;
106
+ for (const [type, target] of memorys) {
107
+ const memory = this.#reflex(target);
108
+ memory.forEach((value, index) => {
109
+ if (value >= index) {
110
+ memory[index] = value - 1;
111
+ }
112
+ });
113
+ if (memory !== target) {
114
+ let reactor;
115
+ memory.forEach((count) => {
116
+ reactor = this.#mount(count, reactor);
117
+ });
118
+ memorys.set(type, reactor);
119
+ }
120
+ }
121
+ return this;
122
+ }
123
+ /**
124
+ * 删除指定类型存储数据
125
+ */
126
+ deleteType(type) {
127
+ const { memorys, list } = this;
128
+ if (!memorys.has(type))
129
+ return this;
130
+ const local = (0, strings_1.default)(this.#reflex(memorys.get(type)));
131
+ const Memory = this.constructor;
132
+ const imitator = new Memory(this.key);
133
+ list.forEach((data, index) => {
134
+ index in local || imitator.push(data);
135
+ });
136
+ this.list = imitator.list;
137
+ this.memorys = imitator.memorys;
138
+ return this;
139
+ }
140
+ /**
141
+ * 清理存储
142
+ */
143
+ clear() {
144
+ this.list = [];
145
+ this.memorys.clear();
146
+ }
147
+ }
148
+ exports.default = MemoryBasic;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const basic_1 = __importDefault(require("./basic"));
7
+ /**
8
+ * 分类存储(基于普通的键值存储)
9
+ */
10
+ class MemoryList extends basic_1.default {
11
+ constructor(key) {
12
+ super(key, {
13
+ mount: (index, reactor) => reactor
14
+ ? (reactor.push(index), reactor)
15
+ : [index],
16
+ reflex: (reactor) => reactor,
17
+ });
18
+ }
19
+ }
20
+ exports.default = MemoryList;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const decon_1 = __importDefault(require("../power/decon"));
7
+ const basic_1 = __importDefault(require("./basic"));
8
+ /**
9
+ * 分类存储(基于2的n次幂之和构建唯一键进行存储)
10
+ */
11
+ class MemoryPower extends basic_1.default {
12
+ constructor(key) {
13
+ super(key, {
14
+ mount: (index, reactor) => (reactor || 0) + 2 ** index,
15
+ reflex: (reactor) => (0, decon_1.default)(reactor, 'asc'),
16
+ });
17
+ }
18
+ }
19
+ exports.default = MemoryPower;
package/cjs/once.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * 缓存函数返回值
5
+ * @param callback 运行返回值的函数
6
+ * @param thisArg 绑定到运行函数的this对象
7
+ */
8
+ exports.default = (func, thisArg) => {
9
+ let local;
10
+ let inited = false;
11
+ return (...list) => inited
12
+ ? local
13
+ : (inited = true,
14
+ local = func.apply(thisArg, list));
15
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ERROR_MESSAGE = {
4
+ INT: '参数必须是整数',
5
+ MIN: '多个2的正整数幂(两两不相等)之和必定大于等于1',
6
+ };
7
+ /**
8
+ * 解构多个2的正整数幂(两两不相等)之和
9
+ * @param sum 幂和
10
+ * @param sort 排序方式(默认降序)
11
+ * @description sum > 2**53则会因为精度问题计算报错
12
+ */
13
+ const deconPowersSum = (sum, sort) => {
14
+ if (sum < 1) {
15
+ throw new Error(ERROR_MESSAGE.MIN);
16
+ }
17
+ else if (sum !== Math.floor(sum)) {
18
+ throw new Error(ERROR_MESSAGE.INT);
19
+ }
20
+ const list = [];
21
+ let cache = sum;
22
+ while (cache) {
23
+ const power = Math.log2(cache) ^ 0;
24
+ list.push(power);
25
+ cache -= Math.pow(2, power);
26
+ }
27
+ return sort === 'asc'
28
+ ? list.reverse()
29
+ : list;
30
+ };
31
+ exports.default = deconPowersSum;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const rad_1 = __importDefault(require("./rad"));
7
+ /**
8
+ * 返回点被旋转指定角度后新的位置
9
+ * @param from 旋转点
10
+ * @param angle 旋转角度
11
+ * @param visit 旋转原点
12
+ */
13
+ const rotateAngle = (from, angle, visit) => (0, rad_1.default)(from, angle / 180 * Math.PI, visit);
14
+ exports.default = rotateAngle;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * 返回点被旋转指定弧度后新的位置
5
+ * @param from 旋转点
6
+ * @param rad 旋转弧度
7
+ * @param visit 旋转原点
8
+ */
9
+ const rotateRad = (from, rad, visit = [0, 0]) => {
10
+ const x = from[0] - visit[0];
11
+ const y = from[1] - visit[1];
12
+ return [
13
+ x * Math.cos(rad) + y * Math.sin(rad) + visit[0],
14
+ y * Math.cos(rad) - x * Math.sin(rad) + visit[1],
15
+ ];
16
+ };
17
+ exports.default = rotateRad;
package/cjs/union.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * 数据联合(用于需要对加入的数据进行智能提示)
5
+ */
6
+ class Union {
7
+ key;
8
+ formater;
9
+ #map = {};
10
+ get value() {
11
+ return this.#map;
12
+ }
13
+ constructor(key, formater) {
14
+ this.key = key;
15
+ this.formater = formater;
16
+ }
17
+ add(data) {
18
+ const { formater } = this;
19
+ this.#map[data[this.key]] = formater
20
+ ? formater(data)
21
+ : data;
22
+ return this;
23
+ }
24
+ }
25
+ exports.default = Union;
package/cjs/url/join.js CHANGED
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.joinURLs = void 0;
4
- const re = /(^|[^:/])\/{2,}/g;
3
+ const re = /([^:])\/{2,}/g;
5
4
  /**
6
5
  * 实现多个路径拼接
7
6
  */
8
- const joinURLs = (...list) => {
7
+ const joinPaths = (...list) => {
9
8
  const { length } = list;
10
9
  if (length === 0)
11
10
  return '';
@@ -13,4 +12,4 @@ const joinURLs = (...list) => {
13
12
  ? list[0]
14
13
  : list.join('/').replace(re, ($0, $1) => `${$1}/`);
15
14
  };
16
- exports.joinURLs = joinURLs;
15
+ exports.default = joinPaths;
package/cjs/wait.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * 等待
5
+ */
6
+ exports.default = (delay = 0) => new Promise((resolve) => window.setTimeout(resolve, delay));
package/lib/clamp.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 获取中间数
3
+ */
4
+ export default (value, min, max) => {
5
+ if (min > max) {
6
+ // js位运算的范围为(-2^32,2^32),超出会产生溢出
7
+ const swap = max;
8
+ max = min;
9
+ min = swap;
10
+ }
11
+ return Math.min(max, Math.max(min, value));
12
+ };
@@ -0,0 +1,20 @@
1
+ const add = (a, b) => a
2
+ ? a + '\u0020' + b
3
+ : b;
4
+ /**
5
+ * 拼接多个class
6
+ */
7
+ export default (...list) => list.reduce((caches, data) => {
8
+ if (typeof data === 'string') {
9
+ data && (caches = add(caches, data));
10
+ }
11
+ else if (Array.isArray(data)) {
12
+ data.forEach((value) => value && (caches = add(caches, value)));
13
+ }
14
+ else if (data) {
15
+ for (const key in data) {
16
+ key && data[key] && (caches = add(caches, key));
17
+ }
18
+ }
19
+ return caches;
20
+ }, '');
@@ -0,0 +1,19 @@
1
+ const CHAR = '.';
2
+ /**
3
+ * 版本号大小比较
4
+ * @description from < to = 1,from === to = 0,from > to = -1
5
+ */
6
+ const compareVersion = (from, to) => {
7
+ const froms = from.split(CHAR);
8
+ const tos = to.split(CHAR);
9
+ for (let i = 0, max = Math.max(froms.length, tos.length); i < max; i++) {
10
+ const fromV = +froms[i] || 0;
11
+ const toV = +tos[i] || 0;
12
+ if (fromV > toV)
13
+ return -1;
14
+ if (fromV < toV)
15
+ return 1;
16
+ }
17
+ return 0;
18
+ };
19
+ export default compareVersion;