mm_expand 1.5.1 → 1.5.3

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 +30 -8
  3. package/lang.js +1 -1
  4. package/package.json +34 -34
  5. package/test.js +22 -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,27 @@ 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
+ };
656
+
657
+ /**
658
+ * @description 随机数
659
+ * @param {Number} margin 上下幅度
660
+ * @return {Number} 返回一个数值
661
+ */
662
+ Number.prototype.range = function(margin = 5) {
663
+ var min = this - margin;
664
+ var max = this + margin;
665
+ return Math.floor(Math.random() * (max - min + 1) + min);
666
+ };
667
+
647
668
  })();
648
669
 
649
670
  /* == 时间原型函数 == */
@@ -1092,7 +1113,8 @@ if (typeof($) === "undefined") {
1092
1113
  bl = /^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+/gi.test(value)
1093
1114
  break;
1094
1115
  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)
1116
+ bl = /^\d{4}(\-|\/|\.)(0[1-9]|1[012]|[1-9])(\-|\/|\.)([12][0-9]|0[1-9]|3[01]|[1-9])$/.test(
1117
+ value)
1096
1118
  break;
1097
1119
  case "time":
1098
1120
  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 +2256,7 @@ if (typeof($) === "undefined") {
2234
2256
  getFile(list, dir, keyword);
2235
2257
  return list;
2236
2258
  };
2237
-
2259
+
2238
2260
  /**
2239
2261
  * @description 加载文件
2240
2262
  * @param {String} file 编码方式
@@ -2269,17 +2291,17 @@ if (typeof($) === "undefined") {
2269
2291
  }
2270
2292
  $.file = new File();
2271
2293
  $.dir = new Dir();
2272
-
2273
-
2294
+
2295
+
2274
2296
  /**
2275
2297
  * @description 获取当前目录下所有文件
2276
2298
  * @param {String} keyword 搜索关键词
2277
2299
  * @return {Array} 文件路径数组
2278
2300
  */
2279
- String.prototype.getFile = function(keyword){
2280
- return $.file.get(this + '', keyword);
2301
+ String.prototype.getFile = function(keyword) {
2302
+ return $.file.get(this + '', keyword);
2281
2303
  };
2282
-
2304
+
2283
2305
  /**
2284
2306
  * @description 搜索当前目录下所有目录
2285
2307
  * @param {String} keyword 搜索关键词
@@ -2288,7 +2310,7 @@ if (typeof($) === "undefined") {
2288
2310
  String.prototype.getDir = function(keyword) {
2289
2311
  return $.dir.get(this + '', keyword);
2290
2312
  };
2291
-
2313
+
2292
2314
  })();
2293
2315
 
2294
2316
  /**
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.1",
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.3",
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,26 @@
1
1
  require('./index.js');
2
2
 
3
+
4
+ var num = 5;
5
+ // 随机一个1-5数值
6
+ // console.log(num.rand(1));
7
+ // console.log(num.rand(1));
8
+ // console.log(num.rand(1));
9
+ // console.log(num.rand(1));
10
+ // console.log(num.rand(1));
11
+ // console.log(num.rand(1));
12
+ // console.log(num.rand(1));
13
+
14
+
15
+ // 随机一个上下浮动10的数值
16
+ console.log(num.range(10));
17
+ console.log(num.range(10));
18
+ console.log(num.range(10));
19
+ console.log(num.range(10));
20
+ console.log(num.range(10));
21
+ console.log(num.range(10));
22
+ console.log(num.range(10));
23
+
3
24
  // /**
4
25
  // * 测试重载模块
5
26
  // */
@@ -348,7 +369,7 @@ require('./index.js');
348
369
  // sex: 0
349
370
  // }
350
371
  // ];
351
-
372
+
352
373
  // var list2 = [
353
374
  // {
354
375
  // id: 2,