@haluo/util 1.0.5 → 1.0.8

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 (54) hide show
  1. package/.babelrc +21 -0
  2. package/.eslintrc.js +216 -0
  3. package/__tests__/unit/date/date.spec.js +14 -0
  4. package/__tests__/unit/jest.conf.js +25 -0
  5. package/__tests__/unit/specs/date.test.js +11 -0
  6. package/dist/index.cjs.js +89 -0
  7. package/dist/{types/index.d.ts → index.d.ts} +12 -12
  8. package/dist/index.esm.js +87 -0
  9. package/dist/index.js +6 -7
  10. package/dist/lib-list.d.ts +2 -0
  11. package/dist/{types/modules → modules}/cookie/index.d.ts +27 -25
  12. package/dist/modules/cookie/index.js +4 -1
  13. package/dist/{types/modules → modules}/date/index.d.ts +1 -1
  14. package/dist/{types/modules/match → modules/dom}/index.d.ts +1 -1
  15. package/dist/{types/modules → modules}/filter/index.d.ts +26 -26
  16. package/dist/modules/filter/index.js +4 -6
  17. package/dist/{types/modules → modules}/format/index.d.ts +13 -13
  18. package/dist/{types/modules/dom → modules/match}/index.d.ts +1 -1
  19. package/dist/modules/monitor/index.js +14 -0
  20. package/dist/modules/monitor/lib/jsError.js +60 -0
  21. package/dist/modules/monitor/lib/timing.js +69 -0
  22. package/dist/modules/monitor/lib/xhr.js +41 -0
  23. package/dist/modules/monitor/utils/onload.js +11 -0
  24. package/dist/modules/monitor/utils/tracker.js +35 -0
  25. package/dist/{types/modules → modules}/number/index.d.ts +39 -39
  26. package/dist/{types/modules → modules}/sentry/index.d.ts +15 -15
  27. package/dist/{types/modules → modules}/tools/index.d.ts +1 -1
  28. package/global.d.ts +0 -0
  29. package/package.json +5 -6
  30. package/publish.sh +11 -0
  31. package/specification/CSS.md +25 -0
  32. package/specification/JS.md +9 -0
  33. package/specification/VUE.md +1 -0
  34. package/src/consts/httpCode.js +10 -0
  35. package/src/index.ts +54 -0
  36. package/src/modules/cookie/index.ts +69 -0
  37. package/src/modules/date/index.ts +196 -0
  38. package/src/modules/dom/index.ts +78 -0
  39. package/src/modules/filter/index.ts +57 -0
  40. package/src/modules/format/index.ts +19 -0
  41. package/src/modules/match/index.ts +31 -0
  42. package/src/modules/monitor/index.ts +8 -0
  43. package/src/modules/monitor/lib/jsError.ts +54 -0
  44. package/src/modules/monitor/lib/timing.ts +75 -0
  45. package/src/modules/monitor/lib/xhr.ts +35 -0
  46. package/src/modules/monitor/utils/onload.ts +8 -0
  47. package/src/modules/monitor/utils/tracker.ts +22 -0
  48. package/src/modules/number/index.ts +108 -0
  49. package/src/modules/sentry/index.ts +82 -0
  50. package/src/modules/tools/index.ts +427 -0
  51. package/tsconfig.json +34 -0
  52. package/dist/tsconfig.tsbuildinfo +0 -1980
  53. package/dist/types/index.js +0 -2
  54. package/dist/types/types/index.d.ts +0 -3
