mm_expand 1.5.4 → 1.5.6

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 +46 -14
  2. package/package.json +4 -4
  3. package/test.js +26 -13
package/index.js CHANGED
@@ -653,7 +653,7 @@ if (typeof($) === "undefined") {
653
653
  Number.prototype.rand = function(min = 1) {
654
654
  return Math.floor(Math.random() * (this - min + 1) + min);
655
655
  };
656
-
656
+
657
657
  /**
658
658
  * @description 随机数
659
659
  * @param {Number} margin 上下幅度
@@ -664,7 +664,7 @@ if (typeof($) === "undefined") {
664
664
  var max = this + margin;
665
665
  return Math.floor(Math.random() * (max - min + 1) + min);
666
666
  };
667
-
667
+
668
668
  })();
669
669
 
670
670
  /* == 时间原型函数 == */
@@ -696,6 +696,7 @@ if (typeof($) === "undefined") {
696
696
  }
697
697
  return format;
698
698
  };
699
+
699
700
  /**
700
701
  * @description 获取当前时间戳
701
702
  * @return {Number} 返回时间戳
@@ -704,6 +705,7 @@ if (typeof($) === "undefined") {
704
705
  var timestamp = Date.parse(this);
705
706
  return timestamp / 1000;
706
707
  };
708
+
707
709
  /**
708
710
  * @description 计算时间差(时间间隔)
709
711
  * @param {String} endTime 结束时间
@@ -716,31 +718,33 @@ if (typeof($) === "undefined") {
716
718
  var etime = Date.parse(new Date(endTime));
717
719
  var usedTime = etime - stime; // 两个时间戳相差的毫秒数
718
720
  if (time_unit === "day") {
719
- return Math.floor(usedTime / (1000 * 60 * 60 * 24));
721
+ return Math.floor(usedTime / 86400000);
720
722
  } else if (time_unit === "hours") {
721
- return Math.floor(usedTime / (1000 * 60 * 60));
723
+ return Math.floor(usedTime / 3600000);
722
724
  } else if (time_unit === "minutes") {
723
- return Math.floor(usedTime / (1000 * 60));
725
+ return Math.floor(usedTime / 60000);
724
726
  } else {
725
727
  return Math.floor(usedTime / 1000);
726
728
  }
727
729
  };
730
+
728
731
  /**
729
732
  * @description 时间添加天数
730
733
  * @param {Number} days 天数
731
734
  * @return {Date} 时间对象
732
735
  */
733
736
  Date.prototype.addDays = function(days) {
734
- this.setDate(this.getDate() + days);
735
- return this;
737
+ var stemp = Date.parse(this);
738
+ return new Date(stemp + days * 86400000);
736
739
  };
740
+
737
741
  /**
738
742
  * @description 时间添加秒数
739
743
  * @param {Date} seconds 时间对象
740
744
  */
741
745
  Date.prototype.addSeconds = function(seconds) {
742
- this.setSeconds(this.getSeconds() + seconds);
743
- return this;
746
+ var stemp = Date.parse(this);
747
+ return new Date(stemp + seconds * 1000);
744
748
  };
745
749
  })();
746
750
 
@@ -1041,6 +1045,37 @@ if (typeof($) === "undefined") {
1041
1045
  var str = this.replace('T', ' ').replace('Z', '').replaceAll('-', '/');
1042
1046
  return str.toTime().toStr(format);
1043
1047
  };
