@haluo/util 2.1.5 → 2.1.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.
@@ -9,14 +9,14 @@ import { createProjectConfig, projectConfigs } from './configs';
9
9
  * 创建 AppCall 实例
10
10
  */
11
11
  export function createAppCall(config) {
12
- const core = new AppCallCoreClass(config);
13
- const appCall = core;
12
+ var core = new AppCallCoreClass(config);
13
+ var appCall = core;
14
14
  appCall.__core = core;
15
15
  // 添加所有扩展方法(所有项目共享)
16
16
  appCall.extend(createAllExtensions(appCall, config));
17
17
  // 添加初始化方法
18
18
  appCall.init = function () {
19
- return new Promise((resolve) => {
19
+ return new Promise(function (resolve) {
20
20
  if (!core.getIsClient()) {
21
21
  resolve();
22
22
  return;
@@ -31,21 +31,21 @@ export function createAppCall(config) {
31
31
  return window.WVJBCallbacks.push(callback);
32
32
  }
33
33
  window.WVJBCallbacks = [callback];
34
- const WVJBIframe = document.createElement('iframe');
34
+ var WVJBIframe = document.createElement('iframe');
35
35
  WVJBIframe.style.display = 'none';
36
36
  WVJBIframe.src = 'motor://__BRIDGE_LOADED__';
37
37
  document.documentElement.appendChild(WVJBIframe);
38
- setTimeout(() => {
38
+ setTimeout(function () {
39
39
  document.documentElement.removeChild(WVJBIframe);
40
40
  }, 0);
41
41
  };
42
- appCall.callIOSHandler('getInterface', [], (data) => {
42
+ appCall.callIOSHandler('getInterface', [], function (data) {
43
43
  core.setIOSInterface(data);
44
44
  if (window.location.href.includes('machine-verification')) {
45
45
  resolve();
46
46
  return;
47
47
  }
48
- appCall.getUserData(() => {
48
+ appCall.getUserData(function () {
49
49
  resolve();
50
50
  });
51
51
  appCall.getDeviceData();
@@ -56,7 +56,7 @@ export function createAppCall(config) {
56
56
  resolve();
57
57
  return;
58
58
  }
59
- appCall.getUserData(() => {
59
+ appCall.getUserData(function () {
60
60
  resolve();
61
61
  });
62
62
  appCall.getDeviceData();
@@ -74,7 +74,7 @@ export function createAppCall(config) {
74
74
  * 快速创建项目 AppCall(使用预设配置)
75
75
  */
76
76
  export function createProjectAppCall(projectType, overrides) {
77
- const config = createProjectConfig(projectType, overrides);
77
+ var config = createProjectConfig(projectType, overrides);
78
78
  return createAppCall(config);
79
79
  }
80
80
  /**
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  /**
2
13
  * AppCall for offline package
3
14
  * 离线包专用的 AppCall,不依赖项目特定的配置
@@ -7,7 +18,8 @@ import { createAllExtensions } from './extensions';
7
18
  /**
8
19
  * 将获取到的设备信息放到本地存储
9
20
  */
10
- const setDeviceinfo = (devicedata = '') => {
21
+ var setDeviceinfo = function (devicedata) {
22
+ if (devicedata === void 0) { devicedata = ''; }
11
23
  if (devicedata && typeof devicedata === 'string') {
12
24
  devicedata = devicedata.replace('undefined', '');
13
25
  devicedata = JSON.parse(devicedata || '{}');
@@ -18,17 +30,12 @@ const setDeviceinfo = (devicedata = '') => {
18
30
  * 创建离线包专用的 AppCall
19
31
  * @param config 配置项
20
32
  */
21
- export function createOfflineAppCall(config = {}) {
22
- const offlineConfig = {
23
- projectName: config.projectName || '摩托范',
24
- domain: config.domain || '58moto.com',
25
- defaultImage: config.defaultImage || 'https://wap.58moto.com/static/img/common/motuofan_small.png',
26
- defaultDesc: config.defaultDesc || '摩托范,摩托发烧友的交流的平台,摩托维修、保养、配件等知识与经验分享社区。',
27
- showTip: config.showTip ?? false,
28
- env: config.env || {},
33
+ export function createOfflineAppCall(config) {
34
+ var _a;
35
+ if (config === void 0) { config = {}; }
36
+ var offlineConfig = __assign({ projectName: config.projectName || '摩托范', domain: config.domain || '58moto.com', defaultImage: config.defaultImage || 'https://wap.58moto.com/static/img/common/motuofan_small.png', defaultDesc: config.defaultDesc || '摩托范,摩托发烧友的交流的平台,摩托维修、保养、配件等知识与经验分享社区。', showTip: (_a = config.showTip) !== null && _a !== void 0 ? _a : false, env: config.env || {},
29
37
  // 离线包不需要这些依赖,提供空函数
30
- getCircleIdByName: () => Promise.resolve({ id: 0, type: '' }),
31
- setUserinfo: (data) => {
38
+ getCircleIdByName: function () { return Promise.resolve({ id: 0, type: '' }); }, setUserinfo: function (data) {
32
39
  console.log('setUserinfo', data);
33
40
  if (data && typeof data === 'string') {
34
41
  data = JSON.parse(data || '{}');
@@ -37,19 +44,16 @@ export function createOfflineAppCall(config = {}) {
37
44
  window.localStorage.setItem('user', JSON.stringify(data));
38
45
  window.localStorage.setItem('token', data.token);
39
46
  }
40
- },
41
- fileToHttps: config.fileToHttps || ((url) => {
47
+ }, fileToHttps: config.fileToHttps || (function (url) {
42
48
  if (url.includes('file://')) {
43
- const suffix = location.href.split('html#')[1];
44
- return `https://wap.58moto.com${suffix}`;
49
+ var suffix = location.href.split('html#')[1];
50
+ return "https://wap.58moto.com".concat(suffix);
45
51
  }
46
52
  return url;
47
- }),
48
- ...config
49
- };
53
+ }) }, config);
50
54
  // 直接使用核心类创建实例,避免循环依赖
51
- const core = new AppCallCoreClass(offlineConfig);
52
- const appCall = core;
55
+ var core = new AppCallCoreClass(offlineConfig);
56
+ var appCall = core;
53
57
  appCall.__core = core;
54
58
  // 添加所有扩展方法(所有项目共享)
55
59
  appCall.extend(createAllExtensions(appCall, offlineConfig));
@@ -62,12 +66,14 @@ export function createOfflineAppCall(config = {}) {
62
66
  // 扩展离线包特定的方法
63
67
  appCall.extend({
64
68
  // 文章 HTML 操作
65
- articleHtmlAction(action = {}, callback) {
69
+ articleHtmlAction: function (action, callback) {
70
+ if (action === void 0) { action = {}; }
66
71
  ;
67
72
  window.enableBridgeLog = false;
68
73
  window.enableBridgeLog && appCall.alert('1.1、articleHtmlAction');
69
74
  Object.assign((window.bridge = window.bridge || {}), {
70
- articleHtmlActionCallback(res = {}) {
75
+ articleHtmlActionCallback: function (res) {
76
+ if (res === void 0) { res = {}; }
71
77
  console.log('articleHtmlActionCallback', res);
72
78
  window.enableBridgeLog && appCall.alert('1.2、articleHtmlActionCallback');
73
79
  if (typeof res === 'string') {
@@ -94,11 +100,12 @@ export function createOfflineAppCall(config = {}) {
94
100
  return appCall.call('articleHtmlAction', JSON.stringify(action), window.bridge.articleHtmlActionCallback);
95
101
  },
96
102
  // 地图导航
97
- navigateMap(params = {}) {
103
+ navigateMap: function (params) {
104
+ if (params === void 0) { params = {}; }
98
105
  return appCall.call('navigateMap', JSON.stringify(params));
99
106
  },
100
107
  // 获取app信息
101
- getDeviceData(callback) {
108
+ getDeviceData: function (callback) {
102
109
  function _callback(data) {
103
110
  // 直接使用已初始化的全局变量
104
111
  if (window.isIOS) {
@@ -110,14 +117,15 @@ export function createOfflineAppCall(config = {}) {
110
117
  }
111
118
  typeof callback === 'function' && callback(data);
112
119
  }
113
- const deviceData = appCall.call('getDeviceData', _callback);
120
+ var deviceData = appCall.call('getDeviceData', _callback);
114
121
  // 安卓没有触发回调,所以自己调用设置一下
115
122
  if (window.isAndroid || window.isHarmonyos) {
116
123
  setDeviceinfo(deviceData);
117
124
  }
118
125
  return deviceData;
119
126
  },
120
- login(params = {}) {
127
+ login: function (params) {
128
+ if (params === void 0) { params = {}; }
121
129
  // 非客户端环境,跳转H5登录
122
130
  if (!window.isClient) {
123
131
  return (window.location.href = '/login');
@@ -133,15 +141,15 @@ export function createOfflineAppCall(config = {}) {
133
141
  * 这里直接使用已初始化的全局变量,避免重复计算和设置
134
142
  */
135
143
  export function initOfflineAppCall(appCall) {
136
- return new Promise((resolve) => {
144
+ return new Promise(function (resolve) {
137
145
  // 获取 core 实例(全局变量已在构造函数中初始化)
138
- const core = appCall.__core;
146
+ var core = appCall.__core;
139
147
  if (!core) {
140
148
  resolve();
141
149
  return;
142
150
  }
143
151
  // 直接使用已初始化的全局变量,避免重复计算
144
- const isClient = core.getIsClient();
152
+ var isClient = core.getIsClient();
145
153
  if (isClient) {
146
154
  if (window.isIOS) {
147
155
  // iOS Bridge 初始化(与 index.ts 中的逻辑保持一致)
@@ -153,24 +161,24 @@ export function initOfflineAppCall(appCall) {
153
161
  return window.WVJBCallbacks.push(callback);
154
162
  }
155
163
  window.WVJBCallbacks = [callback];
156
- const WVJBIframe = document.createElement('iframe');
164
+ var WVJBIframe = document.createElement('iframe');
157
165
  WVJBIframe.style.display = 'none';
158
166
  WVJBIframe.src = 'motor://__BRIDGE_LOADED__';
159
167
  document.documentElement.appendChild(WVJBIframe);
160
- setTimeout(() => {
168
+ setTimeout(function () {
161
169
  document.documentElement.removeChild(WVJBIframe);
162
170
  }, 0);
163
171
  };
164
- appCall.callIOSHandler('getInterface', [], (data) => {
172
+ appCall.callIOSHandler('getInterface', [], function (data) {
165
173
  core.setIOSInterface(data);
166
- appCall.getUserData(() => {
174
+ appCall.getUserData(function () {
167
175
  resolve();
168
176
  });
169
177
  appCall.getDeviceData();
170
178
  });
171
179
  }
172
180
  else if (window.isAndroid || window.isHarmonyos) {
173
- appCall.getUserData(() => {
181
+ appCall.getUserData(function () {
174
182
  resolve();
175
183
  });
176
184
  appCall.getDeviceData();
@@ -4,46 +4,51 @@
4
4
  * @createBy: @2021.01.21
5
5
  */
6
6
  'use strict';
7
- class CookieClass {
7
+ var CookieClass = /** @class */ (function () {
8
+ function CookieClass() {
9
+ }
8
10
  /**
9
11
  * 获取cookie
10
12
  * @param {String} name
11
13
  * @return {String}
12
14
  */
13
- getCookie(name) {
14
- const _name = name + '=';
15
- const ca = document.cookie.split(';');
16
- for (let i = 0; i < ca.length; i++) {
17
- let c = ca[i];
15
+ CookieClass.prototype.getCookie = function (name) {
16
+ var _name = name + '=';
17
+ var ca = document.cookie.split(';');
18
+ for (var i = 0; i < ca.length; i++) {
19
+ var c = ca[i];
18
20
  while (c.charAt(0) === ' ')
19
21
  c = c.substring(1);
20
22
  if (c.includes(_name))
21
23
  return c.substring(_name.length, c.length);
22
24
  }
23
25
  return '';
24
- }
26
+ };
25
27
  /**
26
28
  * 设置cookie
27
29
  * @param {Object} ICookie
28
30
  */
29
- setCookie({ name = '', value = '', exdays = -1, path = '/', domain = '.jddmoto.com', }) {
31
+ CookieClass.prototype.setCookie = function (_a) {
32
+ 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;
30
33
  var d = new Date();
31
34
  d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
32
- var expires = `expires=${d.toUTCString()}`;
33
- document.cookie = `${name}=${value};${expires};path=${path};domain=${domain};`;
34
- }
35
+ var expires = "expires=".concat(d.toUTCString());
36
+ document.cookie = "".concat(name, "=").concat(value, ";").concat(expires, ";path=").concat(path, ";domain=").concat(domain, ";");
37
+ };
35
38
  /**
36
39
  * 清除Cookie
37
40
  * @param {String} name
38
41
  */
39
- clearCookie({ name = '', path = '/', domain = '.jddmoto.com', }) {
42
+ CookieClass.prototype.clearCookie = function (_a) {
43
+ var _b = _a.name, name = _b === void 0 ? '' : _b, _c = _a.path, path = _c === void 0 ? '/' : _c, _d = _a.domain, domain = _d === void 0 ? '.jddmoto.com' : _d;
40
44
  this.setCookie({
41
- name,
45
+ name: name,
42
46
  value: '',
43
47
  exdays: -1,
44
- path,
45
- domain
48
+ path: path,
49
+ domain: domain
46
50
  });
47
- }
48
- }
51
+ };
52
+ return CookieClass;
53
+ }());
49
54
  export default new CookieClass();
@@ -13,7 +13,7 @@
13
13
  function replacementDate(data, fmt) {
14
14
  for (var k in data) {
15
15
  if (new RegExp('(' + k + ')').test(fmt)) {
16
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (data[k]) : ((`00${data[k]}`).substr(('' + data[k]).length)));
16
+ fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (data[k]) : (("00".concat(data[k])).substr(('' + data[k]).length)));
17
17
  }
18
18
  }
19
19
  return fmt;
@@ -30,7 +30,9 @@ function replacementYear(date, fmt) {
30
30
  }
31
31
  return fmt;
32
32
  }
33
- class DateClass {
33
+ var DateClass = /** @class */ (function () {
34
+ function DateClass() {
35
+ }
34
36
  /**
35
37
  * 格式化时间
36
38
  * @param {Date|Number|String} date 需要格式化的时间 2017-11-11、2017/11/11、linux time
@@ -40,10 +42,11 @@ class DateClass {
40
42
  * date.format(new Date(), 'YYYY:MM:DD') // 自定义格式 'YYYY:MM:DD'
41
43
  * @return {String} fmt 'YYYY-MM-DD HH:mm:ss'
42
44
  */
43
- format(date, fmt = 'YYYY-MM-DD HH:mm:ss') {
45
+ DateClass.prototype.format = function (date, fmt) {
46
+ if (fmt === void 0) { fmt = 'YYYY-MM-DD HH:mm:ss'; }
44
47
  if (!date)
45
48
  return '';
46
- let timeData = typeof date === 'string' ? new Date(date.replace(/-/g, '/')) : date;
49
+ var timeData = typeof date === 'string' ? new Date(date.replace(/-/g, '/')) : date;
47
50
  timeData = typeof date === 'number' ? new Date(date) : timeData;
48
51
  var o = {
49
52
  'M+': timeData.getMonth() + 1,
@@ -55,7 +58,7 @@ class DateClass {
55
58
  'q+': Math.floor((timeData.getMonth() + 3) / 3),
56
59
  'S': timeData.getMilliseconds()
57
60
  };
58
- const week = {
61
+ var week = {
59
62
  '0': '\u65e5',
60
63
  '1': '\u4e00',
61
64
  '2': '\u4e8c',
@@ -66,10 +69,10 @@ class DateClass {
66
69
  };
67
70
  fmt = replacementYear(timeData, fmt);
68
71
  if (/(E+)/.test(fmt)) {
69
- fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\u661f\u671f' : '\u5468') : '') + week[`${timeData.getDay()} `]);
72
+ fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\u661f\u671f' : '\u5468') : '') + week["".concat(timeData.getDay(), " ")]);
70
73
  }
71
74
  return replacementDate(o, fmt);
72
- }
75
+ };
73
76
  /**
74
77
  * 天数加减
75
78
  * @param {string | Date} date 传入的时间 2020-10-15 or Date
@@ -78,11 +81,11 @@ class DateClass {
78
81
  * addDaysToDate('2020-10-15', -10) // '2020-10-05'
79
82
  * @return {String} fmt 'YYYY-MM-DD'
80
83
  */
81
- addDaysToDate(date, days) {
82
- const d = typeof date === 'object' ? date : new Date(date);
84
+ DateClass.prototype.addDaysToDate = function (date, days) {
85
+ var d = typeof date === 'object' ? date : new Date(date);
83
86
  d.setDate(d.getDate() + days);
84
87
  return d.toISOString().split('T')[0];
85
- }
88
+ };
86
89
  /**
87
90
  * 获取倒计时剩余时间
88
91
  * @param {Date | Number} endTime 截止时间
@@ -91,55 +94,56 @@ class DateClass {
91
94
  * date.format(1586840260500) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
92
95
  * @return {object | boolean} {dd: '天', hh: '时', mm: '分', ss: '秒'}
93
96
  */
94
- remainTime(endTime, startTime = new Date()) {
95
- const ts = Number(endTime) - Number(startTime); // 计算剩余的毫秒数
96
- let dd = Math.floor(ts / 1000 / 60 / 60 / 24); // 计算剩余的天数
97
- let hh = Math.floor(ts / 1000 / 60 / 60 % 24); // 计算剩余的小时数
98
- let mm = Math.floor(ts / 1000 / 60 % 60); // 计算剩余的分钟数
99
- let ss = Math.floor(ts / 1000 % 60); // 计算剩余的秒数
97
+ DateClass.prototype.remainTime = function (endTime, startTime) {
98
+ if (startTime === void 0) { startTime = new Date(); }
99
+ var ts = Number(endTime) - Number(startTime); // 计算剩余的毫秒数
100
+ var dd = Math.floor(ts / 1000 / 60 / 60 / 24); // 计算剩余的天数
101
+ var hh = Math.floor(ts / 1000 / 60 / 60 % 24); // 计算剩余的小时数
102
+ var mm = Math.floor(ts / 1000 / 60 % 60); // 计算剩余的分钟数
103
+ var ss = Math.floor(ts / 1000 % 60); // 计算剩余的秒数
100
104
  if (ts <= 0)
101
105
  return false;
102
106
  return {
103
- dd: (dd < 10 ? `0${dd}` : dd),
104
- hh: (hh < 10 ? `0${hh}` : hh),
105
- mm: (mm < 10 ? `0${mm}` : mm),
106
- ss: (ss < 10 ? `0${ss}` : ss)
107
+ dd: (dd < 10 ? "0".concat(dd) : dd),
108
+ hh: (hh < 10 ? "0".concat(hh) : hh),
109
+ mm: (mm < 10 ? "0".concat(mm) : mm),
110
+ ss: (ss < 10 ? "0".concat(ss) : ss)
107
111
  };
108
- }
112
+ };
109
113
  /**
110
114
  * 格式化现在的已过时间
111
115
  * @param {Number} startTime
112
116
  * @return {String} *年前 *个月前 *天前 *小时前 *分钟前 刚刚
113
117
  */
114
- formatPassTime(startTime) {
115
- const currentTime = new Date();
116
- const time = currentTime - startTime;
117
- const year = Math.floor(time / (1000 * 60 * 60 * 24) / 30 / 12);
118
+ DateClass.prototype.formatPassTime = function (startTime) {
119
+ var currentTime = new Date();
120
+ var time = currentTime - startTime;
121
+ var year = Math.floor(time / (1000 * 60 * 60 * 24) / 30 / 12);
118
122
  if (year)
119
- return `${year}年前`;
120
- const month = Math.floor(time / (1000 * 60 * 60 * 24) / 30);
123
+ return "".concat(year, "\u5E74\u524D");
124
+ var month = Math.floor(time / (1000 * 60 * 60 * 24) / 30);
121
125
  if (month)
122
- return `${month}个月前`;
123
- const day = Math.floor(time / (1000 * 60 * 60 * 24));
126
+ return "".concat(month, "\u4E2A\u6708\u524D");
127
+ var day = Math.floor(time / (1000 * 60 * 60 * 24));
124
128
  if (day)
125
- return `${day}天前`;
126
- const hour = Math.floor(time / (1000 * 60 * 60));
129
+ return "".concat(day, "\u5929\u524D");
130
+ var hour = Math.floor(time / (1000 * 60 * 60));
127
131
  if (hour)
128
- return `${hour}小时前`;
129
- const min = Math.floor(time / (1000 * 60));
132
+ return "".concat(hour, "\u5C0F\u65F6\u524D");
133
+ var min = Math.floor(time / (1000 * 60));
130
134
  if (min)
131
- return `${min}分钟前`;
135
+ return "".concat(min, "\u5206\u949F\u524D");
132
136
  else
133
137
  return '刚刚';
134
- }
138
+ };
135
139
  /**
136
140
  * 格式化时间 列表里的时间内容格式 待废弃,统一时间格式
137
141
  * @param {Number} time 1494141000*1000
138
142
  * @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
139
143
  */
140
- formatPassTimeForList(time) {
144
+ DateClass.prototype.formatPassTimeForList = function (time) {
141
145
  return DateClass.prototype.formatPassTimeForDetail(time, 'YYYY年MM月DD日', true);
142
- }
146
+ };
143
147
  /**
144
148
  * 格式化时间 详情内容里的时间格式
145
149
  * @param {Number} time 1494141000*1000
@@ -147,24 +151,25 @@ class DateClass {
147
151
  * @param {Boolean} noYear 是否显示年
148
152
  * @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
149
153
  */
150
- formatPassTimeForDetail(time, fmt = 'YYYY-MM-DD', noYear) {
151
- const date = (typeof time === 'number') ? new Date(time) : new Date((time || '').replace(/-/g, '/'));
152
- const diff = (((new Date()).getTime() - date.getTime()) / 1000);
153
- const dayDiff = Math.floor(diff / 86400);
154
- const isValidDate = Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime());
154
+ DateClass.prototype.formatPassTimeForDetail = function (time, fmt, noYear) {
155
+ if (fmt === void 0) { fmt = 'YYYY-MM-DD'; }
156
+ var date = (typeof time === 'number') ? new Date(time) : new Date((time || '').replace(/-/g, '/'));
157
+ var diff = (((new Date()).getTime() - date.getTime()) / 1000);
158
+ var dayDiff = Math.floor(diff / 86400);
159
+ var isValidDate = Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime());
155
160
  if (!isValidDate)
156
161
  return '';
157
- const formatDate = function () {
158
- const today = new Date(date);
162
+ var formatDate = function () {
163
+ var today = new Date(date);
159
164
  var o = {
160
165
  'Y+': today.getFullYear(),
161
166
  'M+': ('0' + (today.getMonth() + 1)).slice(-2),
162
167
  'D+': ('0' + today.getDate()).slice(-2)
163
168
  };
164
169
  fmt = replacementYear(date, fmt);
165
- const year = today.getFullYear();
170
+ var year = today.getFullYear();
166
171
  if (!(new Date().getFullYear() > year) && noYear) {
167
- const backData = replacementDate(o, fmt);
172
+ var backData = replacementDate(o, fmt);
168
173
  return backData.split('年')[1];
169
174
  }
170
175
  return replacementDate(o, fmt);
@@ -180,6 +185,7 @@ class DateClass {
180
185
  (diff < 3600 && Math.floor(diff / 60) + '分钟前') ||
181
186
  (diff < 7200 && '1小时前') ||
182
187
  (diff < 86400 && Math.floor(diff / 3600) + '小时前'))) || (dayDiff < 16 && dayDiff + '天前');
183
- }
184
- }
188
+ };
189
+ return DateClass;
190
+ }());
185
191
  export default new DateClass();
@@ -4,52 +4,58 @@
4
4
  * @createBy: @2021.08.17
5
5
  */
6
6
  'use strict';
7
- class DomClass {
7
+ var DomClass = /** @class */ (function () {
8
+ function DomClass() {
9
+ }
8
10
  /**
9
11
  * 创建一个子元素并添加至父节点
10
12
  * @param {Object} { name = 'div', innerHTML = '', style = {}, parent, }
11
13
  * @return {String}
12
14
  */
13
- createElement({ name = 'div', innerHTML = '', style = {}, parent, }) {
15
+ DomClass.prototype.createElement = function (_a) {
16
+ var _b = _a.name, name = _b === void 0 ? 'div' : _b, _c = _a.innerHTML, innerHTML = _c === void 0 ? '' : _c, _d = _a.style, style = _d === void 0 ? {} : _d, parent = _a.parent;
14
17
  if (!(window && window.document)) {
15
18
  return new Error('仅支持浏览器');
16
19
  }
17
- const element = document.createElement(name);
20
+ var element = document.createElement(name);
18
21
  element.innerHTML = innerHTML;
19
- Object.keys(style).map((_) => element.style[_] = style[_]);
22
+ Object.keys(style).map(function (_) { return element.style[_] = style[_]; });
20
23
  if (parent) {
21
- const body = document.querySelector(parent);
24
+ var body = document.querySelector(parent);
22
25
  body && body.append(element);
23
26
  }
24
27
  return element;
25
- }
28
+ };
26
29
  /**
27
30
  * 获取文本中的url并用a标签包裹
28
31
  * @param {Object} ICookie
29
32
  */
30
- wrapperA(text) {
33
+ DomClass.prototype.wrapperA = function (text) {
31
34
  if (!(window && window.document)) {
32
35
  return new Error('仅支持浏览器');
33
36
  }
34
37
  return text.replace(/((https|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])/g, '<a href="$1">$1</a>');
35
- }
38
+ };
36
39
  /**
37
40
  * 对象转化为formdata
38
41
  * getFormData({a: 1, b: 2})
39
42
  * @param {Object} object
40
43
  */
41
- getFormData(object) {
42
- const formData = new FormData();
43
- Object.keys(object).forEach(key => {
44
- const value = object[key];
44
+ DomClass.prototype.getFormData = function (object) {
45
+ var formData = new FormData();
46
+ Object.keys(object).forEach(function (key) {
47
+ var value = object[key];
45
48
  if (Array.isArray(value)) {
46
- value.forEach((subValue, i) => formData.append(key + `[${i}]`, subValue));
49
+ value.forEach(function (subValue, i) {
50
+ return formData.append(key + "[".concat(i, "]"), subValue);
51
+ });
47
52
  }
48
53
  else {
49
54
  formData.append(key, object[key]);
50
55
  }
51
56
  });
52
57
  return formData;
53
- }
54
- }
58
+ };
59
+ return DomClass;
60
+ }());
55
61
  export default new DomClass();
@@ -7,32 +7,38 @@
7
7
  import dateClass from '../date';
8
8
  import numberClass from '../number';
9
9
  import toolsClass from '../tools';
10
- class FilterClass {
10
+ var FilterClass = /** @class */ (function () {
11
+ function FilterClass() {
12
+ }
11
13
  /**
12
14
  * 格式化时间,示例:1586840260500 | format('YYYY-MM-DD HH:mm:ss')
13
15
  * @param {String|Number} date
14
16
  * @param {String} fmt 'YYYY-MM-DD HH:mm:ss'
15
17
  * @return {String} 'YYYY-MM-DD HH:mm:ss'
16
18
  */
17
- format(date, fmt = 'YYYY-MM-DD HH:mm:ss') {
19
+ FilterClass.prototype.format = function (date, fmt) {
20
+ if (fmt === void 0) { fmt = 'YYYY-MM-DD HH:mm:ss'; }
18
21
  return dateClass.format(date, fmt);
19
- }
22
+ };
20
23
  /**
21
24
  * 格式化金额,示例:123456 | formatMoney
22
25
  * @param {Number} num
23
26
  * @return {String} 123,456
24
27
  */
25
- formatMoney(money) {
28
+ FilterClass.prototype.formatMoney = function (money) {
26
29
  return numberClass.formatMoney(money);
27
- }
30
+ };
28
31
  /**
29
32
  * 截取数组或字符串,示例:'1234' | slice(3)
30
33
  * @param {Array|String} target 数组或字符串
31
34
  * @param {Number} length 截取长度,从0开始
32
35
  * @return {any}
33
36
  */
34
- slice(target = '', length = 0) {
37
+ FilterClass.prototype.slice = function (target, length) {
38
+ if (target === void 0) { target = ''; }
39
+ if (length === void 0) { length = 0; }
35
40
  return toolsClass.slice(target, length);
36
- }
37
- }
41
+ };
42
+ return FilterClass;
43
+ }());
38
44
  export default new FilterClass();
@@ -1,4 +1,6 @@
1
- class Format {
1
+ var Format = /** @class */ (function () {
2
+ function Format() {
3
+ }
2
4
  /**
3
5
  * @desc 对于对象非数字与布尔值的value,当其为falsy时,转换成separator
4
6
  * @param {object} obj 传入的对象
@@ -6,11 +8,13 @@ class Format {
6
8
  * transformObjectNullVal({ a: null, b: 0}, '23') // {a: "23", b: 0}
7
9
  * @return {object}
8
10
  */
9
- transformObjectNullVal(obj, separator = '-') {
10
- return Object.keys(obj).reduce((cur, key) => {
11
+ Format.prototype.transformObjectNullVal = function (obj, separator) {
12
+ if (separator === void 0) { separator = '-'; }
13
+ return Object.keys(obj).reduce(function (cur, key) {
11
14
  cur[key] = obj[key] || ((obj[key] === 0 || obj[key] === false) ? obj[key] : separator);
12
15
  return cur;
13
16
  }, {});
14
- }
15
- }
17
+ };
18
+ return Format;
19
+ }());
16
20
  export default new Format();