mingyang_text 2021.12.28 → 2022.3.11
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/package.json +1 -1
- package/text.js +89 -30
package/package.json
CHANGED
package/text.js
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
* @param {"目标长度"} args_Length
|
6
6
|
* @param {"占位符"} args_PlaceHolder
|
7
7
|
*/
|
8
|
-
|
8
|
+
function func_StringFormat(args_Input, args_Length, args_PlaceHolder) {
|
9
9
|
if (args_Input.toString().length > args_Length) {
|
10
10
|
return args_Input.toString();
|
11
11
|
}
|
@@ -13,6 +13,7 @@ module.exports.do_StringFormat = (args_Input, args_Length, args_PlaceHolder) =>
|
|
13
13
|
return (Array(args_Length).join(args_PlaceHolder) + args_Input).slice(-args_Length);
|
14
14
|
}
|
15
15
|
}
|
16
|
+
module.exports.do_StringFormat = func_StringFormat;
|
16
17
|
|
17
18
|
|
18
19
|
|
@@ -21,12 +22,12 @@ module.exports.do_StringFormat = (args_Input, args_Length, args_PlaceHolder) =>
|
|
21
22
|
* @param {"最小值,随机数可以选中最小值"} args_Min
|
22
23
|
* @param {"最大值,随机数不会选中最大值"} args_Max
|
23
24
|
*/
|
24
|
-
|
25
|
+
function func_Random(args_Min, args_Max) {
|
25
26
|
let temp_Val = Math.floor(Math.random() * (args_Max - args_Min)) + args_Min;
|
26
27
|
//console.log(temp_Val);
|
27
28
|
return temp_Val;
|
28
29
|
}
|
29
|
-
|
30
|
+
module.exports.do_Random = func_Random;
|
30
31
|
|
31
32
|
|
32
33
|
/**
|
@@ -34,7 +35,7 @@ module.exports.do_Random = (args_Min, args_Max) => {
|
|
34
35
|
* @param {"时间对象,如果传入空,那么将使用当前时间"} args_Date
|
35
36
|
* @param {"时间格式,例如【yyyy-MM-dd HH:mm:ss.fff】【yyyyMMddHHmmssfff】"} args_Format
|
36
37
|
*/
|
37
|
-
|
38
|
+
function func_DateTimeToString(args_Date, args_Format) {
|
38
39
|
|
39
40
|
if (args_Date == null) {
|
40
41
|
args_Date = new Date();
|
@@ -52,40 +53,97 @@ module.exports.do_DateTimeToString = (args_Date, args_Format) => {
|
|
52
53
|
let t_Now = "";
|
53
54
|
t_Now = args_Format;
|
54
55
|
t_Now = t_Now.replace("yyyy", t_y);
|
55
|
-
t_Now = t_Now.replace("MM",
|
56
|
-
t_Now = t_Now.replace("dd",
|
57
|
-
t_Now = t_Now.replace("HH",
|
58
|
-
t_Now = t_Now.replace("mm",
|
59
|
-
t_Now = t_Now.replace("ss",
|
60
|
-
t_Now = t_Now.replace("fff",
|
56
|
+
t_Now = t_Now.replace("MM", func_StringFormat(t_M, 2, '0'));
|
57
|
+
t_Now = t_Now.replace("dd", func_StringFormat(t_d, 2, '0'));
|
58
|
+
t_Now = t_Now.replace("HH", func_StringFormat(t_h, 2, '0'));
|
59
|
+
t_Now = t_Now.replace("mm", func_StringFormat(t_m, 2, '0'));
|
60
|
+
t_Now = t_Now.replace("ss", func_StringFormat(t_s, 2, '0'));
|
61
|
+
t_Now = t_Now.replace("fff", func_StringFormat(t_i, 3, '0'));
|
61
62
|
|
62
63
|
return t_Now;
|
63
64
|
}
|
65
|
+
module.exports.do_DateTimeToString = func_DateTimeToString;
|
66
|
+
|
67
|
+
|
68
|
+
/**
|
69
|
+
* 根据给定的左右标签,提取父串中的子串
|
70
|
+
* @param {"输入文本"} args_Text
|
71
|
+
* @param {"左侧标记"} args_Bin
|
72
|
+
* @param {"右侧标记"} args_End
|
73
|
+
*/
|
74
|
+
function func_Filter(args_Text, args_Bin, args_End) {
|
75
|
+
|
76
|
+
if (args_Bin == "" && args_End == "") {
|
77
|
+
return args_Text;
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
let t_iBin = 0;
|
82
|
+
let t_iEnd = 0;
|
83
|
+
let t_Line = "";
|
84
|
+
let t_Start = 0;
|
85
|
+
let t_Result = [];
|
86
|
+
|
87
|
+
do {
|
88
|
+
if (args_Bin == "") {
|
89
|
+
t_iBin = t_Start;
|
90
|
+
}
|
91
|
+
else {
|
92
|
+
t_iBin = args_Text.indexOf(args_Bin, t_Start);
|
93
|
+
if (t_iBin == -1) {
|
94
|
+
return t_Result;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
64
98
|
|
99
|
+
if (args_End == "") {
|
100
|
+
t_iEnd = args_Text.indexOf(args_Bin, t_iBin + args_Bin.length);
|
101
|
+
if (t_iEnd == -1) {
|
102
|
+
t_iEnd = args_Text.length;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
else {
|
106
|
+
t_iEnd = args_Text.indexOf(args_End, t_iBin + args_Bin.length);
|
107
|
+
if (t_iEnd == -1) {
|
108
|
+
return t_Result;
|
109
|
+
}
|
110
|
+
}
|
65
111
|
|
112
|
+
t_Line = args_Text.substr(t_iBin + args_Bin.length, t_iEnd - t_iBin - args_Bin.length);
|
113
|
+
t_Result.push(t_Line);
|
114
|
+
|
115
|
+
t_Start = t_iEnd + args_End.length;
|
116
|
+
} while (t_Start > -1 && t_Start < args_Text.length);
|
117
|
+
|
118
|
+
return t_Result;
|
119
|
+
}
|
120
|
+
module.exports.do_Filter = func_Filter;
|
66
121
|
|
67
122
|
/**
|
68
123
|
* 返回一个36位的时间在左侧的UUID
|
69
124
|
*/
|
70
|
-
|
71
|
-
return
|
125
|
+
function func_TimeID_36() {
|
126
|
+
return func_TimeID(36);
|
72
127
|
}
|
128
|
+
module.exports.do_TimeID_36 = func_TimeID_36;
|
73
129
|
|
74
130
|
/**
|
75
131
|
* 返回一个32位的时间在左侧的UUID
|
76
132
|
*/
|
77
|
-
|
78
|
-
return
|
133
|
+
function func_TimeID_32() {
|
134
|
+
return func_TimeID(32);
|
79
135
|
}
|
136
|
+
module.exports.do_TimeID_32 = func_TimeID_32;
|
137
|
+
|
80
138
|
/**
|
81
139
|
* 返回一个时间在左侧的UUID
|
82
140
|
*/
|
83
|
-
|
141
|
+
function func_TimeID(args_Digit) {
|
84
142
|
let temp_List = new Array(args_Digit);
|
85
143
|
|
86
144
|
let temp_PlaceHolder = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
87
145
|
|
88
|
-
let temp_Time =
|
146
|
+
let temp_Time = func_DateTimeToString(null, "yyyy-MMdd-HHmmss-fff");
|
89
147
|
for (let i = 0; i < temp_Time.length; i++) {
|
90
148
|
temp_List[i] = temp_Time[i];
|
91
149
|
}
|
@@ -93,7 +151,7 @@ module.exports.do_TimeID = (args_Digit) => {
|
|
93
151
|
temp_List[temp_Time.length] = "-";
|
94
152
|
|
95
153
|
for (let i = temp_Time.length + 1; i < args_Digit; i++) {
|
96
|
-
temp_List[i] = temp_PlaceHolder.substr(
|
154
|
+
temp_List[i] = temp_PlaceHolder.substr(func_Random(0, temp_PlaceHolder.length), 1);
|
97
155
|
}
|
98
156
|
|
99
157
|
//temp_List[20] = "-";
|
@@ -102,7 +160,7 @@ module.exports.do_TimeID = (args_Digit) => {
|
|
102
160
|
let temp_UUID = temp_List.join("");
|
103
161
|
return temp_UUID;
|
104
162
|
}
|
105
|
-
|
163
|
+
module.exports.do_TimeID = func_TimeID;
|
106
164
|
|
107
165
|
|
108
166
|
|
@@ -112,22 +170,22 @@ module.exports.do_TimeID = (args_Digit) => {
|
|
112
170
|
* 从【16进制文本】转换为【普通文本】
|
113
171
|
* @param {"16进制文本"} args_Hex
|
114
172
|
*/
|
115
|
-
|
173
|
+
function func_Hex_goto_Plain(args_Hex) {
|
116
174
|
let t_Buffer = Buffer.from(args_Hex, 'hex');
|
117
175
|
return t_Buffer.toString("utf8");
|
118
176
|
}
|
119
|
-
|
177
|
+
module.exports.do_Hex_goto_Plain = func_Hex_goto_Plain;
|
120
178
|
|
121
179
|
|
122
180
|
/**
|
123
181
|
* 从【普通文本】转换为【16进制文本】
|
124
182
|
* @param {"普通文本"} args_Hex
|
125
183
|
*/
|
126
|
-
|
184
|
+
function func_Hex_from_Plain(args_Plain) {
|
127
185
|
let t_Buffer = Buffer.from(args_Plain, "utf8");
|
128
186
|
return t_Buffer.toString("hex");
|
129
187
|
}
|
130
|
-
|
188
|
+
module.exports.do_Hex_from_Plain = func_Hex_from_Plain;
|
131
189
|
|
132
190
|
|
133
191
|
|
@@ -136,7 +194,7 @@ module.exports.do_Hex_from_Plain = (args_Plain) => {
|
|
136
194
|
* @param {"主字符串"} args_Subject
|
137
195
|
* @param {"从字符串"} args_Compare
|
138
196
|
*/
|
139
|
-
|
197
|
+
function func_Bin_With(args_Subject, args_Compare) {
|
140
198
|
if (args_Subject == null || args_Compare == null) {
|
141
199
|
return false;
|
142
200
|
}
|
@@ -151,7 +209,7 @@ module.exports.do_Bin_With = (args_Subject, args_Compare) => {
|
|
151
209
|
}
|
152
210
|
return true;
|
153
211
|
}
|
154
|
-
|
212
|
+
module.exports.do_Bin_With = func_Bin_With;
|
155
213
|
|
156
214
|
|
157
215
|
|
@@ -160,7 +218,7 @@ module.exports.do_Bin_With = (args_Subject, args_Compare) => {
|
|
160
218
|
* @param {"主字符串"} args_Subject
|
161
219
|
* @param {"从字符串"} args_Compare
|
162
220
|
*/
|
163
|
-
|
221
|
+
function func_End_With(args_Subject, args_Compare) {
|
164
222
|
if (args_Subject == null || args_Compare == null) {
|
165
223
|
return false;
|
166
224
|
}
|
@@ -176,7 +234,7 @@ module.exports.do_End_With = (args_Subject, args_Compare) => {
|
|
176
234
|
}
|
177
235
|
return true;
|
178
236
|
}
|
179
|
-
|
237
|
+
module.exports.do_End_With = func_End_With;
|
180
238
|
|
181
239
|
|
182
240
|
|
@@ -187,7 +245,7 @@ module.exports.do_End_With = (args_Subject, args_Compare) => {
|
|
187
245
|
* @param {"分割字符"} args_Split
|
188
246
|
* @param {"等于字符"} args_Equal
|
189
247
|
*/
|
190
|
-
|
248
|
+
function func_KeyValue_Decode(args_Plain, args_Split, args_Equal) {
|
191
249
|
|
192
250
|
let temp_Data = {};
|
193
251
|
let temp_Cookie_List = args_Plain.split(args_Split);
|
@@ -204,7 +262,7 @@ module.exports.do_KeyValue_Decode = (args_Plain, args_Split, args_Equal) => {
|
|
204
262
|
}
|
205
263
|
return temp_Data;
|
206
264
|
}
|
207
|
-
|
265
|
+
module.exports.do_KeyValue_Decode = func_KeyValue_Decode;
|
208
266
|
|
209
267
|
|
210
268
|
/**
|
@@ -213,7 +271,7 @@ module.exports.do_KeyValue_Decode = (args_Plain, args_Split, args_Equal) => {
|
|
213
271
|
* @param {"分割字符"} args_Split
|
214
272
|
* @param {"等于字符"} args_Equal
|
215
273
|
*/
|
216
|
-
|
274
|
+
function func_KeyValue_Encode(args_Datas, args_Split, args_Equal) {
|
217
275
|
|
218
276
|
let temp_Keys = Object.keys(args_Datas);
|
219
277
|
let t_Lenth = temp_Keys.length;
|
@@ -231,4 +289,5 @@ module.exports.do_KeyValue_Encode = (args_Datas, args_Split, args_Equal) => {
|
|
231
289
|
}
|
232
290
|
|
233
291
|
return temp_Line;
|
234
|
-
}
|
292
|
+
}
|
293
|
+
module.exports.do_KeyValue_Encode = func_KeyValue_Encode;
|