mingyang_text 2022.9.27 → 2022.10.27
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 +13 -13
- package/text.js +108 -6
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mingyang_text",
|
3
|
-
"version": "2022.
|
3
|
+
"version": "2022.10.27",
|
4
4
|
"description": "MingYang Packet",
|
5
5
|
"main": "text.js",
|
6
6
|
"scripts": {
|
@@ -8,18 +8,18 @@
|
|
8
8
|
},
|
9
9
|
"keywords": [
|
10
10
|
"mingyang",
|
11
|
-
"
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
17
|
-
"
|
18
|
-
"
|
19
|
-
"
|
20
|
-
"
|
21
|
-
"
|
11
|
+
"mingyang/text",
|
12
|
+
"text/bin_with",
|
13
|
+
"text/end_with",
|
14
|
+
"string/format",
|
15
|
+
"datetime/format",
|
16
|
+
"timeid",
|
17
|
+
"timeno",
|
18
|
+
"time/uuid",
|
19
|
+
"base62",
|
20
|
+
"baseX",
|
21
|
+
"any base system"
|
22
22
|
],
|
23
|
-
"author": "wang.fu.jun@qq.com",
|
23
|
+
"author": "wang.fu.jun@qq.com,wang.ming.yang@126.com",
|
24
24
|
"license": "ISC"
|
25
25
|
}
|
package/text.js
CHANGED
@@ -17,6 +17,8 @@ module.exports.do_StringFormat = func_StringFormat;
|
|
17
17
|
|
18
18
|
|
19
19
|
|
20
|
+
|
21
|
+
|
20
22
|
/**
|
21
23
|
* 生成随机数
|
22
24
|
* @param {"最小值,随机数可以选中最小值"} args_Min
|
@@ -30,6 +32,9 @@ function func_Random(args_Min, args_Max) {
|
|
30
32
|
module.exports.do_Random = func_Random;
|
31
33
|
|
32
34
|
|
35
|
+
|
36
|
+
|
37
|
+
|
33
38
|
/**
|
34
39
|
* 格式化时间
|
35
40
|
* @param {"时间对象,如果传入空,那么将使用当前时间"} args_Date
|
@@ -65,6 +70,9 @@ function func_DateTimeToString(args_Date, args_Format) {
|
|
65
70
|
module.exports.do_DateTimeToString = func_DateTimeToString;
|
66
71
|
|
67
72
|
|
73
|
+
|
74
|
+
|
75
|
+
|
68
76
|
/**
|
69
77
|
* 根据给定的左右标签,提取父串中的子串
|
70
78
|
* @param {"输入文本"} args_Text
|
@@ -109,7 +117,6 @@ function func_Filter(args_Text, args_Bin, args_End) {
|
|
109
117
|
}
|
110
118
|
}
|
111
119
|
|
112
|
-
//t_Line = args_Text.substr(t_iBin + args_Bin.length, t_iEnd - t_iBin - args_Bin.length);
|
113
120
|
t_Line = args_Text.substring(t_iBin + args_Bin.length, t_iEnd);
|
114
121
|
t_Result.push(t_Line);
|
115
122
|
|
@@ -120,6 +127,10 @@ function func_Filter(args_Text, args_Bin, args_End) {
|
|
120
127
|
}
|
121
128
|
module.exports.do_Filter = func_Filter;
|
122
129
|
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
123
134
|
/**
|
124
135
|
* 返回一个36位的时间在左侧的UUID
|
125
136
|
*/
|
@@ -198,7 +209,6 @@ function func_Hex_goto_Plain(args_Hex) {
|
|
198
209
|
}
|
199
210
|
module.exports.do_Hex_goto_Plain = func_Hex_goto_Plain;
|
200
211
|
|
201
|
-
|
202
212
|
/**
|
203
213
|
* 从【普通文本】转换为【16进制文本】
|
204
214
|
* @param {"普通文本"} args_Hex
|
@@ -211,6 +221,8 @@ module.exports.do_Hex_from_Plain = func_Hex_from_Plain;
|
|
211
221
|
|
212
222
|
|
213
223
|
|
224
|
+
|
225
|
+
|
214
226
|
/**
|
215
227
|
* 【主字符串】是否以【从字符串】开头
|
216
228
|
* @param {"主字符串"} args_Subject
|
@@ -233,8 +245,6 @@ function func_Bin_With(args_Subject, args_Compare) {
|
|
233
245
|
}
|
234
246
|
module.exports.do_Bin_With = func_Bin_With;
|
235
247
|
|
236
|
-
|
237
|
-
|
238
248
|
/**
|
239
249
|
* 【主字符串】是否以【从字符串】结尾
|
240
250
|
* @param {"主字符串"} args_Subject
|
@@ -261,6 +271,7 @@ module.exports.do_End_With = func_End_With;
|
|
261
271
|
|
262
272
|
|
263
273
|
|
274
|
+
|
264
275
|
/**
|
265
276
|
* KeyValue解码
|
266
277
|
* @param {"源字符串"} args_Plain
|
@@ -286,7 +297,6 @@ function func_KeyValue_Decode(args_Plain, args_Split, args_Equal) {
|
|
286
297
|
}
|
287
298
|
module.exports.do_KeyValue_Decode = func_KeyValue_Decode;
|
288
299
|
|
289
|
-
|
290
300
|
/**
|
291
301
|
* KeyValue编码
|
292
302
|
* @param {"源数据包"} args_Datas
|
@@ -312,4 +322,96 @@ function func_KeyValue_Encode(args_Datas, args_Split, args_Equal) {
|
|
312
322
|
|
313
323
|
return temp_Line;
|
314
324
|
}
|
315
|
-
module.exports.do_KeyValue_Encode = func_KeyValue_Encode;
|
325
|
+
module.exports.do_KeyValue_Encode = func_KeyValue_Encode;
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
/**
|
332
|
+
* 【十进制数字】转成【它进制数字】
|
333
|
+
* @param {"来源十进制数,例如:110715"} args_DecimalNumber
|
334
|
+
* @param {"目标进制基数,例如:62"} args_NumberSystem
|
335
|
+
* @param {"目标记号字符,例如:0123456789ABCDEF"} args_VisibleChar
|
336
|
+
*/
|
337
|
+
function func_DecimalToOther(args_DecimalNumber, args_NumberSystem, args_VisibleChar = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") {
|
338
|
+
|
339
|
+
{//通用的验证部分
|
340
|
+
if (args_NumberSystem < 2 || args_NumberSystem > 62) {
|
341
|
+
throw new Error(`the numberSystem must be between 2 and 62`);
|
342
|
+
}
|
343
|
+
|
344
|
+
if (args_VisibleChar.length < args_NumberSystem) {
|
345
|
+
throw new Error(`numberSystem can't above to length of visibleChar`);
|
346
|
+
}
|
347
|
+
}
|
348
|
+
|
349
|
+
if (args_DecimalNumber < 1) {
|
350
|
+
return "0";
|
351
|
+
}
|
352
|
+
|
353
|
+
let temp_Result = "";
|
354
|
+
for (; args_DecimalNumber > 0;) {
|
355
|
+
temp_Result = args_VisibleChar[args_DecimalNumber % args_NumberSystem] + temp_Result;
|
356
|
+
args_DecimalNumber = Math.floor(args_DecimalNumber / args_NumberSystem);
|
357
|
+
}
|
358
|
+
|
359
|
+
return temp_Result;
|
360
|
+
}
|
361
|
+
module.exports.do_DecimalToOther = func_DecimalToOther;
|
362
|
+
|
363
|
+
/**
|
364
|
+
* 【它进制数字】转成【十进制数字】
|
365
|
+
* @param {"来源进制数值,例如:TO80HHL"} args_OtherNumber
|
366
|
+
* @param {"来源进制基数,例如:62"} args_NumberSystem
|
367
|
+
* @param {"来源记号字符,例如:0123456789ABCDEF"} args_VisibleChar
|
368
|
+
*/
|
369
|
+
function func_DecimalFromOther(args_OtherNumber, args_NumberSystem, args_VisibleChar = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") {
|
370
|
+
|
371
|
+
{//通用的验证部分
|
372
|
+
if (args_NumberSystem < 2 || args_NumberSystem > 62) {
|
373
|
+
throw new Error(`the numberSystem must be between 2 and 62`);
|
374
|
+
}
|
375
|
+
|
376
|
+
if (args_VisibleChar.length < args_NumberSystem) {
|
377
|
+
throw new Error(`NumberSystem can't above to length of VisibleChar`);
|
378
|
+
}
|
379
|
+
}
|
380
|
+
|
381
|
+
if (args_OtherNumber == null || args_OtherNumber.trim() == "") {
|
382
|
+
return NaN;
|
383
|
+
}
|
384
|
+
|
385
|
+
let temp_Char = "";
|
386
|
+
let temp_Idex = 0;
|
387
|
+
let temp_Result = 0;
|
388
|
+
let temp_Leng = args_OtherNumber.length;
|
389
|
+
for (let i = 0; i < temp_Leng; i++) {
|
390
|
+
temp_Char = args_OtherNumber[i];
|
391
|
+
// console.log(temp_Char);
|
392
|
+
temp_Idex = args_VisibleChar.indexOf(temp_Char);
|
393
|
+
// console.log(temp_Idex);
|
394
|
+
temp_Result += temp_Idex * Math.pow(args_NumberSystem, (temp_Leng - i - 1));
|
395
|
+
}
|
396
|
+
|
397
|
+
return temp_Result;
|
398
|
+
}
|
399
|
+
module.exports.do_DecimalFromOther = func_DecimalFromOther;
|
400
|
+
|
401
|
+
/**
|
402
|
+
* 【10进制数字】转成【62进制数字】
|
403
|
+
* @param {"10进制数"} args_Base10Number
|
404
|
+
*/
|
405
|
+
function func_Base62Encode(args_Base10Number) {
|
406
|
+
return func_DecimalToOther(args_Base10Number, 62);
|
407
|
+
}
|
408
|
+
module.exports.do_Base62Encode = func_Base62Encode;
|
409
|
+
|
410
|
+
/**
|
411
|
+
* 【62进制数字】转成【10进制数字】
|
412
|
+
* @param {"62进制数"} args_Base62Number
|
413
|
+
*/
|
414
|
+
function func_Base62Decode(args_Base62Number) {
|
415
|
+
return func_DecimalFromOther(args_Base62Number, 62);
|
416
|
+
}
|
417
|
+
module.exports.do_Base62Decode = func_Base62Decode;
|