mingyang_text 2021.9.17 → 2021.12.28
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 +12 -119
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
|
+
module.exports.do_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,7 +13,6 @@ function func_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;
|
17
16
|
|
18
17
|
|
19
18
|
|
@@ -30,52 +29,10 @@ module.exports.do_Random = (args_Min, args_Max) => {
|
|
30
29
|
|
31
30
|
|
32
31
|
|
33
|
-
/**
|
34
|
-
* 格式化时间
|
35
|
-
* @param {"指定时间对象,如果传入空,那么函数将自动初始化一个当前时间"} args_Date
|
36
|
-
* @param {"返回的时间字符串是否需要单位"} args_ContainsUnit
|
37
|
-
* @param {"返回的时间字符串是否需要毫秒"} args_ContainsMilliSecond
|
38
|
-
*/
|
39
|
-
module.exports.do_DateTimeFormat = (args_Date, args_ContainsUnit, args_ContainsMilliSecond) => {
|
40
|
-
|
41
|
-
let t_y, t_M, t_d, t_h, t_m, t_s, t_i;
|
42
|
-
|
43
|
-
if (args_Date == null) {
|
44
|
-
args_Date = new Date();
|
45
|
-
}
|
46
|
-
|
47
|
-
t_y = args_Date.getFullYear(); //获取完整的年份(4位)
|
48
|
-
t_M = args_Date.getMonth(); //获取当前月份(0-11,0代表1月)
|
49
|
-
t_d = args_Date.getDate(); //获取当前日(1-31)
|
50
|
-
t_h = args_Date.getHours(); //获取当前小时数(0-23)
|
51
|
-
t_m = args_Date.getMinutes(); //获取当前分钟数(0-59)
|
52
|
-
t_s = args_Date.getSeconds(); //获取当前秒数(0-59)
|
53
|
-
|
54
|
-
if (args_ContainsMilliSecond) {
|
55
|
-
t_i = args_Date.getMilliseconds(); //获取当前毫秒数(0-999)
|
56
|
-
}
|
57
|
-
|
58
|
-
let t_Now = "";
|
59
|
-
if (args_ContainsUnit) {
|
60
|
-
t_Now = t_y + '年' + func_StringFormat((t_M + 1), 2, '0') + '月' + func_StringFormat(t_d, 2, '0') + "日" + func_StringFormat(t_h, 2, '0') + "时" + func_StringFormat(t_m, 2, '0') + "分" + func_StringFormat(t_s, 2, '0') + "秒";
|
61
|
-
if (t_i != undefined) {
|
62
|
-
t_Now += func_StringFormat(t_i, 3, '0') + "毫";
|
63
|
-
}
|
64
|
-
}
|
65
|
-
else {
|
66
|
-
t_Now = t_y + func_StringFormat((t_M + 1), 2, '0') + func_StringFormat(t_d, 2, '0') + func_StringFormat(t_h, 2, '0') + func_StringFormat(t_m, 2, '0') + func_StringFormat(t_s, 2, '0');
|
67
|
-
if (t_i != undefined) {
|
68
|
-
t_Now += func_StringFormat(t_i, 3, '0');
|
69
|
-
}
|
70
|
-
}
|
71
|
-
return t_Now;
|
72
|
-
}
|
73
|
-
|
74
|
-
|
75
32
|
/**
|
76
33
|
* 格式化时间
|
77
34
|
* @param {"时间对象,如果传入空,那么将使用当前时间"} args_Date
|
78
|
-
* @param {"时间格式,例如【yyyy-MM-dd HH:mm:ss.fff】"} args_Format
|
35
|
+
* @param {"时间格式,例如【yyyy-MM-dd HH:mm:ss.fff】【yyyyMMddHHmmssfff】"} args_Format
|
79
36
|
*/
|
80
37
|
module.exports.do_DateTimeToString = (args_Date, args_Format) => {
|
81
38
|
|
@@ -95,49 +52,17 @@ module.exports.do_DateTimeToString = (args_Date, args_Format) => {
|
|
95
52
|
let t_Now = "";
|
96
53
|
t_Now = args_Format;
|
97
54
|
t_Now = t_Now.replace("yyyy", t_y);
|
98
|
-
t_Now = t_Now.replace("MM",
|
99
|
-
t_Now = t_Now.replace("dd",
|
100
|
-
t_Now = t_Now.replace("HH",
|
101
|
-
t_Now = t_Now.replace("mm",
|
102
|
-
t_Now = t_Now.replace("ss",
|
103
|
-
t_Now = t_Now.replace("fff",
|
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'));
|
104
61
|
|
105
62
|
return t_Now;
|
106
63
|
}
|
107
64
|
|
108
65
|
|
109
|
-
/**
|
110
|
-
* 返回一个时间在左侧的UUID,保留次函数,是怕历史代码有调用
|
111
|
-
*/
|
112
|
-
module.exports.do_UUID = () => {
|
113
|
-
let s = [];
|
114
|
-
let l = 36;
|
115
|
-
for (let i = 0; i < l; i++) {
|
116
|
-
s[i] = "-";
|
117
|
-
}
|
118
|
-
|
119
|
-
let hexDigits = "0123456789abcdef";
|
120
|
-
|
121
|
-
let temp_Time = module.exports.do_DateTimeToString(null, "yyyyMMdd-HHmmss-fff");
|
122
|
-
for (let i = 0; i < temp_Time.length; i++) {
|
123
|
-
s[i] = temp_Time[i];
|
124
|
-
}
|
125
|
-
s[temp_Time.length] = hexDigits.substr(module.exports.do_Random(10, 16), 1);
|
126
|
-
|
127
|
-
for (let i = temp_Time.length + 1; i < 36; i++) {
|
128
|
-
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
129
|
-
}
|
130
|
-
|
131
|
-
s[20] = "-";
|
132
|
-
s[27] = "-";
|
133
|
-
|
134
|
-
let uuid = s.join("");
|
135
|
-
return uuid;
|
136
|
-
}
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
66
|
|
142
67
|
/**
|
143
68
|
* 返回一个36位的时间在左侧的UUID
|
@@ -156,12 +81,9 @@ module.exports.do_TimeID_32 = () => {
|
|
156
81
|
* 返回一个时间在左侧的UUID
|
157
82
|
*/
|
158
83
|
module.exports.do_TimeID = (args_Digit) => {
|
159
|
-
let temp_List =
|
160
|
-
for (let i = 0; i < args_Digit; i++) {
|
161
|
-
temp_List[i] = "_";
|
162
|
-
}
|
84
|
+
let temp_List = new Array(args_Digit);
|
163
85
|
|
164
|
-
let
|
86
|
+
let temp_PlaceHolder = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
165
87
|
|
166
88
|
let temp_Time = module.exports.do_DateTimeToString(null, "yyyy-MMdd-HHmmss-fff");
|
167
89
|
for (let i = 0; i < temp_Time.length; i++) {
|
@@ -169,10 +91,9 @@ module.exports.do_TimeID = (args_Digit) => {
|
|
169
91
|
}
|
170
92
|
|
171
93
|
temp_List[temp_Time.length] = "-";
|
172
|
-
//temp_List[temp_Time.length] = temp_Digits.substr(module.exports.do_Random(10, 16), 1);
|
173
94
|
|
174
95
|
for (let i = temp_Time.length + 1; i < args_Digit; i++) {
|
175
|
-
temp_List[i] =
|
96
|
+
temp_List[i] = temp_PlaceHolder.substr(this.do_Random(0, temp_PlaceHolder.length), 1);
|
176
97
|
}
|
177
98
|
|
178
99
|
//temp_List[20] = "-";
|
@@ -197,6 +118,7 @@ module.exports.do_Hex_goto_Plain = (args_Hex) => {
|
|
197
118
|
}
|
198
119
|
|
199
120
|
|
121
|
+
|
200
122
|
/**
|
201
123
|
* 从【普通文本】转换为【16进制文本】
|
202
124
|
* @param {"普通文本"} args_Hex
|
@@ -209,35 +131,6 @@ module.exports.do_Hex_from_Plain = (args_Plain) => {
|
|
209
131
|
|
210
132
|
|
211
133
|
|
212
|
-
|
213
|
-
/**
|
214
|
-
* 将目标字符串截取为3段,下标0 是开始处 到 bin之间的部分(不包含bin);下标1是bin和end之间的字符串(不包含bin和end);下标2 是end 到 结束处之间的部分(不包含end);如果匹配不到返回null
|
215
|
-
* @param {"目标字符串"} args_Text
|
216
|
-
* @param {"开始匹配符"} args_Bin
|
217
|
-
* @param {"结束匹配符"} args_End
|
218
|
-
*/
|
219
|
-
module.exports.do_Subsection = (args_Text, args_Bin, args_End) => {
|
220
|
-
let temp_Bin = args_Text.indexOf(args_Bin);
|
221
|
-
if (temp_Bin > -1) {
|
222
|
-
let temp_End = args_Text.indexOf(args_End, temp_Bin + args_Bin.length);
|
223
|
-
if (temp_End > -1) {
|
224
|
-
let temp_L = args_Text.substr(0, temp_Bin);
|
225
|
-
let temp_C = args_Text.substr(temp_Bin + args_Bin.length, temp_End - temp_Bin - args_Bin.length);
|
226
|
-
let temp_R = args_Text.substr(temp_End + args_End.length);
|
227
|
-
|
228
|
-
return [temp_L, temp_C, temp_R];
|
229
|
-
}
|
230
|
-
else {
|
231
|
-
return null;
|
232
|
-
}
|
233
|
-
}
|
234
|
-
else {
|
235
|
-
return null;
|
236
|
-
}
|
237
|
-
}
|
238
|
-
|
239
|
-
|
240
|
-
|
241
134
|
/**
|
242
135
|
* 【主字符串】是否以【从字符串】开头
|
243
136
|
* @param {"主字符串"} args_Subject
|