@jayfong/x-utils 1.0.0-202407012223
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/_cjs/ai.js +80 -0
- package/_cjs/cli.js +51 -0
- package/_cjs/clipboard.js +65 -0
- package/_cjs/cmd.js +42 -0
- package/_cjs/crawler.js +341 -0
- package/_cjs/csv.js +97 -0
- package/_cjs/data_set.js +115 -0
- package/_cjs/env.js +63 -0
- package/_cjs/fs.js +35 -0
- package/_cjs/html.js +62 -0
- package/_cjs/http_server.js +56 -0
- package/_cjs/json.js +49 -0
- package/_cjs/ksb.js +217 -0
- package/_cjs/number.js +39 -0
- package/_cjs/ocr.js +74 -0
- package/_cjs/path.js +35 -0
- package/_cjs/pinyin.js +32 -0
- package/_cjs/puppeteer.js +271 -0
- package/_cjs/runner.js +88 -0
- package/_cjs/task.js +41 -0
- package/_cjs/text.js +136 -0
- package/_cjs/unicode/lib_unicode.js +58643 -0
- package/_cjs/unicode/unicode.js +441 -0
- package/_cjs/upload.js +100 -0
- package/_cjs/yaml.js +52 -0
- package/ai.d.ts +26 -0
- package/ai.js +60 -0
- package/cli.d.ts +14 -0
- package/cli.js +21 -0
- package/clipboard.d.ts +6 -0
- package/clipboard.js +35 -0
- package/cmd.d.ts +5 -0
- package/cmd.js +22 -0
- package/crawler.d.ts +162 -0
- package/crawler.js +332 -0
- package/csv.d.ts +14 -0
- package/csv.js +67 -0
- package/data_set.d.ts +22 -0
- package/data_set.js +85 -0
- package/env.d.ts +4 -0
- package/env.js +32 -0
- package/fs.d.ts +2 -0
- package/fs.js +5 -0
- package/html.d.ts +7 -0
- package/html.js +45 -0
- package/http_server.d.ts +10 -0
- package/http_server.js +26 -0
- package/json.d.ts +6 -0
- package/json.js +19 -0
- package/ksb.d.ts +32 -0
- package/ksb.js +197 -0
- package/number.d.ts +3 -0
- package/number.js +9 -0
- package/ocr.d.ts +10 -0
- package/ocr.js +54 -0
- package/ofd.d.ts +1 -0
- package/package.json +158 -0
- package/path.d.ts +2 -0
- package/path.js +5 -0
- package/pinyin.d.ts +3 -0
- package/pinyin.js +12 -0
- package/puppeteer.d.ts +38 -0
- package/puppeteer.js +241 -0
- package/runner.d.ts +13 -0
- package/runner.js +58 -0
- package/task.d.ts +6 -0
- package/task.js +21 -0
- package/text.d.ts +63 -0
- package/text.js +119 -0
- package/unicode/lib_unicode.d.ts +4 -0
- package/unicode/lib_unicode.js +58623 -0
- package/unicode/unicode.d.ts +347 -0
- package/unicode/unicode.js +426 -0
- package/upload.d.ts +22 -0
- package/upload.js +70 -0
- package/yaml.d.ts +6 -0
- package/yaml.js +22 -0
package/text.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decode as decodeHtmlEntity,
|
|
3
|
+
encode as encodeHtmlEntity
|
|
4
|
+
} from "html-entities";
|
|
5
|
+
class XText {
|
|
6
|
+
constructor(text) {
|
|
7
|
+
this.text = text;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 将字符串分割为字符数组。
|
|
11
|
+
*
|
|
12
|
+
* @see https://stackoverflow.com/a/71619350
|
|
13
|
+
*/
|
|
14
|
+
static split(text) {
|
|
15
|
+
return [...new Intl.Segmenter().segment(text)].map((x) => x.segment);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 纯粹为了书写 HTML 有提示。
|
|
19
|
+
*/
|
|
20
|
+
static html(literals, ...interpolations) {
|
|
21
|
+
let result = "";
|
|
22
|
+
for (let i = 0; i < interpolations.length; i++) {
|
|
23
|
+
result += literals[i];
|
|
24
|
+
result += interpolations[i];
|
|
25
|
+
}
|
|
26
|
+
result += literals[literals.length - 1];
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 切割字符串。
|
|
31
|
+
*/
|
|
32
|
+
static cut(text, start, end) {
|
|
33
|
+
text = text.split(start)[1].split(end)[0];
|
|
34
|
+
return text;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 移除全部空白字符。
|
|
38
|
+
*/
|
|
39
|
+
static stripWhitespace(text) {
|
|
40
|
+
text = text.replace(/\s+/g, "");
|
|
41
|
+
return text;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 移除首尾空白字符。
|
|
45
|
+
*/
|
|
46
|
+
static stripMarginWhitespace(text) {
|
|
47
|
+
text = text.trim();
|
|
48
|
+
return text;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* HTML 实体编码。
|
|
52
|
+
*/
|
|
53
|
+
static encodeHtmlEntity(text) {
|
|
54
|
+
text = encodeHtmlEntity(text);
|
|
55
|
+
return text;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* HTML 实体解码。
|
|
59
|
+
*/
|
|
60
|
+
static decodeHtmlEntity(text) {
|
|
61
|
+
text = decodeHtmlEntity(text);
|
|
62
|
+
return text;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 移除 HTML 代码。
|
|
66
|
+
*/
|
|
67
|
+
static stripHtml(text) {
|
|
68
|
+
text = text.replace(/<script[\s>].+?<\/script>/g, "").replace(/<style[\s>].+?<\/style>/g, "").replace(/<(.+?)>/g, "");
|
|
69
|
+
return text;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 切割字符串。
|
|
73
|
+
*/
|
|
74
|
+
cut(start, end) {
|
|
75
|
+
this.text = XText.cut(this.text, start, end);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 移除全部空白字符。
|
|
80
|
+
*/
|
|
81
|
+
stripWhitespace() {
|
|
82
|
+
this.text = XText.stripWhitespace(this.text);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 移除首尾空白字符。
|
|
87
|
+
*/
|
|
88
|
+
stripMarginWhitespace() {
|
|
89
|
+
this.text = XText.stripMarginWhitespace(this.text);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* HTML 实体编码。
|
|
94
|
+
*/
|
|
95
|
+
encodeHtmlEntity() {
|
|
96
|
+
this.text = XText.encodeHtmlEntity(this.text);
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* HTML 实体解码。
|
|
101
|
+
*/
|
|
102
|
+
decodeHtmlEntity() {
|
|
103
|
+
this.text = XText.decodeHtmlEntity(this.text);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 移除 HTML 代码。
|
|
108
|
+
*/
|
|
109
|
+
stripHtml() {
|
|
110
|
+
this.text = XText.stripHtml(this.text);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
toString() {
|
|
114
|
+
return this.text;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
XText
|
|
119
|
+
};
|