@haluo/util 2.0.15 → 2.0.16

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.
package/README.md CHANGED
@@ -175,6 +175,12 @@ number.random(1, 100) // 4
175
175
  number.formatMoney(123456) // 123,456
176
176
  ```
177
177
 
178
+ - formatPhoneNumber 格式化手机号码
179
+
180
+ ```js
181
+ number.formatPhoneNumber(13111111111) // 131 1111 1111
182
+ ```
183
+
178
184
 
179
185
 
180
186
  ### tools
package/dist/index.js CHANGED
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
8
12
  }));
9
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
13
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -33,8 +33,8 @@ var CookieClass = /** @class */ (function () {
33
33
  var _b = _a.name, name = _b === void 0 ? '' : _b, _c = _a.value, value = _c === void 0 ? '' : _c, _d = _a.exdays, exdays = _d === void 0 ? -1 : _d, _e = _a.path, path = _e === void 0 ? '/' : _e, _f = _a.domain, domain = _f === void 0 ? '.jddmoto.com' : _f;
34
34
  var d = new Date();
35
35
  d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
36
- var expires = "expires=" + d.toUTCString();
37
- document.cookie = name + "=" + value + ";" + expires + ";path=" + path + ";domain=" + domain + ";";
36
+ var expires = "expires=".concat(d.toUTCString());
37
+ document.cookie = "".concat(name, "=").concat(value, ";").concat(expires, ";path=").concat(path, ";domain=").concat(domain, ";");
38
38
  };
39
39
  /**
40
40
  * 清除Cookie
@@ -14,7 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  function replacementDate(data, fmt) {
15
15
  for (var k in data) {
16
16
  if (new RegExp('(' + k + ')').test(fmt)) {
17
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (data[k]) : (("00" + data[k]).substr(('' + data[k]).length)));
17
+ fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (data[k]) : (("00".concat(data[k])).substr(('' + data[k]).length)));
18
18
  }
19
19
  }
20
20
  return fmt;
@@ -70,7 +70,7 @@ var DateClass = /** @class */ (function () {
70
70
  };
71
71
  fmt = replacementYear(timeData, fmt);
72
72
  if (/(E+)/.test(fmt)) {
73
- fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\u661f\u671f' : '\u5468') : '') + week[timeData.getDay() + " "]);
73
+ fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\u661f\u671f' : '\u5468') : '') + week["".concat(timeData.getDay(), " ")]);
74
74
  }
75
75
  return replacementDate(o, fmt);
76
76
  };
@@ -105,10 +105,10 @@ var DateClass = /** @class */ (function () {
105
105
  if (ts <= 0)
106
106
  return false;
107
107
  return {
108
- dd: (dd < 10 ? "0" + dd : dd),
109
- hh: (hh < 10 ? "0" + hh : hh),
110
- mm: (mm < 10 ? "0" + mm : mm),
111
- ss: (ss < 10 ? "0" + ss : ss)
108
+ dd: (dd < 10 ? "0".concat(dd) : dd),
109
+ hh: (hh < 10 ? "0".concat(hh) : hh),
110
+ mm: (mm < 10 ? "0".concat(mm) : mm),
111
+ ss: (ss < 10 ? "0".concat(ss) : ss)
112
112
  };
113
113
  };
114
114
  /**
@@ -121,19 +121,19 @@ var DateClass = /** @class */ (function () {
121
121
  var time = currentTime - startTime;
122
122
  var year = Math.floor(time / (1000 * 60 * 60 * 24) / 30 / 12);
123
123
  if (year)
124
- return year + "\u5E74\u524D";
124
+ return "".concat(year, "\u5E74\u524D");
125
125
  var month = Math.floor(time / (1000 * 60 * 60 * 24) / 30);
126
126
  if (month)
127
- return month + "\u4E2A\u6708\u524D";
127
+ return "".concat(month, "\u4E2A\u6708\u524D");
128
128
  var day = Math.floor(time / (1000 * 60 * 60 * 24));
129
129
  if (day)
130
- return day + "\u5929\u524D";
130
+ return "".concat(day, "\u5929\u524D");
131
131
  var hour = Math.floor(time / (1000 * 60 * 60));
132
132
  if (hour)
133
- return hour + "\u5C0F\u65F6\u524D";
133
+ return "".concat(hour, "\u5C0F\u65F6\u524D");
134
134
  var min = Math.floor(time / (1000 * 60));
135
135
  if (min)
136
- return min + "\u5206\u949F\u524D";
136
+ return "".concat(min, "\u5206\u949F\u524D");
137
137
  else
138
138
  return '刚刚';
139
139
  };
@@ -48,7 +48,7 @@ var DomClass = /** @class */ (function () {
48
48
  var value = object[key];
49
49
  if (Array.isArray(value)) {
50
50
  value.forEach(function (subValue, i) {
51
- return formData.append(key + ("[" + i + "]"), subValue);
51
+ return formData.append(key + "[".concat(i, "]"), subValue);
52
52
  });
53
53
  }
54
54
  else {
@@ -10,8 +10,8 @@ var tracker_1 = __importDefault(require("./utils/tracker"));
10
10
  exports.Tracker = tracker_1.default;
11
11
  // import timing from './lib/timing'
12
12
  function setup(data) {
13
- jsError_1.injectJsError(data);
14
- xhr_1.default(data);
13
+ (0, jsError_1.injectJsError)(data);
14
+ (0, xhr_1.default)(data);
15
15
  }
16
16
  exports.default = setup;
17
17
  // timing()
@@ -25,7 +25,7 @@ function injectJsError(data) {
25
25
  ));
26
26
  return;
27
27
  }
28
- tracker_1.default.send(__assign({ kind: 'stability', type: 'error', title: 'jsError', message: e.message, filename: e.filename, position: e.lineno + ":" + e.colno, reason: e.error.stack }, data
28
+ tracker_1.default.send(__assign({ kind: 'stability', type: 'error', title: 'jsError', message: e.message, filename: e.filename, position: "".concat(e.lineno, ":").concat(e.colno), reason: e.error.stack }, data
29
29
  // selector: lastEvent ? get
30
30
  ));
31
31
  }, true);
@@ -45,8 +45,7 @@ function injectJsError(data) {
45
45
  message = reason.message;
46
46
  stack = reason.stack;
47
47
  }
48
- tracker_1.default.send(__assign({ kind: 'stability', type: 'error', title: 'promiseError', message: message,
49
- filename: filename, position: line + ":" + column, reason: stack }, data
48
+ tracker_1.default.send(__assign({ kind: 'stability', type: 'error', title: 'promiseError', message: message, filename: filename, position: "".concat(line, ":").concat(column), reason: stack }, data
50
49
  // selector: lastEvent ? get
51
50
  ));
52
51
  });
@@ -35,7 +35,7 @@ function timing() {
35
35
  }
36
36
  observer.disconnect(); // 不再观察
37
37
  }).observe({ type: 'first-input', buffered: true }); // 观察页面中最大的元素
38
- onload_1.default(function () {
38
+ (0, onload_1.default)(function () {
39
39
  setTimeout(function () {
40
40
  console.dir(window.performance);
41
41
  var _a = performance.getEntriesByType('navigation')[0], fetchStart = _a.fetchStart, connectStart = _a.connectStart, connectEnd = _a.connectEnd, requestStart = _a.requestStart, responseStart = _a.responseStart, responseEnd = _a.responseEnd, domInteractive = _a.domInteractive, domContentLoadedEventStart = _a.domContentLoadedEventStart, domContentLoadedEventEnd = _a.domContentLoadedEventEnd, loadEventStart = _a.loadEventStart;
@@ -36,7 +36,7 @@ function injectXHR(data) {
36
36
  var duration = Date.now() - startTime_1;
37
37
  var status = _this.status;
38
38
  var statusText = _this.statusText;
39
- tracker_1.default.send(__assign({ kind: 'stability', type: 'xhr', eventType: event.type, pathname: _this.logData.url, status: status + '-' + statusText, duration: duration, response: _this.response ? JSON.stringify(_this.response) : '', params: body || '', title: 'xhr', reason: status + '-' + statusText + (" " + _this.logData.url + " " + (_this.response ? JSON.stringify(_this.response) : '')) }, data));
39
+ tracker_1.default.send(__assign({ kind: 'stability', type: 'xhr', eventType: event.type, pathname: _this.logData.url, status: status + '-' + statusText, duration: duration, response: _this.response ? JSON.stringify(_this.response) : '', params: body || '', title: 'xhr', reason: status + '-' + statusText + " ".concat(_this.logData.url, " ").concat(_this.response ? JSON.stringify(_this.response) : '') }, data));
40
40
  }; };
41
41
  this.addEventListener('load', handler('load'), false);
42
42
  this.addEventListener('error', handler('error'), false);
@@ -57,6 +57,7 @@ function getExtraData() {
57
57
  title: '',
58
58
  frontStatus: 3,
59
59
  occurTimeStamp: Date.now(),
60
+ // userAgent: new Parser().getResult()
60
61
  };
61
62
  }
62
63
  exports.default = new SendTracker();
@@ -36,6 +36,12 @@ declare class NumberClass {
36
36
  * @return {String} 123,456
37
37
  */
38
38
  formatMoney(money: number | string, signal?: string): string;
39
+ /**
40
+ * 格式化手机号
41
+ * @param {string} number 手机号
42
+ * @returns {string} 格式化后的手机号 12345678901 -> 123 4567 8901
43
+ */
44
+ formatPhoneNumber(number: string | number): string;
39
45
  }
40
46
  declare const _default: NumberClass;
41
47
  export default _default;
@@ -92,12 +92,27 @@ var NumberClass = /** @class */ (function () {
92
92
  var price = money.split('.')[0] + '';
93
93
  var pricePoint = money.split('.')[1];
94
94
  result = price.length > 6 ?
95
- "" + price.substring(0, price.length - 6) + signal + price.substring(price.length - 6, price.length - 3) + "," + price.substring(price.length - 3, price.length)
95
+ "".concat(price.substring(0, price.length - 6)).concat(signal).concat(price.substring(price.length - 6, price.length - 3), ",").concat(price.substring(price.length - 3, price.length))
96
96
  :
97
- "" + price.substring(0, price.length - 3) + signal + price.substring(price.length - 3, price.length);
98
- result = pricePoint ? "" + result + signal + pricePoint : result;
97
+ "".concat(price.substring(0, price.length - 3)).concat(signal).concat(price.substring(price.length - 3, price.length));
98
+ result = pricePoint ? "".concat(result).concat(signal).concat(pricePoint) : result;
99
99
  return result;
100
100
  };
101
+ /**
102
+ * 格式化手机号
103
+ * @param {string} number 手机号
104
+ * @returns {string} 格式化后的手机号 12345678901 -> 123 4567 8901
105
+ */
106
+ NumberClass.prototype.formatPhoneNumber = function (number) {
107
+ var numStr = String(number).replace(/\s/g, '');
108
+ if (numStr.length < 11) {
109
+ return numStr;
110
+ }
111
+ var firstPart = numStr.slice(0, 3);
112
+ var secondPart = numStr.slice(3, 7);
113
+ var thirdPart = numStr.slice(7, 11);
114
+ return "".concat(firstPart, " ").concat(secondPart, " ").concat(thirdPart);
115
+ };
101
116
  return NumberClass;
102
117
  }());
103
118
  exports.default = new NumberClass();
@@ -25,7 +25,7 @@ var ToolsClass = /** @class */ (function () {
25
25
  body.style.overflow = 'hidden';
26
26
  body.style.height = '100%';
27
27
  if (className) {
28
- var dom = document.querySelector("." + className);
28
+ var dom = document.querySelector(".".concat(className));
29
29
  dom && dom.addEventListener('touchmove', _this.__setDefault__);
30
30
  }
31
31
  };
@@ -45,7 +45,7 @@ var ToolsClass = /** @class */ (function () {
45
45
  body.style.overflow = 'visible';
46
46
  body.style.height = 'auto';
47
47
  if (className) {
48
- var dom = document.querySelector("." + className);
48
+ var dom = document.querySelector(".".concat(className));
49
49
  dom && dom.removeEventListener('touchmove', _this.__setDefault__);
50
50
  }
51
51
  };
@@ -384,9 +384,9 @@ var ToolsClass = /** @class */ (function () {
384
384
  }
385
385
  // 匹配中文、英文、数字
386
386
  var regItem = '[\u4e00-\u9fa5a-zA-Z0-9]';
387
- var regExp = "(" + regItem + "{" + before + "})" + regItem + "*(" + regItem + "{" + after + "})";
387
+ var regExp = "(".concat(regItem, "{").concat(before, "})").concat(regItem, "*(").concat(regItem, "{").concat(after, "})");
388
388
  var reg = new RegExp(regExp);
389
- return field.replace(reg, "$1" + "*".repeat(sensitiveLen) + "$2");
389
+ return field.replace(reg, "$1".concat("*".repeat(sensitiveLen), "$2"));
390
390
  };
391
391
  return ToolsClass;
392
392
  }());