mm_expand 1.5.2 → 1.5.4

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 (3) hide show
  1. package/index.js +18 -7
  2. package/package.json +2 -1
  3. package/test.js +22 -7
package/index.js CHANGED
@@ -647,12 +647,24 @@ if (typeof($) === "undefined") {
647
647
 
648
648
  /**
649
649
  * @description 随机数
650
- * @@param {Number} min 最小值
650
+ * @param {Number} min 最小值
651
651
  * @return {Number} 返回一个数值
652
652
  */
653
653
  Number.prototype.rand = function(min = 1) {
654
654
  return Math.floor(Math.random() * (this - min + 1) + min);
655
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
+
656
668
  })();
657
669
 
658
670
  /* == 时间原型函数 == */
@@ -1308,10 +1320,10 @@ if (typeof($) === "undefined") {
1308
1320
 
1309
1321
  /**
1310
1322
  * @description 删除文件
1311
- * @param {String} dir 当前路径
1323
+ * @param {String} file 当前路径
1312
1324
  */
1313
- String.prototype.delFile = function(dir) {
1314
- unlink(this.fullname(dir), function(e) {});
1325
+ String.prototype.delFile = function(file) {
1326
+ unlink(this.fullname(file), function(e) {});
1315
1327
  };
1316
1328
 
1317
1329
  /**
@@ -2263,15 +2275,14 @@ if (typeof($) === "undefined") {
2263
2275
  * @description 加载文件
2264
2276
  * @param {String} file 文件路径
2265
2277
  * @param {String} data 编码方式
2266
- * @param {Boolean} options 写出成功返回true, 失败返回false
2267
2278
  * @return {Boolean} 保存成功返回true,否则返回false
2268
2279
  */
2269
- File.prototype.save = function(file, data, options) {
2280
+ File.prototype.save = function(file, data, encode) {
2270
2281
  if (data) {
2271
2282
  if (!encode) {
2272
2283
  encode = "utf-8"
2273
2284
  }
2274
- return writeFileSync(file, encode);
2285
+ return writeFileSync(file, data, encode);
2275
2286
  } else {
2276
2287
  return false;
2277
2288
  }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "mm_expand",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "这是超级美眉原型函数拓展模块,更有利于对string、array、object的操作,避免出错,简化业务逻辑。",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
+ "dev": "nodemon test.js",
7
8
  "test": "node test.js"
8
9
  },
9
10
  "repository": {
package/test.js CHANGED
@@ -2,13 +2,28 @@ require('./index.js');
2
2
 
3
3
 
4
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());
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
+ "./中文/的".addDir();
14
+ "./中文/test.json".saveJson({ name: "123" });
15
+ "./中文/test.json".delFile();
16
+ "./中文".delDir();
17
+ console.log()
18
+
19
+ // 随机一个上下浮动10的数值
20
+ console.log(num.range(10));
21
+ console.log(num.range(10));
22
+ console.log(num.range(10));
23
+ console.log(num.range(10));
24
+ console.log(num.range(10));
25
+ console.log(num.range(10));
26
+ console.log(num.range(10));
12
27
 
13
28
  // /**
14
29
  // * 测试重载模块