mingyang_text 2021.11.11 → 2022.8.8

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 (2) hide show
  1. package/package.json +1 -1
  2. package/text.js +90 -59
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mingyang_text",
3
- "version": "2021.11.11",
3
+ "version": "2022.08.08",
4
4
  "description": "MingYang Packet",
5
5
  "main": "text.js",
6
6
  "scripts": {
package/text.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * @param {"目标长度"} args_Length
6
6
  * @param {"占位符"} args_PlaceHolder
7
7
  */
8
- module.exports.do_StringFormat = (args_Input, args_Length, args_PlaceHolder) => {
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
- module.exports.do_Random = (args_Min, args_Max) => {
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
- module.exports.do_DateTimeToString = (args_Date, args_Format) => {
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,98 @@ 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", module.exports.do_StringFormat(t_M, 2, '0'));
56
- t_Now = t_Now.replace("dd", module.exports.do_StringFormat(t_d, 2, '0'));
57
- t_Now = t_Now.replace("HH", module.exports.do_StringFormat(t_h, 2, '0'));
58
- t_Now = t_Now.replace("mm", module.exports.do_StringFormat(t_m, 2, '0'));
59
- t_Now = t_Now.replace("ss", module.exports.do_StringFormat(t_s, 2, '0'));
60
- t_Now = t_Now.replace("fff", module.exports.do_StringFormat(t_i, 3, '0'));
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) {
64
75
 
76
+ if (args_Bin == "" && args_End == "") {
77
+ return args_Text;
78
+ }
65
79
 
66
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
+
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
+ }
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;
121
+
67
122
  /**
68
123
  * 返回一个36位的时间在左侧的UUID
69
124
  */
70
- module.exports.do_TimeID_36 = () => {
71
- return module.exports.do_TimeID(36);
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
- module.exports.do_TimeID_32 = () => {
78
- return module.exports.do_TimeID(32);
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
- module.exports.do_TimeID = (args_Digit) => {
141
+ function func_TimeID(args_Digit) {
84
142
  let temp_List = new Array(args_Digit);
85
143
 
144
+ //let temp_PlaceHolder = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
86
145
  let temp_PlaceHolder = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
87
146
 
88
- let temp_Time = module.exports.do_DateTimeToString(null, "yyyy-MMdd-HHmmss-fff");
147
+ let temp_Time = func_DateTimeToString(null, "yyyy-MMdd-HHmmss-fff");
89
148
  for (let i = 0; i < temp_Time.length; i++) {
90
149
  temp_List[i] = temp_Time[i];
91
150
  }
@@ -93,7 +152,7 @@ module.exports.do_TimeID = (args_Digit) => {
93
152
  temp_List[temp_Time.length] = "-";
94
153
 
95
154
  for (let i = temp_Time.length + 1; i < args_Digit; i++) {
96
- temp_List[i] = temp_PlaceHolder.substr(this.do_Random(0, temp_PlaceHolder.length), 1);
155
+ temp_List[i] = temp_PlaceHolder[func_Random(0, temp_PlaceHolder.length)];
97
156
  }
98
157
 
99
158
  //temp_List[20] = "-";
@@ -102,7 +161,7 @@ module.exports.do_TimeID = (args_Digit) => {
102
161
  let temp_UUID = temp_List.join("");
103
162
  return temp_UUID;
104
163
  }
105
-
164
+ module.exports.do_TimeID = func_TimeID;
106
165
 
107
166
 
108
167
 
@@ -112,51 +171,22 @@ module.exports.do_TimeID = (args_Digit) => {
112
171
  * 从【16进制文本】转换为【普通文本】
113
172
  * @param {"16进制文本"} args_Hex
114
173
  */
115
- module.exports.do_Hex_goto_Plain = (args_Hex) => {
174
+ function func_Hex_goto_Plain(args_Hex) {
116
175
  let t_Buffer = Buffer.from(args_Hex, 'hex');
117
176
  return t_Buffer.toString("utf8");
118
177
  }
119
-
178
+ module.exports.do_Hex_goto_Plain = func_Hex_goto_Plain;
120
179
 
121
180
 
122
181
  /**
123
182
  * 从【普通文本】转换为【16进制文本】
124
183
  * @param {"普通文本"} args_Hex
125
184
  */
126
- module.exports.do_Hex_from_Plain = (args_Plain) => {
185
+ function func_Hex_from_Plain(args_Plain) {
127
186
  let t_Buffer = Buffer.from(args_Plain, "utf8");
128
187
  return t_Buffer.toString("hex");
129
188
  }
130
-
131
-
132
-
133
-
134
-
135
- /**
136
- * 将目标字符串截取为3段,下标0 是开始处 到 bin之间的部分(不包含bin);下标1是bin和end之间的字符串(不包含bin和end);下标2 是end 到 结束处之间的部分(不包含end);如果匹配不到返回null
137
- * @param {"目标字符串"} args_Text
138
- * @param {"开始匹配符"} args_Bin
139
- * @param {"结束匹配符"} args_End
140
- */
141
- module.exports.do_Subsection = (args_Text, args_Bin, args_End) => {
142
- let temp_Bin = args_Text.indexOf(args_Bin);
143
- if (temp_Bin > -1) {
144
- let temp_End = args_Text.indexOf(args_End, temp_Bin + args_Bin.length);
145
- if (temp_End > -1) {
146
- let temp_L = args_Text.substr(0, temp_Bin);
147
- let temp_C = args_Text.substr(temp_Bin + args_Bin.length, temp_End - temp_Bin - args_Bin.length);
148
- let temp_R = args_Text.substr(temp_End + args_End.length);
149
-
150
- return [temp_L, temp_C, temp_R];
151
- }
152
- else {
153
- return null;
154
- }
155
- }
156
- else {
157
- return null;
158
- }
159
- }
189
+ module.exports.do_Hex_from_Plain = func_Hex_from_Plain;
160
190
 
161
191
 
162
192
 
@@ -165,7 +195,7 @@ module.exports.do_Subsection = (args_Text, args_Bin, args_End) => {
165
195
  * @param {"主字符串"} args_Subject
166
196
  * @param {"从字符串"} args_Compare
167
197
  */
168
- module.exports.do_Bin_With = (args_Subject, args_Compare) => {
198
+ function func_Bin_With(args_Subject, args_Compare) {
169
199
  if (args_Subject == null || args_Compare == null) {
170
200
  return false;
171
201
  }
@@ -180,7 +210,7 @@ module.exports.do_Bin_With = (args_Subject, args_Compare) => {
180
210
  }
181
211
  return true;
182
212
  }
183
-
213
+ module.exports.do_Bin_With = func_Bin_With;
184
214
 
185
215
 
186
216
 
@@ -189,7 +219,7 @@ module.exports.do_Bin_With = (args_Subject, args_Compare) => {
189
219
  * @param {"主字符串"} args_Subject
190
220
  * @param {"从字符串"} args_Compare
191
221
  */
192
- module.exports.do_End_With = (args_Subject, args_Compare) => {
222
+ function func_End_With(args_Subject, args_Compare) {
193
223
  if (args_Subject == null || args_Compare == null) {
194
224
  return false;
195
225
  }
@@ -205,7 +235,7 @@ module.exports.do_End_With = (args_Subject, args_Compare) => {
205
235
  }
206
236
  return true;
207
237
  }
208
-
238
+ module.exports.do_End_With = func_End_With;
209
239
 
210
240
 
211
241
 
@@ -216,7 +246,7 @@ module.exports.do_End_With = (args_Subject, args_Compare) => {
216
246
  * @param {"分割字符"} args_Split
217
247
  * @param {"等于字符"} args_Equal
218
248
  */
219
- module.exports.do_KeyValue_Decode = (args_Plain, args_Split, args_Equal) => {
249
+ function func_KeyValue_Decode(args_Plain, args_Split, args_Equal) {
220
250
 
221
251
  let temp_Data = {};
222
252
  let temp_Cookie_List = args_Plain.split(args_Split);
@@ -233,7 +263,7 @@ module.exports.do_KeyValue_Decode = (args_Plain, args_Split, args_Equal) => {
233
263
  }
234
264
  return temp_Data;
235
265
  }
236
-
266
+ module.exports.do_KeyValue_Decode = func_KeyValue_Decode;
237
267
 
238
268
 
239
269
  /**
@@ -242,7 +272,7 @@ module.exports.do_KeyValue_Decode = (args_Plain, args_Split, args_Equal) => {
242
272
  * @param {"分割字符"} args_Split
243
273
  * @param {"等于字符"} args_Equal
244
274
  */
245
- module.exports.do_KeyValue_Encode = (args_Datas, args_Split, args_Equal) => {
275
+ function func_KeyValue_Encode(args_Datas, args_Split, args_Equal) {
246
276
 
247
277
  let temp_Keys = Object.keys(args_Datas);
248
278
  let t_Lenth = temp_Keys.length;
@@ -260,4 +290,5 @@ module.exports.do_KeyValue_Encode = (args_Datas, args_Split, args_Equal) => {
260
290
  }
261
291
 
262
292
  return temp_Line;
263
- }
293
+ }
294
+ module.exports.do_KeyValue_Encode = func_KeyValue_Encode;