lgutils 1.3.12 → 1.3.13
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/index.d.ts +227 -179
- package/lib/lgutils.cjs.js +51 -48
- package/lib/lgutils.cjs.prod.js +1 -1
- package/lib/lgutils.esm-bundler.js +51 -45
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,179 +1,227 @@
|
|
|
1
|
-
export declare const accAdd: (arg1: number, arg2: number) => number
|
|
2
|
-
|
|
3
|
-
export declare const accDiv: (arg1: number, arg2: number) => number
|
|
4
|
-
|
|
5
|
-
export declare const accMul: (arg1: number, arg2: number) => number
|
|
6
|
-
|
|
7
|
-
export declare const accSub: (arg1: number, arg2: number) => string
|
|
8
|
-
|
|
9
|
-
export declare
|
|
10
|
-
|
|
11
|
-
export declare const
|
|
12
|
-
|
|
13
|
-
export declare
|
|
14
|
-
|
|
15
|
-
export declare function
|
|
16
|
-
|
|
17
|
-
export declare
|
|
18
|
-
|
|
19
|
-
export declare const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export declare const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export declare
|
|
84
|
-
|
|
85
|
-
declare
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
export declare const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
export declare const
|
|
123
|
-
|
|
124
|
-
declare
|
|
125
|
-
|
|
126
|
-
export declare const
|
|
127
|
-
|
|
128
|
-
export declare
|
|
129
|
-
|
|
130
|
-
export declare
|
|
131
|
-
|
|
132
|
-
export declare const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export declare const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
export declare const
|
|
162
|
-
|
|
163
|
-
export declare
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
1
|
+
export declare const accAdd: (arg1: number, arg2: number) => number
|
|
2
|
+
|
|
3
|
+
export declare const accDiv: (arg1: number, arg2: number) => number
|
|
4
|
+
|
|
5
|
+
export declare const accMul: (arg1: number, arg2: number) => number
|
|
6
|
+
|
|
7
|
+
export declare const accSub: (arg1: number, arg2: number) => string
|
|
8
|
+
|
|
9
|
+
export declare function copyToClipboard(txt: string): void
|
|
10
|
+
|
|
11
|
+
export declare const cutTimeFn: (n: number) => string
|
|
12
|
+
|
|
13
|
+
export declare const DATE_FORMAT = 'YYYY/MM/DD'
|
|
14
|
+
|
|
15
|
+
export declare function digitCnUppercase(n: number): string
|
|
16
|
+
|
|
17
|
+
export declare function disableBrowserZoom(): void
|
|
18
|
+
|
|
19
|
+
export declare const download: (
|
|
20
|
+
data: string,
|
|
21
|
+
strFileName?: string,
|
|
22
|
+
strMimeType?: string,
|
|
23
|
+
isImgUrl?: boolean | undefined
|
|
24
|
+
) => true | undefined
|
|
25
|
+
|
|
26
|
+
export declare const fileReaderToBase64: (
|
|
27
|
+
target: any
|
|
28
|
+
) => (cb: (p: any) => void) => void
|
|
29
|
+
|
|
30
|
+
export declare const format10k: (n: number) => string
|
|
31
|
+
|
|
32
|
+
export declare const format10kNil: (d: number | NIL) => string
|
|
33
|
+
|
|
34
|
+
export declare const FORMAT_DATE = 'YYYY-MM-DD'
|
|
35
|
+
|
|
36
|
+
export declare const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss'
|
|
37
|
+
|
|
38
|
+
export declare const formatCash: (
|
|
39
|
+
n:
|
|
40
|
+
| number
|
|
41
|
+
| {
|
|
42
|
+
valueOf(): number
|
|
43
|
+
}
|
|
44
|
+
) => string
|
|
45
|
+
|
|
46
|
+
export declare const formatCash2: (num: number) => string
|
|
47
|
+
|
|
48
|
+
export declare const formatCashInt: (
|
|
49
|
+
n:
|
|
50
|
+
| number
|
|
51
|
+
| {
|
|
52
|
+
valueOf(): number
|
|
53
|
+
}
|
|
54
|
+
) => string
|
|
55
|
+
|
|
56
|
+
export declare const formatCashIntNil: (
|
|
57
|
+
d:
|
|
58
|
+
| number
|
|
59
|
+
| {
|
|
60
|
+
valueOf(): number
|
|
61
|
+
}
|
|
62
|
+
| NIL
|
|
63
|
+
) => string
|
|
64
|
+
|
|
65
|
+
export declare const formatCashNil: (
|
|
66
|
+
d:
|
|
67
|
+
| number
|
|
68
|
+
| {
|
|
69
|
+
valueOf(): number
|
|
70
|
+
}
|
|
71
|
+
| NIL
|
|
72
|
+
) => string
|
|
73
|
+
|
|
74
|
+
export declare function formatDate(
|
|
75
|
+
d: string | number,
|
|
76
|
+
formatType?: string
|
|
77
|
+
): string
|
|
78
|
+
|
|
79
|
+
export declare const formatDateNil: (
|
|
80
|
+
d: string | number | null | undefined
|
|
81
|
+
) => string
|
|
82
|
+
|
|
83
|
+
export declare function formatDuration(period: string): string
|
|
84
|
+
|
|
85
|
+
export declare const formatDurationNil: (d: string | null | undefined) => string
|
|
86
|
+
|
|
87
|
+
export declare const formatRatio: (
|
|
88
|
+
n:
|
|
89
|
+
| number
|
|
90
|
+
| {
|
|
91
|
+
valueOf(): number
|
|
92
|
+
}
|
|
93
|
+
) => string
|
|
94
|
+
|
|
95
|
+
export declare const formatRatioNil: (
|
|
96
|
+
d:
|
|
97
|
+
| number
|
|
98
|
+
| {
|
|
99
|
+
valueOf(): number
|
|
100
|
+
}
|
|
101
|
+
| NIL
|
|
102
|
+
) => string
|
|
103
|
+
|
|
104
|
+
export declare const getBase64: (file: File) => Promise<unknown>
|
|
105
|
+
|
|
106
|
+
export declare const getItem: (key: string) => any
|
|
107
|
+
|
|
108
|
+
export declare const getQueryObject: (url?: string) => any
|
|
109
|
+
|
|
110
|
+
export declare const getSearchParams: (search: string) => URLSearchParams
|
|
111
|
+
|
|
112
|
+
export declare const getValOfArr: (_array: number[]) => {
|
|
113
|
+
min: any
|
|
114
|
+
max: any
|
|
115
|
+
sum: number
|
|
116
|
+
average: number
|
|
117
|
+
mull: number
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export declare const getValueWithNil: (val: any) => any
|
|
121
|
+
|
|
122
|
+
export declare const inBrowser: boolean
|
|
123
|
+
|
|
124
|
+
export declare const isArray: (value: any) => boolean
|
|
125
|
+
|
|
126
|
+
export declare const isBlob: (value: any) => any
|
|
127
|
+
|
|
128
|
+
export declare const isCardNo: (cardNum: any) => boolean
|
|
129
|
+
|
|
130
|
+
export declare const isDate: (value: any) => boolean
|
|
131
|
+
|
|
132
|
+
export declare const isEmail: (emailStr: string) => boolean
|
|
133
|
+
|
|
134
|
+
export declare const isFile: (value: any) => any
|
|
135
|
+
|
|
136
|
+
export declare const isNil: (val: any) => val is NIL
|
|
137
|
+
|
|
138
|
+
export declare const isNull: (value: any) => boolean
|
|
139
|
+
|
|
140
|
+
export declare const isObject: (value: any) => boolean
|
|
141
|
+
|
|
142
|
+
export declare const isPhone: (phone: any) => boolean
|
|
143
|
+
|
|
144
|
+
export declare const isSMSCode: (code: any) => any
|
|
145
|
+
|
|
146
|
+
export declare const isUndefined: (value: any) => boolean
|
|
147
|
+
|
|
148
|
+
declare interface IWSObj {
|
|
149
|
+
open?: (params?: any) => any
|
|
150
|
+
msg: (params: any) => any
|
|
151
|
+
error?: (params?: any) => any
|
|
152
|
+
disconnect?: (params?: any) => any
|
|
153
|
+
close?: (params?: any) => any
|
|
154
|
+
heartInfo?: any
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export declare const log: (...rest: any) => void
|
|
158
|
+
|
|
159
|
+
declare type NIL = undefined | null | ''
|
|
160
|
+
|
|
161
|
+
export declare const NIL_STRING = '\u2014\u2014'
|
|
162
|
+
|
|
163
|
+
export declare const os: () => {
|
|
164
|
+
isTablet: boolean
|
|
165
|
+
isPhone: boolean
|
|
166
|
+
isAndroid: boolean
|
|
167
|
+
isPc: boolean
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export declare const playAudio: (mp3Id: string) => void
|
|
171
|
+
|
|
172
|
+
export declare const random: (min: number, max: number) => number
|
|
173
|
+
|
|
174
|
+
export declare const randomString: (len?: number) => string
|
|
175
|
+
|
|
176
|
+
export declare const removeAll: () => any
|
|
177
|
+
|
|
178
|
+
export declare const removeItem: (key: string) => any
|
|
179
|
+
|
|
180
|
+
export declare const setItem: (key: string, value: any) => any
|
|
181
|
+
|
|
182
|
+
export declare const setProxyObj: (
|
|
183
|
+
data: object,
|
|
184
|
+
getFn: () => void,
|
|
185
|
+
setFn: () => void
|
|
186
|
+
) => object
|
|
187
|
+
|
|
188
|
+
export declare const sortObj: <
|
|
189
|
+
T extends keyof D,
|
|
190
|
+
D extends {
|
|
191
|
+
[key: string]: any
|
|
192
|
+
}
|
|
193
|
+
>(
|
|
194
|
+
obj: D[],
|
|
195
|
+
property: T,
|
|
196
|
+
type?: 'asc' | 'desc'
|
|
197
|
+
) => D[]
|
|
198
|
+
|
|
199
|
+
export declare const sumObj: <
|
|
200
|
+
T extends keyof D,
|
|
201
|
+
D extends {
|
|
202
|
+
[key: string]: any
|
|
203
|
+
}
|
|
204
|
+
>(
|
|
205
|
+
obj: D[],
|
|
206
|
+
key: T
|
|
207
|
+
) => number
|
|
208
|
+
|
|
209
|
+
export declare const trimString: (str: string) => string
|
|
210
|
+
|
|
211
|
+
export declare class WS {
|
|
212
|
+
socket: any
|
|
213
|
+
timer: any
|
|
214
|
+
ioUrl: string
|
|
215
|
+
heartInfo: any
|
|
216
|
+
private heartTime
|
|
217
|
+
constructor(ioUrl: string, token?: string)
|
|
218
|
+
init(obj: IWSObj): void
|
|
219
|
+
close(): void
|
|
220
|
+
start(info: string): void
|
|
221
|
+
send(msg: AnyObj): void
|
|
222
|
+
reset(): void
|
|
223
|
+
getSocketState(): any
|
|
224
|
+
setHeartTime(time: number): void
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export {}
|
package/lib/lgutils.cjs.js
CHANGED
|
@@ -4,12 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var qs = require('qs');
|
|
6
6
|
var d3Format = require('d3-format');
|
|
7
|
-
var omit = require('lodash/omit');
|
|
8
7
|
var moment = require('moment');
|
|
9
8
|
|
|
10
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
|
|
11
10
|
|
|
12
|
-
var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
|
|
13
11
|
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
14
12
|
|
|
15
13
|
const log = (...rest) => {
|
|
@@ -238,49 +236,44 @@ const SERVER_DATE_FROMAT = 'YYYY-MM-DD';
|
|
|
238
236
|
const DATE_FORMAT = 'YYYY/MM/DD';
|
|
239
237
|
const FORMAT_DATE = SERVER_DATE_FROMAT;
|
|
240
238
|
const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss';
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return function (yes) {
|
|
278
|
-
return yes ? field : '不' + field;
|
|
279
|
-
};
|
|
280
|
-
}
|
|
239
|
+
// type IndexType = { [x: string]: any }
|
|
240
|
+
// export function normalizeFormValues<T extends IndexType>(values: T) {
|
|
241
|
+
// return Object.entries(values)
|
|
242
|
+
// .filter(([key, value]) => value !== undefined && value !== 'all')
|
|
243
|
+
// .reduce((mem: any, [key, value]) => {
|
|
244
|
+
// // array for [moment, moment]
|
|
245
|
+
// if (Array.isArray(value) && value.some((val) => moment.isMoment(val))) {
|
|
246
|
+
// if (value[0]) {
|
|
247
|
+
// mem.startDate = value[0].format(SERVER_DATE_FROMAT)
|
|
248
|
+
// }
|
|
249
|
+
// if (value[1]) {
|
|
250
|
+
// mem.endDate = value[1].format(SERVER_DATE_FROMAT)
|
|
251
|
+
// }
|
|
252
|
+
// } else if (moment.isMoment(value)) {
|
|
253
|
+
// mem[key] = value.format(SERVER_DATE_FROMAT)
|
|
254
|
+
// } else mem[key] = value
|
|
255
|
+
// return mem
|
|
256
|
+
// }, {} as T)
|
|
257
|
+
// }
|
|
258
|
+
// export function normalizeSearchParams(params: IndexType) {
|
|
259
|
+
// if (params.startDate || params.endDate) {
|
|
260
|
+
// params = {
|
|
261
|
+
// ...omit(params, ['startDate', 'endDate']),
|
|
262
|
+
// dateRange: [
|
|
263
|
+
// params.startDate && moment(params.startDate),
|
|
264
|
+
// params.endDate && moment(params.endDate),
|
|
265
|
+
// ],
|
|
266
|
+
// }
|
|
267
|
+
// }
|
|
268
|
+
// Object.entries(params).forEach(([key, value]) => {
|
|
269
|
+
// if (typeof value === 'string' && value.includes(',')) {
|
|
270
|
+
// params[key] = 'all'
|
|
271
|
+
// }
|
|
272
|
+
// })
|
|
273
|
+
// return params
|
|
274
|
+
// }
|
|
281
275
|
const format10k = (n) => formatCash(n / 10000);
|
|
282
276
|
const format10kNil = withDefaultNil(format10k);
|
|
283
|
-
const formatCreditEnhanced = formatBool('增信');
|
|
284
277
|
// null == undefined
|
|
285
278
|
const isNil = (val) => val == null || val === '';
|
|
286
279
|
const NIL_STRING = '——';
|
|
@@ -289,7 +282,10 @@ const getValueWithNil = (val) => (isNil(val) ? NIL_STRING : val);
|
|
|
289
282
|
function digitCnUppercase(n) {
|
|
290
283
|
var fraction = ['角', '分'];
|
|
291
284
|
var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
292
|
-
var unit = [
|
|
285
|
+
var unit = [
|
|
286
|
+
['元', '万', '亿'],
|
|
287
|
+
['', '拾', '佰', '仟'],
|
|
288
|
+
];
|
|
293
289
|
var head = n < 0 ? '欠' : '';
|
|
294
290
|
n = Math.abs(n);
|
|
295
291
|
var s = '';
|
|
@@ -319,7 +315,7 @@ const formatDateNil = withDefaultNil(formatDate);
|
|
|
319
315
|
const unit = {
|
|
320
316
|
d: '天',
|
|
321
317
|
m: '个月',
|
|
322
|
-
y: '年'
|
|
318
|
+
y: '年',
|
|
323
319
|
};
|
|
324
320
|
function formatDuration(period) {
|
|
325
321
|
if (!period)
|
|
@@ -557,6 +553,15 @@ function disableBrowserZoom() {
|
|
|
557
553
|
});
|
|
558
554
|
}
|
|
559
555
|
|
|
556
|
+
function copyToClipboard(txt) {
|
|
557
|
+
var textarea = document.createElement('textarea');
|
|
558
|
+
textarea.value = txt;
|
|
559
|
+
document.body.appendChild(textarea);
|
|
560
|
+
textarea.select();
|
|
561
|
+
document.execCommand('copy');
|
|
562
|
+
document.body.removeChild(textarea);
|
|
563
|
+
}
|
|
564
|
+
|
|
560
565
|
exports.DATE_FORMAT = DATE_FORMAT;
|
|
561
566
|
exports.FORMAT_DATE = FORMAT_DATE;
|
|
562
567
|
exports.FORMAT_TIME = FORMAT_TIME;
|
|
@@ -566,6 +571,7 @@ exports.accAdd = accAdd;
|
|
|
566
571
|
exports.accDiv = accDiv;
|
|
567
572
|
exports.accMul = accMul;
|
|
568
573
|
exports.accSub = accSub;
|
|
574
|
+
exports.copyToClipboard = copyToClipboard;
|
|
569
575
|
exports.cutTimeFn = cutTimeFn;
|
|
570
576
|
exports.digitCnUppercase = digitCnUppercase;
|
|
571
577
|
exports.disableBrowserZoom = disableBrowserZoom;
|
|
@@ -578,7 +584,6 @@ exports.formatCash2 = formatCash2;
|
|
|
578
584
|
exports.formatCashInt = formatCashInt;
|
|
579
585
|
exports.formatCashIntNil = formatCashIntNil;
|
|
580
586
|
exports.formatCashNil = formatCashNil;
|
|
581
|
-
exports.formatCreditEnhanced = formatCreditEnhanced;
|
|
582
587
|
exports.formatDate = formatDate;
|
|
583
588
|
exports.formatDateNil = formatDateNil;
|
|
584
589
|
exports.formatDuration = formatDuration;
|
|
@@ -605,8 +610,6 @@ exports.isPhone = isPhone;
|
|
|
605
610
|
exports.isSMSCode = isSMSCode;
|
|
606
611
|
exports.isUndefined = isUndefined;
|
|
607
612
|
exports.log = log;
|
|
608
|
-
exports.normalizeFormValues = normalizeFormValues;
|
|
609
|
-
exports.normalizeSearchParams = normalizeSearchParams;
|
|
610
613
|
exports.os = os;
|
|
611
614
|
exports.playAudio = playAudio;
|
|
612
615
|
exports.random = random;
|
package/lib/lgutils.cjs.prod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("qs"),t=require("d3-format")
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("qs"),t=require("d3-format");function o(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r=o(require("moment"));const s=(...e)=>{console.group("====================="),console.info(...e),console.groupEnd()},n="undefined"!=typeof window,a=e=>e&&"number"==typeof e.size&&"string"==typeof e.type&&"function"==typeof e.slice,i=n?localStorage:{};let c={};const l=t.format(",.2f"),p=t.format(","),d=t.format(".2%"),u=f(l),h=f(p),m=f(d);function f(e){return t=>y(t)?w:e(t)}const x=e=>l(e/1e4),g=f(x),y=e=>null==e||""===e,w="——";function b(e,t="YYYY-MM-DD"){return r(new Date(e)).format(t)}const M=f(b),S={d:"天",m:"个月",y:"年"};function v(e){return e?`${parseInt(e,10)}${S[e.slice(-1).toLowerCase()]}`:e}const D=f(v);exports.DATE_FORMAT="YYYY/MM/DD",exports.FORMAT_DATE="YYYY-MM-DD",exports.FORMAT_TIME="YYYY-MM-DD HH:mm:ss",exports.NIL_STRING=w,exports.WS=class{constructor(e,t){this.socket=null,this.timer=null,this.ioUrl="",this.heartTime=1e4;this.ioUrl=e,this.socket=t?new WebSocket(e,t):new WebSocket(e)}init(e){const t=this;t.heartInfo=(null==e?void 0:e.heartInfo)?JSON.stringify(null==e?void 0:e.heartInfo):"ws HeartBeat!",t.socket.addEventListener("open",(()=>{s("ws connect!"),t.start(t.heartInfo),e.open&&e.open()}),!1),t.socket.addEventListener("disconnect",(()=>{console.info("[ws info]: disconnect and reconnect... "),e.disconnect&&e.disconnect(),t.socket=new WebSocket(t.ioUrl)}),!1),t.socket.addEventListener("error",(t=>{console.info("---------------"),console.info("[ws error]: "),console.info(t),console.info("---------------"),e.error&&e.error()}),!1),t.socket.addEventListener("close",e.close,!1),t.socket.addEventListener("message",(o=>{t.reset(),e.msg(o)}),!1)}close(){this.timer&&clearTimeout(this.timer),console.info("[ws close]: close!"),this.socket.close()}start(e){const t=this;t.timer=setTimeout((()=>{t.socket.send(e)}),t.heartTime)}send(e){this.socket.send(e)}reset(){const e=this;clearTimeout(e.timer),e.start(e.heartInfo)}getSocketState(){return this.socket.readyState}setHeartTime(e){this.heartTime=e,this.reset()}},exports.accAdd=(e,t)=>{let o,r,s;try{o=e.toString().split(".")[1].length}catch(n){o=0}try{r=t.toString().split(".")[1].length}catch(n){r=0}return s=Math.pow(10,Math.max(o,r)),(e*s+t*s)/s},exports.accDiv=(e,t)=>{let o,r,s=0,n=0;try{s=e.toString().split(".")[1].length}catch(a){}try{n=t.toString().split(".")[1].length}catch(a){}return o=Number(e.toString().replace(".","")),r=Number(t.toString().replace(".","")),o/r*Math.pow(10,n-s)},exports.accMul=(e,t)=>{let o=0,r=e.toString(),s=t.toString();try{o+=r.split(".")[1].length}catch(n){}try{o+=s.split(".")[1].length}catch(n){}return Number(r.replace(".",""))*Number(s.replace(".",""))/Math.pow(10,o)},exports.accSub=function(e,t){let o,r,s,n;try{o=e.toString().split(".")[1].length}catch(a){o=0}try{r=t.toString().split(".")[1].length}catch(a){r=0}return s=Math.pow(10,Math.max(o,r)),n=o>=r?o:r,((e*s-t*s)/s).toFixed(n)},exports.copyToClipboard=function(e){var t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)},exports.cutTimeFn=e=>`00‘${0===e?"00":"0"+Math.floor(e/60)}’${0===e?"00":e%60>=10?e%60:"0"+e%60}`,exports.digitCnUppercase=function(e){var t=["角","分"],o=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],r=[["元","万","亿"],["","拾","佰","仟"]],s=e<0?"欠":"";e=Math.abs(e);for(var n="",a=0;a<t.length;a++)n+=(o[Math.floor(10*e*Math.pow(10,a))%10]+t[a]).replace(/零./,"");for(n=n||"整",e=Math.floor(e),a=0;a<r[0].length&&e>0;a++){for(var i="",c=0;c<r[1].length&&e>0;c++)i=o[e%10]+r[1][c]+i,e=Math.floor(e/10);n=i.replace(/(零.)*零$/,"").replace(/^$/,"零")+r[0][a]+n}return s+n.replace(/(零.)*零元/,"元").replace(/(零.)+/g,"零").replace(/^整$/,"零元整")},exports.disableBrowserZoom=function(){document.addEventListener("keydown",(function(e){!0!==e.ctrlKey&&!0!==e.metaKey||61!==e.which&&107!==e.which&&173!==e.which&&109!==e.which&&187!==e.which&&189!==e.which||e.preventDefault()}),!1),window.addEventListener("mousewheel",(function(e){(!0===e.ctrlKey||e.metaKey)&&e.preventDefault()}),{passive:!1}),window.addEventListener("DOMMouseScroll",(function(e){(!0===e.ctrlKey||e.metaKey)&&e.preventDefault()}),{passive:!1})},exports.download=(e,t="download",o="application/octet-stream",r)=>{const s=window;let n=o,a=e;const i=document,c=i.createElement("a"),l=e=>String(e),p=s.Blob||l(c),d=t;let u=null,h=null;const m=(t,o)=>{if("download"in c)return c.href=r?e:t,c.setAttribute("download",d),c.innerHTML="downloading...",i.body.appendChild(c),setTimeout((()=>{c.click(),i.body.removeChild(c),!0===o&&setTimeout((()=>{s.URL.revokeObjectURL(c.href)}),250)}),66),!0;const n=i.createElement("iframe");i.body.appendChild(n),o||(t="data:"+t.replace(/^data:([\w\/\-\+]+)/,"application/octet-stream")),n.src=t,setTimeout((()=>{i.body.removeChild(n)}),333)};if(String(a).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/))return m(a);try{u=a instanceof p?a:new p([a],{type:n})}catch(f){}if(s.URL)m(s.URL.createObjectURL(u),!0);else{if("string"==typeof u||u.constructor===l(c))try{return m("data:"+n+";base64,"+s.btoa(u))}catch(f){return m("data:"+n+","+encodeURIComponent(u))}h=new FileReader,h.onload=function(){m(this.result)},h.readAsDataURL(u)}return!0},exports.fileReaderToBase64=e=>t=>{const o=new FileReader;o.onload=e=>{t&&t(e.target.result)},o.readAsDataURL(e)},exports.format10k=x,exports.format10kNil=g,exports.formatCash=l,exports.formatCash2=e=>(Math.floor(100*e)/100).toFixed(2),exports.formatCashInt=p,exports.formatCashIntNil=h,exports.formatCashNil=u,exports.formatDate=b,exports.formatDateNil=M,exports.formatDuration=v,exports.formatDurationNil=D,exports.formatRatio=d,exports.formatRatioNil=m,exports.getBase64=e=>new Promise(((t,o)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=()=>t(r.result),r.onerror=e=>o(e)})),exports.getItem=e=>((c[e]||i.getItem(""+e))&&(c[e]=JSON.parse(i.getItem(""+e)||"null")),c[e]),exports.getQueryObject=(t=window.location.href)=>{const o=t.split("?")[1];return e.parse(o||"")},exports.getSearchParams=e=>new URLSearchParams(e),exports.getValOfArr=e=>{const t=e.length,o=e.reduce(((e,t)=>e+t),0),r=e.reduce(((e,t)=>e*t),1);return{min:Math.min.apply(null,e),max:Math.max.apply(null,e),sum:o,average:o/t,mull:r}},exports.getValueWithNil=e=>y(e)?w:e,exports.inBrowser=n,exports.isArray=e=>Array.isArray(e),exports.isBlob=a,exports.isCardNo=e=>/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/.test(e),exports.isDate=e=>e instanceof Date,exports.isEmail=e=>/^(.+)@(.+)\.(.+)$/.test(e),exports.isFile=e=>a(e)&&"string"==typeof e.name&&("object"==typeof e.lastModifiedDate||"number"==typeof e.lastModified),exports.isNil=y,exports.isNull=e=>null===e,exports.isObject=e=>e===Object(e),exports.isPhone=e=>/^[1](\d{10})$/.test(e),exports.isSMSCode=e=>e.match(/^\d{6}$/),exports.isUndefined=e=>void 0===e,exports.log=s,exports.os=()=>{if(!n)return{isTablet:!1,isPhone:!1,isAndroid:!1,isPc:!1};const e=navigator.userAgent,t=/(?:Windows Phone)/.test(e),o=/(?:SymbianOS)/.test(e)||t,r=/(?:Android)/.test(e),s=/(?:Firefox)/.test(e),a=/(?:iPad|PlayBook)/.test(e)||r&&!/(?:Mobile)/.test(e)||s&&/(?:Tablet)/.test(e),i=/(?:iPhone)/.test(e)&&!a;return{isTablet:a,isPhone:i,isAndroid:r,isPc:!i&&!r&&!o}},exports.playAudio=e=>{const t=document.querySelectorAll("audio");Array.from(t).forEach((e=>{e.pause(),e.currentTime=0})),document.querySelector(`#${e}`).play()},exports.random=(e,t)=>Math.round(Math.random()*(t-e)+e),exports.randomString=(e=32)=>{const t="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",o=t.length;let r="";for(let s=0;s<e;s++)r+=t.charAt(Math.floor(Math.random()*o));return r},exports.removeAll=()=>(c={},i.clear()),exports.removeItem=e=>(delete c[e],i.removeItem(""+e)),exports.setItem=(e,t)=>(c[e]=t,i.setItem(""+e,JSON.stringify(t))),exports.setProxyObj=(e,t,o)=>new Proxy(e,{get:(e,o)=>(t(),Reflect.get(e,o)),set:(e,t,r)=>(o(),Reflect.set(e,t,r))}),exports.sortObj=(e,t,o="asc")=>e.sort(((e,r)=>"asc"===o?r[t]-e[t]:e[t]-r[t])),exports.sumObj=(e,t)=>e.reduce(((e,o)=>o[t]+e),0),exports.trimString=e=>e.replace(/(^\s*)|(\s*$)/g,"");
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { parse } from 'qs';
|
|
2
2
|
import { format } from 'd3-format';
|
|
3
|
-
import omit from 'lodash/omit';
|
|
4
3
|
import moment from 'moment';
|
|
5
4
|
|
|
6
5
|
const log = (...rest) => {
|
|
@@ -229,49 +228,44 @@ const SERVER_DATE_FROMAT = 'YYYY-MM-DD';
|
|
|
229
228
|
const DATE_FORMAT = 'YYYY/MM/DD';
|
|
230
229
|
const FORMAT_DATE = SERVER_DATE_FROMAT;
|
|
231
230
|
const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss';
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return function (yes) {
|
|
269
|
-
return yes ? field : '不' + field;
|
|
270
|
-
};
|
|
271
|
-
}
|
|
231
|
+
// type IndexType = { [x: string]: any }
|
|
232
|
+
// export function normalizeFormValues<T extends IndexType>(values: T) {
|
|
233
|
+
// return Object.entries(values)
|
|
234
|
+
// .filter(([key, value]) => value !== undefined && value !== 'all')
|
|
235
|
+
// .reduce((mem: any, [key, value]) => {
|
|
236
|
+
// // array for [moment, moment]
|
|
237
|
+
// if (Array.isArray(value) && value.some((val) => moment.isMoment(val))) {
|
|
238
|
+
// if (value[0]) {
|
|
239
|
+
// mem.startDate = value[0].format(SERVER_DATE_FROMAT)
|
|
240
|
+
// }
|
|
241
|
+
// if (value[1]) {
|
|
242
|
+
// mem.endDate = value[1].format(SERVER_DATE_FROMAT)
|
|
243
|
+
// }
|
|
244
|
+
// } else if (moment.isMoment(value)) {
|
|
245
|
+
// mem[key] = value.format(SERVER_DATE_FROMAT)
|
|
246
|
+
// } else mem[key] = value
|
|
247
|
+
// return mem
|
|
248
|
+
// }, {} as T)
|
|
249
|
+
// }
|
|
250
|
+
// export function normalizeSearchParams(params: IndexType) {
|
|
251
|
+
// if (params.startDate || params.endDate) {
|
|
252
|
+
// params = {
|
|
253
|
+
// ...omit(params, ['startDate', 'endDate']),
|
|
254
|
+
// dateRange: [
|
|
255
|
+
// params.startDate && moment(params.startDate),
|
|
256
|
+
// params.endDate && moment(params.endDate),
|
|
257
|
+
// ],
|
|
258
|
+
// }
|
|
259
|
+
// }
|
|
260
|
+
// Object.entries(params).forEach(([key, value]) => {
|
|
261
|
+
// if (typeof value === 'string' && value.includes(',')) {
|
|
262
|
+
// params[key] = 'all'
|
|
263
|
+
// }
|
|
264
|
+
// })
|
|
265
|
+
// return params
|
|
266
|
+
// }
|
|
272
267
|
const format10k = (n) => formatCash(n / 10000);
|
|
273
268
|
const format10kNil = withDefaultNil(format10k);
|
|
274
|
-
const formatCreditEnhanced = formatBool('增信');
|
|
275
269
|
// null == undefined
|
|
276
270
|
const isNil = (val) => val == null || val === '';
|
|
277
271
|
const NIL_STRING = '——';
|
|
@@ -280,7 +274,10 @@ const getValueWithNil = (val) => (isNil(val) ? NIL_STRING : val);
|
|
|
280
274
|
function digitCnUppercase(n) {
|
|
281
275
|
var fraction = ['角', '分'];
|
|
282
276
|
var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
283
|
-
var unit = [
|
|
277
|
+
var unit = [
|
|
278
|
+
['元', '万', '亿'],
|
|
279
|
+
['', '拾', '佰', '仟'],
|
|
280
|
+
];
|
|
284
281
|
var head = n < 0 ? '欠' : '';
|
|
285
282
|
n = Math.abs(n);
|
|
286
283
|
var s = '';
|
|
@@ -310,7 +307,7 @@ const formatDateNil = withDefaultNil(formatDate);
|
|
|
310
307
|
const unit = {
|
|
311
308
|
d: '天',
|
|
312
309
|
m: '个月',
|
|
313
|
-
y: '年'
|
|
310
|
+
y: '年',
|
|
314
311
|
};
|
|
315
312
|
function formatDuration(period) {
|
|
316
313
|
if (!period)
|
|
@@ -548,4 +545,13 @@ function disableBrowserZoom() {
|
|
|
548
545
|
});
|
|
549
546
|
}
|
|
550
547
|
|
|
551
|
-
|
|
548
|
+
function copyToClipboard(txt) {
|
|
549
|
+
var textarea = document.createElement('textarea');
|
|
550
|
+
textarea.value = txt;
|
|
551
|
+
document.body.appendChild(textarea);
|
|
552
|
+
textarea.select();
|
|
553
|
+
document.execCommand('copy');
|
|
554
|
+
document.body.removeChild(textarea);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, WS, accAdd, accDiv, accMul, accSub, copyToClipboard, cutTimeFn, digitCnUppercase, disableBrowserZoom, download, fileReaderToBase64, format10k, format10kNil, formatCash, formatCash2, formatCashInt, formatCashIntNil, formatCashNil, formatDate, formatDateNil, formatDuration, formatDurationNil, formatRatio, formatRatioNil, getBase64, getItem, getQueryObject, getSearchParams, getValOfArr, getValueWithNil, inBrowser, isArray, isBlob, isCardNo, isDate, isEmail, isFile, isNil, isNull, isObject, isPhone, isSMSCode, isUndefined, log, os, playAudio, random, randomString, removeAll, removeItem, setItem, setProxyObj, sortObj, sumObj, trimString };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lgutils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.13",
|
|
4
4
|
"description": "lgutils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "lib/lgutils.cjs.prod.js",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"@types/moment": "^2.13.0",
|
|
36
36
|
"@types/qs": "^6.9.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "a959d0e30cde5def91971ade7fc0a13640eeb8ed"
|
|
39
39
|
}
|