@@ -1,13 +1,13 @@
1
- interface Obj {
2
- [prop: string]: any;
3
- }
4
- declare class Format {
5
- /**
6
- * @desc 对于对象非数字与布尔值的value,当其为falsy时,转换成separator
7
- * @param {object} obj 传入的对象
8
- * @param {string} separator 替换后的值
9
- * transformObjectNullVal({ a: null, b: 0}, '23') // {a: "23", b: 0}
10
- * @return {object}
11
- */
12
- transformObjectNullVal<T extends Obj>(obj: T, separator?: string): T;
13
- }
1
+ interface Obj {
2
+ [prop: string]: any;
3
+ }
4
+ declare class Format {
5
+ /**
6
+ * @desc 对于对象非数字与布尔值的value,当其为falsy时,转换成separator
7
+ * @param {object} obj 传入的对象
8
+ * @param {string} separator 替换后的值
9
+ * transformObjectNullVal({ a: null, b: 0}, '23') // {a: "23", b: 0}
10
+ * @return {object}
11
+ */
12
+ transformObjectNullVal<T extends Obj>(obj: T, separator?: string): T;
13
+ }
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var jsError_1 = require("./lib/jsError");
7
+ var xhr_1 = __importDefault(require("./lib/xhr"));
8
+ // import timing from './lib/timing'
9
+ function setup() {
10
+ jsError_1.injectJsError();
11
+ xhr_1.default();
12
+ }
13
+ exports.default = setup;
14
+ // timing()
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.injectJsError = void 0;
7
+ var tracker_1 = __importDefault(require("../utils/tracker"));
8
+ function injectJsError() {
9
+ window.addEventListener('error', function (e) {
10
+ console.log(e);
11
+ if (e.target && (e.target.src || e.target.href)) {
12
+ tracker_1.default.send({
13
+ kind: 'stability',
14
+ type: 'error',
15
+ errorType: 'resourceError',
16
+ filename: e.target.src || e.target.href,
17
+ tagName: e.target.tagName
18
+ // selector: lastEvent ? get
19
+ });
20
+ return;
21
+ }
22
+ tracker_1.default.send({
23
+ kind: 'stability',
24
+ type: 'error',
25
+ errorType: 'jsError',
26
+ message: e.message,
27
+ filename: e.filename,
28
+ position: e.lineno + ":" + e.colno,
29
+ stack: e.error.stack,
30
+ });
31
+ }, true);
32
+ window.addEventListener('unhandledrejection', function (e) {
33
+ var message, filename, line, column, stack;
34
+ var reason = e.reason;
35
+ if (typeof reason === 'string') {
36
+ message = reason;
37
+ }
38
+ else if (typeof reason === 'object') {
39
+ if (reason.stack) {
40
+ var matchResult = reason.stack.match(/at\s+(.+):(\d+):(\d+)/);
41
+ filename = matchResult[1];
42
+ line = matchResult[2];
43
+ column = matchResult[3];
44
+ }
45
+ message = reason.message;
46
+ stack = reason.stack;
47
+ }
48
+ tracker_1.default.send({
49
+ kind: 'stability',
50
+ type: 'error',
51
+ errorType: 'promiseError',
52
+ message: message,
53
+ filename: filename,
54
+ position: line + ":" + column,
55
+ stack: stack
56
+ // selector: lastEvent ? get
57
+ });
58
+ });
59
+ }
60
+ exports.injectJsError = injectJsError;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var onload_1 = __importDefault(require("../utils/onload"));
7
+ var tracker_1 = __importDefault(require("../utils/tracker"));
8
+ function timing() {
9
+ var FMP, LCP;
10
+ new PerformanceObserver(function (entryList, observer) {
11
+ var perfEntries = entryList.getEntries();
12
+ FMP = perfEntries[0];
13
+ observer.disconnect(); // 不再观察
14
+ }).observe({ entryTypes: ['element'] }); // 观察页面中有意义的元素
15
+ new PerformanceObserver(function (entryList, observer) {
16
+ var perfEntries = entryList.getEntries();
17
+ LCP = perfEntries[0];
18
+ observer.disconnect(); // 不再观察
19
+ }).observe({ entryTypes: ['largest-contentful-paint'] }); // 观察页面中最大的元素
20
+ new PerformanceObserver(function (entryList, observer) {
21
+ var firstInput = entryList.getEntries();
22
+ console.log('FID', firstInput);
23
+ if (firstInput) {
24
+ var inputDelay = firstInput.processingStart - firstInput.startTime;
25
+ var duration = firstInput.duration;
26
+ if (inputDelay > 0 || duration > 0) {
27
+ tracker_1.default.send({
28
+ kind: 'experience',
29
+ type: 'firstInputDelay',
30
+ inputDelay: inputDelay,
31
+ duration: duration,
32
+ startTime: firstInput.startTime
33
+ });
34
+ }
35
+ }
36
+ observer.disconnect(); // 不再观察
37
+ }).observe({ type: 'first-input', buffered: true }); // 观察页面中最大的元素
38
+ onload_1.default(function () {
39
+ setTimeout(function () {
40
+ console.dir(window.performance);
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;
42
+ tracker_1.default.send({
43
+ kind: 'experience',
44
+ type: 'timing',
45
+ connectTime: connectEnd - connectStart,
46
+ ttfbTime: responseStart - requestStart,
47
+ responseTime: responseEnd - responseStart,
48
+ domContentLoadedTime: domContentLoadedEventEnd - domContentLoadedEventStart,
49
+ timeToInteractive: domInteractive - fetchStart,
50
+ loadTime: loadEventStart - fetchStart // 完整的页面加载时间
51
+ });
52
+ var FP = performance.getEntriesByName('first-paint')[0];
53
+ var FCP = performance.getEntriesByName('first-contentful-paint')[0];
54
+ console.log('FP', FP);
55
+ console.log('FCP', FCP);
56
+ console.log('FMP', FMP);
57
+ console.log('LCP', LCP);
58
+ tracker_1.default.send({
59
+ kind: 'experience',
60
+ type: 'paint',
61
+ FP: FP.startTime,
62
+ FCP: FCP.startTime,
63
+ FMP: FMP.startTime,
64
+ LCP: LCP.startTime,
65
+ });
66
+ }, 3000);
67
+ });
68
+ }
69
+ exports.default = timing;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var tracker_1 = __importDefault(require("../utils/tracker"));
7
+ function injectXHR() {
8
+ var XMLHttpRequest = window.XMLHttpRequest;
9
+ var oldOpen = XMLHttpRequest.prototype.open;
10
+ XMLHttpRequest.prototype.open = function (method, url, async) {
11
+ this.logData = { method: method, url: url, async: async };
12
+ return oldOpen.apply(this, arguments);
13
+ };
14
+ var oldSend = XMLHttpRequest.prototype.send;
15
+ XMLHttpRequest.prototype.send = function (body) {
16
+ var _this = this;
17
+ if (this.logData) {
18
+ var startTime_1 = Date.now();
19
+ var handler = function (type) { return function (event) {
20
+ var duration = Date.now() - startTime_1;
21
+ var status = _this.status;
22
+ var statusText = _this.statusText;
23
+ tracker_1.default.send({
24
+ kind: 'stability',
25
+ type: 'xhr',
26
+ eventType: event.type,
27
+ pathname: _this.logData.url,
28
+ status: status + '-' + statusText,
29
+ duration: duration,
30
+ response: _this.response ? JSON.stringify(_this.response) : '',
31
+ params: body || ''
32
+ });
33
+ }; };
34
+ this.addEventListener('load', handler('load'), false);
35
+ this.addEventListener('error', handler('error'), false);
36
+ this.addEventListener('abort', handler('abort'), false);
37
+ }
38
+ return oldSend.apply(this, arguments);
39
+ };
40
+ }
41
+ exports.default = injectXHR;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function onload(cb) {
4
+ if (document.readyState) {
5
+ cb();
6
+ }
7
+ else {
8
+ window.addEventListener('load', cb);
9
+ }
10
+ }
11
+ exports.default = onload;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var Parser = require('ua-parser-js');
15
+ var SendTracker = /** @class */ (function () {
16
+ function SendTracker() {
17
+ this.url = '';
18
+ this.xhr = new XMLHttpRequest();
19
+ }
20
+ SendTracker.prototype.send = function (data) {
21
+ if (data === void 0) { data = {}; }
22
+ var log = __assign(__assign({}, getExtraData()), data);
23
+ console.log(log);
24
+ };
25
+ return SendTracker;
26
+ }());
27
+ function getExtraData() {
28
+ return {
29
+ title: document.title,
30
+ url: location.href,
31
+ timestamp: Date.now(),
32
+ userAgent: new Parser().getResult()
33
+ };
34
+ }
35
+ exports.default = new SendTracker();
@@ -1,39 +1,39 @@
1
- declare class NumberClass {
2
- /**
3
- * 个位数前面补0
4
- * @param {Number} num 需要格式化的数字
5
- * @return {String} '01'
6
- */
7
- formatNumber(num: number): string;
8
- /**
9
- * 将手机号中间部分替换为星号
10
- * @param {String} phone 手机号码
11
- * @return {String} 131****1111
12
- */
13
- formatPhone(phone: string): string;
14
- /**
15
- * 格式化数字 万
16
- * @param {Number} num
17
- * @return {String} 12.3万
18
- */
19
- convertToWan(num: number): string | number;
20
- /**
21
- * 格式化数字 k
22
- * @param {Number} num
23
- * @return {String} 1.2k
24
- */
25
- convertToThousand(num: number): string | number;
26
- /**
27
- * 随机数,指定范围
28
- * @param {Number} min 开始
29
- * @param {Number} max 结束
30
- * @return {Number|Object}
31
- */
32
- random(min: number, max: number): number | null;
33
- /**
34
- * 格式化金额
35
- * @param {Number} num
36
- * @return {String} 123,456
37
- */
38
- formatMoney(money: number | string, signal: string): string;
39
- }
1
+ declare class NumberClass {
2
+ /**
3
+ * 个位数前面补0
4
+ * @param {Number} num 需要格式化的数字
5
+ * @return {String} '01'
6
+ */
7
+ formatNumber(num: number): string;
8
+ /**
9
+ * 将手机号中间部分替换为星号
10
+ * @param {String} phone 手机号码
11
+ * @return {String} 131****1111
12
+ */
13
+ formatPhone(phone: string): string;
14
+ /**
15
+ * 格式化数字 万
16
+ * @param {Number} num
17
+ * @return {String} 12.3万
18
+ */
19
+ convertToWan(num: number): string | number;
20
+ /**
21
+ * 格式化数字 k
22
+ * @param {Number} num
23
+ * @return {String} 1.2k
24
+ */
25
+ convertToThousand(num: number): string | number;
26
+ /**
27
+ * 随机数,指定范围
28
+ * @param {Number} min 开始
29
+ * @param {Number} max 结束
30
+ * @return {Number|Object}
31
+ */
32
+ random(min: number, max: number): number | null;
33
+ /**
34
+ * 格式化金额
35
+ * @param {Number} num
36
+ * @return {String} 123,456
37
+ */
38
+ formatMoney(money: number | string, signal: string): string;
39
+ }
@@ -1,15 +1,15 @@
1
- declare class Report {
2
- static instance: any;
3
- constructor(Vue: Object, options?: {});
4
- [key: string]: any;
5
- static getInstance(Vue: Object, Option: Object): any;
6
- install(): void;
7
- /**
8
- * 主动上报
9
- * @param {String} data
10
- * @param {String} type 'info','warning','error'
11
- * @param {Object} options
12
- */
13
- log(data?: any, type?: any, options?: any): void;
14
- }
15
- export default Report;
1
+ declare class Report {
2
+ static instance: any;
3
+ constructor(Vue: Object, options?: {});
4
+ [key: string]: any;
5
+ static getInstance(Vue: Object, Option: Object): any;
6
+ install(): void;
7
+ /**
8
+ * 主动上报
9
+ * @param {String} data
10
+ * @param {String} type 'info','warning','error'
11
+ * @param {Object} options
12
+ */
13
+ log(data?: any, type?: any, options?: any): void;
14
+ }
15
+ export default Report;
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/global.d.ts ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haluo/util",
3
- "version": "1.0.5",
3
+ "version": "1.0.8",
4
4
  "main": "./dist/index.js",