1048
+
1049
+ /**
1050
+ * @description 时间增加秒数
1051
+ * @param {Number} seconds 增加秒数
1052
+ * @param {String} format 转换的格式
1053
+ * @return {String|Date} 时间格式字符串
1054
+ */
1055
+ String.prototype.addSeconds = function(seconds, format) {
1056
+ var str = this;
1057
+ var time = str.toTime().addSeconds(seconds);
1058
+ if (format) {
1059
+ return time.toStr(format);
1060
+ }
1061
+ return time;
1062
+ };
1063
+
1064
+ /**
1065
+ * @description 时间增加天数
1066
+ * @param {Number} days 增加天数
1067
+ * @param {String} format 转换的格式
1068
+ * @return {String|Date} 时间格式字符串
1069
+ */
1070
+ String.prototype.addDays = function(days, format) {
1071
+ var str = this;
1072
+ var time = str.toTime().addDays(days);
1073
+ if (format) {
1074
+ return time.toStr(format);
1075
+ }
1076
+ return time;
1077
+ };
1078
+
1044
1079
  /**
1045
1080
  * @description 转为数组
1046
1081
  * @param {String|Regex} separator 分隔符或正则
@@ -2265,10 +2300,7 @@ if (typeof($) === "undefined") {
2265
2300
  */
2266
2301
  File.prototype.load = function(file, encode) {
2267
2302
  if (isFile(file)) {
2268
- if (!encode) {
2269
- encode = "utf-8"
2270
- }
2271
- return readFileSync(file, type);
2303
+ return readFileSync(file, encode);
2272
2304
  }
2273
2305
  };
2274
2306
  /**
@@ -2690,4 +2722,4 @@ if (typeof($) === "undefined") {
2690
2722
  module.exports = {
2691
2723
  Lang,
2692
2724
  Base
2693
- };
2725
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_expand",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
4
4
  "description": "这是超级美眉原型函数拓展模块,更有利于对string、array、object的操作,避免出错,简化业务逻辑。",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -29,8 +29,8 @@
29
29
  },
30
30
  "homepage": "https://github.com/qiuwenwu/mm_expand#readme",
31
31
  "dependencies": {
32
- "fast-xml-parser": "^3.15.1",
33
- "json5": "^2.1.1",
32
+ "fast-xml-parser": "^3.21.1",
33
+ "json5": "^2.2.3",
34
34
  "pinyinlite": "^1.2.1"
35
35
  }
36
- }
36
+ }
package/test.js CHANGED
@@ -1,7 +1,25 @@
1
1
  require('./index.js');
2
2
 
3
+ var timeStr = "1970-01-01 00:00:00";
3
4
 
4
- var num = 5;
5
+ var time = timeStr.toTime();
6
+ console.log(time);
7
+
8
+ var time2 = timeStr.addDays(367);
9
+ console.log(time2);
10
+
11
+ var time3 = timeStr.addSeconds(60);
12
+ console.log(time3.toStr("yyyy-MM-dd hh:mm:ss"));
13
+
14
+ var time4 = timeStr.addSeconds(60, "yyyy-MM-dd hh:mm:ss");
15
+ console.log(time4);
16
+
17
+ // "./中文/的".addDir(__dirname);
18
+ // "./中文/test.json".saveJson({ name: "123" });
19
+ // "./中文/test.json".delFile();
20
+ // "./中文".delDir(__dirname);
21
+
22
+ // var num = 5;
5
23
  // 随机一个1-5数值
6
24
  // console.log(num.rand(1));
7
25
  // console.log(num.rand(1));
@@ -10,20 +28,15 @@ var num = 5;
10
28
  // console.log(num.rand(1));
11
29
  // console.log(num.rand(1));
12
30
  // console.log(num.rand(1));
13
- "./中文/的".addDir();
14
- "./中文/test.json".saveJson({ name: "123" });
15
- "./中文/test.json".delFile();
16
- "./中文".delDir();
17
- console.log()
18
31
 
19
32
  // 随机一个上下浮动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));
33
+ // console.log(num.range(10));
34
+ // console.log(num.range(10));
35
+ // console.log(num.range(10));
36
+ // console.log(num.range(10));
37
+ // console.log(num.range(10));
38
+ // console.log(num.range(10));
39
+ // console.log(num.range(10));
27
40
 
28
41
  // /**
29
42
  // * 测试重载模块