mingyang_text 2021.12.28 → 2022.8.26

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 +91 -30
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mingyang_text",
3
- "version": "2021.12.28",
3
+ "version": "2022.08.26",
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,99 @@ 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) {
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_Line = args_Text.substring(t_iBin + args_Bin.length, t_iEnd);
114
+ t_Result.push(t_Line);
115
+
116
+ t_Start = t_iEnd + args_End.length;
117
+ } while (t_Start > -1 && t_Start < args_Text.length);
118
+
119
+ return t_Result;
120
+ }
121
+ module.exports.do_Filter = func_Filter;
66
122
 
67
123
  /**
68
124
  * 返回一个36位的时间在左侧的UUID
69
125
  */
70
- module.exports.do_TimeID_36 = () => {
71
- return module.exports.do_TimeID(36);
126
+ function func_TimeID_36() {
127
+ return func_TimeID(36);
72
128
  }
129
+ module.exports.do_TimeID_36 = func_TimeID_36;
73
130
 
74
131
  /**
75
132
  * 返回一个32位的时间在左侧的UUID
76
133
  */
77
- module.exports.do_TimeID_32 = () => {
78
- return module.exports.do_TimeID(32);
134
+ function func_TimeID_32() {
135
+ return func_TimeID(32);
79
136
  }
137
+ module.exports.do_TimeID_32 = func_TimeID_32;
138
+
80
139
  /**
81
140
  * 返回一个时间在左侧的UUID
82
141
  */
83
- module.exports.do_TimeID = (args_Digit) => {
142
+ function func_TimeID(args_Digit) {
84
143
  let temp_List = new Array(args_Digit);
85
144
 
145
+ //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
146
  let temp_PlaceHolder = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
87
147
 
88
- let temp_Time = module.exports.do_DateTimeToString(null, "yyyy-MMdd-HHmmss-fff");
148
+ let temp_Time = func_DateTimeToString(null, "yyyy-MMdd-HHmmss-fff");
89
149
  for (let i = 0; i < temp_Time.length; i++) {
90
150
  temp_List[i] = temp_Time[i];
91
151
  }
@@ -93,7 +153,7 @@ module.exports.do_TimeID = (args_Digit) => {
93
153
  temp_List[temp_Time.length] = "-";
94
154
 
95
155
  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);
156
+ temp_List[i] = temp_PlaceHolder[func_Random(0, temp_PlaceHolder.length)];
97
157
  }
98
158
 
99
159
  //temp_List[20] = "-";
@@ -102,7 +162,7 @@ module.exports.do_TimeID = (args_Digit) => {
102
162
  let temp_UUID = temp_List.join("");
103
163
  return temp_UUID;
104
164
  }
105
-
165
+ module.exports.do_TimeID = func_TimeID;
106
166
 
107
167
 
108
168
 
@@ -112,22 +172,22 @@ module.exports.do_TimeID = (args_Digit) => {
112
172
  * 从【16进制文本】转换为【普通文本】
113
173
  * @param {"16进制文本"} args_Hex
114
174
  */
115
- module.exports.do_Hex_goto_Plain = (args_Hex) => {
175
+ function func_Hex_goto_Plain(args_Hex) {
116
176
  let t_Buffer = Buffer.from(args_Hex, 'hex');
117
177
  return t_Buffer.toString("utf8");
118
178
  }
119
-
179
+ module.exports.do_Hex_goto_Plain = func_Hex_goto_Plain;
120
180
 
121
181
 
122
182
  /**
123
183
  * 从【普通文本】转换为【16进制文本】
124
184
  * @param {"普通文本"} args_Hex
125
185
  */
126
- module.exports.do_Hex_from_Plain = (args_Plain) => {
186
+ function func_Hex_from_Plain(args_Plain) {
127
187
  let t_Buffer = Buffer.from(args_Plain, "utf8");
128
188
  return t_Buffer.toString("hex");
129
189
  }
130
-
190
+ module.exports.do_Hex_from_Plain = func_Hex_from_Plain;
131
191
 
132
192
 
133
193
 
@@ -136,7 +196,7 @@ module.exports.do_Hex_from_Plain = (args_Plain) => {
136
196
  * @param {"主字符串"} args_Subject
137
197
  * @param {"从字符串"} args_Compare
138
198
  */
139
- module.exports.do_Bin_With = (args_Subject, args_Compare) => {
199
+ function func_Bin_With(args_Subject, args_Compare) {
140
200
  if (args_Subject == null || args_Compare == null) {
141
201
  return false;
142
202
  }
@@ -151,7 +211,7 @@ module.exports.do_Bin_With = (args_Subject, args_Compare) => {
151
211
  }
152
212
  return true;
153
213
  }
154
-
214
+ module.exports.do_Bin_With = func_Bin_With;
155
215
 
156
216
 
157
217
 
@@ -160,7 +220,7 @@ module.exports.do_Bin_With = (args_Subject, args_Compare) => {
160
220
  * @param {"主字符串"} args_Subject
161
221
  * @param {"从字符串"} args_Compare
162
222
  */
163
- module.exports.do_End_With = (args_Subject, args_Compare) => {
223
+ function func_End_With(args_Subject, args_Compare) {
164
224
  if (args_Subject == null || args_Compare == null) {
165
225
  return false;
166
226
  }
@@ -176,7 +236,7 @@ module.exports.do_End_With = (args_Subject, args_Compare) => {
176
236
  }
177
237
  return true;
178
238
  }
179
-
239
+ module.exports.do_End_With = func_End_With;
180
240
 
181
241
 
182
242
 
@@ -187,7 +247,7 @@ module.exports.do_End_With = (args_Subject, args_Compare) => {
187
247
  * @param {"分割字符"} args_Split
188
248
  * @param {"等于字符"} args_Equal
189
249
  */
190
- module.exports.do_KeyValue_Decode = (args_Plain, args_Split, args_Equal) => {
250
+ function func_KeyValue_Decode(args_Plain, args_Split, args_Equal) {
191
251
 
192
252
  let temp_Data = {};
193
253
  let temp_Cookie_List = args_Plain.split(args_Split);
@@ -204,7 +264,7 @@ module.exports.do_KeyValue_Decode = (args_Plain, args_Split, args_Equal) => {
204
264
  }
205
265
  return temp_Data;
206
266
  }
207
-
267
+ module.exports.do_KeyValue_Decode = func_KeyValue_Decode;
208
268
 
209
269
 
210
270
  /**
@@ -213,7 +273,7 @@ module.exports.do_KeyValue_Decode = (args_Plain, args_Split, args_Equal) => {
213
273
  * @param {"分割字符"} args_Split
214
274
  * @param {"等于字符"} args_Equal
215
275
  */
216
- module.exports.do_KeyValue_Encode = (args_Datas, args_Split, args_Equal) => {
276
+ function func_KeyValue_Encode(args_Datas, args_Split, args_Equal) {
217
277
 
218
278
  let temp_Keys = Object.keys(args_Datas);
219
279
  let t_Lenth = temp_Keys.length;
@@ -231,4 +291,5 @@ module.exports.do_KeyValue_Encode = (args_Datas, args_Split, args_Equal) => {
231
291
  }
232
292
 
233
293
  return temp_Line;
234
- }
294
+ }
295
+ module.exports.do_KeyValue_Encode = func_KeyValue_Encode;