mingyang_text 2022.10.3 → 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.
Files changed (2) hide show
  1. package/package.json +8 -3
  2. package/text.js +108 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mingyang_text",
3
- "version": "2022.10.03",
3
+ "version": "2022.10.27",
4
4
  "description": "MingYang Packet",
5
5
  "main": "text.js",
6
6
  "scripts": {
@@ -9,11 +9,16 @@
9
9
  "keywords": [
10
10
  "mingyang",
11
11
  "mingyang/text",
12
- "text/Bin_with",
12
+ "text/bin_with",
13
13
  "text/end_with",
14
14
  "string/format",
15
+ "datetime/format",
15
16
  "timeid",
16
- "time/uuid"
17
+ "timeno",
18
+ "time/uuid",
19
+ "base62",
20
+ "baseX",
21
+ "any base system"
17
22
  ],
18
23
  "author": "wang.fu.jun@qq.com,wang.ming.yang@126.com",
19
24
  "license": "ISC"
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
@@ -119,6 +127,10 @@ function func_Filter(args_Text, args_Bin, args_End) {
119
127
  }
120
128
  module.exports.do_Filter = func_Filter;
121
129
 
130
+
131
+
132
+
133
+
122
134
  /**
123
135
  * 返回一个36位的时间在左侧的UUID
124
136
  */
@@ -197,7 +209,6 @@ function func_Hex_goto_Plain(args_Hex) {
197
209
  }
198
210
  module.exports.do_Hex_goto_Plain = func_Hex_goto_Plain;
199
211
 
200
-
201
212
  /**
202
213
  * 从【普通文本】转换为【16进制文本】
203
214
  * @param {"普通文本"} args_Hex
@@ -210,6 +221,8 @@ module.exports.do_Hex_from_Plain = func_Hex_from_Plain;
210
221
 
211
222
 
212
223
 
224
+
225
+
213
226
  /**
214
227
  * 【主字符串】是否以【从字符串】开头
215
228
  * @param {"主字符串"} args_Subject
@@ -232,8 +245,6 @@ function func_Bin_With(args_Subject, args_Compare) {
232
245
  }
233
246
  module.exports.do_Bin_With = func_Bin_With;
234
247
 
235
-
236
-
237
248
  /**
238
249
  * 【主字符串】是否以【从字符串】结尾
239
250
  * @param {"主字符串"} args_Subject
@@ -260,6 +271,7 @@ module.exports.do_End_With = func_End_With;
260
271
 
261
272
 
262
273
 
274
+
263
275
  /**
264
276
  * KeyValue解码
265
277
  * @param {"源字符串"} args_Plain
@@ -285,7 +297,6 @@ function func_KeyValue_Decode(args_Plain, args_Split, args_Equal) {
285
297
  }
286
298
  module.exports.do_KeyValue_Decode = func_KeyValue_Decode;
287
299
 
288
-
289
300
  /**
290
301
  * KeyValue编码
291
302
  * @param {"源数据包"} args_Datas
@@ -311,4 +322,96 @@ function func_KeyValue_Encode(args_Datas, args_Split, args_Equal) {
311
322
 
312
323
  return temp_Line;
313
324
  }
314
- 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;