@vope/utils 1.6.0-bate.6 → 1.6.0-bate.7

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.
package/dist/clamp.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
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
+ clamp: () => clamp
22
+ });
23
+ module.exports = __toCommonJS(clamp_exports);
24
+ const clamp = (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));
31
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
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
+ classnames: () => classnames
22
+ });
23
+ module.exports = __toCommonJS(classnames_exports);
24
+ var import_lodash_es = require("lodash-es");
25
+ const add = (a, b) => a ? a + " " + b : b;
26
+ const classnames = (...list) => list.reduce((caches, data) => {
27
+ if ((0, import_lodash_es.isString)(data)) {
28
+ data && (caches = add(caches, data));
29
+ } else if (Array.isArray(data)) {
30
+ data.forEach((value) => value && (0, import_lodash_es.isString)(value) && (caches = add(caches, value)));
31
+ } else if (!(0, import_lodash_es.isBoolean)(data)) {
32
+ for (const key in data) {
33
+ key && data[key] && (caches = add(caches, key));
34
+ }
35
+ }
36
+ return caches;
37
+ }, "");
@@ -0,0 +1,35 @@
1
+ "use strict";
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
+ compareVersion: () => compareVersion
22
+ });
23
+ module.exports = __toCommonJS(version_exports);
24
+ const CHAR = ".";
25
+ const compareVersion = (from, to) => {
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) return -1;
32
+ if (fromV < toV) return 1;
33
+ }
34
+ return 0;
35
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
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
+ deepWeakEqual: () => deepWeakEqual
22
+ });
23
+ module.exports = __toCommonJS(weak_equal_exports);
24
+ var import_strings = require("../convert/strings");
25
+ const deepWeakEqual = (from, to, exclude) => {
26
+ if (typeof from !== "object" || from === null || typeof to !== "object" || to === null) return from === to;
27
+ if (Array.isArray(from) && Array.isArray(to)) {
28
+ if (from.length !== to.length) return false;
29
+ return !from.some((t1, index) => {
30
+ if (!deepWeakEqual(t1, to[index])) {
31
+ return true;
32
+ }
33
+ });
34
+ } else {
35
+ const caches = {};
36
+ const excludeCaches = exclude && (0, import_strings.hash8strings)(exclude);
37
+ for (const key in from) {
38
+ if (excludeCaches && key in excludeCaches) continue;
39
+ if (!deepWeakEqual(from[key], to[key])) {
40
+ return false;
41
+ } else {
42
+ caches[key] = key;
43
+ }
44
+ }
45
+ for (const key in to) {
46
+ if (excludeCaches && key in excludeCaches || key in caches) continue;
47
+ if (!deepWeakEqual(from[key], to[key])) {
48
+ return false;
49
+ }
50
+ }
51
+ }
52
+ return true;
53
+ };
@@ -0,0 +1,27 @@
1
+ "use strict";
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
+ hash8json: () => hash8json
22
+ });
23
+ module.exports = __toCommonJS(json_exports);
24
+ const hash8json = (list, key) => list.reduce((caches, data) => {
25
+ caches[data[key]] = data;
26
+ return caches;
27
+ }, {});
@@ -0,0 +1,27 @@
1
+ "use strict";
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
+ hash8object: () => hash8object
22
+ });
23
+ module.exports = __toCommonJS(object_exports);
24
+ const hash8object = (list, key) => list.reduce((caches, data) => {
25
+ caches.set(data[key], data);
26
+ return caches;
27
+ }, /* @__PURE__ */ new Map());
@@ -0,0 +1,27 @@
1
+ "use strict";
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
+ hash8strings: () => hash8strings
22
+ });
23
+ module.exports = __toCommonJS(strings_exports);
24
+ const hash8strings = (list) => list.reduce((caches, data, index) => {
25
+ caches[data] = index;
26
+ return caches;
27
+ }, {});
package/dist/desens.js ADDED
@@ -0,0 +1,71 @@
1
+ "use strict";
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 desens_exports = {};
20
+ __export(desens_exports, {
21
+ desensDecrypt: () => desensDecrypt,
22
+ desensEncrypt: () => desensEncrypt,
23
+ desensReplace: () => desensReplace
24
+ });
25
+ module.exports = __toCommonJS(desens_exports);
26
+ var import_lodash_es = require("lodash-es");
27
+ const desensEncrypt = (plaintext, encrypt) => {
28
+ const rules = [];
29
+ let point = -1;
30
+ let ciphertext = encrypt(plaintext).reduce((cache, { range, ciphertext: ciphertext2 }) => {
31
+ cache += plaintext.slice(point + 1, range[0]) + ciphertext2;
32
+ point = range[1];
33
+ rules.push({
34
+ range,
35
+ modify: ciphertext2.length
36
+ });
37
+ return cache;
38
+ }, "");
39
+ if (point !== -1) {
40
+ ciphertext += plaintext.slice(point + 1);
41
+ }
42
+ return {
43
+ ciphertext,
44
+ rules
45
+ };
46
+ };
47
+ const desensDecrypt = (ciphertext, rules, decrypt) => {
48
+ Array.isArray(rules) || (rules = [rules]);
49
+ let offset = 0;
50
+ let from = 0;
51
+ return rules.reduce((cache, { range: [start, stop], modify }) => {
52
+ cache += ciphertext.slice(from, start + offset) + decrypt(ciphertext.slice(start + offset, start + offset + modify));
53
+ from = start + offset + modify;
54
+ offset += modify - (stop + 1 - start);
55
+ return cache;
56
+ }, "") + ciphertext.slice(from);
57
+ };
58
+ const desensReplace = (ciphertext, rules, replacer = "*") => {
59
+ Array.isArray(rules) || (rules = [rules]);
60
+ let offset = 0;
61
+ let from = 0;
62
+ return rules.reduce((cache, { range: [start, stop], modify }) => {
63
+ const part = ciphertext.slice(start + offset, start + offset + modify);
64
+ const size = stop + 1 - start;
65
+ const replaceValue = (0, import_lodash_es.isString)(replacer) ? replacer.repeat(size) : replacer[Symbol.replace](part, size);
66
+ cache += ciphertext.slice(from, start + offset) + replaceValue;
67
+ from = start + offset + modify;
68
+ offset += modify - size;
69
+ return cache;
70
+ }, "") + ciphertext.slice(from);
71
+ };
@@ -0,0 +1,76 @@
1
+ "use strict";
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
+ getEncoding: () => getEncoding
22
+ });
23
+ module.exports = __toCommonJS(encoding_exports);
24
+ const utf8_first_prefix = /^1{2,}/g;
25
+ const utf8_other_prefix = /^10/;
26
+ const Encodes = {
27
+ UTF_8: "utf-8",
28
+ UTF_16LE: "utf-16le",
29
+ UTF_16BE: "utf-16be",
30
+ GBK: "gbk"
31
+ };
32
+ const BOM = {
33
+ UTF_8: [239, 187, 191],
34
+ UTF_16LE: [255, 254],
35
+ UTF_16BE: [254, 255]
36
+ };
37
+ const equal = (uint, list) => {
38
+ return uint.length === list.length ? !uint.some((value, index) => value !== list[index]) : false;
39
+ };
40
+ const getEncoding = (uint, limit = 1024) => {
41
+ let encoding;
42
+ let offset = 0;
43
+ for (const key in BOM) {
44
+ const head = BOM[key];
45
+ if (equal(uint.slice(0, head.length), head)) {
46
+ offset = head.length;
47
+ encoding = Encodes[key];
48
+ break;
49
+ }
50
+ }
51
+ if (!encoding) {
52
+ let isBreak = false;
53
+ top:
54
+ for (let i = 0, max = Math.min(uint.length, limit); i < max; i++) {
55
+ const data = uint[i];
56
+ if (data < 128) 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;
65
+ }
66
+ }
67
+ } else {
68
+ encoding = Encodes.GBK;
69
+ isBreak = true;
70
+ break;
71
+ }
72
+ }
73
+ isBreak || (encoding = Encodes.UTF_8);
74
+ }
75
+ return { encoding, offset };
76
+ };