@haluo/util 1.0.1 → 1.0.4

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.
@@ -0,0 +1,11 @@
1
+ declare const modules: any;
2
+ declare class Utils {
3
+ [key: string]: Object;
4
+ constructor();
5
+ /**
6
+ * 挂载各组件
7
+ * 示例:this.$cookie、this.$date、this.$match、this.$number、this.$tools
8
+ * @param {Object} app 需要挂载的目标对象
9
+ */
10
+ install(app: any): void;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +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
+ }
@@ -0,0 +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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +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
+ }
@@ -0,0 +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;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export interface IObjectKey<T> {
2
+ [key: string]: T;
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haluo/util",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
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/"],
16
17
  "lint-staged": {
17
18
  "src/**/*.{js,vue}": [
18
19
  "eslint --fix",
package/.babelrc DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "env": {
3
- "development": {
4
- "plugins": [
5
- "@babel/plugin-proposal-class-properties"
6
- ]
7
- },
8
- "test": {
9
- "presets": [
10
- [
11
- "@babel/preset-env",
12
- {
13
- "targets": {
14
- "node": "current"
15
- }
16
- }
17
- ]
18
- ]
19
- }
20
- },
21
- }
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/global.d.ts DELETED
File without changes
package/publish.sh DELETED
@@ -1,11 +0,0 @@
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
@@ -1,25 +0,0 @@
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
- ```
@@ -1,9 +0,0 @@
1
- ### [JS](http://alloyteam.github.io/CodeGuide/)
2
-
3
- ```
4
- 1、路由命名:name 大写,path和文件名 小写加中划线
5
- 2、组件使用:组件文件、引用名、页面使用 名称保持一致
6
- 3、JS
7
- > 接口请求参数做解构
8
- > 公共文件,多尝试用class
9
- ```
@@ -1 +0,0 @@
1
- ### [VUE](https://cn.vuejs.org/v2/style-guide/)
@@ -1,10 +0,0 @@
1
- /**
2
- * 处理http返回的错误码等信息
3
- * @Author: wanghui
4
- */
5
- export default {
6
- SUCCESS: {
7
- 'resultCode': '0',
8
- 'resultDesc': '处理成功'
9
- },
10
- }
package/src/index.ts DELETED
@@ -1,53 +0,0 @@
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} app 需要挂载的目标对象
29
- */
30
- install(app: any) {
31
- Object.keys(modules).forEach((key) => {
32
- if (key === 'filter') {
33
- return modules[key].install(app)
34
- }
35
- app.config.globalProperties['$' + key] = modules[key]
36
- })
37
- }
38
-
39
- // loadModules() {
40
- // const modules = require['context']('./modules/', true, /.js$/)
41
- // modules.keys().forEach((modulesKey: string) => {
42
- // const attr: string = modulesKey.replace('./', '').replace('.js', '').replace('/index', '')
43
- // const haveDefault = ['sentry']
44
- // if (haveDefault.includes(attr)) {
45
- // this[attr] = modules(modulesKey).default
46
- // } else {
47
- // this[attr] = modules(modulesKey)
48
- // }
49
- // })
50
- // }
51
- }
52
-
53
- module.exports = new Utils()
@@ -1,63 +0,0 @@
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(name: string) {
54
- this.setCookie({
55
- name,
56
- value: '',
57
- exdays: -1,
58
- })
59
- }
60
- }
61
-
62
- module.exports = new CookieClass()
63
-