@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.
- package/.babelrc +21 -0
- package/.eslintrc.js +216 -0
- package/__tests__/unit/date/date.spec.js +14 -0
- package/__tests__/unit/jest.conf.js +25 -0
- package/__tests__/unit/specs/date.test.js +11 -0
- package/dist/index.cjs.js +89 -0
- package/dist/{types/index.d.ts → index.d.ts} +12 -12
- package/dist/index.esm.js +87 -0
- package/dist/index.js +6 -7
- package/dist/lib-list.d.ts +2 -0
- package/dist/{types/modules → modules}/cookie/index.d.ts +27 -25
- package/dist/modules/cookie/index.js +4 -1
- package/dist/{types/modules → modules}/date/index.d.ts +1 -1
- package/dist/{types/modules/match → modules/dom}/index.d.ts +1 -1
- package/dist/{types/modules → modules}/filter/index.d.ts +26 -26
- package/dist/modules/filter/index.js +4 -6
- package/dist/{types/modules → modules}/format/index.d.ts +13 -13
- package/dist/{types/modules/dom → modules/match}/index.d.ts +1 -1
- package/dist/modules/monitor/index.js +14 -0
- package/dist/modules/monitor/lib/jsError.js +60 -0
- package/dist/modules/monitor/lib/timing.js +69 -0
- package/dist/modules/monitor/lib/xhr.js +41 -0
- package/dist/modules/monitor/utils/onload.js +11 -0
- package/dist/modules/monitor/utils/tracker.js +35 -0
- package/dist/{types/modules → modules}/number/index.d.ts +39 -39
- package/dist/{types/modules → modules}/sentry/index.d.ts +15 -15
- package/dist/{types/modules → modules}/tools/index.d.ts +1 -1
- package/global.d.ts +0 -0
- package/package.json +5 -6
- package/publish.sh +11 -0
- package/specification/CSS.md +25 -0
- package/specification/JS.md +9 -0
- package/specification/VUE.md +1 -0
- package/src/consts/httpCode.js +10 -0
- package/src/index.ts +54 -0
- package/src/modules/cookie/index.ts +69 -0
- package/src/modules/date/index.ts +196 -0
- package/src/modules/dom/index.ts +78 -0
- package/src/modules/filter/index.ts +57 -0
- package/src/modules/format/index.ts +19 -0
- package/src/modules/match/index.ts +31 -0
- package/src/modules/monitor/index.ts +8 -0
- package/src/modules/monitor/lib/jsError.ts +54 -0
- package/src/modules/monitor/lib/timing.ts +75 -0
- package/src/modules/monitor/lib/xhr.ts +35 -0
- package/src/modules/monitor/utils/onload.ts +8 -0
- package/src/modules/monitor/utils/tracker.ts +22 -0
- package/src/modules/number/index.ts +108 -0
- package/src/modules/sentry/index.ts +82 -0
- package/src/modules/tools/index.ts +427 -0
- package/tsconfig.json +34 -0
- package/dist/tsconfig.tsbuildinfo +0 -1980
- package/dist/types/index.js +0 -2
- package/dist/types/types/index.d.ts +0 -3
package/.babelrc
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
const DOMGlobals = [] // ['window']
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
root: true,
|
|
5
|
+
parserOptions: {
|
|
6
|
+
parser: '@typescript-eslint/parser',
|
|
7
|
+
sourceType: 'module'
|
|
8
|
+
},
|
|
9
|
+
env: {
|
|
10
|
+
browser: true,
|
|
11
|
+
node: true,
|
|
12
|
+
es6: true,
|
|
13
|
+
jest: true
|
|
14
|
+
},
|
|
15
|
+
extends: ['plugin:vue/recommended', 'eslint:recommended', "plugin:@typescript-eslint/recommended"],
|
|
16
|
+
globals: {
|
|
17
|
+
document: true,
|
|
18
|
+
navigator: true,
|
|
19
|
+
window: true,
|
|
20
|
+
wx: true,
|
|
21
|
+
Toast: true,
|
|
22
|
+
AppCall: true,
|
|
23
|
+
QRCode: true
|
|
24
|
+
},
|
|
25
|
+
// 0 关闭 1警告 2报错
|
|
26
|
+
// add your custom rules here
|
|
27
|
+
// it is base on https://github.com/vuejs/eslint-config-vue
|
|
28
|
+
rules: {
|
|
29
|
+
'vue/max-attributes-per-line': [2, {
|
|
30
|
+
'singleline': 10,
|
|
31
|
+
'multiline': {
|
|
32
|
+
'max': 1,
|
|
33
|
+
'allowFirstLine': false
|
|
34
|
+
}
|
|
35
|
+
}],
|
|
36
|
+
'vue/name-property-casing': [2, 'PascalCase'],
|
|
37
|
+
'vue/no-parsing-error': [2, { 'x-invalid-end-tag': false }],
|
|
38
|
+
'vue/require-prop-types': 0,
|
|
39
|
+
'vue/html-self-closing': 0,
|
|
40
|
+
'accessor-pairs': 2,
|
|
41
|
+
'arrow-spacing': [2, {
|
|
42
|
+
'before': true,
|
|
43
|
+
'after': true
|
|
44
|
+
}],
|
|
45
|
+
'block-spacing': [2, 'always'],
|
|
46
|
+
'brace-style': [2, '1tbs', {
|
|
47
|
+
'allowSingleLine': true
|
|
48
|
+
}],
|
|
49
|
+
'camelcase': [0, {
|
|
50
|
+
'properties': 'always'
|
|
51
|
+
}],
|
|
52
|
+
'comma-dangle': 0, // [2, 'never'],
|
|
53
|
+
'comma-spacing': [2, {
|
|
54
|
+
'before': false,
|
|
55
|
+
'after': true
|
|
56
|
+
}],
|
|
57
|
+
'comma-style': [2, 'last'],
|
|
58
|
+
'constructor-super': 2,
|
|
59
|
+
'curly': [2, 'multi-line'],
|
|
60
|
+
'dot-location': [2, 'property'],
|
|
61
|
+
'eol-last': 2,
|
|
62
|
+
'eqeqeq': [2, 'allow-null'],
|
|
63
|
+
'generator-star-spacing': [2, {
|
|
64
|
+
'before': true,
|
|
65
|
+
'after': true
|
|
66
|
+
}],
|
|
67
|
+
'handle-callback-err': [2, '^(err|error)$'],
|
|
68
|
+
'indent': 0, // [2, 2, { 'SwitchCase': 1 }],
|
|
69
|
+
'jsx-quotes': [2, 'prefer-single'],
|
|
70
|
+
'key-spacing': [2, {
|
|
71
|
+
'beforeColon': false,
|
|
72
|
+
'afterColon': true
|
|
73
|
+
}],
|
|
74
|
+
'keyword-spacing': [2, {
|
|
75
|
+
'before': true,
|
|
76
|
+
'after': true
|
|
77
|
+
}],
|
|
78
|
+
'max-depth': [1, { 'max': 4 }],
|
|
79
|
+
'max-len': [1, { 'code': 150, 'tabWidth': 2, 'ignoreUrls': true, 'ignoreRegExpLiterals': true }],
|
|
80
|
+
'max-lines': [1, { 'max': 1000, 'skipBlankLines': true, 'skipComments': true }],
|
|
81
|
+
// 'max-lines-per-function': [1, { 'max': 20, 'skipComments': true }],
|
|
82
|
+
'max-params': [1, 3],
|
|
83
|
+
'new-cap': [2, {
|
|
84
|
+
'newIsCap': true,
|
|
85
|
+
'capIsNew': false
|
|
86
|
+
}],
|
|
87
|
+
'new-parens': 2,
|
|
88
|
+
'no-array-constructor': 2,
|
|
89
|
+
'no-caller': 2,
|
|
90
|
+
'no-console': 0,
|
|
91
|
+
'no-class-assign': 2,
|
|
92
|
+
'no-cond-assign': 2,
|
|
93
|
+
'no-const-assign': 2,
|
|
94
|
+
'no-control-regex': 0,
|
|
95
|
+
'no-delete-var': 2,
|
|
96
|
+
'no-dupe-args': 2,
|
|
97
|
+
'no-dupe-class-members': 2,
|
|
98
|
+
'no-dupe-keys': 2,
|
|
99
|
+
'no-duplicate-case': 2,
|
|
100
|
+
'no-empty-character-class': 2,
|
|
101
|
+
'no-empty-pattern': 2,
|
|
102
|
+
'no-eval': 2,
|
|
103
|
+
'no-ex-assign': 2,
|
|
104
|
+
'no-extend-native': 2,
|
|
105
|
+
'no-extra-bind': 2,
|
|
106
|
+
'no-extra-boolean-cast': 2,
|
|
107
|
+
'no-extra-parens': [2, 'functions'],
|
|
108
|
+
'no-fallthrough': 2,
|
|
109
|
+
'no-floating-decimal': 2,
|
|
110
|
+
'no-func-assign': 2,
|
|
111
|
+
'no-implied-eval': 2,
|
|
112
|
+
'no-inner-declarations': [2, 'functions'],
|
|
113
|
+
'no-invalid-regexp': 2,
|
|
114
|
+
'no-irregular-whitespace': 2,
|
|
115
|
+
'no-iterator': 2,
|
|
116
|
+
'no-label-var': 2,
|
|
117
|
+
'no-labels': [2, {
|
|
118
|
+
'allowLoop': false,
|
|
119
|
+
'allowSwitch': false
|
|
120
|
+
}],
|
|
121
|
+
'no-lone-blocks': 2,
|
|
122
|
+
'no-magic-numbers': [1, { 'ignore': [-1, 0, 1, 10, 12, 24, 30, 60, 100, 200, 1000, 2000, 3000, 3600, 5000], "ignoreArrayIndexes": true }],
|
|
123
|
+
'no-mixed-spaces-and-tabs': 2,
|
|
124
|
+
'no-multi-spaces': 2,
|
|
125
|
+
'no-multi-str': 2,
|
|
126
|
+
'no-multiple-empty-lines': [2, {
|
|
127
|
+
'max': 1
|
|
128
|
+
}],
|
|
129
|
+
'no-native-reassign': 2,
|
|
130
|
+
'no-negated-in-lhs': 2,
|
|
131
|
+
'no-new-object': 2,
|
|
132
|
+
'no-new-require': 2,
|
|
133
|
+
'no-new-symbol': 2,
|
|
134
|
+
'no-new-wrappers': 2,
|
|
135
|
+
'no-obj-calls': 2,
|
|
136
|
+
'no-octal': 2,
|
|
137
|
+
'no-octal-escape': 2,
|
|
138
|
+
'no-path-concat': 2,
|
|
139
|
+
'no-proto': 2,
|
|
140
|
+
'no-redeclare': 2,
|
|
141
|
+
'no-regex-spaces': 2,
|
|
142
|
+
'no-return-assign': 0,
|
|
143
|
+
'no-restricted-globals': [1, ...DOMGlobals],
|
|
144
|
+
'no-self-assign': 2,
|
|
145
|
+
'no-self-compare': 2,
|
|
146
|
+
'no-sequences': 0,
|
|
147
|
+
'no-shadow-restricted-names': 2,
|
|
148
|
+
'no-spaced-func': 2,
|
|
149
|
+
'no-sparse-arrays': 2,
|
|
150
|
+
'no-this-before-super': 2,
|
|
151
|
+
'no-throw-literal': 2,
|
|
152
|
+
'no-trailing-spaces': 2,
|
|
153
|
+
'no-undef': 2,
|
|
154
|
+
'no-undef-init': 2,
|
|
155
|
+
'no-unexpected-multiline': 2,
|
|
156
|
+
'no-unmodified-loop-condition': 2,
|
|
157
|
+
'no-unneeded-ternary': [2, {
|
|
158
|
+
'defaultAssignment': false
|
|
159
|
+
}],
|
|
160
|
+
'no-unreachable': 2,
|
|
161
|
+
'no-unsafe-finally': 2,
|
|
162
|
+
'no-unused-vars': [2, {
|
|
163
|
+
'vars': 'all',
|
|
164
|
+
'args': 'none'
|
|
165
|
+
}],
|
|
166
|
+
'no-useless-call': 2,
|
|
167
|
+
'no-useless-computed-key': 2,
|
|
168
|
+
'no-useless-constructor': 2,
|
|
169
|
+
'no-useless-escape': 0,
|
|
170
|
+
'no-whitespace-before-property': 2,
|
|
171
|
+
'no-with': 2,
|
|
172
|
+
'one-var': [2, {
|
|
173
|
+
'initialized': 'never'
|
|
174
|
+
}],
|
|
175
|
+
'operator-linebreak': [2, 'after', {
|
|
176
|
+
'overrides': {
|
|
177
|
+
'?': 'before',
|
|
178
|
+
':': 'before'
|
|
179
|
+
}
|
|
180
|
+
}],
|
|
181
|
+
'padded-blocks': [2, 'never'],
|
|
182
|
+
'quotes': [2, 'single', {
|
|
183
|
+
'avoidEscape': true,
|
|
184
|
+
'allowTemplateLiterals': true
|
|
185
|
+
}],
|
|
186
|
+
'semi': 0,
|
|
187
|
+
'semi-spacing': [2, {
|
|
188
|
+
'before': false,
|
|
189
|
+
'after': true
|
|
190
|
+
}],
|
|
191
|
+
'space-before-blocks': [2, 'always'],
|
|
192
|
+
'space-before-function-paren': 0,
|
|
193
|
+
'space-before-function-paren': 0,
|
|
194
|
+
'space-in-parens': [2, 'never'],
|
|
195
|
+
'space-infix-ops': 2,
|
|
196
|
+
'space-unary-ops': [2, {
|
|
197
|
+
'words': true,
|
|
198
|
+
'nonwords': false
|
|
199
|
+
}],
|
|
200
|
+
'spaced-comment': [2, 'always', {
|
|
201
|
+
'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ',']
|
|
202
|
+
}],
|
|
203
|
+
'template-curly-spacing': [2, 'never'],
|
|
204
|
+
'use-isnan': 2,
|
|
205
|
+
'valid-typeof': 2,
|
|
206
|
+
'wrap-iife': [2, 'any'],
|
|
207
|
+
'yield-star-spacing': [2, 'both'],
|
|
208
|
+
'yoda': [2, 'never'],
|
|
209
|
+
'prefer-const': 2,
|
|
210
|
+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
|
|
211
|
+
'object-curly-spacing': [2, 'always', {
|
|
212
|
+
objectsInObjects: false
|
|
213
|
+
}],
|
|
214
|
+
'array-bracket-spacing': [2, 'never']
|
|
215
|
+
}
|
|
216
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { format, formatPassTimeForDetail } from '../../../src/modules/date/index.ts'
|
|
2
|
+
describe('date', () => {
|
|
3
|
+
it('formatTime()默认格式,返回时间格式是否正常', () => {
|
|
4
|
+
expect(format(1586934316925)).toBe('2020-04-15 15:05:16')
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
it('formatTime()传参数,返回时间格式是否正常', () => {
|
|
8
|
+
expect(format(1586934316925, 'YYYY.MM.DD')).toBe('2020.04.15')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('formatPassTimeForDetail()传参数,返回时间格式是否正常', () => {
|
|
12
|
+
expect(formatPassTimeForDetail(Date.now() - 60 * 60 * 1000)).toBe('1小时前')
|
|
13
|
+
})
|
|
14
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
preset: 'ts-jest',
|
|
5
|
+
verbose: true,
|
|
6
|
+
rootDir: path.resolve(__dirname, '../../'),
|
|
7
|
+
moduleFileExtensions: [
|
|
8
|
+
'js',
|
|
9
|
+
'json',
|
|
10
|
+
'ts'
|
|
11
|
+
],
|
|
12
|
+
transform: {
|
|
13
|
+
'^.+\\.ts$': 'ts-jest',
|
|
14
|
+
'^.+\\.js$': 'babel-jest',
|
|
15
|
+
},
|
|
16
|
+
testMatch: [
|
|
17
|
+
'**/__tests__/**/*.(spec|test).[jt]s?(x)',
|
|
18
|
+
],
|
|
19
|
+
transformIgnorePatterns: ['/node_modules/'],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// 语句覆盖率(statement coverage)
|
|
23
|
+
// 分支覆盖率(branch coverage)
|
|
24
|
+
// 函数覆盖率(function coverage)
|
|
25
|
+
// 行覆盖率(line coverage)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const date = require('../../../src/modules/date/index');
|
|
2
|
+
|
|
3
|
+
console.log(date);
|
|
4
|
+
describe('date 模块', () => {
|
|
5
|
+
test('formatTime()默认格式,返回时间格式是否正常', () => {
|
|
6
|
+
expect(date.format(1586934316925)).toBe('2020-04-15 15:05:16');
|
|
7
|
+
})
|
|
8
|
+
test('format()传参数,返回时间格式是否正常', () => {
|
|
9
|
+
expect(date.format(1586934316925, 'YYYY.MM.DD')).toBe('2020.04.15');
|
|
10
|
+
})
|
|
11
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Cookie
|
|
5
|
+
* @Author: wanghui
|
|
6
|
+
* @createBy: @2021.01.21
|
|
7
|
+
*/
|
|
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=" + d.toUTCString();
|
|
37
|
+
document.cookie = name + "=" + value + ";" + expires + ";path=" + path + ";domain=" + domain + ";";
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* 清除Cookie
|
|
41
|
+
* @param {String} name
|
|
42
|
+
*/
|
|
43
|
+
CookieClass.prototype.clearCookie = function (name) {
|
|
44
|
+
this.setCookie({
|
|
45
|
+
name: name,
|
|
46
|
+
value: '',
|
|
47
|
+
exdays: -1,
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
return CookieClass;
|
|
51
|
+
}());
|
|
52
|
+
var cookie = new CookieClass();
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @Author: wanghui
|
|
56
|
+
* createBy: @2020.05.21
|
|
57
|
+
*/
|
|
58
|
+
// import date from './modules/date'
|
|
59
|
+
// import dom from './modules/dom'
|
|
60
|
+
// import filter from './modules/filter'
|
|
61
|
+
// import format from './modules/format'
|
|
62
|
+
// import match from './modules/match'
|
|
63
|
+
// import number from './modules/number'
|
|
64
|
+
// import tools from './modules/tools'
|
|
65
|
+
var modules = {
|
|
66
|
+
cookie: cookie,
|
|
67
|
+
};
|
|
68
|
+
var Utils = /** @class */ (function () {
|
|
69
|
+
function Utils() {
|
|
70
|
+
Object.assign(this, modules);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 挂载各组件
|
|
74
|
+
* 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
|
|
75
|
+
* @param {Object} app 需要挂载的目标对象
|
|
76
|
+
*/
|
|
77
|
+
Utils.prototype.install = function (app) {
|
|
78
|
+
Object.keys(modules).forEach(function (key) {
|
|
79
|
+
if (key === 'filter') {
|
|
80
|
+
return modules[key].install(app);
|
|
81
|
+
}
|
|
82
|
+
app.config.globalProperties['$' + key] = modules[key];
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
return Utils;
|
|
86
|
+
}());
|
|
87
|
+
var utils = new Utils();
|
|
88
|
+
|
|
89
|
+
module.exports = utils;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
declare class Utils {
|
|
2
|
-
[key: string]: Object;
|
|
3
|
-
constructor();
|
|
4
|
-
/**
|
|
5
|
-
* 挂载各组件
|
|
6
|
-
* 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
|
|
7
|
-
* @param {Object} app 需要挂载的目标对象
|
|
8
|
-
*/
|
|
9
|
-
install(app: any): void;
|
|
10
|
-
}
|
|
11
|
-
declare const utils: Utils;
|
|
12
|
-
export default utils;
|
|
1
|
+
declare class Utils {
|
|
2
|
+
[key: string]: Object;
|
|
3
|
+
constructor();
|
|
4
|
+
/**
|
|
5
|
+
* 挂载各组件
|
|
6
|
+
* 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
|
|
7
|
+
* @param {Object} app 需要挂载的目标对象
|
|
8
|
+
*/
|
|
9
|
+
install(app: any): void;
|
|
10
|
+
}
|
|
11
|
+
declare const utils: Utils;
|
|
12
|
+
export default utils;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Cookie
|
|
3
|
+
* @Author: wanghui
|
|
4
|
+
* @createBy: @2021.01.21
|
|
5
|
+
*/
|
|
6
|
+
var CookieClass = /** @class */ (function () {
|
|
7
|
+
function CookieClass() {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 获取cookie
|
|
11
|
+
* @param {String} name
|
|
12
|
+
* @return {String}
|
|
13
|
+
*/
|
|
14
|
+
CookieClass.prototype.getCookie = function (name) {
|
|
15
|
+
var _name = name + '=';
|
|
16
|
+
var ca = document.cookie.split(';');
|
|
17
|
+
for (var i = 0; i < ca.length; i++) {
|
|
18
|
+
var c = ca[i];
|
|
19
|
+
while (c.charAt(0) === ' ')
|
|
20
|
+
c = c.substring(1);
|
|
21
|
+
if (c.includes(_name))
|
|
22
|
+
return c.substring(_name.length, c.length);
|
|
23
|
+
}
|
|
24
|
+
return '';
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* 设置cookie
|
|
28
|
+
* @param {Object} ICookie
|
|
29
|
+
*/
|
|
30
|
+
CookieClass.prototype.setCookie = function (_a) {
|
|
31
|
+
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;
|
|
32
|
+
var d = new Date();
|
|
33
|
+
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
|
34
|
+
var expires = "expires=" + d.toUTCString();
|
|
35
|
+
document.cookie = name + "=" + value + ";" + expires + ";path=" + path + ";domain=" + domain + ";";
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* 清除Cookie
|
|
39
|
+
* @param {String} name
|
|
40
|
+
*/
|
|
41
|
+
CookieClass.prototype.clearCookie = function (name) {
|
|
42
|
+
this.setCookie({
|
|
43
|
+
name: name,
|
|
44
|
+
value: '',
|
|
45
|
+
exdays: -1,
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
return CookieClass;
|
|
49
|
+
}());
|
|
50
|
+
var cookie = new CookieClass();
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @Author: wanghui
|
|
54
|
+
* createBy: @2020.05.21
|
|
55
|
+
*/
|
|
56
|
+
// import date from './modules/date'
|
|
57
|
+
// import dom from './modules/dom'
|
|
58
|
+
// import filter from './modules/filter'
|
|
59
|
+
// import format from './modules/format'
|
|
60
|
+
// import match from './modules/match'
|
|
61
|
+
// import number from './modules/number'
|
|
62
|
+
// import tools from './modules/tools'
|
|
63
|
+
var modules = {
|
|
64
|
+
cookie: cookie,
|
|
65
|
+
};
|
|
66
|
+
var Utils = /** @class */ (function () {
|
|
67
|
+
function Utils() {
|
|
68
|
+
Object.assign(this, modules);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 挂载各组件
|
|
72
|
+
* 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
|
|
73
|
+
* @param {Object} app 需要挂载的目标对象
|
|
74
|
+
*/
|
|
75
|
+
Utils.prototype.install = function (app) {
|
|
76
|
+
Object.keys(modules).forEach(function (key) {
|
|
77
|
+
if (key === 'filter') {
|
|
78
|
+
return modules[key].install(app);
|
|
79
|
+
}
|
|
80
|
+
app.config.globalProperties['$' + key] = modules[key];
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
return Utils;
|
|
84
|
+
}());
|
|
85
|
+
var utils = new Utils();
|
|
86
|
+
|
|
87
|
+
export { utils as default };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* createBy: @2020.05.21
|
|
4
4
|
*/
|
|
5
5
|
'use strict';
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
6
|
var modules = {
|
|
8
7
|
cookie: require('./modules/cookie'),
|
|
9
8
|
date: require('./modules/date'),
|
|
@@ -21,17 +20,17 @@ var Utils = /** @class */ (function () {
|
|
|
21
20
|
/**
|
|
22
21
|
* 挂载各组件
|
|
23
22
|
* 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
|
|
24
|
-
* @param {Object}
|
|
23
|
+
* @param {Object} Vue 需要挂载的目标对象
|
|
25
24
|
*/
|
|
26
|
-
Utils.prototype.install = function (
|
|
25
|
+
Utils.prototype.install = function (Vue) {
|
|
27
26
|
Object.keys(modules).forEach(function (key) {
|
|
28
27
|
if (key === 'filter') {
|
|
29
|
-
return modules[key].install(
|
|
28
|
+
return modules[key].install(Vue);
|
|
30
29
|
}
|
|
31
|
-
|
|
30
|
+
Vue.prototype['$' + key] = modules[key];
|
|
31
|
+
Vue['$' + key] = modules[key];
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
return Utils;
|
|
35
35
|
}());
|
|
36
|
-
|
|
37
|
-
exports.default = utils;
|
|
36
|
+
module.exports = new Utils();
|
|
@@ -1,25 +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: string): void;
|
|
25
|
-
}
|
|
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: string): void;
|
|
25
|
+
}
|
|
26
|
+
declare const _default: CookieClass;
|
|
27
|
+
export default _default;
|
|
@@ -39,11 +39,14 @@ var CookieClass = /** @class */ (function () {
|
|
|
39
39
|
* 清除Cookie
|
|
40
40
|
* @param {String} name
|
|
41
41
|
*/
|
|
42
|
-
CookieClass.prototype.clearCookie = function (
|
|
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;
|
|
43
44
|
this.setCookie({
|
|
44
45
|
name: name,
|
|
45
46
|
value: '',
|
|
46
47
|
exdays: -1,
|
|
48
|
+
path: path,
|
|
49
|
+
domain: domain
|
|
47
50
|
});
|
|
48
51
|
};
|
|
49
52
|
return CookieClass;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
declare const dateClass: any;
|
|
2
|
-
declare const numberClass: any;
|
|
3
|
-
declare const toolsClass: any;
|
|
4
|
-
declare class FilterClass {
|
|
5
|
-
/**
|
|
6
|
-
* 格式化时间,示例:1586840260500 | format('YYYY-MM-DD HH:mm:ss')
|
|
7
|
-
* @param {String|Number} date
|
|
8
|
-
* @param {String} fmt 'YYYY-MM-DD HH:mm:ss'
|
|
9
|
-
* @return {String} 'YYYY-MM-DD HH:mm:ss'
|
|
10
|
-
*/
|
|
11
|
-
format(date: string | number, fmt?: string): any;
|
|
12
|
-
/**
|
|
13
|
-
* 格式化金额,示例:123456 | formatMoney
|
|
14
|
-
* @param {Number} num
|
|
15
|
-
* @return {String} 123,456
|
|
16
|
-
*/
|
|
17
|
-
formatMoney(money: number | string): string;
|
|
18
|
-
/**
|
|
19
|
-
* 截取数组或字符串,示例:'1234' | slice(3)
|
|
20
|
-
* @param {Array|String} target 数组或字符串
|
|
21
|
-
* @param {Number} length 截取长度,从0开始
|
|
22
|
-
* @return {any}
|
|
23
|
-
*/
|
|
24
|
-
slice(target?: Array<any> | string, length?: number): any;
|
|
25
|
-
install(app: any): void;
|
|
26
|
-
}
|
|
1
|
+
declare const dateClass: any;
|
|
2
|
+
declare const numberClass: any;
|
|
3
|
+
declare const toolsClass: any;
|
|
4
|
+
declare class FilterClass {
|
|
5
|
+
/**
|
|
6
|
+
* 格式化时间,示例:1586840260500 | format('YYYY-MM-DD HH:mm:ss')
|
|
7
|
+
* @param {String|Number} date
|
|
8
|
+
* @param {String} fmt 'YYYY-MM-DD HH:mm:ss'
|
|
9
|
+
* @return {String} 'YYYY-MM-DD HH:mm:ss'
|
|
10
|
+
*/
|
|
11
|
+
format(date: string | number, fmt?: string): any;
|
|
12
|
+
/**
|
|
13
|
+
* 格式化金额,示例:123456 | formatMoney
|
|
14
|
+
* @param {Number} num
|
|
15
|
+
* @return {String} 123,456
|
|
16
|
+
*/
|
|
17
|
+
formatMoney(money: number | string): string;
|
|
18
|
+
/**
|
|
19
|
+
* 截取数组或字符串,示例:'1234' | slice(3)
|
|
20
|
+
* @param {Array|String} target 数组或字符串
|
|
21
|
+
* @param {Number} length 截取长度,从0开始
|
|
22
|
+
* @return {any}
|
|
23
|
+
*/
|
|
24
|
+
slice(target?: Array<any> | string, length?: number): any;
|
|
25
|
+
install(app: any): void;
|
|
26
|
+
}
|
|
@@ -46,13 +46,11 @@ var FilterClass = /** @class */ (function () {
|
|
|
46
46
|
if (length === void 0) { length = 0; }
|
|
47
47
|
return toolsClass.slice(target, length);
|
|
48
48
|
};
|
|
49
|
-
FilterClass.prototype.install = function (
|
|
49
|
+
FilterClass.prototype.install = function (Vue) {
|
|
50
50
|
var _this = this;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
globalProperties.$filters.formatMoney = _this.formatMoney;
|
|
55
|
-
globalProperties.$filters.slice = _this.slice;
|
|
51
|
+
Vue.filter('format', _this.format);
|
|
52
|
+
Vue.filter('formatMoney', _this.formatMoney);
|
|
53
|
+
Vue.filter('slice', _this.slice);
|
|
56
54
|
};
|
|
57
55
|
return FilterClass;
|
|
58
56
|
}());
|