5
5
  "author": "<wanghui@jddmoto.com>",
6
6
  "description": "哈罗摩托工具库",
@@ -13,9 +13,6 @@
13
13
  "precommit": "lint-staged"
14
14
  },
15
15
  "types": "dist/types/index.d.ts",
16
- "files": [
17
- "dist/"
18
- ],
19
16
  "lint-staged": {
20
17
  "src/**/*.{js,vue}": [
21
18
  "eslint --fix",
@@ -33,7 +30,8 @@
33
30
  "axios": "^0.19.2",
34
31
  "clipboard-copy": "^4.0.1",
35
32
  "jest": "^27.0.6",
36
- "raven-js": "^3.27.2"
33
+ "raven-js": "^3.27.2",
34
+ "ua-parser-js": "^1.0.2"
37
35
  },
38
36
  "devDependencies": {
39
37
  "@babel/core": "^7.0.0",
@@ -43,8 +41,9 @@
43
41
  "@babel/polyfill": "^7.0.0",
44
42
  "@babel/preset-env": "^7.14.7",
45
43
  "@babel/preset-typescript": "^7.14.5",
46
- "@types/node": "^17.0.36",
44
+ "@types/node": "^14.0.13",
47
45
  "@types/webpack-env": "^1.15.2",
46
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
48
47
  "autoprefixer-loader": "^2.1.0",
49
48
  "babel-eslint": "^8.2.3",
50
49
  "babel-jest": "^26.0.1",
package/publish.sh ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bash
2
+ # npm config get registry # 检查仓库镜像库
3
+ # npm config set registry=http://registry.npmjs.org
4
+ # echo '请进行登录相关操作:'
5
+ # npm login # 登陆
6
+ tsc
7
+ echo "-------publishing-------"
8
+ npm publish # 发布
9
+ # npm config set registry=https://registry.npm.taobao.org # 设置为淘宝镜像
10
+ echo "发布完成"
11
+ exit
@@ -0,0 +1,25 @@
1
+ ### CSS
2
+
3
+
4
+ #### [BEM](http://getbem.com/)
5
+ **BlockElementModifier其实是块(block)、元素(element)、修饰符(modifier)**
6
+ > * block 代表了更高级别的抽象或组件
7
+ > * block__element 代表 block 的后代,用于形成一个完整的 block 的整体
8
+ > * block--modifier代表 block 的不同状态或不同版本
9
+
10
+ ```css
11
+ /* demo */
12
+ person{} /* 人 */
13
+ person__hand{} /* 人的手 */
14
+ person--female{} /* 女人 */
15
+ person--female__hand{} /* 女人的手 */
16
+ person__hand--left{} /* 人的左手 */
17
+ ```
18
+
19
+ #### Z-Index
20
+ ```
21
+ 页面元素:1-99
22
+ fixed:100-199
23
+ 弹框:200-299
24
+ Toast:300-399
25
+ ```
@@ -0,0 +1,9 @@
1
+ ### [JS](http://alloyteam.github.io/CodeGuide/)
2
+
3
+ ```
4
+ 1、路由命名:name 大写,path和文件名 小写加中划线
5
+ 2、组件使用:组件文件、引用名、页面使用 名称保持一致
6
+ 3、JS
7
+ > 接口请求参数做解构
8
+ > 公共文件,多尝试用class
9
+ ```
@@ -0,0 +1 @@
1
+ ### [VUE](https://cn.vuejs.org/v2/style-guide/)
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 处理http返回的错误码等信息
3
+ * @Author: wanghui
4
+ */
5
+ export default {
6
+ SUCCESS: {
7
+ 'resultCode': '0',
8
+ 'resultDesc': '处理成功'
9
+ },
10
+ }
package/src/index.ts ADDED
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @Author: wanghui
3
+ * createBy: @2020.05.21
4
+ */
5
+ 'use strict'
6
+
7
+ const modules: any = {
8
+ cookie: require('./modules/cookie'),
9
+ date: require('./modules/date'),
10
+ dom: require('./modules/dom'),
11
+ filter: require('./modules/filter'),
12
+ format: require('./modules/format'),
13
+ match: require('./modules/match'),
14
+ number: require('./modules/number'),
15
+ tools: require('./modules/tools'),
16
+ }
17
+
18
+ class Utils {
19
+ [key: string]: Object
20
+
21
+ constructor() {
22
+ Object.assign(this, modules)
23
+ }
24
+
25
+ /**
26
+ * 挂载各组件
27
+ * 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
28
+ * @param {Object} Vue 需要挂载的目标对象
29
+ */
30
+ install(Vue: any) {
31
+ Object.keys(modules).forEach((key) => {
32
+ if (key === 'filter') {
33
+ return modules[key].install(Vue)
34
+ }
35
+ Vue.prototype['$' + key] = modules[key]
36
+ Vue['$' + key] = modules[key]
37
+ })
38
+ }
39
+
40
+ // loadModules() {
41
+ // const modules = require['context']('./modules/', true, /.js$/)
42
+ // modules.keys().forEach((modulesKey: string) => {
43
+ // const attr: string = modulesKey.replace('./', '').replace('.js', '').replace('/index', '')
44
+ // const haveDefault = ['sentry']
45
+ // if (haveDefault.includes(attr)) {
46
+ // this[attr] = modules(modulesKey).default
47
+ // } else {
48
+ // this[attr] = modules(modulesKey)
49
+ // }
50
+ // })
51
+ // }
52
+ }
53
+
54
+ module.exports = new Utils()
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @file Cookie
3
+ * @Author: wanghui
4
+ * @createBy: @2021.01.21
5
+ */
6
+ 'use strict'
7
+ interface ICookie {
8
+ name: string,
9
+ value: string,
10
+ exdays: number,
11
+ path?: string,
12
+ domain?: string,
13
+ }
14
+
15
+ class CookieClass {
16
+ /**
17
+ * 获取cookie
18
+ * @param {String} name
19
+ * @return {String}
20
+ */
21
+ getCookie(name: string) {
22
+ const _name = name + '='
23
+ const ca = document.cookie.split(';')
24
+ for (let i = 0; i < ca.length; i++) {
25
+ let c = ca[i]
26
+ while (c.charAt(0) === ' ') c = c.substring(1)
27
+ if (c.includes(_name)) return c.substring(_name.length, c.length)
28
+ }
29
+ return ''
30
+ }
31
+
32
+ /**
33
+ * 设置cookie
34
+ * @param {Object} ICookie
35
+ */
36
+ setCookie({
37
+ name = '',
38
+ value = '',
39
+ exdays = -1,
40
+ path = '/',
41
+ domain = '.jddmoto.com',
42
+ }: ICookie) {
43
+ var d = new Date();
44
+ d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000))
45
+ var expires = `expires=${d.toUTCString()}`
46
+ document.cookie = `${name}=${value};${expires};path=${path};domain=${domain};`
47
+ }
48
+
49
+ /**
50
+ * 清除Cookie
51
+ * @param {String} name
52
+ */
53
+ clearCookie({
54
+ name = '',
55
+ path = '/',
56
+ domain = '.jddmoto.com',
57
+ }: ICookie) {
58
+ this.setCookie({
59
+ name,
60
+ value: '',
61
+ exdays: -1,
62
+ path,
63
+ domain
64
+ })
65
+ }
66
+ }
67
+
68
+ module.exports = new CookieClass()
69
+