@haluo/util 1.0.1 → 1.0.2
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/package.json +2 -1
- package/.babelrc +0 -21
- package/.eslintrc.js +0 -216
- package/__tests__/unit/date/date.spec.js +0 -14
- package/__tests__/unit/jest.conf.js +0 -25
- package/__tests__/unit/specs/date.test.js +0 -11
- package/dist/index.js +0 -35
- package/dist/modules/cookie/index.js +0 -51
- package/dist/modules/date/index.js +0 -192
- package/dist/modules/dom/index.js +0 -62
- package/dist/modules/filter/index.js +0 -59
- package/dist/modules/format/index.js +0 -21
- package/dist/modules/match/index.js +0 -31
- package/dist/modules/number/index.js +0 -102
- package/dist/modules/sentry/index.js +0 -81
- package/dist/modules/tools/index.js +0 -393
- package/global.d.ts +0 -0
- package/publish.sh +0 -11
- package/specification/CSS.md +0 -25
- package/specification/JS.md +0 -9
- package/specification/VUE.md +0 -1
- package/src/consts/httpCode.js +0 -10
- package/src/index.ts +0 -53
- package/src/modules/cookie/index.ts +0 -63
- package/src/modules/date/index.ts +0 -196
- package/src/modules/dom/index.ts +0 -78
- package/src/modules/filter/index.ts +0 -59
- package/src/modules/format/index.ts +0 -19
- package/src/modules/match/index.ts +0 -31
- package/src/modules/number/index.ts +0 -108
- package/src/modules/sentry/index.ts +0 -82
- package/src/modules/tools/index.ts +0 -427
- package/tsconfig.json +0 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haluo/util",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"author": "<wanghui@jddmoto.com>",
|
|
6
6
|
"description": "哈罗摩托工具库",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"precommit": "lint-staged"
|
|
14
14
|
},
|
|
15
15
|
"types": "dist/types/index.d.ts",
|
|
16
|
+
"files": ["./dist/", "./package.json"],
|
|
16
17
|
"lint-staged": {
|
|
17
18
|
"src/**/*.{js,vue}": [
|
|
18
19
|
"eslint --fix",
|
package/.babelrc
DELETED
package/.eslintrc.js
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
const DOMGlobals = [] // ['window']
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
root: true,
|
|
5
|
-
parserOptions: {
|
|
6
|
-
parser: 'babel-eslint',
|
|
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'],
|
|
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
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,25 +0,0 @@
|
|
|
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)
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
});
|
package/dist/index.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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} app 需要挂载的目标对象
|
|
24
|
-
*/
|
|
25
|
-
Utils.prototype.install = function (app) {
|
|
26
|
-
Object.keys(modules).forEach(function (key) {
|
|
27
|
-
if (key === 'filter') {
|
|
28
|
-
return modules[key].install(app);
|
|
29
|
-
}
|
|
30
|
-
app.config.globalProperties['$' + key] = modules[key];
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
return Utils;
|
|
34
|
-
}());
|
|
35
|
-
module.exports = new Utils();
|
|
@@ -1,51 +0,0 @@
|
|
|
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=" + d.toUTCString();
|
|
36
|
-
document.cookie = name + "=" + value + ";" + expires + ";path=" + path + ";domain=" + domain + ";";
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* 清除Cookie
|
|
40
|
-
* @param {String} name
|
|
41
|
-
*/
|
|
42
|
-
CookieClass.prototype.clearCookie = function (name) {
|
|
43
|
-
this.setCookie({
|
|
44
|
-
name: name,
|
|
45
|
-
value: '',
|
|
46
|
-
exdays: -1,
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
return CookieClass;
|
|
50
|
-
}());
|
|
51
|
-
module.exports = new CookieClass();
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file date 格式化
|
|
3
|
-
* @Author: wanghui
|
|
4
|
-
* @createBy: @2020.05.21
|
|
5
|
-
*/
|
|
6
|
-
'use strict';
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
/**
|
|
9
|
-
* 格式化时间 详情内容里的时间格式
|
|
10
|
-
* @param {Object} data 格式,可参考format 中的o属性
|
|
11
|
-
* @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
|
|
12
|
-
* @return 返回fmt 格式 时间
|
|
13
|
-
*/
|
|
14
|
-
function replacementDate(data, fmt) {
|
|
15
|
-
for (var k in data) {
|
|
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)));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return fmt;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 格式化年份
|
|
24
|
-
* @param {String} date Date 格式
|
|
25
|
-
* @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
|
|
26
|
-
* @return 仅返回年份
|
|
27
|
-
*/
|
|
28
|
-
function replacementYear(date, fmt) {
|
|
29
|
-
if (/(Y+)/.test(fmt)) {
|
|
30
|
-
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
|
|
31
|
-
}
|
|
32
|
-
return fmt;
|
|
33
|
-
}
|
|
34
|
-
var DateClass = /** @class */ (function () {
|
|
35
|
-
function DateClass() {
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 格式化时间
|
|
39
|
-
* @param {String|Number} date 需要格式化的时间 2017-11-11、2017/11/11、linux time
|
|
40
|
-
* @param {String} fmt 想要格式化的格式 'YYYY-MM-DD HH:mm:ss'、'YYYY-MM-DD'、'YYYY年MM月DD日 HH时mm分ss秒'、'YYYY年MM月DD日'
|
|
41
|
-
* date.format(new Date()) // 默认格式 'YYYY-MM-DD HH:mm:ss'
|
|
42
|
-
* date.format(1586840260500) // 默认格式,传参为linux时间
|
|
43
|
-
* date.format(new Date(), 'YYYY:MM:DD') // 自定义格式 'YYYY:MM:DD'
|
|
44
|
-
* @return {String} fmt 'YYYY-MM-DD HH:mm:ss'
|
|
45
|
-
*/
|
|
46
|
-
DateClass.prototype.format = function (date, fmt) {
|
|
47
|
-
if (fmt === void 0) { fmt = 'YYYY-MM-DD HH:mm:ss'; }
|
|
48
|
-
if (!date)
|
|
49
|
-
return '';
|
|
50
|
-
var timeData = typeof date === 'string' ? new Date(date.replace(/-/g, '/')) : date;
|
|
51
|
-
timeData = typeof date === 'number' ? new Date(date) : timeData;
|
|
52
|
-
var o = {
|
|
53
|
-
'M+': timeData.getMonth() + 1,
|
|
54
|
-
'D+': timeData.getDate(),
|
|
55
|
-
'h+': timeData.getHours() % 12 === 0 ? 12 : timeData.getHours() % 12,
|
|
56
|
-
'H+': timeData.getHours(),
|
|
57
|
-
'm+': timeData.getMinutes(),
|
|
58
|
-
's+': timeData.getSeconds(),
|
|
59
|
-
'q+': Math.floor((timeData.getMonth() + 3) / 3),
|
|
60
|
-
'S': timeData.getMilliseconds()
|
|
61
|
-
};
|
|
62
|
-
var week = {
|
|
63
|
-
'0': '\u65e5',
|
|
64
|
-
'1': '\u4e00',
|
|
65
|
-
'2': '\u4e8c',
|
|
66
|
-
'3': '\u4e09',
|
|
67
|
-
'4': '\u56db',
|
|
68
|
-
'5': '\u4e94',
|
|
69
|
-
'6': '\u516d'
|
|
70
|
-
};
|
|
71
|
-
fmt = replacementYear(timeData, fmt);
|
|
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() + " "]);
|
|
74
|
-
}
|
|
75
|
-
return replacementDate(o, fmt);
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* 天数加减
|
|
79
|
-
* @param {string | Date} date 传入的时间 2020-10-15 or Date
|
|
80
|
-
* @param {String} days 天数
|
|
81
|
-
* addDaysToDate('2020-10-15', 10) // '2020-10-25'
|
|
82
|
-
* addDaysToDate('2020-10-15', -10) // '2020-10-05'
|
|
83
|
-
* @return {String} fmt 'YYYY-MM-DD'
|
|
84
|
-
*/
|
|
85
|
-
DateClass.prototype.addDaysToDate = function (date, days) {
|
|
86
|
-
var d = typeof date === 'object' ? date : new Date(date);
|
|
87
|
-
d.setDate(d.getDate() + days);
|
|
88
|
-
return d.toISOString().split('T')[0];
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* 获取倒计时剩余时间
|
|
92
|
-
* @param {Date | Number} endTime 截止时间
|
|
93
|
-
* @param {Date | Number} startTime 开始时间,默认取客户端当前时间
|
|
94
|
-
* date.format(new Date()) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
|
|
95
|
-
* date.format(1586840260500) // 返回 {dd: '天', hh: '时', mm: '分', ss: '秒'}
|
|
96
|
-
* @return {object | boolean} {dd: '天', hh: '时', mm: '分', ss: '秒'}
|
|
97
|
-
*/
|
|
98
|
-
DateClass.prototype.remainTime = function (endTime, startTime) {
|
|
99
|
-
if (startTime === void 0) { startTime = new Date(); }
|
|
100
|
-
var ts = Number(endTime) - Number(startTime); // 计算剩余的毫秒数
|
|
101
|
-
var dd = Math.floor(ts / 1000 / 60 / 60 / 24); // 计算剩余的天数
|
|
102
|
-
var hh = Math.floor(ts / 1000 / 60 / 60 % 24); // 计算剩余的小时数
|
|
103
|
-
var mm = Math.floor(ts / 1000 / 60 % 60); // 计算剩余的分钟数
|
|
104
|
-
var ss = Math.floor(ts / 1000 % 60); // 计算剩余的秒数
|
|
105
|
-
if (ts <= 0)
|
|
106
|
-
return false;
|
|
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)
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* 格式化现在的已过时间
|
|
116
|
-
* @param {Number} startTime
|
|
117
|
-
* @return {String} *年前 *个月前 *天前 *小时前 *分钟前 刚刚
|
|
118
|
-
*/
|
|
119
|
-
DateClass.prototype.formatPassTime = function (startTime) {
|
|
120
|
-
var currentTime = new Date();
|
|
121
|
-
var time = currentTime - startTime;
|
|
122
|
-
var year = Math.floor(time / (1000 * 60 * 60 * 24) / 30 / 12);
|
|
123
|
-
if (year)
|
|
124
|
-
return year + "\u5E74\u524D";
|
|
125
|
-
var month = Math.floor(time / (1000 * 60 * 60 * 24) / 30);
|
|
126
|
-
if (month)
|
|
127
|
-
return month + "\u4E2A\u6708\u524D";
|
|
128
|
-
var day = Math.floor(time / (1000 * 60 * 60 * 24));
|
|
129
|
-
if (day)
|
|
130
|
-
return day + "\u5929\u524D";
|
|
131
|
-
var hour = Math.floor(time / (1000 * 60 * 60));
|
|
132
|
-
if (hour)
|
|
133
|
-
return hour + "\u5C0F\u65F6\u524D";
|
|
134
|
-
var min = Math.floor(time / (1000 * 60));
|
|
135
|
-
if (min)
|
|
136
|
-
return min + "\u5206\u949F\u524D";
|
|
137
|
-
else
|
|
138
|
-
return '刚刚';
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* 格式化时间 列表里的时间内容格式 待废弃,统一时间格式
|
|
142
|
-
* @param {Number} time 1494141000*1000
|
|
143
|
-
* @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
|
|
144
|
-
*/
|
|
145
|
-
DateClass.prototype.formatPassTimeForList = function (time) {
|
|
146
|
-
return DateClass.prototype.formatPassTimeForDetail(time, 'YYYY年MM月DD日', true);
|
|
147
|
-
};
|
|
148
|
-
/**
|
|
149
|
-
* 格式化时间 详情内容里的时间格式
|
|
150
|
-
* @param {Number} time 1494141000*1000
|
|
151
|
-
* @param {String} fmt 想要格式化的格式
|
|
152
|
-
* @param {Boolean} noYear 是否显示年
|
|
153
|
-
* @return {String} *年*月*日 *月*日 刚刚(1-60秒) 1-60分钟前 1-24小时前 1-3天前
|
|
154
|
-
*/
|
|
155
|
-
DateClass.prototype.formatPassTimeForDetail = function (time, fmt, noYear) {
|
|
156
|
-
if (fmt === void 0) { fmt = 'YYYY-MM-DD'; }
|
|
157
|
-
var date = (typeof time === 'number') ? new Date(time) : new Date((time || '').replace(/-/g, '/'));
|
|
158
|
-
var diff = (((new Date()).getTime() - date.getTime()) / 1000);
|
|
159
|
-
var dayDiff = Math.floor(diff / 86400);
|
|
160
|
-
var isValidDate = Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime());
|
|
161
|
-
if (!isValidDate)
|
|
162
|
-
return '';
|
|
163
|
-
var formatDate = function () {
|
|
164
|
-
var today = new Date(date);
|
|
165
|
-
var o = {
|
|
166
|
-
'Y+': today.getFullYear(),
|
|
167
|
-
'M+': ('0' + (today.getMonth() + 1)).slice(-2),
|
|
168
|
-
'D+': ('0' + today.getDate()).slice(-2)
|
|
169
|
-
};
|
|
170
|
-
fmt = replacementYear(date, fmt);
|
|
171
|
-
var year = today.getFullYear();
|
|
172
|
-
if (!(new Date().getFullYear() > year) && noYear) {
|
|
173
|
-
var backData = replacementDate(o, fmt);
|
|
174
|
-
return backData.split('年')[1];
|
|
175
|
-
}
|
|
176
|
-
return replacementDate(o, fmt);
|
|
177
|
-
};
|
|
178
|
-
if (dayDiff === -1) {
|
|
179
|
-
return '刚刚';
|
|
180
|
-
}
|
|
181
|
-
else if (isNaN(dayDiff) || dayDiff < 0 || dayDiff >= 15) {
|
|
182
|
-
return formatDate();
|
|
183
|
-
}
|
|
184
|
-
return (dayDiff === 0 && ((diff < 60 && '刚刚') ||
|
|
185
|
-
(diff < 120 && '1分钟前') ||
|
|
186
|
-
(diff < 3600 && Math.floor(diff / 60) + '分钟前') ||
|
|
187
|
-
(diff < 7200 && '1小时前') ||
|
|
188
|
-
(diff < 86400 && Math.floor(diff / 3600) + '小时前'))) || (dayDiff < 16 && dayDiff + '天前');
|
|
189
|
-
};
|
|
190
|
-
return DateClass;
|
|
191
|
-
}());
|
|
192
|
-
module.exports = new DateClass();
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Cookie
|
|
3
|
-
* @Author: wanghui
|
|
4
|
-
* @createBy: @2021.08.17
|
|
5
|
-
*/
|
|
6
|
-
'use strict';
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
var DomClass = /** @class */ (function () {
|
|
9
|
-
function DomClass() {
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* 创建一个子元素并添加至父节点
|
|
13
|
-
* @param {Object} { name = 'div', innerHTML = '', style = {}, parent, }
|
|
14
|
-
* @return {String}
|
|
15
|
-
*/
|
|
16
|
-
DomClass.prototype.createElement = function (_a) {
|
|
17
|
-
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;
|
|
18
|
-
if (!(window && window.document)) {
|
|
19
|
-
return new Error('仅支持浏览器');
|
|
20
|
-
}
|
|
21
|
-
var element = document.createElement(name);
|
|
22
|
-
element.innerHTML = innerHTML;
|
|
23
|
-
Object.keys(style).map(function (_) { return element.style[_] = style[_]; });
|
|
24
|
-
if (parent) {
|
|
25
|
-
var body = document.querySelector(parent);
|
|
26
|
-
body && body.append(element);
|
|
27
|
-
}
|
|
28
|
-
return element;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* 获取文本中的url并用a标签包裹
|
|
32
|
-
* @param {Object} ICookie
|
|
33
|
-
*/
|
|
34
|
-
DomClass.prototype.wrapperA = function (text) {
|
|
35
|
-
if (!(window && window.document)) {
|
|
36
|
-
return new Error('仅支持浏览器');
|
|
37
|
-
}
|
|
38
|
-
return text.replace(/((https|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])/g, '<a href="$1">$1</a>');
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* 对象转化为formdata
|
|
42
|
-
* getFormData({a: 1, b: 2})
|
|
43
|
-
* @param {Object} object
|
|
44
|
-
*/
|
|
45
|
-
DomClass.prototype.getFormData = function (object) {
|
|
46
|
-
var formData = new FormData();
|
|
47
|
-
Object.keys(object).forEach(function (key) {
|
|
48
|
-
var value = object[key];
|
|
49
|
-
if (Array.isArray(value)) {
|
|
50
|
-
value.forEach(function (subValue, i) {
|
|
51
|
-
return formData.append(key + ("[" + i + "]"), subValue);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
formData.append(key, object[key]);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return formData;
|
|
59
|
-
};
|
|
60
|
-
return DomClass;
|
|
61
|
-
}());
|
|
62
|
-
module.exports = new DomClass();
|