mingyang_text 2022.10.3 → 2023.1.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.
Files changed (2) hide show
  1. package/package.json +8 -3
  2. package/text.js +146 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mingyang_text",
3
- "version": "2022.10.03",
3
+ "version": "2023.01.28",
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
@@ -1,9 +1,9 @@
1
1
 
2
2
  /**
3
3
  * 对【数字】或【字符】进行【左侧补齐】操作
4
- * @param {"数字或字符"} args_Input
5
- * @param {"目标长度"} args_Length
6
- * @param {"占位符"} args_PlaceHolder
4
+ * @param {"数字或字符"} args_Input
5
+ * @param {"目标长度"} args_Length
6
+ * @param {"占位符"} args_PlaceHolder
7
7
  */
8
8
  function func_StringFormat(args_Input, args_Length, args_PlaceHolder) {
9
9
  if (args_Input.toString().length > args_Length) {
@@ -17,10 +17,12 @@ module.exports.do_StringFormat = func_StringFormat;
17
17
 
18
18
 
19
19
 
20
+
21
+
20
22
  /**
21
23
  * 生成随机数
22
- * @param {"最小值,随机数可以选中最小值"} args_Min
23
- * @param {"最大值,随机数不会选中最大值"} args_Max
24
+ * @param {"最小值,随机数可以选中最小值"} args_Min
25
+ * @param {"最大值,随机数不会选中最大值"} args_Max
24
26
  */
25
27
  function func_Random(args_Min, args_Max) {
26
28
  let temp_Val = Math.floor(Math.random() * (args_Max - args_Min)) + args_Min;
@@ -30,9 +32,12 @@ 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
- * @param {"时间对象,如果传入空,那么将使用当前时间"} args_Date
40
+ * @param {"时间对象,如果传入空,那么将使用当前时间"} args_Date
36
41
  * @param {"时间格式,例如【yyyy-MM-dd HH:mm:ss.fff】【yyyyMMddHHmmssfff】"} args_Format
37
42
  */
38
43
  function func_DateTimeToString(args_Date, args_Format) {
@@ -65,11 +70,14 @@ 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
- * @param {"输入文本"} args_Text
71
- * @param {"左侧标记"} args_Bin
72
- * @param {"右侧标记"} args_End
78
+ * @param {"输入文本"} args_Text
79
+ * @param {"左侧标记"} args_Bin
80
+ * @param {"右侧标记"} args_End
73
81
  */
74
82
  function func_Filter(args_Text, args_Bin, args_End) {
75
83
 
@@ -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
  */
@@ -189,7 +201,7 @@ module.exports.do_TimeID = func_TimeID;
189
201
 
190
202
  /**
191
203
  * 从【16进制文本】转换为【普通文本】
192
- * @param {"16进制文本"} args_Hex
204
+ * @param {"16进制文本"} args_Hex
193
205
  */
194
206
  function func_Hex_goto_Plain(args_Hex) {
195
207
  let t_Buffer = Buffer.from(args_Hex, 'hex');
@@ -197,10 +209,9 @@ 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
- * @param {"普通文本"} args_Hex
214
+ * @param {"普通文本"} args_Hex
204
215
  */
205
216
  function func_Hex_from_Plain(args_Plain) {
206
217
  let t_Buffer = Buffer.from(args_Plain, "utf8");
@@ -210,10 +221,12 @@ module.exports.do_Hex_from_Plain = func_Hex_from_Plain;
210
221
 
211
222
 
212
223
 
224
+
225
+
213
226
  /**
214
227
  * 【主字符串】是否以【从字符串】开头
215
- * @param {"主字符串"} args_Subject
216
- * @param {"从字符串"} args_Compare
228
+ * @param {"主字符串"} args_Subject
229
+ * @param {"从字符串"} args_Compare
217
230
  */
218
231
  function func_Bin_With(args_Subject, args_Compare) {
219
232
  if (args_Subject == null || args_Compare == null) {
@@ -232,12 +245,10 @@ 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
- * @param {"主字符串"} args_Subject
240
- * @param {"从字符串"} args_Compare
250
+ * @param {"主字符串"} args_Subject
251
+ * @param {"从字符串"} args_Compare
241
252
  */
242
253
  function func_End_With(args_Subject, args_Compare) {
243
254
  if (args_Subject == null || args_Compare == null) {
@@ -260,11 +271,12 @@ module.exports.do_End_With = func_End_With;
260
271
 
261
272
 
262
273
 
274
+
263
275
  /**
264
276
  * KeyValue解码
265
- * @param {"源字符串"} args_Plain
266
- * @param {"分割字符"} args_Split
267
- * @param {"等于字符"} args_Equal
277
+ * @param {"源字符串"} args_Plain
278
+ * @param {"分割字符"} args_Split
279
+ * @param {"等于字符"} args_Equal
268
280
  */
269
281
  function func_KeyValue_Decode(args_Plain, args_Split, args_Equal) {
270
282
 
@@ -285,12 +297,11 @@ 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
- * @param {"源数据包"} args_Datas
292
- * @param {"分割字符"} args_Split
293
- * @param {"等于字符"} args_Equal
302
+ * @param {"源数据包"} args_Datas
303
+ * @param {"分割字符"} args_Split
304
+ * @param {"等于字符"} args_Equal
294
305
  */
295
306
  function func_KeyValue_Encode(args_Datas, args_Split, args_Equal) {
296
307
 
@@ -311,4 +322,113 @@ 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;
418
+
419
+
420
+ /**
421
+ * 按照字节长度截取字符串
422
+ * @param {"原始字符"} args_InputString
423
+ * @param {"目标长度"} args_ByteLength
424
+ * @param {"编码方式"} args_Encoding
425
+ */
426
+ module.exports.do_Byte_Truncate = (args_InputString, args_ByteLength, args_Encoding = "utf8") => {
427
+ let temp_Description = args_InputString.substring(0, args_ByteLength);
428
+ let temp_Buffer = Buffer.from(temp_Description, args_Encoding);
429
+ while (temp_Buffer.length > args_ByteLength) {
430
+ temp_Description = temp_Description.substring(0, temp_Description.length - 1);
431
+ temp_Buffer = Buffer.from(temp_Description, args_Encoding);
432
+ }
433
+ return temp_Description;
434
+ }