@haluo/util 2.0.0 → 2.0.2-0.1

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 (89) hide show
  1. package/README.md +12 -1
  2. package/dist/index.d.ts +39 -0
  3. package/dist/index.js +74 -33
  4. package/dist/modules/cookie/index.d.ts +27 -0
  5. package/dist/modules/cookie/index.js +55 -54
  6. package/dist/modules/date/index.d.ts +52 -0
  7. package/dist/modules/date/index.js +192 -192
  8. package/dist/modules/dom/index.d.ts +28 -0
  9. package/dist/modules/dom/index.js +62 -62
  10. package/dist/modules/filter/index.d.ts +24 -0
  11. package/dist/modules/filter/index.js +48 -44
  12. package/dist/modules/format/index.d.ts +15 -0
  13. package/dist/modules/format/index.js +22 -21
  14. package/dist/modules/match/index.d.ts +12 -0
  15. package/dist/modules/match/index.js +31 -31
  16. package/dist/modules/monitor/index.d.ts +3 -0
  17. package/dist/modules/monitor/index.js +17 -17
  18. package/dist/modules/monitor/lib/jsError.d.ts +1 -0
  19. package/dist/modules/monitor/lib/jsError.js +53 -53
  20. package/dist/modules/monitor/lib/timing.d.ts +1 -0
  21. package/dist/modules/monitor/lib/timing.js +69 -69
  22. package/dist/modules/monitor/lib/xhr.d.ts +1 -0
  23. package/dist/modules/monitor/lib/xhr.js +48 -48
  24. package/dist/modules/monitor/utils/onload.d.ts +1 -0
  25. package/dist/modules/monitor/utils/onload.js +11 -11
  26. package/dist/modules/monitor/utils/tracker.d.ts +7 -0
  27. package/dist/modules/monitor/utils/tracker.js +63 -63
  28. package/dist/modules/number/index.d.ts +47 -0
  29. package/dist/modules/number/index.js +118 -102
  30. package/dist/modules/open-app/index.d.ts +84 -0
  31. package/dist/modules/open-app/index.js +239 -0
  32. package/dist/modules/sentry/index.d.ts +15 -0
  33. package/dist/modules/sentry/index.js +81 -81
  34. package/dist/modules/tools/index.d.ts +166 -0
  35. package/dist/modules/tools/index.js +393 -393
  36. package/dist/modules/upload/ALIOSS_EXAMPLE.d.ts +12 -0
  37. package/dist/modules/upload/ALIOSS_EXAMPLE.js +320 -0
  38. package/dist/modules/upload/aliOss.d.ts +324 -0
  39. package/dist/modules/upload/aliOss.js +838 -0
  40. package/dist/modules/upload/index.d.ts +51 -0
  41. package/dist/modules/upload/index.js +55 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -0
  43. package/dist/types/index.d.ts +3 -0
  44. package/dist/types/index.js +2 -0
  45. package/dist/types/modules/cookie/index.d.ts +27 -0
  46. package/dist/types/modules/date/index.d.ts +52 -0
  47. package/dist/types/modules/dom/index.d.ts +28 -0
  48. package/dist/types/modules/filter/index.d.ts +24 -0
  49. package/dist/types/modules/format/index.d.ts +15 -0
  50. package/dist/types/modules/match/index.d.ts +12 -0
  51. package/dist/types/modules/monitor/index.d.ts +3 -0
  52. package/dist/types/modules/monitor/lib/jsError.d.ts +1 -0
  53. package/dist/types/modules/monitor/lib/timing.d.ts +1 -0
  54. package/dist/types/modules/monitor/lib/xhr.d.ts +1 -0
  55. package/dist/types/modules/monitor/utils/onload.d.ts +1 -0
  56. package/dist/types/modules/monitor/utils/tracker.d.ts +7 -0
  57. package/dist/types/modules/number/index.d.ts +41 -0
  58. package/dist/types/modules/sentry/index.d.ts +15 -0
  59. package/dist/types/modules/tools/index.d.ts +166 -0
  60. package/dist/types/types/index.d.ts +3 -0
  61. package/package.json +18 -13
  62. package/.babelrc +0 -21
  63. package/.eslintrc.js +0 -216
  64. package/__tests__/unit/date/date.spec.js +0 -14
  65. package/__tests__/unit/jest.conf.js +0 -25
  66. package/__tests__/unit/specs/date.test.js +0 -11
  67. package/global.d.ts +0 -0
  68. package/publish.sh +0 -11
  69. package/specification/CSS.md +0 -25
  70. package/specification/JS.md +0 -9
  71. package/specification/VUE.md +0 -1
  72. package/src/consts/httpCode.js +0 -10
  73. package/src/index.ts +0 -51
  74. package/src/modules/cookie/index.ts +0 -69
  75. package/src/modules/date/index.ts +0 -196
  76. package/src/modules/dom/index.ts +0 -78
  77. package/src/modules/filter/index.ts +0 -43
  78. package/src/modules/format/index.ts +0 -19
  79. package/src/modules/match/index.ts +0 -31
  80. package/src/modules/monitor/index.ts +0 -13
  81. package/src/modules/monitor/lib/jsError.ts +0 -57
  82. package/src/modules/monitor/lib/timing.ts +0 -75
  83. package/src/modules/monitor/lib/xhr.ts +0 -40
  84. package/src/modules/monitor/utils/onload.ts +0 -8
  85. package/src/modules/monitor/utils/tracker.ts +0 -47
  86. package/src/modules/number/index.ts +0 -108
  87. package/src/modules/sentry/index.ts +0 -82
  88. package/src/modules/tools/index.ts +0 -427
  89. package/tsconfig.json +0 -34
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ### @haluo/util
2
2
 
