@unicom-cloud/utils 0.1.20 → 0.1.21
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/index.js +2 -70
- package/nzh/src/index.js +1 -1
- package/package.json +1 -1
- package/tree/search/index.js +127 -67
- package/types/index.d.ts +1 -30
- package/types/tree/search/index.d.ts +22 -0
- package/types/turbo-stream/src/shared.d.ts +3 -3
- package/types/version/index.d.ts +2 -0
- package/version/index.js +5 -0
- package/version.js +5 -0
- package/diff/index.js +0 -7
- package/diff/src/diff.d.ts +0 -21
- package/diff/src/diff.js +0 -381
- package/diff.js +0 -7
- package/types/diff/index.d.ts +0 -2
- package/types/diff/src/diff.d.ts +0 -40
package/index.js
CHANGED
|
@@ -1,72 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as e from "./date/index.js";
|
|
3
|
-
import * as r from "./is/index.js";
|
|
4
|
-
import * as t from "./math/index.js";
|
|
5
|
-
import * as a from "./snapdom/index.js";
|
|
6
|
-
import * as s from "./tree/index.js";
|
|
7
|
-
import * as i from "./turbo-stream/index.js";
|
|
8
|
-
import * as m from "./ui-color/index.js";
|
|
9
|
-
import * as p from "./url-toolkit/index.js";
|
|
10
|
-
import { default as u } from "./case-name/index.js";
|
|
11
|
-
import { default as C } from "./class-name/index.js";
|
|
12
|
-
import { default as b } from "./clipboard-copy/index.js";
|
|
13
|
-
import { default as k, getContentDispositionFromHeader as y, getContentDispositionParametersFilenameFromHeader as T, getContentDispositionParametersFromHeader as g } from "./content-disposition/index.js";
|
|
14
|
-
import { splitCookiesString as D } from "./cookie/index.js";
|
|
15
|
-
import { default as S } from "./decimal/decimal.js";
|
|
16
|
-
import { default as j } from "./diff/src/diff.js";
|
|
17
|
-
import { Emitter as L } from "./emitter/src/index.js";
|
|
18
|
-
import { fileToURL as P } from "./file/fileToURL.js";
|
|
19
|
-
import { saveAs as E } from "./file/saveAs.js";
|
|
20
|
-
import * as f from "./filesize/src/constants.js";
|
|
21
|
-
import { filesize as R, partial as U } from "./filesize/src/filesize.js";
|
|
22
|
-
import { default as $ } from "./invariant/index.js";
|
|
23
|
-
import { default as w } from "./js-cookie/src/api.js";
|
|
24
|
-
import * as n from "./lunar/lib/index.js";
|
|
25
|
-
import { default as G } from "./md5/index.js";
|
|
26
|
-
import { default as J } from "./normalize-wheel/index.js";
|
|
27
|
-
import { default as O } from "./number-to-chinese/index.js";
|
|
28
|
-
import { default as V } from "./nzh/nzh.js";
|
|
29
|
-
import { default as Y } from "./object-keys-sort/index.js";
|
|
30
|
-
import { default as oo } from "./pinyin/src/simplified.js";
|
|
31
|
-
import { default as ro } from "./screenfull/index.js";
|
|
32
|
-
import { TinyColor as ao } from "./tinycolor/src/index.js";
|
|
33
|
-
import * as x from "./cookie/src/index.js";
|
|
1
|
+
import { VERSION as e } from "./version/index.js";
|
|
34
2
|
export {
|
|
35
|
-
|
|
36
|
-
u as caseName,
|
|
37
|
-
C as className,
|
|
38
|
-
b as clipboardCopy,
|
|
39
|
-
o as constant,
|
|
40
|
-
k as contentDisposition,
|
|
41
|
-
x as cookie,
|
|
42
|
-
e as date,
|
|
43
|
-
S as decimal,
|
|
44
|
-
j as diff,
|
|
45
|
-
L as emitter,
|
|
46
|
-
P as fileToURL,
|
|
47
|
-
R as filesize,
|
|
48
|
-
f as filesizeConstants,
|
|
49
|
-
y as getContentDispositionFromHeader,
|
|
50
|
-
T as getContentDispositionParametersFilenameFromHeader,
|
|
51
|
-
g as getContentDispositionParametersFromHeader,
|
|
52
|
-
$ as invariant,
|
|
53
|
-
r as is,
|
|
54
|
-
w as jsCookie,
|
|
55
|
-
t as math,
|
|
56
|
-
G as md5,
|
|
57
|
-
J as normalizeWheel,
|
|
58
|
-
O as numberToChinese,
|
|
59
|
-
V as nzh,
|
|
60
|
-
Y as objectKeysSort,
|
|
61
|
-
U as partial,
|
|
62
|
-
oo as pinyin,
|
|
63
|
-
E as saveAs,
|
|
64
|
-
ro as screenfull,
|
|
65
|
-
a as snapdom,
|
|
66
|
-
D as splitCookiesString,
|
|
67
|
-
ao as tinycolor,
|
|
68
|
-
s as tree,
|
|
69
|
-
i as turboStream,
|
|
70
|
-
m as uiColor,
|
|
71
|
-
p as urlToolkit
|
|
3
|
+
e as version
|
|
72
4
|
};
|
package/nzh/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getNumbResult as R, clearZero as Y, unshiftZero as L, centerArray as j,
|
|
1
|
+
import { getNumbResult as R, extend as E, clearZero as Y, unshiftZero as L, centerArray as j, getDigit as C } from "./utils.js";
|
|
2
2
|
function z(m, h) {
|
|
3
3
|
let _ = R(m);
|
|
4
4
|
if (!_)
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@unicom-cloud/utils","version":"0.1.
|
|
1
|
+
{"name":"@unicom-cloud/utils","version":"0.1.21","dependencies":{},"peerDependencies":{"lodash":"^4.17.21"},"main":"./index.js","type":"module","types":"types/index.d.ts","publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"}}
|
package/tree/search/index.js
CHANGED
|
@@ -1,15 +1,80 @@
|
|
|
1
1
|
import "../../is/index.js";
|
|
2
2
|
import A from "lodash/isArray";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
function
|
|
7
|
-
return
|
|
3
|
+
import T from "lodash/isObjectLike";
|
|
4
|
+
import F from "lodash/isString";
|
|
5
|
+
import x from "lodash/isFunction";
|
|
6
|
+
function z(c, r, e, i) {
|
|
7
|
+
return r && c ? { shouldExit: !0, newMatch: !0 } : e && !c ? { shouldExit: !0, newMatch: !1 } : { shouldExit: !1, newMatch: i || c };
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
9
|
+
function O(c, r, e) {
|
|
10
|
+
const { strict: i, fuzzyMatch: l, caseSensitive: u, matchMode: S, allowEmptyString: y } = e, n = S === "OR", p = S === "AND";
|
|
11
|
+
let M = !1;
|
|
12
|
+
const t = Object.entries(r), m = {};
|
|
13
|
+
for (const [d, s] of t) {
|
|
14
|
+
const a = c[d];
|
|
15
|
+
if (s === "")
|
|
16
|
+
if (y)
|
|
17
|
+
m[d] = a === "";
|
|
18
|
+
else {
|
|
19
|
+
m[d] = !1;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
let o = !1;
|
|
23
|
+
try {
|
|
24
|
+
if (s instanceof RegExp)
|
|
25
|
+
o = F(a) ? s.test(a) : !1;
|
|
26
|
+
else if (x(s))
|
|
27
|
+
o = !!s(a);
|
|
28
|
+
else if (l && F(s)) {
|
|
29
|
+
const h = String(a), D = u ? s : s.toLowerCase();
|
|
30
|
+
o = (u ? h : h.toLowerCase()).includes(D);
|
|
31
|
+
} else
|
|
32
|
+
o = i ? a === s : a == s;
|
|
33
|
+
} catch {
|
|
34
|
+
o = !1;
|
|
35
|
+
}
|
|
36
|
+
m[d] = o;
|
|
37
|
+
const g = z(o, n, p, M);
|
|
38
|
+
if (g.shouldExit)
|
|
39
|
+
return { match: g.newMatch, matches: m };
|
|
40
|
+
M = g.newMatch;
|
|
41
|
+
}
|
|
42
|
+
return { match: M, matches: m };
|
|
43
|
+
}
|
|
44
|
+
function K(c, r, e) {
|
|
45
|
+
const i = [];
|
|
46
|
+
for (const l of c) {
|
|
47
|
+
const { match: u, matches: S } = O(
|
|
48
|
+
l,
|
|
49
|
+
r,
|
|
50
|
+
e
|
|
51
|
+
);
|
|
52
|
+
let y = u;
|
|
53
|
+
if (e.customMatcher)
|
|
54
|
+
try {
|
|
55
|
+
const t = e.customMatcher(l, S);
|
|
56
|
+
typeof t == "boolean" ? y = t : t && typeof t.match == "boolean" && (y = t.match);
|
|
57
|
+
} catch (t) {
|
|
58
|
+
console.warn("Custom matcher function error:", t);
|
|
59
|
+
}
|
|
60
|
+
const n = { ...l }, p = l[e.childrenKey];
|
|
61
|
+
if (A(p)) {
|
|
62
|
+
const t = K(
|
|
63
|
+
p,
|
|
64
|
+
r,
|
|
65
|
+
e
|
|
66
|
+
);
|
|
67
|
+
t.length > 0 ? n[e.childrenKey] = t : delete n[e.childrenKey];
|
|
68
|
+
}
|
|
69
|
+
const M = n[e.childrenKey] && n[e.childrenKey].length > 0;
|
|
70
|
+
(y || M) && i.push(n);
|
|
71
|
+
}
|
|
72
|
+
return i;
|
|
73
|
+
}
|
|
74
|
+
function V(c, r, e = {}) {
|
|
75
|
+
if (!A(c)) throw new TypeError("参数treeData必须是一个数组");
|
|
76
|
+
if (!T(r)) throw new TypeError("参数searchCondition必须是一个对象");
|
|
77
|
+
const i = {
|
|
13
78
|
strategy: "BFS",
|
|
14
79
|
childrenKey: "children",
|
|
15
80
|
strict: !1,
|
|
@@ -18,73 +83,68 @@ function q(r, l, a = {}) {
|
|
|
18
83
|
caseSensitive: !1,
|
|
19
84
|
allowEmptyString: !1,
|
|
20
85
|
matchMode: "AND",
|
|
21
|
-
|
|
86
|
+
preserveTreeStructure: !1,
|
|
87
|
+
customMatcher: void 0,
|
|
88
|
+
...e
|
|
22
89
|
// 用户配置覆盖默认值
|
|
23
90
|
}, {
|
|
24
|
-
strategy:
|
|
25
|
-
childrenKey:
|
|
26
|
-
strict:
|
|
27
|
-
fuzzyMatch:
|
|
28
|
-
returnAllMatches:
|
|
29
|
-
caseSensitive:
|
|
30
|
-
allowEmptyString:
|
|
31
|
-
matchMode:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
o = (m ? d : d.toLowerCase()).includes(R);
|
|
53
|
-
} else
|
|
54
|
-
o = x ? i === e : i == e;
|
|
55
|
-
} catch {
|
|
56
|
-
o = !1;
|
|
57
|
-
}
|
|
58
|
-
const u = v(o, M, g, t);
|
|
59
|
-
if (u.shouldExit)
|
|
60
|
-
return u.newMatch;
|
|
61
|
-
t = u.newMatch;
|
|
62
|
-
}
|
|
63
|
-
return t;
|
|
64
|
-
};
|
|
65
|
-
for (; c.length > 0; ) {
|
|
66
|
-
const s = h ? c.shift() : c.pop();
|
|
67
|
-
if (!s) continue;
|
|
91
|
+
strategy: l,
|
|
92
|
+
childrenKey: u,
|
|
93
|
+
strict: S,
|
|
94
|
+
fuzzyMatch: y,
|
|
95
|
+
returnAllMatches: n,
|
|
96
|
+
caseSensitive: p,
|
|
97
|
+
allowEmptyString: M,
|
|
98
|
+
matchMode: t,
|
|
99
|
+
preserveTreeStructure: m,
|
|
100
|
+
customMatcher: d
|
|
101
|
+
} = i;
|
|
102
|
+
if (m) {
|
|
103
|
+
const f = K(
|
|
104
|
+
c,
|
|
105
|
+
r,
|
|
106
|
+
i
|
|
107
|
+
);
|
|
108
|
+
return n ? f : f[0] || null;
|
|
109
|
+
}
|
|
110
|
+
const s = t === "OR", a = t === "AND", o = l === "BFS";
|
|
111
|
+
if (!(o || l === "DFS")) throw new Error('配置 strategy 必须是 "BFS" 或 "DFS"');
|
|
112
|
+
if (!(s || a)) throw new Error('配置 matchMode 必须是 "AND" 或 "OR"');
|
|
113
|
+
if (!F(u)) throw new TypeError("配置 childrenKey 必须是字符串");
|
|
114
|
+
const h = [...c], D = [];
|
|
115
|
+
if (Object.entries(r).length)
|
|
116
|
+
for (; h.length > 0; ) {
|
|
117
|
+
const f = o ? h.shift() : h.pop();
|
|
118
|
+
if (!f) continue;
|
|
68
119
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
120
|
+
const { match: w, matches: v } = O(
|
|
121
|
+
f,
|
|
122
|
+
r,
|
|
123
|
+
i
|
|
124
|
+
);
|
|
125
|
+
let R = w;
|
|
126
|
+
if (d) {
|
|
127
|
+
const E = d(f, v);
|
|
128
|
+
typeof E == "boolean" ? R = E : E && typeof E.match == "boolean" && (R = E.match);
|
|
129
|
+
}
|
|
130
|
+
if (R)
|
|
131
|
+
if (n)
|
|
132
|
+
D.push(f);
|
|
72
133
|
else
|
|
73
|
-
return
|
|
134
|
+
return f;
|
|
74
135
|
} catch {
|
|
75
136
|
continue;
|
|
76
137
|
}
|
|
77
|
-
const
|
|
78
|
-
if (A(
|
|
79
|
-
if (
|
|
80
|
-
|
|
138
|
+
const N = f[u];
|
|
139
|
+
if (A(N))
|
|
140
|
+
if (o)
|
|
141
|
+
h.push(...N);
|
|
81
142
|
else
|
|
82
|
-
for (let
|
|
83
|
-
|
|
143
|
+
for (let w = N.length - 1; w >= 0; w--)
|
|
144
|
+
h.push(N[w]);
|
|
84
145
|
}
|
|
85
|
-
|
|
86
|
-
return y ? F : null;
|
|
146
|
+
return n ? D : null;
|
|
87
147
|
}
|
|
88
148
|
export {
|
|
89
|
-
|
|
149
|
+
V as default
|
|
90
150
|
};
|
package/types/index.d.ts
CHANGED
|
@@ -1,30 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * as date from "./date";
|
|
3
|
-
export * as is from "./is";
|
|
4
|
-
export * as math from "./math";
|
|
5
|
-
export * as snapdom from "./snapdom";
|
|
6
|
-
export * as tree from "./tree";
|
|
7
|
-
export * as turboStream from "./turbo-stream";
|
|
8
|
-
export * as uiColor from "./ui-color";
|
|
9
|
-
export * as urlToolkit from "./url-toolkit";
|
|
10
|
-
export { default as caseName } from "./case-name";
|
|
11
|
-
export { default as className } from "./class-name";
|
|
12
|
-
export { default as clipboardCopy } from "./clipboard-copy";
|
|
13
|
-
export { default as decimal } from "./decimal";
|
|
14
|
-
export { default as diff } from "./diff";
|
|
15
|
-
export { default as emitter } from "./emitter";
|
|
16
|
-
export { default as invariant } from "./invariant";
|
|
17
|
-
export { default as jsCookie } from "./js-cookie";
|
|
18
|
-
export { default as Lunar } from "./lunar";
|
|
19
|
-
export { default as md5 } from "./md5";
|
|
20
|
-
export { default as normalizeWheel } from "./normalize-wheel";
|
|
21
|
-
export { default as numberToChinese } from "./number-to-chinese";
|
|
22
|
-
export { default as nzh } from "./nzh";
|
|
23
|
-
export { default as objectKeysSort } from "./object-keys-sort";
|
|
24
|
-
export { default as pinyin } from "./pinyin";
|
|
25
|
-
export { default as screenfull } from "./screenfull";
|
|
26
|
-
export { default as tinycolor } from "./tinycolor";
|
|
27
|
-
export { default as contentDisposition, getContentDispositionFromHeader, getContentDispositionParametersFilenameFromHeader, getContentDispositionParametersFromHeader } from "./content-disposition";
|
|
28
|
-
export { default as cookie, splitCookiesString } from "./cookie";
|
|
29
|
-
export { fileToURL, saveAs } from "./file";
|
|
30
|
-
export { default as filesize, filesizeConstants, partial } from "./filesize";
|
|
1
|
+
export { default as version } from "./version";
|
|
@@ -10,6 +10,18 @@ type Primitive = string | number | boolean | symbol | null | undefined;
|
|
|
10
10
|
* @template T 节点值的泛型类型
|
|
11
11
|
*/
|
|
12
12
|
type ConditionValue<T = unknown> = Primitive | ((value: T) => boolean) | RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* 自定义匹配函数类型
|
|
15
|
+
* @param node 当前节点
|
|
16
|
+
* @param matches 当前已匹配的条件信息
|
|
17
|
+
* @returns 返回boolean或对象包含匹配详情
|
|
18
|
+
*/
|
|
19
|
+
type CustomMatchFunction = (node: TreeNode, matches: {
|
|
20
|
+
[key: string]: boolean;
|
|
21
|
+
}) => boolean | {
|
|
22
|
+
match: boolean;
|
|
23
|
+
reason?: string;
|
|
24
|
+
};
|
|
13
25
|
/**
|
|
14
26
|
* 树搜索配置选项接口
|
|
15
27
|
*/
|
|
@@ -54,6 +66,16 @@ interface SearchOptions {
|
|
|
54
66
|
* @default false
|
|
55
67
|
*/
|
|
56
68
|
allowEmptyString?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* 是否保留树形结构(返回包含匹配节点的最小完整子树)
|
|
71
|
+
* @default false
|
|
72
|
+
*/
|
|
73
|
+
preserveTreeStructure?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* 自定义匹配函数,可以覆盖默认的匹配逻辑
|
|
76
|
+
* 返回true表示匹配,false表示不匹配
|
|
77
|
+
*/
|
|
78
|
+
customMatcher?: CustomMatchFunction;
|
|
57
79
|
}
|
|
58
80
|
/**
|
|
59
81
|
* 树节点接口定义
|
|
@@ -80,11 +80,11 @@ export declare class TurboBlob extends Blob {
|
|
|
80
80
|
text(): Promise<string>;
|
|
81
81
|
}
|
|
82
82
|
declare const FileBaseClass: {
|
|
83
|
-
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
|
|
84
|
-
prototype: Blob;
|
|
85
|
-
} | {
|
|
86
83
|
new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File;
|
|
87
84
|
prototype: File;
|
|
85
|
+
} | {
|
|
86
|
+
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
|
|
87
|
+
prototype: Blob;
|
|
88
88
|
};
|
|
89
89
|
export declare class TurboFile extends FileBaseClass {
|
|
90
90
|
#private;
|
package/version/index.js
ADDED
package/version.js
ADDED
package/diff/index.js
DELETED
package/diff/src/diff.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
declare function diff(
|
|
2
|
-
text1: string,
|
|
3
|
-
text2: string,
|
|
4
|
-
cursorPos?: number | diff.CursorInfo,
|
|
5
|
-
cleanup?: boolean,
|
|
6
|
-
): diff.Diff[];
|
|
7
|
-
|
|
8
|
-
declare namespace diff {
|
|
9
|
-
type Diff = [-1 | 0 | 1, string];
|
|
10
|
-
|
|
11
|
-
const DELETE: -1;
|
|
12
|
-
const INSERT: 1;
|
|
13
|
-
const EQUAL: 0;
|
|
14
|
-
|
|
15
|
-
interface CursorInfo {
|
|
16
|
-
oldRange: { index: number; length: number };
|
|
17
|
-
newRange: { index: number; length: number };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export = diff;
|
package/diff/src/diff.js
DELETED
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
let L = -1, w = 1, A = 0;
|
|
2
|
-
function S(e, t, l, r, i) {
|
|
3
|
-
if (e === t)
|
|
4
|
-
return e ? [[A, e]] : [];
|
|
5
|
-
if (l != null) {
|
|
6
|
-
let a = T(e, t, l);
|
|
7
|
-
if (a)
|
|
8
|
-
return a;
|
|
9
|
-
}
|
|
10
|
-
let n = D(e, t), h = e.substring(0, n);
|
|
11
|
-
e = e.substring(n), t = t.substring(n), n = I(e, t);
|
|
12
|
-
let g = e.substring(e.length - n);
|
|
13
|
-
e = e.substring(0, e.length - n), t = t.substring(0, t.length - n);
|
|
14
|
-
let s = G(e, t);
|
|
15
|
-
return h && s.unshift([A, h]), g && s.push([A, g]), F(s, i), r && K(s), s;
|
|
16
|
-
}
|
|
17
|
-
function G(e, t) {
|
|
18
|
-
let l;
|
|
19
|
-
if (!e)
|
|
20
|
-
return [[w, t]];
|
|
21
|
-
if (!t)
|
|
22
|
-
return [[L, e]];
|
|
23
|
-
let r = e.length > t.length ? e : t, i = e.length > t.length ? t : e, n = r.indexOf(i);
|
|
24
|
-
if (n !== -1)
|
|
25
|
-
return l = [
|
|
26
|
-
[w, r.substring(0, n)],
|
|
27
|
-
[A, i],
|
|
28
|
-
[w, r.substring(n + i.length)]
|
|
29
|
-
], e.length > t.length && (l[0][0] = l[2][0] = L), l;
|
|
30
|
-
if (i.length === 1)
|
|
31
|
-
return [
|
|
32
|
-
[L, e],
|
|
33
|
-
[w, t]
|
|
34
|
-
];
|
|
35
|
-
let h = J(e, t);
|
|
36
|
-
if (h) {
|
|
37
|
-
let g = h[0], s = h[1], a = h[2], u = h[3], c = h[4], f = S(g, a), b = S(s, u);
|
|
38
|
-
return f.concat([[A, c]], b);
|
|
39
|
-
}
|
|
40
|
-
return H(e, t);
|
|
41
|
-
}
|
|
42
|
-
function H(e, t) {
|
|
43
|
-
let l = e.length, r = t.length, i = Math.ceil((l + r) / 2), n = i, h = 2 * i, g = new Array(h), s = new Array(h);
|
|
44
|
-
for (let _ = 0; _ < h; _++)
|
|
45
|
-
g[_] = -1, s[_] = -1;
|
|
46
|
-
g[n + 1] = 0, s[n + 1] = 0;
|
|
47
|
-
let a = l - r, u = a % 2 !== 0, c = 0, f = 0, b = 0, p = 0;
|
|
48
|
-
for (let _ = 0; _ < i; _++) {
|
|
49
|
-
for (let k = -_ + c; k <= _ - f; k += 2) {
|
|
50
|
-
let m = n + k, o;
|
|
51
|
-
k === -_ || k !== _ && g[m - 1] < g[m + 1] ? o = g[m + 1] : o = g[m - 1] + 1;
|
|
52
|
-
let M = o - k;
|
|
53
|
-
for (; o < l && M < r && e.charAt(o) === t.charAt(M); )
|
|
54
|
-
o++, M++;
|
|
55
|
-
if (g[m] = o, o > l)
|
|
56
|
-
f += 2;
|
|
57
|
-
else if (M > r)
|
|
58
|
-
c += 2;
|
|
59
|
-
else if (u) {
|
|
60
|
-
let E = n + a - k;
|
|
61
|
-
if (E >= 0 && E < h && s[E] !== -1) {
|
|
62
|
-
let y = l - s[E];
|
|
63
|
-
if (o >= y)
|
|
64
|
-
return C(e, t, o, M);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
for (let k = -_ + b; k <= _ - p; k += 2) {
|
|
69
|
-
let m = n + k, o;
|
|
70
|
-
k === -_ || k !== _ && s[m - 1] < s[m + 1] ? o = s[m + 1] : o = s[m - 1] + 1;
|
|
71
|
-
let M = o - k;
|
|
72
|
-
for (; o < l && M < r && e.charAt(l - o - 1) === t.charAt(r - M - 1); )
|
|
73
|
-
o++, M++;
|
|
74
|
-
if (s[m] = o, o > l)
|
|
75
|
-
p += 2;
|
|
76
|
-
else if (M > r)
|
|
77
|
-
b += 2;
|
|
78
|
-
else if (!u) {
|
|
79
|
-
let E = n + a - k;
|
|
80
|
-
if (E >= 0 && E < h && g[E] !== -1) {
|
|
81
|
-
let y = g[E], R = n + y - E;
|
|
82
|
-
if (o = l - o, y >= o)
|
|
83
|
-
return C(e, t, y, R);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return [
|
|
89
|
-
[L, e],
|
|
90
|
-
[w, t]
|
|
91
|
-
];
|
|
92
|
-
}
|
|
93
|
-
function C(e, t, l, r) {
|
|
94
|
-
let i = e.substring(0, l), n = t.substring(0, r), h = e.substring(l), g = t.substring(r), s = S(i, n), a = S(h, g);
|
|
95
|
-
return s.concat(a);
|
|
96
|
-
}
|
|
97
|
-
function D(e, t) {
|
|
98
|
-
if (!e || !t || e.charAt(0) !== t.charAt(0))
|
|
99
|
-
return 0;
|
|
100
|
-
let l = 0, r = Math.min(e.length, t.length), i = r, n = 0;
|
|
101
|
-
for (; l < i; )
|
|
102
|
-
e.substring(n, i) == t.substring(n, i) ? (l = i, n = l) : r = i, i = Math.floor((r - l) / 2 + l);
|
|
103
|
-
return j(e.charCodeAt(i - 1)) && i--, i;
|
|
104
|
-
}
|
|
105
|
-
function O(e, t) {
|
|
106
|
-
let l = e.length, r = t.length;
|
|
107
|
-
if (l == 0 || r == 0)
|
|
108
|
-
return 0;
|
|
109
|
-
l > r ? e = e.substring(l - r) : l < r && (t = t.substring(0, l));
|
|
110
|
-
let i = Math.min(l, r);
|
|
111
|
-
if (e == t)
|
|
112
|
-
return i;
|
|
113
|
-
let n = 0, h = 1;
|
|
114
|
-
for (; ; ) {
|
|
115
|
-
let g = e.substring(i - h), s = t.indexOf(g);
|
|
116
|
-
if (s == -1)
|
|
117
|
-
return n;
|
|
118
|
-
h += s, (s == 0 || e.substring(i - h) == t.substring(0, h)) && (n = h, h++);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function I(e, t) {
|
|
122
|
-
if (!e || !t || e.slice(-1) !== t.slice(-1))
|
|
123
|
-
return 0;
|
|
124
|
-
let l = 0, r = Math.min(e.length, t.length), i = r, n = 0;
|
|
125
|
-
for (; l < i; )
|
|
126
|
-
e.substring(e.length - i, e.length - n) == t.substring(t.length - i, t.length - n) ? (l = i, n = l) : r = i, i = Math.floor((r - l) / 2 + l);
|
|
127
|
-
return z(e.charCodeAt(e.length - i)) && i--, i;
|
|
128
|
-
}
|
|
129
|
-
function J(e, t) {
|
|
130
|
-
let l = e.length > t.length ? e : t, r = e.length > t.length ? t : e;
|
|
131
|
-
if (l.length < 4 || r.length * 2 < l.length)
|
|
132
|
-
return null;
|
|
133
|
-
function i(b, p, _) {
|
|
134
|
-
let k = b.substring(_, _ + Math.floor(b.length / 4)), m = -1, o = "", M, E, y, R;
|
|
135
|
-
for (; (m = p.indexOf(k, m + 1)) !== -1; ) {
|
|
136
|
-
let v = D(
|
|
137
|
-
b.substring(_),
|
|
138
|
-
p.substring(m)
|
|
139
|
-
), q = I(
|
|
140
|
-
b.substring(0, _),
|
|
141
|
-
p.substring(0, m)
|
|
142
|
-
);
|
|
143
|
-
o.length < q + v && (o = p.substring(m - q, m) + p.substring(m, m + v), M = b.substring(0, _ - q), E = b.substring(_ + v), y = p.substring(0, m - q), R = p.substring(m + v));
|
|
144
|
-
}
|
|
145
|
-
return o.length * 2 >= b.length ? [
|
|
146
|
-
M,
|
|
147
|
-
E,
|
|
148
|
-
y,
|
|
149
|
-
R,
|
|
150
|
-
o
|
|
151
|
-
] : null;
|
|
152
|
-
}
|
|
153
|
-
let n = i(
|
|
154
|
-
l,
|
|
155
|
-
r,
|
|
156
|
-
Math.ceil(l.length / 4)
|
|
157
|
-
), h = i(
|
|
158
|
-
l,
|
|
159
|
-
r,
|
|
160
|
-
Math.ceil(l.length / 2)
|
|
161
|
-
), g;
|
|
162
|
-
if (!n && !h)
|
|
163
|
-
return null;
|
|
164
|
-
h ? n ? g = n[4].length > h[4].length ? n : h : g = h : g = n;
|
|
165
|
-
let s, a, u, c;
|
|
166
|
-
e.length > t.length ? (s = g[0], a = g[1], u = g[2], c = g[3]) : (u = g[0], c = g[1], s = g[2], a = g[3]);
|
|
167
|
-
let f = g[4];
|
|
168
|
-
return [s, a, u, c, f];
|
|
169
|
-
}
|
|
170
|
-
function K(e) {
|
|
171
|
-
let t = !1, l = [], r = 0, i = null, n = 0, h = 0, g = 0, s = 0, a = 0;
|
|
172
|
-
for (; n < e.length; )
|
|
173
|
-
e[n][0] == A ? (l[r++] = n, h = s, g = a, s = 0, a = 0, i = e[n][1]) : (e[n][0] == w ? s += e[n][1].length : a += e[n][1].length, i && i.length <= Math.max(h, g) && i.length <= Math.max(s, a) && (e.splice(l[r - 1], 0, [
|
|
174
|
-
L,
|
|
175
|
-
i
|
|
176
|
-
]), e[l[r - 1] + 1][0] = w, r--, r--, n = r > 0 ? l[r - 1] : -1, h = 0, g = 0, s = 0, a = 0, i = null, t = !0)), n++;
|
|
177
|
-
for (t && F(e), X(e), n = 1; n < e.length; ) {
|
|
178
|
-
if (e[n - 1][0] == L && e[n][0] == w) {
|
|
179
|
-
let u = e[n - 1][1], c = e[n][1], f = O(u, c), b = O(c, u);
|
|
180
|
-
f >= b ? (f >= u.length / 2 || f >= c.length / 2) && (e.splice(n, 0, [
|
|
181
|
-
A,
|
|
182
|
-
c.substring(0, f)
|
|
183
|
-
]), e[n - 1][1] = u.substring(
|
|
184
|
-
0,
|
|
185
|
-
u.length - f
|
|
186
|
-
), e[n + 1][1] = c.substring(f), n++) : (b >= u.length / 2 || b >= c.length / 2) && (e.splice(n, 0, [
|
|
187
|
-
A,
|
|
188
|
-
u.substring(0, b)
|
|
189
|
-
]), e[n - 1][0] = w, e[n - 1][1] = c.substring(
|
|
190
|
-
0,
|
|
191
|
-
c.length - b
|
|
192
|
-
), e[n + 1][0] = L, e[n + 1][1] = u.substring(b), n++), n++;
|
|
193
|
-
}
|
|
194
|
-
n++;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
let P = /[^a-zA-Z0-9]/, Q = /\s/, U = /[\r\n]/, V = /\n\r?\n$/, W = /^\r?\n\r?\n/;
|
|
198
|
-
function X(e) {
|
|
199
|
-
function t(r, i) {
|
|
200
|
-
if (!r || !i)
|
|
201
|
-
return 6;
|
|
202
|
-
let n = r.charAt(r.length - 1), h = i.charAt(0), g = n.match(P), s = h.match(P), a = g && n.match(Q), u = s && h.match(Q), c = a && n.match(U), f = u && h.match(U), b = c && r.match(V), p = f && i.match(W);
|
|
203
|
-
return b || p ? 5 : c || f ? 4 : g && !a && u ? 3 : a || u ? 2 : g || s ? 1 : 0;
|
|
204
|
-
}
|
|
205
|
-
let l = 1;
|
|
206
|
-
for (; l < e.length - 1; ) {
|
|
207
|
-
if (e[l - 1][0] == A && e[l + 1][0] == A) {
|
|
208
|
-
let r = e[l - 1][1], i = e[l][1], n = e[l + 1][1], h = I(r, i);
|
|
209
|
-
if (h) {
|
|
210
|
-
let c = i.substring(i.length - h);
|
|
211
|
-
r = r.substring(0, r.length - h), i = c + i.substring(0, i.length - h), n = c + n;
|
|
212
|
-
}
|
|
213
|
-
let g = r, s = i, a = n, u = t(r, i) + t(i, n);
|
|
214
|
-
for (; i.charAt(0) === n.charAt(0); ) {
|
|
215
|
-
r += i.charAt(0), i = i.substring(1) + n.charAt(0), n = n.substring(1);
|
|
216
|
-
let c = t(r, i) + t(i, n);
|
|
217
|
-
c >= u && (u = c, g = r, s = i, a = n);
|
|
218
|
-
}
|
|
219
|
-
e[l - 1][1] != g && (g ? e[l - 1][1] = g : (e.splice(l - 1, 1), l--), e[l][1] = s, a ? e[l + 1][1] = a : (e.splice(l + 1, 1), l--));
|
|
220
|
-
}
|
|
221
|
-
l++;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function F(e, t) {
|
|
225
|
-
e.push([A, ""]);
|
|
226
|
-
let l = 0, r = 0, i = 0, n = "", h = "", g;
|
|
227
|
-
for (; l < e.length; ) {
|
|
228
|
-
if (l < e.length - 1 && !e[l][1]) {
|
|
229
|
-
e.splice(l, 1);
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
switch (e[l][0]) {
|
|
233
|
-
case w: {
|
|
234
|
-
i++, h += e[l][1], l++;
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
case L:
|
|
238
|
-
r++, n += e[l][1], l++;
|
|
239
|
-
break;
|
|
240
|
-
case A: {
|
|
241
|
-
let a = l - i - r - 1;
|
|
242
|
-
if (t) {
|
|
243
|
-
if (a >= 0 && $(e[a][1])) {
|
|
244
|
-
let u = e[a][1].slice(-1);
|
|
245
|
-
if (e[a][1] = e[a][1].slice(
|
|
246
|
-
0,
|
|
247
|
-
-1
|
|
248
|
-
), n = u + n, h = u + h, !e[a][1]) {
|
|
249
|
-
e.splice(a, 1), l--;
|
|
250
|
-
let c = a - 1;
|
|
251
|
-
e[c] && e[c][0] === w && (i++, h = e[c][1] + h, c--), e[c] && e[c][0] === L && (r++, n = e[c][1] + n, c--), a = c;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
if (Z(e[l][1])) {
|
|
255
|
-
let u = e[l][1].charAt(0);
|
|
256
|
-
e[l][1] = e[l][1].slice(1), n += u, h += u;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (l < e.length - 1 && !e[l][1]) {
|
|
260
|
-
e.splice(l, 1);
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
if (n.length > 0 || h.length > 0) {
|
|
264
|
-
n.length > 0 && h.length > 0 && (g = D(h, n), g !== 0 && (a >= 0 ? e[a][1] += h.substring(
|
|
265
|
-
0,
|
|
266
|
-
g
|
|
267
|
-
) : (e.splice(0, 0, [
|
|
268
|
-
A,
|
|
269
|
-
h.substring(0, g)
|
|
270
|
-
]), l++), h = h.substring(g), n = n.substring(g)), g = I(h, n), g !== 0 && (e[l][1] = h.substring(h.length - g) + e[l][1], h = h.substring(
|
|
271
|
-
0,
|
|
272
|
-
h.length - g
|
|
273
|
-
), n = n.substring(
|
|
274
|
-
0,
|
|
275
|
-
n.length - g
|
|
276
|
-
)));
|
|
277
|
-
let u = i + r;
|
|
278
|
-
n.length === 0 && h.length === 0 ? (e.splice(l - u, u), l = l - u) : n.length === 0 ? (e.splice(l - u, u, [w, h]), l = l - u + 1) : h.length === 0 ? (e.splice(l - u, u, [L, n]), l = l - u + 1) : (e.splice(
|
|
279
|
-
l - u,
|
|
280
|
-
u,
|
|
281
|
-
[L, n],
|
|
282
|
-
[w, h]
|
|
283
|
-
), l = l - u + 2);
|
|
284
|
-
}
|
|
285
|
-
l !== 0 && e[l - 1][0] === A ? (e[l - 1][1] += e[l][1], e.splice(l, 1)) : l++, i = 0, r = 0, n = "", h = "";
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
e[e.length - 1][1] === "" && e.pop();
|
|
291
|
-
let s = !1;
|
|
292
|
-
for (l = 1; l < e.length - 1; )
|
|
293
|
-
e[l - 1][0] === A && e[l + 1][0] === A && (e[l][1].substring(
|
|
294
|
-
e[l][1].length - e[l - 1][1].length
|
|
295
|
-
) === e[l - 1][1] ? (e[l][1] = e[l - 1][1] + e[l][1].substring(
|
|
296
|
-
0,
|
|
297
|
-
e[l][1].length - e[l - 1][1].length
|
|
298
|
-
), e[l + 1][1] = e[l - 1][1] + e[l + 1][1], e.splice(l - 1, 1), s = !0) : e[l][1].substring(0, e[l + 1][1].length) == e[l + 1][1] && (e[l - 1][1] += e[l + 1][1], e[l][1] = e[l][1].substring(e[l + 1][1].length) + e[l + 1][1], e.splice(l + 1, 1), s = !0)), l++;
|
|
299
|
-
s && F(e, t);
|
|
300
|
-
}
|
|
301
|
-
function j(e) {
|
|
302
|
-
return e >= 55296 && e <= 56319;
|
|
303
|
-
}
|
|
304
|
-
function z(e) {
|
|
305
|
-
return e >= 56320 && e <= 57343;
|
|
306
|
-
}
|
|
307
|
-
function Z(e) {
|
|
308
|
-
return z(e.charCodeAt(0));
|
|
309
|
-
}
|
|
310
|
-
function $(e) {
|
|
311
|
-
return j(e.charCodeAt(e.length - 1));
|
|
312
|
-
}
|
|
313
|
-
function Y(e) {
|
|
314
|
-
let t = [];
|
|
315
|
-
for (let l = 0; l < e.length; l++)
|
|
316
|
-
e[l][1].length > 0 && t.push(e[l]);
|
|
317
|
-
return t;
|
|
318
|
-
}
|
|
319
|
-
function N(e, t, l, r) {
|
|
320
|
-
return $(e) || Z(r) ? null : Y([
|
|
321
|
-
[A, e],
|
|
322
|
-
[L, t],
|
|
323
|
-
[w, l],
|
|
324
|
-
[A, r]
|
|
325
|
-
]);
|
|
326
|
-
}
|
|
327
|
-
function T(e, t, l) {
|
|
328
|
-
let r = typeof l == "number" ? { index: l, length: 0 } : l.oldRange, i = typeof l == "number" ? null : l.newRange, n = e.length, h = t.length;
|
|
329
|
-
if (r.length === 0 && (i === null || i.length === 0)) {
|
|
330
|
-
let g = r.index, s = e.slice(0, g), a = e.slice(g), u = i ? i.index : null;
|
|
331
|
-
e: {
|
|
332
|
-
let c = g + h - n;
|
|
333
|
-
if (u !== null && u !== c || c < 0 || c > h)
|
|
334
|
-
break e;
|
|
335
|
-
let f = t.slice(0, c);
|
|
336
|
-
if (t.slice(c) !== a)
|
|
337
|
-
break e;
|
|
338
|
-
let p = Math.min(g, c), _ = s.slice(0, p), k = f.slice(0, p);
|
|
339
|
-
if (_ !== k)
|
|
340
|
-
break e;
|
|
341
|
-
let m = s.slice(p), o = f.slice(p);
|
|
342
|
-
return N(_, m, o, a);
|
|
343
|
-
}
|
|
344
|
-
e: {
|
|
345
|
-
if (u !== null && u !== g)
|
|
346
|
-
break e;
|
|
347
|
-
let c = g, f = t.slice(0, c), b = t.slice(c);
|
|
348
|
-
if (f !== s)
|
|
349
|
-
break e;
|
|
350
|
-
let p = Math.min(n - c, h - c), _ = a.slice(a.length - p), k = b.slice(b.length - p);
|
|
351
|
-
if (_ !== k)
|
|
352
|
-
break e;
|
|
353
|
-
let m = a.slice(0, a.length - p), o = b.slice(0, b.length - p);
|
|
354
|
-
return N(s, m, o, _);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
if (r.length > 0 && i && i.length === 0)
|
|
358
|
-
e: {
|
|
359
|
-
let g = e.slice(0, r.index), s = e.slice(r.index + r.length), a = g.length, u = s.length;
|
|
360
|
-
if (h < a + u)
|
|
361
|
-
break e;
|
|
362
|
-
let c = t.slice(0, a), f = t.slice(h - u);
|
|
363
|
-
if (g !== c || s !== f)
|
|
364
|
-
break e;
|
|
365
|
-
let b = e.slice(a, n - u), p = t.slice(a, h - u);
|
|
366
|
-
return N(g, b, p, s);
|
|
367
|
-
}
|
|
368
|
-
return null;
|
|
369
|
-
}
|
|
370
|
-
function B(e, t, l, r) {
|
|
371
|
-
return S(e, t, l, r, !0);
|
|
372
|
-
}
|
|
373
|
-
B.INSERT = w;
|
|
374
|
-
B.DELETE = L;
|
|
375
|
-
B.EQUAL = A;
|
|
376
|
-
export {
|
|
377
|
-
L as DELETE,
|
|
378
|
-
A as EQUAL,
|
|
379
|
-
w as INSERT,
|
|
380
|
-
B as default
|
|
381
|
-
};
|
package/diff.js
DELETED
package/types/diff/index.d.ts
DELETED
package/types/diff/src/diff.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export default diff;
|
|
2
|
-
/**
|
|
3
|
-
* This library modifies the diff-patch-match library by Neil Fraser
|
|
4
|
-
* by removing the patch and match functionality and certain advanced
|
|
5
|
-
* options in the diff function. The original license is as follows:
|
|
6
|
-
*
|
|
7
|
-
* ===
|
|
8
|
-
*
|
|
9
|
-
* Diff Match and Patch
|
|
10
|
-
*
|
|
11
|
-
* Copyright 2006 Google Inc.
|
|
12
|
-
* http://code.google.com/p/google-diff-match-patch/
|
|
13
|
-
*
|
|
14
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
15
|
-
* you may not use this file except in compliance with the License.
|
|
16
|
-
* You may obtain a copy of the License at
|
|
17
|
-
*
|
|
18
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
-
*
|
|
20
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
21
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
22
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
23
|
-
* See the License for the specific language governing permissions and
|
|
24
|
-
* limitations under the License.
|
|
25
|
-
*/
|
|
26
|
-
/**
|
|
27
|
-
* The data structure representing a diff is an array of tuples:
|
|
28
|
-
* [[DIFF_DELETE, 'Hello'], [DIFF_INSERT, 'Goodbye'], [DIFF_EQUAL, ' world.']]
|
|
29
|
-
* which means: delete 'Hello', add 'Goodbye' and keep ' world.'
|
|
30
|
-
*/
|
|
31
|
-
declare let DIFF_DELETE: number;
|
|
32
|
-
declare let DIFF_EQUAL: number;
|
|
33
|
-
declare let DIFF_INSERT: number;
|
|
34
|
-
declare function diff(text1: any, text2: any, cursor_pos: any, cleanup: any): any[];
|
|
35
|
-
declare namespace diff {
|
|
36
|
-
export { DIFF_INSERT as INSERT };
|
|
37
|
-
export { DIFF_DELETE as DELETE };
|
|
38
|
-
export { DIFF_EQUAL as EQUAL };
|
|
39
|
-
}
|
|
40
|
-
export { DIFF_DELETE as DELETE, DIFF_EQUAL as EQUAL, DIFF_INSERT as INSERT };
|