lgutils 1.3.7 → 1.3.10
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 +233 -232
- package/lib/lgutils.cjs.js +14 -7
- package/lib/lgutils.cjs.prod.js +1 -1
- package/lib/lgutils.esm-bundler.js +14 -7
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,232 +1,233 @@
|
|
|
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 const cutTimeFn: (n: number) => string
|
|
10
|
-
|
|
11
|
-
export declare const DATE_FORMAT = 'YYYY/MM/DD'
|
|
12
|
-
|
|
13
|
-
export declare function digitCnUppercase(n: number): string
|
|
14
|
-
|
|
15
|
-
export declare const download: (
|
|
16
|
-
data: string,
|
|
17
|
-
strFileName?: string,
|
|
18
|
-
strMimeType?: string,
|
|
19
|
-
isImgUrl?: boolean | undefined
|
|
20
|
-
) => true | undefined
|
|
21
|
-
|
|
22
|
-
export declare const fileReaderToBase64: (
|
|
23
|
-
target: any
|
|
24
|
-
) => (cb: (p: any) => void) => void
|
|
25
|
-
|
|
26
|
-
export declare const format10k: (n: number) => string
|
|
27
|
-
|
|
28
|
-
export declare const format10kNil: (d: number | NIL) => string
|
|
29
|
-
|
|
30
|
-
export declare const FORMAT_DATE = 'YYYY-MM-DD'
|
|
31
|
-
|
|
32
|
-
export declare const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss'
|
|
33
|
-
|
|
34
|
-
export declare const formatCash: (
|
|
35
|
-
n:
|
|
36
|
-
| number
|
|
37
|
-
| {
|
|
38
|
-
valueOf(): number
|
|
39
|
-
}
|
|
40
|
-
) => string
|
|
41
|
-
|
|
42
|
-
export declare const formatCash2: (num: number) => string
|
|
43
|
-
|
|
44
|
-
export declare const formatCashInt: (
|
|
45
|
-
n:
|
|
46
|
-
| number
|
|
47
|
-
| {
|
|
48
|
-
valueOf(): number
|
|
49
|
-
}
|
|
50
|
-
) => string
|
|
51
|
-
|
|
52
|
-
export declare const formatCashIntNil: (
|
|
53
|
-
d:
|
|
54
|
-
| number
|
|
55
|
-
| {
|
|
56
|
-
valueOf(): number
|
|
57
|
-
}
|
|
58
|
-
| NIL
|
|
59
|
-
) => string
|
|
60
|
-
|
|
61
|
-
export declare const formatCashNil: (
|
|
62
|
-
d:
|
|
63
|
-
| number
|
|
64
|
-
| {
|
|
65
|
-
valueOf(): number
|
|
66
|
-
}
|
|
67
|
-
| NIL
|
|
68
|
-
) => string
|
|
69
|
-
|
|
70
|
-
export declare const formatCreditEnhanced: (yes: boolean) => string
|
|
71
|
-
|
|
72
|
-
export declare function formatDate(
|
|
73
|
-
d: string | number,
|
|
74
|
-
formatType?: string
|
|
75
|
-
): string
|
|
76
|
-
|
|
77
|
-
export declare const formatDateNil: (
|
|
78
|
-
d: string | number | null | undefined
|
|
79
|
-
) => string
|
|
80
|
-
|
|
81
|
-
export declare function formatDuration(period: string): string
|
|
82
|
-
|
|
83
|
-
export declare const formatDurationNil: (d: string | null | undefined) => string
|
|
84
|
-
|
|
85
|
-
export declare const formatRatio: (
|
|
86
|
-
n:
|
|
87
|
-
| number
|
|
88
|
-
| {
|
|
89
|
-
valueOf(): number
|
|
90
|
-
}
|
|
91
|
-
) => string
|
|
92
|
-
|
|
93
|
-
export declare const formatRatioNil: (
|
|
94
|
-
d:
|
|
95
|
-
| number
|
|
96
|
-
| {
|
|
97
|
-
valueOf(): number
|
|
98
|
-
}
|
|
99
|
-
| NIL
|
|
100
|
-
) => string
|
|
101
|
-
|
|
102
|
-
export declare const getBase64: (file: File) => Promise<unknown>
|
|
103
|
-
|
|
104
|
-
export declare const getItem: (key: string) => any
|
|
105
|
-
|
|
106
|
-
export declare const getQueryObject: (url?: string) => any
|
|
107
|
-
|
|
108
|
-
export declare const getSearchParams: (search: string) => URLSearchParams
|
|
109
|
-
|
|
110
|
-
export declare const getValOfArr: (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
export declare const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
export declare const
|
|
129
|
-
|
|
130
|
-
export declare const
|
|
131
|
-
|
|
132
|
-
export declare const
|
|
133
|
-
|
|
134
|
-
export declare const
|
|
135
|
-
|
|
136
|
-
export declare const
|
|
137
|
-
|
|
138
|
-
export declare const
|
|
139
|
-
|
|
140
|
-
export declare const
|
|
141
|
-
|
|
142
|
-
export declare const
|
|
143
|
-
|
|
144
|
-
export declare const
|
|
145
|
-
|
|
146
|
-
export declare const
|
|
147
|
-
|
|
148
|
-
export declare const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
private
|
|
223
|
-
constructor(ioUrl: string, token?: string)
|
|
224
|
-
init(obj: IWSObj): void
|
|
225
|
-
close(): void
|
|
226
|
-
start(): void
|
|
227
|
-
send(msg: AnyObj): void
|
|
228
|
-
reset(): void
|
|
229
|
-
getSocketState(): any
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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 const cutTimeFn: (n: number) => string
|
|
10
|
+
|
|
11
|
+
export declare const DATE_FORMAT = 'YYYY/MM/DD'
|
|
12
|
+
|
|
13
|
+
export declare function digitCnUppercase(n: number): string
|
|
14
|
+
|
|
15
|
+
export declare const download: (
|
|
16
|
+
data: string,
|
|
17
|
+
strFileName?: string,
|
|
18
|
+
strMimeType?: string,
|
|
19
|
+
isImgUrl?: boolean | undefined
|
|
20
|
+
) => true | undefined
|
|
21
|
+
|
|
22
|
+
export declare const fileReaderToBase64: (
|
|
23
|
+
target: any
|
|
24
|
+
) => (cb: (p: any) => void) => void
|
|
25
|
+
|
|
26
|
+
export declare const format10k: (n: number) => string
|
|
27
|
+
|
|
28
|
+
export declare const format10kNil: (d: number | NIL) => string
|
|
29
|
+
|
|
30
|
+
export declare const FORMAT_DATE = 'YYYY-MM-DD'
|
|
31
|
+
|
|
32
|
+
export declare const FORMAT_TIME = 'YYYY-MM-DD HH:mm:ss'
|
|
33
|
+
|
|
34
|
+
export declare const formatCash: (
|
|
35
|
+
n:
|
|
36
|
+
| number
|
|
37
|
+
| {
|
|
38
|
+
valueOf(): number
|
|
39
|
+
}
|
|
40
|
+
) => string
|
|
41
|
+
|
|
42
|
+
export declare const formatCash2: (num: number) => string
|
|
43
|
+
|
|
44
|
+
export declare const formatCashInt: (
|
|
45
|
+
n:
|
|
46
|
+
| number
|
|
47
|
+
| {
|
|
48
|
+
valueOf(): number
|
|
49
|
+
}
|
|
50
|
+
) => string
|
|
51
|
+
|
|
52
|
+
export declare const formatCashIntNil: (
|
|
53
|
+
d:
|
|
54
|
+
| number
|
|
55
|
+
| {
|
|
56
|
+
valueOf(): number
|
|
57
|
+
}
|
|
58
|
+
| NIL
|
|
59
|
+
) => string
|
|
60
|
+
|
|
61
|
+
export declare const formatCashNil: (
|
|
62
|
+
d:
|
|
63
|
+
| number
|
|
64
|
+
| {
|
|
65
|
+
valueOf(): number
|
|
66
|
+
}
|
|
67
|
+
| NIL
|
|
68
|
+
) => string
|
|
69
|
+
|
|
70
|
+
export declare const formatCreditEnhanced: (yes: boolean) => string
|
|
71
|
+
|
|
72
|
+
export declare function formatDate(
|
|
73
|
+
d: string | number,
|
|
74
|
+
formatType?: string
|
|
75
|
+
): string
|
|
76
|
+
|
|
77
|
+
export declare const formatDateNil: (
|
|
78
|
+
d: string | number | null | undefined
|
|
79
|
+
) => string
|
|
80
|
+
|
|
81
|
+
export declare function formatDuration(period: string): string
|
|
82
|
+
|
|
83
|
+
export declare const formatDurationNil: (d: string | null | undefined) => string
|
|
84
|
+
|
|
85
|
+
export declare const formatRatio: (
|
|
86
|
+
n:
|
|
87
|
+
| number
|
|
88
|
+
| {
|
|
89
|
+
valueOf(): number
|
|
90
|
+
}
|
|
91
|
+
) => string
|
|
92
|
+
|
|
93
|
+
export declare const formatRatioNil: (
|
|
94
|
+
d:
|
|
95
|
+
| number
|
|
96
|
+
| {
|
|
97
|
+
valueOf(): number
|
|
98
|
+
}
|
|
99
|
+
| NIL
|
|
100
|
+
) => string
|
|
101
|
+
|
|
102
|
+
export declare const getBase64: (file: File) => Promise<unknown>
|
|
103
|
+
|
|
104
|
+
export declare const getItem: (key: string) => any
|
|
105
|
+
|
|
106
|
+
export declare const getQueryObject: (url?: string) => any
|
|
107
|
+
|
|
108
|
+
export declare const getSearchParams: (search: string) => URLSearchParams
|
|
109
|
+
|
|
110
|
+
export declare const getValOfArr: (_array: number[]) => {
|
|
111
|
+
min: any
|
|
112
|
+
max: any
|
|
113
|
+
sum: number
|
|
114
|
+
average: number
|
|
115
|
+
mull: number
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export declare const getValueWithNil: (val: any) => any
|
|
119
|
+
|
|
120
|
+
export declare const inBrowser: boolean
|
|
121
|
+
|
|
122
|
+
declare type IndexType = {
|
|
123
|
+
[x: string]: any
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export declare const isArray: (value: any) => boolean
|
|
127
|
+
|
|
128
|
+
export declare const isBlob: (value: any) => any
|
|
129
|
+
|
|
130
|
+
export declare const isCardNo: (cardNum: any) => boolean
|
|
131
|
+
|
|
132
|
+
export declare const isDate: (value: any) => boolean
|
|
133
|
+
|
|
134
|
+
export declare const isEmail: (emailStr: string) => boolean
|
|
135
|
+
|
|
136
|
+
export declare const isFile: (value: any) => any
|
|
137
|
+
|
|
138
|
+
export declare const isNil: (val: any) => val is NIL
|
|
139
|
+
|
|
140
|
+
export declare const isNull: (value: any) => boolean
|
|
141
|
+
|
|
142
|
+
export declare const isObject: (value: any) => boolean
|
|
143
|
+
|
|
144
|
+
export declare const isPhone: (phone: any) => boolean
|
|
145
|
+
|
|
146
|
+
export declare const isSMSCode: (code: any) => any
|
|
147
|
+
|
|
148
|
+
export declare const isUndefined: (value: any) => boolean
|
|
149
|
+
|
|
150
|
+
declare interface IWSObj {
|
|
151
|
+
open?: (params?: any) => any
|
|
152
|
+
msg: (params: any) => any
|
|
153
|
+
error?: (params?: any) => any
|
|
154
|
+
disconnect?: (params?: any) => any
|
|
155
|
+
close?: (params?: any) => any
|
|
156
|
+
heartInfo?: any
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export declare const log: (...rest: any) => void
|
|
160
|
+
|
|
161
|
+
declare type NIL = undefined | null | ''
|
|
162
|
+
|
|
163
|
+
export declare const NIL_STRING = '\u2014\u2014'
|
|
164
|
+
|
|
165
|
+
export declare function normalizeFormValues<T extends IndexType>(values: T): any
|
|
166
|
+
|
|
167
|
+
export declare function normalizeSearchParams(params: IndexType): IndexType
|
|
168
|
+
|
|
169
|
+
export declare const os: () => {
|
|
170
|
+
isTablet: boolean
|
|
171
|
+
isPhone: boolean
|
|
172
|
+
isAndroid: boolean
|
|
173
|
+
isPc: boolean
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export declare const playAudio: (mp3Id: string) => void
|
|
177
|
+
|
|
178
|
+
export declare const random: (min: number, max: number) => number
|
|
179
|
+
|
|
180
|
+
export declare const randomString: (len?: number) => string
|
|
181
|
+
|
|
182
|
+
export declare const removeAll: () => any
|
|
183
|
+
|
|
184
|
+
export declare const removeItem: (key: string) => any
|
|
185
|
+
|
|
186
|
+
export declare const setItem: (key: string, value: any) => any
|
|
187
|
+
|
|
188
|
+
export declare const setProxyObj: (
|
|
189
|
+
data: object,
|
|
190
|
+
getFn: () => void,
|
|
191
|
+
setFn: () => void
|
|
192
|
+
) => object
|
|
193
|
+
|
|
194
|
+
export declare const sortObj: <
|
|
195
|
+
T extends keyof D,
|
|
196
|
+
D extends {
|
|
197
|
+
[key: string]: any
|
|
198
|
+
}
|
|
199
|
+
>(
|
|
200
|
+
obj: D[],
|
|
201
|
+
property: T,
|
|
202
|
+
type?: 'asc' | 'desc'
|
|
203
|
+
) => D[]
|
|
204
|
+
|
|
205
|
+
export declare const sumObj: <
|
|
206
|
+
T extends keyof D,
|
|
207
|
+
D extends {
|
|
208
|
+
[key: string]: any
|
|
209
|
+
}
|
|
210
|
+
>(
|
|
211
|
+
obj: D[],
|
|
212
|
+
key: T
|
|
213
|
+
) => number
|
|
214
|
+
|
|
215
|
+
export declare const trimString: (str: string) => string
|
|
216
|
+
|
|
217
|
+
export declare class WS {
|
|
218
|
+
socket: any
|
|
219
|
+
timer: any
|
|
220
|
+
ioUrl: string
|
|
221
|
+
heartInfo: any
|
|
222
|
+
private heartTime
|
|
223
|
+
constructor(ioUrl: string, token?: string)
|
|
224
|
+
init(obj: IWSObj): void
|
|
225
|
+
close(): void
|
|
226
|
+
start(info: string): void
|
|
227
|
+
send(msg: AnyObj): void
|
|
228
|
+
reset(): void
|
|
229
|
+
getSocketState(): any
|
|
230
|
+
setHeartTime(time: number): void
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export {}
|
package/lib/lgutils.cjs.js
CHANGED
|
@@ -458,16 +458,19 @@ class WS {
|
|
|
458
458
|
this.socket = null;
|
|
459
459
|
this.timer = null;
|
|
460
460
|
this.ioUrl = '';
|
|
461
|
-
this.
|
|
461
|
+
this.heartTime = 10000;
|
|
462
462
|
const that = this;
|
|
463
463
|
that.ioUrl = ioUrl;
|
|
464
464
|
that.socket = token ? new WebSocket(ioUrl, token) : new WebSocket(ioUrl);
|
|
465
465
|
}
|
|
466
466
|
init(obj) {
|
|
467
467
|
const that = this;
|
|
468
|
+
that.heartInfo = (obj === null || obj === void 0 ? void 0 : obj.heartInfo)
|
|
469
|
+
? JSON.stringify(obj === null || obj === void 0 ? void 0 : obj.heartInfo)
|
|
470
|
+
: `ws HeartBeat!`;
|
|
468
471
|
that.socket.addEventListener('open', () => {
|
|
469
472
|
log('ws connect!');
|
|
470
|
-
that.start();
|
|
473
|
+
that.start(that.heartInfo);
|
|
471
474
|
if (obj.open)
|
|
472
475
|
obj.open();
|
|
473
476
|
}, false);
|
|
@@ -497,23 +500,27 @@ class WS {
|
|
|
497
500
|
console.info('[ws close]: close!');
|
|
498
501
|
this.socket.close();
|
|
499
502
|
}
|
|
500
|
-
start() {
|
|
503
|
+
start(info) {
|
|
501
504
|
const that = this;
|
|
502
505
|
that.timer = setTimeout(() => {
|
|
503
|
-
that.socket.send(
|
|
504
|
-
}, that.
|
|
506
|
+
that.socket.send(info);
|
|
507
|
+
}, that.heartTime);
|
|
505
508
|
}
|
|
506
509
|
send(msg) {
|
|
507
510
|
const that = this;
|
|
508
511
|
that.socket.send(msg);
|
|
509
512
|
}
|
|
510
513
|
reset() {
|
|
511
|
-
|
|
512
|
-
|
|
514
|
+
const that = this;
|
|
515
|
+
clearTimeout(that.timer);
|
|
516
|
+
that.start(that.heartInfo);
|
|
513
517
|
}
|
|
514
518
|
getSocketState() {
|
|
515
519
|
return this.socket.readyState;
|
|
516
520
|
}
|
|
521
|
+
setHeartTime(time) {
|
|
522
|
+
this.heartTime = time;
|
|
523
|
+
}
|
|
517
524
|
}
|
|
518
525
|
|
|
519
526
|
exports.DATE_FORMAT = DATE_FORMAT;
|
package/lib/lgutils.cjs.prod.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("qs"),e=require("d3-format"),r=require("lodash/omit"),o=require("moment");function s(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var n=s(r),a=s(o);const i=(...t)=>{console.group("====================="),console.info(...t),console.groupEnd()},c="undefined"!=typeof window,l=t=>t&&"number"==typeof t.size&&"string"==typeof t.type&&"function"==typeof t.slice,p=c?localStorage:{};let d={};const m=e.format(",.2f"),u=e.format(","),f=e.format(".2%"),h=
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("qs"),e=require("d3-format"),r=require("lodash/omit"),o=require("moment");function s(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var n=s(r),a=s(o);const i=(...t)=>{console.group("====================="),console.info(...t),console.groupEnd()},c="undefined"!=typeof window,l=t=>t&&"number"==typeof t.size&&"string"==typeof t.type&&"function"==typeof t.slice,p=c?localStorage:{};let d={};const m=e.format(",.2f"),u=e.format(","),f=e.format(".2%"),h=y(m),x=y(u),g=y(f);function y(t){return e=>S(e)?Y:t(e)}const M=t=>m(t/1e4),b=y(M),w=(D="增信",function(t){return t?D:"不"+D});var D;const S=t=>null==t||""===t,Y="——";function A(t,e="YYYY-MM-DD"){return a(new Date(t)).format(e)}const v=y(A),T={d:"天",m:"个月",y:"年"};function R(t){return t?`${parseInt(t,10)}${T[t.slice(-1).toLowerCase()]}`:t}const k=y(R);exports.DATE_FORMAT="YYYY/MM/DD",exports.FORMAT_DATE="YYYY-MM-DD",exports.FORMAT_TIME="YYYY-MM-DD HH:mm:ss",exports.NIL_STRING=Y,exports.WS=class{constructor(t,e){this.socket=null,this.timer=null,this.ioUrl="",this.heartTime=1e4;this.ioUrl=t,this.socket=e?new WebSocket(t,e):new WebSocket(t)}init(t){const e=this;e.heartInfo=(null==t?void 0:t.heartInfo)?JSON.stringify(null==t?void 0:t.heartInfo):"ws HeartBeat!",e.socket.addEventListener("open",(()=>{i("ws connect!"),e.start(e.heartInfo),t.open&&t.open()}),!1),e.socket.addEventListener("disconnect",(()=>{console.info("[ws info]: disconnect and reconnect... "),t.disconnect&&t.disconnect(),e.socket=new WebSocket(e.ioUrl)}),!1),e.socket.addEventListener("error",(e=>{console.info("---------------"),console.info("[ws error]: "),console.info(e),console.info("---------------"),t.error&&t.error()}),!1),e.socket.addEventListener("close",t.close,!1),e.socket.addEventListener("message",(r=>{e.reset(),t.msg(r)}),!1)}close(){this.timer&&clearTimeout(this.timer),console.info("[ws close]: close!"),this.socket.close()}start(t){const e=this;e.timer=setTimeout((()=>{e.socket.send(t)}),e.heartTime)}send(t){this.socket.send(t)}reset(){const t=this;clearTimeout(t.timer),t.start(t.heartInfo)}getSocketState(){return this.socket.readyState}setHeartTime(t){this.heartTime=t}},exports.accAdd=(t,e)=>{let r,o,s;try{r=t.toString().split(".")[1].length}catch(n){r=0}try{o=e.toString().split(".")[1].length}catch(n){o=0}return s=Math.pow(10,Math.max(r,o)),(t*s+e*s)/s},exports.accDiv=(t,e)=>{let r,o,s=0,n=0;try{s=t.toString().split(".")[1].length}catch(a){}try{n=e.toString().split(".")[1].length}catch(a){}return r=Number(t.toString().replace(".","")),o=Number(e.toString().replace(".","")),r/o*Math.pow(10,n-s)},exports.accMul=(t,e)=>{let r=0,o=t.toString(),s=e.toString();try{r+=o.split(".")[1].length}catch(n){}try{r+=s.split(".")[1].length}catch(n){}return Number(o.replace(".",""))*Number(s.replace(".",""))/Math.pow(10,r)},exports.accSub=function(t,e){let r,o,s,n;try{r=t.toString().split(".")[1].length}catch(a){r=0}try{o=e.toString().split(".")[1].length}catch(a){o=0}return s=Math.pow(10,Math.max(r,o)),n=r>=o?r:o,((t*s-e*s)/s).toFixed(n)},exports.cutTimeFn=t=>`00‘${0===t?"00":"0"+Math.floor(t/60)}’${0===t?"00":t%60>=10?t%60:"0"+t%60}`,exports.digitCnUppercase=function(t){var e=["角","分"],r=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"],o=[["元","万","亿"],["","拾","佰","仟"]],s=t<0?"欠":"";t=Math.abs(t);for(var n="",a=0;a<e.length;a++)n+=(r[Math.floor(10*t*Math.pow(10,a))%10]+e[a]).replace(/零./,"");for(n=n||"整",t=Math.floor(t),a=0;a<o[0].length&&t>0;a++){for(var i="",c=0;c<o[1].length&&t>0;c++)i=r[t%10]+o[1][c]+i,t=Math.floor(t/10);n=i.replace(/(零.)*零$/,"").replace(/^$/,"零")+o[0][a]+n}return s+n.replace(/(零.)*零元/,"元").replace(/(零.)+/g,"零").replace(/^整$/,"零元整")},exports.download=(t,e="download",r="application/octet-stream",o)=>{const s=window;let n=r,a=t;const i=document,c=i.createElement("a"),l=t=>String(t),p=s.Blob||l(c),d=e;let m=null,u=null;const f=(e,r)=>{if("download"in c)return c.href=o?t:e,c.setAttribute("download",d),c.innerHTML="downloading...",i.body.appendChild(c),setTimeout((()=>{c.click(),i.body.removeChild(c),!0===r&&setTimeout((()=>{s.URL.revokeObjectURL(c.href)}),250)}),66),!0;const n=i.createElement("iframe");i.body.appendChild(n),r||(e="data:"+e.replace(/^data:([\w\/\-\+]+)/,"application/octet-stream")),n.src=e,setTimeout((()=>{i.body.removeChild(n)}),333)};if(String(a).match(/^data\:[\w+\-]+\/[\w+\-]+[,;]/))return f(a);try{m=a instanceof p?a:new p([a],{type:n})}catch(h){}if(s.URL)f(s.URL.createObjectURL(m),!0);else{if("string"==typeof m||m.constructor===l(c))try{return f("data:"+n+";base64,"+s.btoa(m))}catch(h){return f("data:"+n+","+encodeURIComponent(m))}u=new FileReader,u.onload=function(){f(this.result)},u.readAsDataURL(m)}return!0},exports.fileReaderToBase64=t=>e=>{const r=new FileReader;r.onload=t=>{e&&e(t.target.result)},r.readAsDataURL(t)},exports.format10k=M,exports.format10kNil=b,exports.formatCash=m,exports.formatCash2=t=>(Math.floor(100*t)/100).toFixed(2),exports.formatCashInt=u,exports.formatCashIntNil=x,exports.formatCashNil=h,exports.formatCreditEnhanced=w,exports.formatDate=A,exports.formatDateNil=v,exports.formatDuration=R,exports.formatDurationNil=k,exports.formatRatio=f,exports.formatRatioNil=g,exports.getBase64=t=>new Promise(((e,r)=>{const o=new FileReader;o.readAsDataURL(t),o.onload=()=>e(o.result),o.onerror=t=>r(t)})),exports.getItem=t=>((d[t]||p.getItem(""+t))&&(d[t]=JSON.parse(p.getItem(""+t)||"null")),d[t]),exports.getQueryObject=(e=window.location.href)=>{const r=e.split("?")[1];return t.parse(r||"")},exports.getSearchParams=t=>new URLSearchParams(t),exports.getValOfArr=t=>{const e=t.length,r=t.reduce(((t,e)=>t+e),0),o=t.reduce(((t,e)=>t*e),1);return{min:Math.min.apply(null,t),max:Math.max.apply(null,t),sum:r,average:r/e,mull:o}},exports.getValueWithNil=t=>S(t)?Y:t,exports.inBrowser=c,exports.isArray=t=>Array.isArray(t),exports.isBlob=l,exports.isCardNo=t=>/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/.test(t),exports.isDate=t=>t instanceof Date,exports.isEmail=t=>/^(.+)@(.+)\.(.+)$/.test(t),exports.isFile=t=>l(t)&&"string"==typeof t.name&&("object"==typeof t.lastModifiedDate||"number"==typeof t.lastModified),exports.isNil=S,exports.isNull=t=>null===t,exports.isObject=t=>t===Object(t),exports.isPhone=t=>/^[1](\d{10})$/.test(t),exports.isSMSCode=t=>t.match(/^\d{6}$/),exports.isUndefined=t=>void 0===t,exports.log=i,exports.normalizeFormValues=function(t){return Object.entries(t).filter((([t,e])=>void 0!==e&&"all"!==e)).reduce(((t,[e,r])=>(Array.isArray(r)&&r.some((t=>a.isMoment(t)))?(r[0]&&(t.startDate=r[0].format("YYYY-MM-DD")),r[1]&&(t.endDate=r[1].format("YYYY-MM-DD"))):t[e]=a.isMoment(r)?r.format("YYYY-MM-DD"):r,t)),{})},exports.normalizeSearchParams=function(t){return(t.startDate||t.endDate)&&(t=Object.assign(Object.assign({},n(t,["startDate","endDate"])),{dateRange:[t.startDate&&a(t.startDate),t.endDate&&a(t.endDate)]})),Object.entries(t).forEach((([e,r])=>{"string"==typeof r&&r.includes(",")&&(t[e]="all")})),t},exports.os=()=>{if(!c)return{isTablet:!1,isPhone:!1,isAndroid:!1,isPc:!1};const t=navigator.userAgent,e=/(?:Windows Phone)/.test(t),r=/(?:SymbianOS)/.test(t)||e,o=/(?:Android)/.test(t),s=/(?:Firefox)/.test(t),n=/(?:iPad|PlayBook)/.test(t)||o&&!/(?:Mobile)/.test(t)||s&&/(?:Tablet)/.test(t),a=/(?:iPhone)/.test(t)&&!n;return{isTablet:n,isPhone:a,isAndroid:o,isPc:!a&&!o&&!r}},exports.playAudio=t=>{const e=document.querySelectorAll("audio");Array.from(e).forEach((t=>{t.pause(),t.currentTime=0})),document.querySelector(`#${t}`).play()},exports.random=(t,e)=>Math.round(Math.random()*(e-t)+t),exports.randomString=(t=32)=>{const e="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",r=e.length;let o="";for(let s=0;s<t;s++)o+=e.charAt(Math.floor(Math.random()*r));return o},exports.removeAll=()=>(d={},p.clear()),exports.removeItem=t=>(delete d[t],p.removeItem(""+t)),exports.setItem=(t,e)=>(d[t]=e,p.setItem(""+t,JSON.stringify(e))),exports.setProxyObj=(t,e,r)=>new Proxy(t,{get:(t,r)=>(e(),Reflect.get(t,r)),set:(t,e,o)=>(r(),Reflect.set(t,e,o))}),exports.sortObj=(t,e,r="asc")=>t.sort(((t,o)=>"asc"===r?o[e]-t[e]:t[e]-o[e])),exports.sumObj=(t,e)=>t.reduce(((t,r)=>r[e]+t),0),exports.trimString=t=>t.replace(/(^\s*)|(\s*$)/g,"");
|
|
@@ -449,16 +449,19 @@ class WS {
|
|
|
449
449
|
this.socket = null;
|
|
450
450
|
this.timer = null;
|
|
451
451
|
this.ioUrl = '';
|
|
452
|
-
this.
|
|
452
|
+
this.heartTime = 10000;
|
|
453
453
|
const that = this;
|
|
454
454
|
that.ioUrl = ioUrl;
|
|
455
455
|
that.socket = token ? new WebSocket(ioUrl, token) : new WebSocket(ioUrl);
|
|
456
456
|
}
|
|
457
457
|
init(obj) {
|
|
458
458
|
const that = this;
|
|
459
|
+
that.heartInfo = (obj === null || obj === void 0 ? void 0 : obj.heartInfo)
|
|
460
|
+
? JSON.stringify(obj === null || obj === void 0 ? void 0 : obj.heartInfo)
|
|
461
|
+
: `ws HeartBeat!`;
|
|
459
462
|
that.socket.addEventListener('open', () => {
|
|
460
463
|
log('ws connect!');
|
|
461
|
-
that.start();
|
|
464
|
+
that.start(that.heartInfo);
|
|
462
465
|
if (obj.open)
|
|
463
466
|
obj.open();
|
|
464
467
|
}, false);
|
|
@@ -488,23 +491,27 @@ class WS {
|
|
|
488
491
|
console.info('[ws close]: close!');
|
|
489
492
|
this.socket.close();
|
|
490
493
|
}
|
|
491
|
-
start() {
|
|
494
|
+
start(info) {
|
|
492
495
|
const that = this;
|
|
493
496
|
that.timer = setTimeout(() => {
|
|
494
|
-
that.socket.send(
|
|
495
|
-
}, that.
|
|
497
|
+
that.socket.send(info);
|
|
498
|
+
}, that.heartTime);
|
|
496
499
|
}
|
|
497
500
|
send(msg) {
|
|
498
501
|
const that = this;
|
|
499
502
|
that.socket.send(msg);
|
|
500
503
|
}
|
|
501
504
|
reset() {
|
|
502
|
-
|
|
503
|
-
|
|
505
|
+
const that = this;
|
|
506
|
+
clearTimeout(that.timer);
|
|
507
|
+
that.start(that.heartInfo);
|
|
504
508
|
}
|
|
505
509
|
getSocketState() {
|
|
506
510
|
return this.socket.readyState;
|
|
507
511
|
}
|
|
512
|
+
setHeartTime(time) {
|
|
513
|
+
this.heartTime = time;
|
|
514
|
+
}
|
|
508
515
|
}
|
|
509
516
|
|
|
510
517
|
export { DATE_FORMAT, FORMAT_DATE, FORMAT_TIME, NIL_STRING, WS, accAdd, accDiv, accMul, accSub, cutTimeFn, digitCnUppercase, download, fileReaderToBase64, format10k, format10kNil, formatCash, formatCash2, formatCashInt, formatCashIntNil, formatCashNil, formatCreditEnhanced, 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, normalizeFormValues, normalizeSearchParams, 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.10",
|
|
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": "c332434122393a6ee6e267e4dce6fbabfae884f5"
|
|
39
39
|
}
|