3
- > 哈罗摩托工具库
3
+ > 摩托范工具库
4
4
 
5
5
 
6
6
 
@@ -175,6 +175,17 @@ 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
+
184
+ ### openApp
185
+
186
+ > import { openApp } from '@haluo/util';
187
+
188
+ - export default new openApp(env, postJddTrack, trackId, openAppState)
178
189
 
179
190
 
180
191
  ### tools
@@ -0,0 +1,39 @@
1
+ import cookie from './modules/cookie';
2
+ import date from './modules/date';
3
+ import dom from './modules/dom';
4
+ import filter from './modules/filter';
5
+ import format from './modules/format';
6
+ import match from './modules/match';
7
+ import number from './modules/number';
8
+ import openApp from './modules/open-app';
9
+ import tools from './modules/tools';
10
+ import upload from './modules/upload';
11
+ import monitor from './modules/monitor';
12
+ export * from './modules/monitor';
13
+ interface Modules {
14
+ cookie: typeof cookie;
15
+ date: typeof date;
16
+ dom: typeof dom;
17
+ filter: typeof filter;
18
+ format: typeof format;
19
+ match: typeof match;
20
+ number: typeof number;
21
+ openApp: typeof openApp;
22
+ tools: typeof tools;
23
+ upload: typeof upload;
24
+ monitor: typeof monitor;
25
+ }
26
+ declare class Utils {
27
+ constructor();
28
+ /**
29
+ * 挂载各组件
30
+ * 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
31
+ * @param {Object} Vue 需要挂载的目标对象
32
+ */
33
+ install(app: any): void;
34
+ }
35
+ interface Utils extends Modules {
36
+ }
37
+ declare const _default: Utils;
38
+ export default _default;
39
+ export { cookie, date, dom, filter, format, match, number, openApp, tools, upload, monitor };
package/dist/index.js CHANGED
@@ -1,33 +1,74 @@
1
- /**
2
- * @Author: wanghui
3
- * createBy: @2020.05.21
4
- */
5
- 'use strict';
6
- var modules = {
7
- cookie: require('./modules/cookie'),
8
- date: require('./modules/date'),
9
- dom: require('./modules/dom'),
10
- filter: require('./modules/filter'),
11
- format: require('./modules/format'),
12
- match: require('./modules/match'),
13
- number: require('./modules/number'),
14
- tools: require('./modules/tools'),
15
- };
16
- var Utils = /** @class */ (function () {
17
- function Utils() {
18
- Object.assign(this, modules);
19
- }
20
- /**
21
- * 挂载各组件
22
- * 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
23
- * @param {Object} Vue 需要挂载的目标对象
24
- */
25
- Utils.prototype.install = function (app) {
26
- Object.keys(modules).forEach(function (key) {
27
- var globalProperties = app.config.globalProperties;
28
- globalProperties['$' + key] = modules[key];
29
- });
30
- };
31
- return Utils;
32
- }());
33
- module.exports = new Utils();
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.monitor = exports.upload = exports.tools = exports.openApp = exports.number = exports.match = exports.format = exports.filter = exports.dom = exports.date = exports.cookie = void 0;
21
+ var cookie_1 = __importDefault(require("./modules/cookie"));
22
+ exports.cookie = cookie_1.default;
23
+ var date_1 = __importDefault(require("./modules/date"));
24
+ exports.date = date_1.default;
25
+ var dom_1 = __importDefault(require("./modules/dom"));
26
+ exports.dom = dom_1.default;
27
+ var filter_1 = __importDefault(require("./modules/filter"));
28
+ exports.filter = filter_1.default;
29
+ var format_1 = __importDefault(require("./modules/format"));
30
+ exports.format = format_1.default;
31
+ var match_1 = __importDefault(require("./modules/match"));
32
+ exports.match = match_1.default;
33
+ var number_1 = __importDefault(require("./modules/number"));
34
+ exports.number = number_1.default;
35
+ var open_app_1 = __importDefault(require("./modules/open-app"));
36
+ exports.openApp = open_app_1.default;
37
+ var tools_1 = __importDefault(require("./modules/tools"));
38
+ exports.tools = tools_1.default;
39
+ var upload_1 = __importDefault(require("./modules/upload"));
40
+ exports.upload = upload_1.default;
41
+ var monitor_1 = __importDefault(require("./modules/monitor"));
42
+ exports.monitor = monitor_1.default;
43
+ __exportStar(require("./modules/monitor"), exports);
44
+ var modules = {
45
+ cookie: cookie_1.default,
46
+ date: date_1.default,
47
+ dom: dom_1.default,
48
+ filter: filter_1.default,
49
+ format: format_1.default,
50
+ match: match_1.default,
51
+ number: number_1.default,
52
+ openApp: open_app_1.default,
53
+ tools: tools_1.default,
54
+ upload: upload_1.default,
55
+ monitor: monitor_1.default
56
+ };
57
+ var Utils = /** @class */ (function () {
58
+ function Utils() {
59
+ Object.assign(this, modules);
60
+ }
61
+ /**
62
+ * 挂载各组件
63
+ * 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
64
+ * @param {Object} Vue 需要挂载的目标对象
65
+ */
66
+ Utils.prototype.install = function (app) {
67
+ Object.keys(modules).forEach(function (key) {
68
+ var globalProperties = app.config.globalProperties;
69
+ globalProperties['$' + key] = modules[key];
70
+ });
71
+ };
72
+ return Utils;
73
+ }());
74
+ exports.default = new Utils();
@@ -0,0 +1,27 @@
1
+ interface ICookie {
2
+ name: string;
3
+ value: string;
4
+ exdays: number;
5
+ path?: string;
6
+ domain?: string;
7
+ }
8
+ declare class CookieClass {
9
+ /**
10
+ * 获取cookie
11
+ * @param {String} name
12
+ * @return {String}
13
+ */
14
+ getCookie(name: string): string;
15
+ /**
16
+ * 设置cookie
17
+ * @param {Object} ICookie
18
+ */
19
+ setCookie({ name, value, exdays, path, domain, }: ICookie): void;
20
+ /**
21
+ * 清除Cookie
22
+ * @param {String} name
23
+ */
24
+ clearCookie({ name, path, domain, }: ICookie): void;
25
+ }
26
+ declare const _default: CookieClass;
27
+ export default _default;
@@ -1,54 +1,55 @@
1
- /**
2
- * @file Cookie
3
- * @Author: wanghui
4
- * @createBy: @2021.01.21
5
- */
6
- 'use strict';
7
- var CookieClass = /** @class */ (function () {
8
- function CookieClass() {
9
- }
10
- /**
11
- * 获取cookie
12
- * @param {String} name
13
- * @return {String}
14
- */
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];
20
- while (c.charAt(0) === ' ')
21
- c = c.substring(1);
22
- if (c.includes(_name))
23
- return c.substring(_name.length, c.length);
24
- }
25
- return '';
26
- };
27
- /**
28
- * 设置cookie
29
- * @param {Object} ICookie
30
- */
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;
33
- var d = new Date();
34
- d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
35
- var expires = "expires=".concat(d.toUTCString());
36
- document.cookie = "".concat(name, "=").concat(value, ";").concat(expires, ";path=").concat(path, ";domain=").concat(domain, ";");
37
- };
38
- /**
39
- * 清除Cookie
40
- * @param {String} name
41
- */
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;
44
- this.setCookie({
45
- name: name,
46
- value: '',
47
- exdays: -1,
48
- path: path,
49
- domain: domain
50
- });
51
- };
52
- return CookieClass;
53
- }());
54
- module.exports = new CookieClass();
1
+ /**
2
+ * @file Cookie
3
+ * @Author: wanghui
4
+ * @createBy: @2021.01.21
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ var CookieClass = /** @class */ (function () {
9
+ function CookieClass() {
10
+ }
11
+ /**
12
+ * 获取cookie
13
+ * @param {String} name
14
+ * @return {String}
15
+ */
16
+ CookieClass.prototype.getCookie = function (name) {
17
+ var _name = name + '=';
18
+ var ca = document.cookie.split(';');
19
+ for (var i = 0; i < ca.length; i++) {
20
+ var c = ca[i];
21
+ while (c.charAt(0) === ' ')
22
+ c = c.substring(1);
23
+ if (c.includes(_name))
24
+ return c.substring(_name.length, c.length);
25
+ }
26
+ return '';
27
+ };
28
+ /**
29
+ * 设置cookie
30
+ * @param {Object} ICookie
31
+ */
32
+ CookieClass.prototype.setCookie = function (_a) {
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
+ var d = new Date();
35
+ d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
36
+ var expires = "expires=".concat(d.toUTCString());
37
+ document.cookie = "".concat(name, "=").concat(value, ";").concat(expires, ";path=").concat(path, ";domain=").concat(domain, ";");
38
+ };
39
+ /**
40
+ * 清除Cookie
41
+ * @param {String} name
42
+ */
43
+ CookieClass.prototype.clearCookie = function (_a) {
44
+ 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;
45
+ this.setCookie({
46
+ name: name,
47
+ value: '',
48
+ exdays: -1,
49
+ path: path,
50
+ domain: domain
51
+ });
52
+ };
53
+ return CookieClass;
54
+ }());
55
+ exports.default = new CookieClass();
@@ -0,0 +1,52 @@
1
+ declare class DateClass {
2
+ /**
3
+ * 格式化时间
4
+ * @param {String|Number} date 需要格式化的时间 2017-11-11、2017/11/11、linux time
5
+ * @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
6
+ * date.format(new Date()) // 默认格式 'YYYY-MM-DD HH:mm:ss'
7
+ * date.format(1586840260500) // 默认格式,传参为linux时间
8
+ * date.format(new Date(), 'YYYY:MM:DD') // 自定义格式 'YYYY:MM:DD'
9
+ * @return {String} fmt 'YYYY-MM-DD HH:mm:ss'
10
+ */
11
+ format(date: string | number, fmt?: string): string;
12
+ /**
13
+ * 天数加减
14
+ * @param {string | Date} date 传入的时间 2020-10-15 or Date
15
+ * @param {String} days 天数
16
+ * addDaysToDate('2020-10-15', 10) // '2020-10-25'
17
+ * addDaysToDate('2020-10-15', -10) // '2020-10-05'
18
+ * @return {String} fmt 'YYYY-MM-DD'
19
+ */
20
+ addDaysToDate(date: string | Date, days: number): string;
21
+ /**
22
+ * 获取倒计时剩余时间
23
+ * @param {Date | Number} endTime 截止时间
24
+ * @param {Date | Number} startTime 开始时间,默认取客户端当前时间
25
+ * date.format(new Date()) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
26
+ * date.format(1586840260500) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
27
+ * @return {object | boolean} {dd: '天', hh: '时', mm: '分', ss: '秒'}
28
+ */
29
+ remainTime(endTime: Date | Number, startTime?: Date | Number): object | boolean;
30
+ /**
31
+ * 格式化现在的已过时间
32
+ * @param {Number} startTime
33
+ * @return {String} *年前 *个月前 *天前 *小时前 *分钟前 刚刚
34
+ */
35
+ formatPassTime(startTime: any): string;
36
+ /**
37
+ * 格式化时间 列表里的时间内容格式 待废弃,统一时间格式
38
+ * @param {Number} time 1494141000*1000
39
+ * @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
40
+ */
41
+ formatPassTimeForList(time: string): string | false;
42
+ /**
43
+ * 格式化时间 详情内容里的时间格式
44
+ * @param {Number} time 1494141000*1000
45
+ * @param {String} fmt 想要格式化的格式
46
+ * @param {Boolean} noYear 是否显示年
47
+ * @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
48
+ */
49
+ formatPassTimeForDetail(time: string, fmt: string | undefined, noYear: Boolean): string | false;
50
+ }
51
+ declare const _default: DateClass;
52
+ export default _default;