mm_expand 1.5.0 → 1.5.2

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 (5) hide show
  1. package/base.js +1 -1
  2. package/index.js +21 -11
  3. package/lang.js +1 -1
  4. package/package.json +34 -34
  5. package/test.js +11 -1
package/base.js CHANGED
@@ -288,4 +288,4 @@ Base.prototype.create_class = function(cs_old) {
288
288
  return cs;
289
289
  };
290
290
 
291
- module.exports = Base;
291
+ module.exports = Base;
package/index.js CHANGED
@@ -644,6 +644,15 @@ if (typeof($) === "undefined") {
644
644
  Number.prototype.toTime = function() {
645
645
  return new Date(this * 1000);
646
646
  };
647
+
648
+ /**
649
+ * @description 随机数
650
+ * @@param {Number} min 最小值
651
+ * @return {Number} 返回一个数值
652
+ */
653
+ Number.prototype.rand = function(min = 1) {
654
+ return Math.floor(Math.random() * (this - min + 1) + min);
655
+ };
647
656
  })();
648
657
 
649
658
  /* == 时间原型函数 == */
@@ -1008,7 +1017,7 @@ if (typeof($) === "undefined") {
1008
1017
  * @return {Date} 时间对象
1009
1018
  */
1010
1019
  String.prototype.toTime = function() {
1011
- var str = this.replace('T', ' ').replace('Z', '').replaceAll('.', '/').replaceAll('-', '/');
1020
+ var str = this.replace('T', ' ').replace('Z', '').replaceAll('-', '/');
1012
1021
  return new Date(str);
1013
1022
  };
1014
1023
  /**
@@ -1017,8 +1026,8 @@ if (typeof($) === "undefined") {
1017
1026
  * @return {String} 时间格式字符串
1018
1027
  */
1019
1028
  String.prototype.toTimeFormat = function(format) {
1020
- var str = this.replace('T', ' ').replace('Z', '').replaceAll('.', '/').replaceAll('-', '/');
1021
- return new Date(str).toStr(format);
1029
+ var str = this.replace('T', ' ').replace('Z', '').replaceAll('-', '/');
1030
+ return str.toTime().toStr(format);
1022
1031
  };
1023
1032
  /**
1024
1033
  * @description 转为数组
@@ -1092,7 +1101,8 @@ if (typeof($) === "undefined") {
1092
1101
  bl = /^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+/gi.test(value)
1093
1102
  break;
1094
1103
  case "date":
1095
- bl = /^\d{4}(\-|\/|\.)(0[1-9]|1[012]|[1-9])(\-|\/|\.)([12][0-9]|0[1-9]|3[01]|[1-9])$/.test(value)
1104
+ bl = /^\d{4}(\-|\/|\.)(0[1-9]|1[012]|[1-9])(\-|\/|\.)([12][0-9]|0[1-9]|3[01]|[1-9])$/.test(
1105
+ value)
1096
1106
  break;
1097
1107
  case "time":
1098
1108
  bl = /^([01][0-9]|2[0-3]):([0-4][0-9]|5[0-9])(:([0-4][0-9]|5[0-9]))?$/.test(value)
@@ -2234,7 +2244,7 @@ if (typeof($) === "undefined") {
2234
2244
  getFile(list, dir, keyword);
2235
2245
  return list;
2236
2246
  };
2237
-
2247
+
2238
2248
  /**
2239
2249
  * @description 加载文件
2240
2250
  * @param {String} file 编码方式
@@ -2269,17 +2279,17 @@ if (typeof($) === "undefined") {
2269
2279
  }
2270
2280
  $.file = new File();
2271
2281
  $.dir = new Dir();
2272
-
2273
-
2282
+
2283
+
2274
2284
  /**
2275
2285
  * @description 获取当前目录下所有文件
2276
2286
  * @param {String} keyword 搜索关键词
2277
2287
  * @return {Array} 文件路径数组
2278
2288
  */
2279
- String.prototype.getFile = function(keyword){
2280
- return $.file.get(this + '', keyword);
2289
+ String.prototype.getFile = function(keyword) {
2290
+ return $.file.get(this + '', keyword);
2281
2291
  };
2282
-
2292
+
2283
2293
  /**
2284
2294
  * @description 搜索当前目录下所有目录
2285
2295
  * @param {String} keyword 搜索关键词
@@ -2288,7 +2298,7 @@ if (typeof($) === "undefined") {
2288
2298
  String.prototype.getDir = function(keyword) {
2289
2299
  return $.dir.get(this + '', keyword);
2290
2300
  };
2291
-
2301
+
2292
2302
  })();
2293
2303
 
2294
2304
  /**
package/lang.js CHANGED
@@ -78,4 +78,4 @@ Lang.prototype.set = function(key, value) {
78
78
  return val;
79
79
  };
80
80
 
81
- module.exports = Lang;
81
+ module.exports = Lang;
package/package.json CHANGED
@@ -1,35 +1,35 @@
1
- {
2
- "name": "mm_expand",
3
- "version": "1.5.0",
4
- "description": "这是超级美眉原型函数拓展模块,更有利于对string、array、object的操作,避免出错,简化业务逻辑。",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "node test.js"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/qiuwenwu/mm_expand.git"
12
- },
13
- "keywords": [
14
- "string",
15
- "array",
16
- "object",
17
- "date",
18
- "get",
19
- "set",
20
- "prototype",
21
- "expand",
22
- "$"
23
- ],
24
- "author": "邱文武",
25
- "license": "ISC",
26
- "bugs": {
27
- "url": "https://github.com/qiuwenwu/mm_expand/issues"
28
- },
29
- "homepage": "https://github.com/qiuwenwu/mm_expand#readme",
30
- "dependencies": {
31
- "fast-xml-parser": "^3.15.1",
32
- "json5": "^2.1.1",
33
- "pinyinlite": "^1.2.1"
34
- }
1
+ {
2
+ "name": "mm_expand",
3
+ "version": "1.5.2",
4
+ "description": "这是超级美眉原型函数拓展模块,更有利于对string、array、object的操作,避免出错,简化业务逻辑。",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "node test.js"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/qiuwenwu/mm_expand.git"
12
+ },
13
+ "keywords": [
14
+ "string",
15
+ "array",
16
+ "object",
17
+ "date",
18
+ "get",
19
+ "set",
20
+ "prototype",
21
+ "expand",
22
+ "$"
23
+ ],
24
+ "author": "邱文武",
25
+ "license": "ISC",
26
+ "bugs": {
27
+ "url": "https://github.com/qiuwenwu/mm_expand/issues"
28
+ },
29
+ "homepage": "https://github.com/qiuwenwu/mm_expand#readme",
30
+ "dependencies": {
31
+ "fast-xml-parser": "^3.15.1",
32
+ "json5": "^2.1.1",
33
+ "pinyinlite": "^1.2.1"
34
+ }
35
35
  }
package/test.js CHANGED
@@ -1,5 +1,15 @@
1
1
  require('./index.js');
2
2
 
3
+
4
+ var num = 5;
5
+ console.log(num.rand());
6
+ console.log(num.rand());
7
+ console.log(num.rand());
8
+ console.log(num.rand());
9
+ console.log(num.rand());
10
+ console.log(num.rand());
11
+ console.log(num.rand());
12
+
3
13
  // /**
4
14
  // * 测试重载模块
5
15
  // */
@@ -348,7 +358,7 @@ require('./index.js');
348
358
  // sex: 0
349
359
  // }
350
360
  // ];
351
-
361
+
352
362
  // var list2 = [
353
363
  // {
354
364
  // id: 2,