@vope/utils 1.6.0-bate.2 → 1.6.0-bate.3

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 (73) hide show
  1. package/dist/clamp.d.ts +4 -0
  2. package/dist/clamp.mjs +11 -0
  3. package/dist/classnames.d.ts +7 -0
  4. package/dist/classnames.mjs +17 -0
  5. package/dist/compare/version.d.ts +5 -0
  6. package/dist/compare/version.mjs +15 -0
  7. package/dist/compare/weak-equal.d.ts +4 -0
  8. package/dist/compare/weak-equal.mjs +33 -0
  9. package/dist/convert/json.d.ts +12 -0
  10. package/dist/convert/json.mjs +7 -0
  11. package/dist/convert/object.d.ts +12 -0
  12. package/dist/convert/object.mjs +7 -0
  13. package/dist/convert/strings.d.ts +6 -0
  14. package/dist/convert/strings.mjs +7 -0
  15. package/dist/desens.d.ts +40 -0
  16. package/dist/desens.mjs +51 -0
  17. package/dist/encoding.d.ts +9 -0
  18. package/dist/encoding.mjs +56 -0
  19. package/dist/index.d.ts +34 -0
  20. package/dist/index.js +1361 -0
  21. package/dist/index.mjs +73 -0
  22. package/dist/input-regex.d.ts +12 -0
  23. package/dist/input-regex.mjs +8 -0
  24. package/dist/is/class.d.ts +4 -0
  25. package/dist/is/class.mjs +22 -0
  26. package/dist/is/empty.d.ts +4 -0
  27. package/dist/is/empty.mjs +5 -0
  28. package/dist/is/key.d.ts +4 -0
  29. package/dist/is/key.mjs +4 -0
  30. package/dist/is/null.d.ts +4 -0
  31. package/dist/is/null.mjs +4 -0
  32. package/dist/load/image.d.ts +5 -0
  33. package/dist/load/image.mjs +11 -0
  34. package/dist/memory/basic.d.ts +79 -0
  35. package/dist/memory/basic.mjs +167 -0
  36. package/dist/memory/list.d.ts +8 -0
  37. package/dist/memory/list.mjs +12 -0
  38. package/dist/memory/power.d.ts +8 -0
  39. package/dist/memory/power.mjs +13 -0
  40. package/dist/memory/simple.d.ts +60 -0
  41. package/dist/memory/simple.mjs +94 -0
  42. package/dist/neo4j-anchors.d.ts +50 -0
  43. package/dist/neo4j-anchors.mjs +169 -0
  44. package/dist/neo4j.d.ts +82 -0
  45. package/dist/neo4j.mjs +161 -0
  46. package/dist/once.d.ts +6 -0
  47. package/dist/once.mjs +8 -0
  48. package/dist/parse/num.d.ts +8 -0
  49. package/dist/parse/num.mjs +31 -0
  50. package/dist/power/decon.d.ts +9 -0
  51. package/dist/power/decon.mjs +22 -0
  52. package/dist/rotate/angle.d.ts +8 -0
  53. package/dist/rotate/angle.mjs +5 -0
  54. package/dist/rotate/rad.d.ts +8 -0
  55. package/dist/rotate/rad.mjs +11 -0
  56. package/dist/serialize/url-params.d.ts +43 -0
  57. package/dist/serialize/url-params.mjs +53 -0
  58. package/dist/storage/offline.d.ts +51 -0
  59. package/dist/style/css.d.ts +9 -0
  60. package/dist/style/css.mjs +25 -0
  61. package/dist/subscriber.d.ts +11 -0
  62. package/dist/subscriber.mjs +64 -0
  63. package/dist/table/flex.d.ts +43 -0
  64. package/dist/table/flex.mjs +96 -0
  65. package/dist/union.d.ts +34 -0
  66. package/dist/union.mjs +47 -0
  67. package/dist/url/join.d.ts +4 -0
  68. package/dist/url/join.mjs +9 -0
  69. package/dist/url/params.d.ts +8 -0
  70. package/dist/url/params.mjs +8 -0
  71. package/dist/wait.d.ts +4 -0
  72. package/dist/wait.mjs +4 -0
  73. package/package.json +3 -4
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 获取中间数
3
+ */
4
+ export declare const clamp: (value: number, min: number, max: number) => number;
package/dist/clamp.mjs ADDED
@@ -0,0 +1,11 @@
1
+ const clamp = (value, min, max) => {
2
+ if (min > max) {
3
+ const swap = max;
4
+ max = min;
5
+ min = swap;
6
+ }
7
+ return Math.min(max, Math.max(min, value));
8
+ };
9
+ export {
10
+ clamp
11
+ };
@@ -0,0 +1,7 @@
1
+ type Base = string | boolean | undefined | null;
2
+ type Item = Base | Base[] | Record<string, boolean>;
3
+ /**
4
+ * 拼接多个class
5
+ */
6
+ export declare const classnames: (...list: Item[]) => string;
7
+ export {};
@@ -0,0 +1,17 @@
1
+ import { isBoolean, isString } from "lodash-es";
2
+ const add = (a, b) => a ? a + " " + b : b;
3
+ const classnames = (...list) => list.reduce((caches, data) => {
4
+ if (isString(data)) {
5
+ data && (caches = add(caches, data));
6
+ } else if (Array.isArray(data)) {
7
+ data.forEach((value) => value && isString(value) && (caches = add(caches, value)));
8
+ } else if (!isBoolean(data)) {
9
+ for (const key in data) {
10
+ key && data[key] && (caches = add(caches, key));
11
+ }
12
+ }
13
+ return caches;
14
+ }, "");
15
+ export {
16
+ classnames
17
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 版本号大小比较
3
+ * @description from < to = 1,from === to = 0,from > to = -1
4
+ */
5
+ export declare const compareVersion: (from: string, to: string) => 0 | 1 | -1;
@@ -0,0 +1,15 @@
1
+ const CHAR = ".";
2
+ const compareVersion = (from, to) => {
3
+ const froms = from.split(CHAR);
4
+ const tos = to.split(CHAR);
5
+ for (let i = 0, max = Math.max(froms.length, tos.length); i < max; i++) {
6
+ const fromV = +froms[i] || 0;
7
+ const toV = +tos[i] || 0;
8
+ if (fromV > toV) return -1;
9
+ if (fromV < toV) return 1;
10
+ }
11
+ return 0;
12
+ };
13
+ export {
14
+ compareVersion
15
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 深度相等性比较(弱比较)
3
+ */
4
+ export declare const deepWeakEqual: <A, B>(from: A, to: B, exclude?: Extract<keyof A | keyof B, string | number>[]) => boolean;
@@ -0,0 +1,33 @@
1
+ import { hash8strings } from "../convert/strings";
2
+ const deepWeakEqual = (from, to, exclude) => {
3
+ if (typeof from !== "object" || from === null || typeof to !== "object" || to === null) return from === to;
4
+ if (Array.isArray(from) && Array.isArray(to)) {
5
+ if (from.length !== to.length) return false;
6
+ return !from.some((t1, index) => {
7
+ if (!deepWeakEqual(t1, to[index])) {
8
+ return true;
9
+ }
10
+ });
11
+ } else {
12
+ const caches = {};
13
+ const excludeCaches = exclude && hash8strings(exclude);
14
+ for (const key in from) {
15
+ if (excludeCaches && key in excludeCaches) continue;
16
+ if (!deepWeakEqual(from[key], to[key])) {
17
+ return false;
18
+ } else {
19
+ caches[key] = key;
20
+ }
21
+ }
22
+ for (const key in to) {
23
+ if (excludeCaches && key in excludeCaches || key in caches) continue;
24
+ if (!deepWeakEqual(from[key], to[key])) {
25
+ return false;
26
+ }
27
+ }
28
+ }
29
+ return true;
30
+ };
31
+ export {
32
+ deepWeakEqual
33
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 对象数组转hash(要求主键值为string|number类型)
3
+ * @example
4
+ * hash8json(
5
+ * [
6
+ * { key: 'a', value: 1 },
7
+ * { key: 'b', value: 2 }
8
+ * ],
9
+ * 'key'
10
+ * ).a.value // 1
11
+ */
12
+ export declare const hash8json: <K extends string | symbol, T extends Record<K, string | number>>(list: T[], key: K) => Record<T[K], T>;
@@ -0,0 +1,7 @@
1
+ const hash8json = (list, key) => list.reduce((caches, data) => {
2
+ caches[data[key]] = data;
3
+ return caches;
4
+ }, {});
5
+ export {
6
+ hash8json
7
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 对象数组转hash
3
+ * @example
4
+ * hash8object(
5
+ * [
6
+ * { key: String, value: 1 },
7
+ * { key: Object, value: 2 }
8
+ * ],
9
+ * 'key'
10
+ * ).get(Object).value // 2
11
+ */
12
+ export declare const hash8object: <K extends string | symbol, T extends Record<K, unknown>>(list: T[], key: K) => Map<T[K], T>;
@@ -0,0 +1,7 @@
1
+ const hash8object = (list, key) => list.reduce((caches, data) => {
2
+ caches.set(data[key], data);
3
+ return caches;
4
+ }, /* @__PURE__ */ new Map());
5
+ export {
6
+ hash8object
7
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 字符数组转hash
3
+ * @example
4
+ * hash8strings(['a', 'b']).a // 0
5
+ */
6
+ export declare const hash8strings: <T extends string | number>(list: T[]) => { [P in T]: number; };
@@ -0,0 +1,7 @@
1
+ const hash8strings = (list) => list.reduce((caches, data, index) => {
2
+ caches[data] = index;
3
+ return caches;
4
+ }, {});
5
+ export {
6
+ hash8strings
7
+ };
@@ -0,0 +1,40 @@
1
+ interface Rule {
2
+ /** 加密的开始(包含)和结束(包含)位置(位置信息基于明文) */
3
+ range: [number, number];
4
+ }
5
+ export interface DesensDecrypt extends Rule {
6
+ /** 密文长度 */
7
+ modify: number;
8
+ }
9
+ export interface DesensEncrypt extends Rule {
10
+ /** 密文 */
11
+ ciphertext: string;
12
+ }
13
+ /**
14
+ * 脱敏加密(对明文进行多个片段加密)
15
+ * @param plaintext 明文
16
+ * @param encrypt 加密方法
17
+ * @returns 解密要素
18
+ */
19
+ export declare const desensEncrypt: (plaintext: string, encrypt: (plaintext: string) => DesensEncrypt[]) => {
20
+ ciphertext: string;
21
+ rules: DesensDecrypt[];
22
+ };
23
+ /**
24
+ * 脱敏解密(对密文进行多个片段解密)
25
+ * @param ciphertext 密文
26
+ * @param rules 解密要素
27
+ * @param decrypt 解密方法
28
+ */
29
+ export declare const desensDecrypt: (ciphertext: string, rules: DesensDecrypt | DesensDecrypt[], decrypt: (ciphertext: string) => string) => string;
30
+ type Replacer = string | {
31
+ [Symbol.replace](text: string, size: number): string;
32
+ };
33
+ /**
34
+ * 脱敏平替
35
+ * @param plaintext 密文
36
+ * @param rules 解密要素
37
+ * @param replacer 替换者
38
+ */
39
+ export declare const desensReplace: (ciphertext: string, rules: DesensDecrypt | DesensDecrypt[], replacer?: Replacer) => string;
40
+ export {};
@@ -0,0 +1,51 @@
1
+ import { isString } from "lodash-es";
2
+ const desensEncrypt = (plaintext, encrypt) => {
3
+ const rules = [];
4
+ let point = -1;
5
+ let ciphertext = encrypt(plaintext).reduce((cache, { range, ciphertext: ciphertext2 }) => {
6
+ cache += plaintext.slice(point + 1, range[0]) + ciphertext2;
7
+ point = range[1];
8
+ rules.push({
9
+ range,
10
+ modify: ciphertext2.length
11
+ });
12
+ return cache;
13
+ }, "");
14
+ if (point !== -1) {
15
+ ciphertext += plaintext.slice(point + 1);
16
+ }
17
+ return {
18
+ ciphertext,
19
+ rules
20
+ };
21
+ };
22
+ const desensDecrypt = (ciphertext, rules, decrypt) => {
23
+ Array.isArray(rules) || (rules = [rules]);
24
+ let offset = 0;
25
+ let from = 0;
26
+ return rules.reduce((cache, { range: [start, stop], modify }) => {
27
+ cache += ciphertext.slice(from, start + offset) + decrypt(ciphertext.slice(start + offset, start + offset + modify));
28
+ from = start + offset + modify;
29
+ offset += modify - (stop + 1 - start);
30
+ return cache;
31
+ }, "") + ciphertext.slice(from);
32
+ };
33
+ const desensReplace = (ciphertext, rules, replacer = "*") => {
34
+ Array.isArray(rules) || (rules = [rules]);
35
+ let offset = 0;
36
+ let from = 0;
37
+ return rules.reduce((cache, { range: [start, stop], modify }) => {
38
+ const part = ciphertext.slice(start + offset, start + offset + modify);
39
+ const size = stop + 1 - start;
40
+ const replaceValue = isString(replacer) ? replacer.repeat(size) : replacer[Symbol.replace](part, size);
41
+ cache += ciphertext.slice(from, start + offset) + replaceValue;
42
+ from = start + offset + modify;
43
+ offset += modify - size;
44
+ return cache;
45
+ }, "") + ciphertext.slice(from);
46
+ };
47
+ export {
48
+ desensDecrypt,
49
+ desensEncrypt,
50
+ desensReplace
51
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 根据文件内容判断文件的编码
3
+ * @param uint 文件内容Uint8Array格式
4
+ * @param limit 用于约束GBK和utf_8的判定上限
5
+ */
6
+ export declare const getEncoding: (uint: Uint8Array, limit?: number) => {
7
+ encoding: "utf-8" | "utf-16le" | "utf-16be" | "gbk";
8
+ offset: number;
9
+ };
@@ -0,0 +1,56 @@
1
+ const utf8_first_prefix = /^1{2,}/g;
2
+ const utf8_other_prefix = /^10/;
3
+ const Encodes = {
4
+ UTF_8: "utf-8",
5
+ UTF_16LE: "utf-16le",
6
+ UTF_16BE: "utf-16be",
7
+ GBK: "gbk"
8
+ };
9
+ const BOM = {
10
+ UTF_8: [239, 187, 191],
11
+ UTF_16LE: [255, 254],
12
+ UTF_16BE: [254, 255]
13
+ };
14
+ const equal = (uint, list) => {
15
+ return uint.length === list.length ? !uint.some((value, index) => value !== list[index]) : false;
16
+ };
17
+ const getEncoding = (uint, limit = 1024) => {
18
+ let encoding;
19
+ let offset = 0;
20
+ for (const key in BOM) {
21
+ const head = BOM[key];
22
+ if (equal(uint.slice(0, head.length), head)) {
23
+ offset = head.length;
24
+ encoding = Encodes[key];
25
+ break;
26
+ }
27
+ }
28
+ if (!encoding) {
29
+ let isBreak = false;
30
+ top:
31
+ for (let i = 0, max = Math.min(uint.length, limit); i < max; i++) {
32
+ const data = uint[i];
33
+ if (data < 128) continue;
34
+ const match = data.toString(2).match(utf8_first_prefix);
35
+ if (match) {
36
+ for (let m = 0; m < match[0].length - 1; m++) {
37
+ const target = uint[++i];
38
+ if (target == void 0 || !utf8_other_prefix.test(target.toString(2))) {
39
+ encoding = Encodes.GBK;
40
+ isBreak = true;
41
+ break top;
42
+ }
43
+ }
44
+ } else {
45
+ encoding = Encodes.GBK;
46
+ isBreak = true;
47
+ break;
48
+ }
49
+ }
50
+ isBreak || (encoding = Encodes.UTF_8);
51
+ }
52
+ return { encoding, offset };
53
+ };
54
+ export {
55
+ getEncoding
56
+ };
@@ -0,0 +1,34 @@
1
+ export { clamp } from './clamp';
2
+ export { classnames } from './classnames';
3
+ export { compareVersion } from './compare/version';
4
+ export { deepWeakEqual } from './compare/weak-equal';
5
+ export { hash8json } from './convert/json';
6
+ export { hash8object } from './convert/object';
7
+ export { hash8strings } from './convert/strings';
8
+ export { type DesensDecrypt, type DesensEncrypt, desensEncrypt, desensDecrypt, desensReplace } from './desens';
9
+ export { getEncoding } from './encoding';
10
+ export { inputRegex } from './input-regex';
11
+ export { isClass } from './is/class';
12
+ export { isEmpty } from './is/empty';
13
+ export { isKey } from './is/key';
14
+ export { isNull } from './is/null';
15
+ export { loadImage } from './load/image';
16
+ export { MemoryBasic } from './memory/basic';
17
+ export { MemoryList } from './memory/list';
18
+ export { MemoryPower } from './memory/power';
19
+ export { MemorySimple } from './memory/simple';
20
+ export { default as Neo4jAhchors } from './neo4j-anchors';
21
+ export { default as Neo4j } from './neo4j';
22
+ export { once } from './once';
23
+ export { parseNum } from './parse/num';
24
+ export { deconPowersSum } from './power/decon';
25
+ export { rotateAngle } from './rotate/angle';
26
+ export { rotateRad } from './rotate/rad';
27
+ export { type Serializes, cubeURLParams, flatURLParams } from './serialize/url-params';
28
+ export { type CSSProperties, type StyleValue, css } from './style/css';
29
+ export { type SModel, default as Subscriber } from './subscriber';
30
+ export { FlexTable } from './table/flex';
31
+ export { Union } from './union';
32
+ export { joinPaths } from './url/join';
33
+ export { connectURLParams } from './url/params';
34
+ export { wait } from './wait';