@jhqn/utils-core 0.0.1-beta.2 → 0.0.1-beta.20
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/dist/index.cjs +85 -0
- package/dist/index.d.ts +254 -2
- package/dist/index.mjs +75 -1
- package/package.json +20 -15
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const detectBrowser = require('detect-browser');
|
|
4
|
+
|
|
3
5
|
const snake2Kebab = (str) => str.replace(/_([a-z])/g, (_, letter) => `-${letter.toLowerCase()}`);
|
|
4
6
|
const snake2Pascal = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^[a-z]/, (letter) => letter.toUpperCase());
|
|
5
7
|
const snake2Camel = (str) => str.replace(/(_([a-z]))/g, (match) => match[1].toUpperCase());
|
|
@@ -83,6 +85,23 @@ const isTel = (val) => {
|
|
|
83
85
|
return false;
|
|
84
86
|
return cnTelRE.test(val.toString());
|
|
85
87
|
};
|
|
88
|
+
const isEmail = (val) => {
|
|
89
|
+
if (!isDef(val))
|
|
90
|
+
return false;
|
|
91
|
+
const reg = /^[a-zA-Z\d](?:\w|-)+@[a-zA-Z\d]+\.[a-zA-Z]{2,5}$/;
|
|
92
|
+
return reg.test(val);
|
|
93
|
+
};
|
|
94
|
+
const isIdCard = (val) => {
|
|
95
|
+
if (!isDef(val))
|
|
96
|
+
return false;
|
|
97
|
+
const card15 = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dXx]$/;
|
|
98
|
+
const card18 = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:[0-2][1-9]|10|20|30|31)\d{3}[\dXx]$/;
|
|
99
|
+
return card15.test(val) || card18.test(val);
|
|
100
|
+
};
|
|
101
|
+
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
102
|
+
const isValidRes = (res) => res.code === 200 && isDef(res.data);
|
|
103
|
+
const isValidArrRes = (res) => res.code === 200 && Array.isArray(res.data);
|
|
104
|
+
const isValidPageRes = (res) => res.code === 200 && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
86
105
|
|
|
87
106
|
const hidePhone = (str) => {
|
|
88
107
|
if (str) {
|
|
@@ -138,6 +157,61 @@ const hideThird = (str) => {
|
|
|
138
157
|
return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
|
|
139
158
|
};
|
|
140
159
|
|
|
160
|
+
const inBrowser = typeof window !== "undefined";
|
|
161
|
+
const waitTime = (time = 100) => {
|
|
162
|
+
return new Promise((resolve) => {
|
|
163
|
+
setTimeout(() => {
|
|
164
|
+
resolve(true);
|
|
165
|
+
}, time);
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
const fixiOSInputAutoZoomIn = () => {
|
|
169
|
+
if (CSS.supports("(font:-apple-system-body) and (-webkit-touch-callout:none) and (-webkit-tap-highlight-color:hotpink)")) {
|
|
170
|
+
const viewport = document.querySelector('meta[name="viewport"]');
|
|
171
|
+
if (viewport !== null) {
|
|
172
|
+
viewport.content = `${viewport.content}, user-scalable=no`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const userAgent = inBrowser ? window.navigator.userAgent : "";
|
|
177
|
+
const getHostEnv = () => {
|
|
178
|
+
const ua = userAgent.toLowerCase();
|
|
179
|
+
const baseInfo = detectBrowser.detect();
|
|
180
|
+
const zlb = ua.includes("@zlb");
|
|
181
|
+
const zyd = ua.includes("saas");
|
|
182
|
+
const zzd = ua.includes("zhejiang") || ua.includes("tauruszjd");
|
|
183
|
+
const wx = ua.includes("micromessenger");
|
|
184
|
+
const zfb = ua.includes("alipay");
|
|
185
|
+
const mini = ua.includes("miniprogram");
|
|
186
|
+
return {
|
|
187
|
+
...baseInfo,
|
|
188
|
+
/**
|
|
189
|
+
* 是否是浙里办
|
|
190
|
+
*/
|
|
191
|
+
zlb,
|
|
192
|
+
/**
|
|
193
|
+
* 是否是专有钉
|
|
194
|
+
*/
|
|
195
|
+
zyd,
|
|
196
|
+
/**
|
|
197
|
+
* 是否是浙政钉
|
|
198
|
+
*/
|
|
199
|
+
zzd,
|
|
200
|
+
/**
|
|
201
|
+
* 是否是微信
|
|
202
|
+
*/
|
|
203
|
+
wx,
|
|
204
|
+
/**
|
|
205
|
+
* 是否是支付宝
|
|
206
|
+
*/
|
|
207
|
+
zfb,
|
|
208
|
+
/**
|
|
209
|
+
* 是否是小程序
|
|
210
|
+
*/
|
|
211
|
+
mini
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
|
|
141
215
|
const parseToJSON = (str, reviver2) => isJSONStr(str) ? JSON.parse(str, reviver2) : null;
|
|
142
216
|
const replacer = (_, value) => {
|
|
143
217
|
if (value instanceof Map) {
|
|
@@ -164,18 +238,26 @@ exports.camel2Snake = camel2Snake;
|
|
|
164
238
|
exports.camel2Title = camel2Title;
|
|
165
239
|
exports.checkImg = checkImg;
|
|
166
240
|
exports.filterObj = filterObj;
|
|
241
|
+
exports.fixiOSInputAutoZoomIn = fixiOSInputAutoZoomIn;
|
|
242
|
+
exports.getHostEnv = getHostEnv;
|
|
167
243
|
exports.hideCardNo = hideCardNo;
|
|
168
244
|
exports.hideMiddle = hideMiddle;
|
|
169
245
|
exports.hideName = hideName;
|
|
170
246
|
exports.hidePhone = hidePhone;
|
|
171
247
|
exports.hideThird = hideThird;
|
|
248
|
+
exports.inBrowser = inBrowser;
|
|
172
249
|
exports.isArrStr = isArrStr;
|
|
173
250
|
exports.isDef = isDef;
|
|
251
|
+
exports.isEmail = isEmail;
|
|
252
|
+
exports.isIdCard = isIdCard;
|
|
174
253
|
exports.isJSONStr = isJSONStr;
|
|
175
254
|
exports.isNumeric = isNumeric;
|
|
176
255
|
exports.isPhone = isPhone;
|
|
177
256
|
exports.isTel = isTel;
|
|
257
|
+
exports.isValidArrRes = isValidArrRes;
|
|
178
258
|
exports.isValidKey = isValidKey;
|
|
259
|
+
exports.isValidPageRes = isValidPageRes;
|
|
260
|
+
exports.isValidRes = isValidRes;
|
|
179
261
|
exports.jClear = jClear;
|
|
180
262
|
exports.jDebug = jDebug;
|
|
181
263
|
exports.jError = jError;
|
|
@@ -191,6 +273,7 @@ exports.kebab2Camel = kebab2Camel;
|
|
|
191
273
|
exports.kebab2Pascal = kebab2Pascal;
|
|
192
274
|
exports.kebab2Snake = kebab2Snake;
|
|
193
275
|
exports.kebab2Title = kebab2Title;
|
|
276
|
+
exports.nonASCII = nonASCII;
|
|
194
277
|
exports.parseToJSON = parseToJSON;
|
|
195
278
|
exports.pascal2Camel = pascal2Camel;
|
|
196
279
|
exports.pascal2Kebab = pascal2Kebab;
|
|
@@ -206,3 +289,5 @@ exports.title2Camel = title2Camel;
|
|
|
206
289
|
exports.title2Kebab = title2Kebab;
|
|
207
290
|
exports.title2Pascal = title2Pascal;
|
|
208
291
|
exports.title2Snake = title2Snake;
|
|
292
|
+
exports.userAgent = userAgent;
|
|
293
|
+
exports.waitTime = waitTime;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as detect_browser from 'detect-browser';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* snake2Kebab
|
|
3
5
|
* @param {string} str 字符串
|
|
@@ -212,6 +214,18 @@ declare type Undefinable<T> = T | undefined;
|
|
|
212
214
|
* 可 Null 或 Undefined
|
|
213
215
|
*/
|
|
214
216
|
declare type NullOrUndefinable<T> = Nullable<Undefinable<T>>;
|
|
217
|
+
/**
|
|
218
|
+
* 请求结果
|
|
219
|
+
*/
|
|
220
|
+
declare type Res<T = any> = Service.Response<T>;
|
|
221
|
+
/**
|
|
222
|
+
* 分页请求结果数据
|
|
223
|
+
*/
|
|
224
|
+
declare type PageResData<T = any> = Service.PageResponseData<T>;
|
|
225
|
+
/**
|
|
226
|
+
* 分页请求结果
|
|
227
|
+
*/
|
|
228
|
+
declare type PageRes<T = any> = Service.PageResponse<T>;
|
|
215
229
|
|
|
216
230
|
/**
|
|
217
231
|
* 隐藏手机号
|
|
@@ -239,12 +253,208 @@ declare const hideMiddle: (str: NullOrUndefinable<string>) => string;
|
|
|
239
253
|
*/
|
|
240
254
|
declare const hideThird: (str: NullOrUndefinable<string>) => string;
|
|
241
255
|
|
|
256
|
+
/**
|
|
257
|
+
* 判断是否是浏览器环境
|
|
258
|
+
*/
|
|
259
|
+
declare const inBrowser: boolean;
|
|
260
|
+
/**
|
|
261
|
+
* 等待一段时间
|
|
262
|
+
* @param time
|
|
263
|
+
*/
|
|
264
|
+
declare const waitTime: (time?: number) => Promise<unknown>;
|
|
265
|
+
/**
|
|
266
|
+
* 防止 iOS 因输入框字体小于16px 而在 focus 时页面缩放变大需要手动回正的情况。
|
|
267
|
+
* iOS 10+ 允许 pinch-zoom, 即使 viewport 是不可伸缩的。
|
|
268
|
+
* 只对这些浏览器添加额外规则
|
|
269
|
+
*/
|
|
270
|
+
declare const fixiOSInputAutoZoomIn: () => void;
|
|
271
|
+
/**
|
|
272
|
+
* 用户代理
|
|
273
|
+
*/
|
|
274
|
+
declare const userAgent: string;
|
|
275
|
+
/**
|
|
276
|
+
* 获取宿主环境信息
|
|
277
|
+
*/
|
|
278
|
+
declare const getHostEnv: () => {
|
|
279
|
+
/**
|
|
280
|
+
* 是否是浙里办
|
|
281
|
+
*/
|
|
282
|
+
zlb: boolean;
|
|
283
|
+
/**
|
|
284
|
+
* 是否是专有钉
|
|
285
|
+
*/
|
|
286
|
+
zyd: boolean;
|
|
287
|
+
/**
|
|
288
|
+
* 是否是浙政钉
|
|
289
|
+
*/
|
|
290
|
+
zzd: boolean;
|
|
291
|
+
/**
|
|
292
|
+
* 是否是微信
|
|
293
|
+
*/
|
|
294
|
+
wx: boolean;
|
|
295
|
+
/**
|
|
296
|
+
* 是否是支付宝
|
|
297
|
+
*/
|
|
298
|
+
zfb: boolean;
|
|
299
|
+
/**
|
|
300
|
+
* 是否是小程序
|
|
301
|
+
*/
|
|
302
|
+
mini: boolean;
|
|
303
|
+
} | {
|
|
304
|
+
/**
|
|
305
|
+
* 是否是浙里办
|
|
306
|
+
*/
|
|
307
|
+
zlb: boolean;
|
|
308
|
+
/**
|
|
309
|
+
* 是否是专有钉
|
|
310
|
+
*/
|
|
311
|
+
zyd: boolean;
|
|
312
|
+
/**
|
|
313
|
+
* 是否是浙政钉
|
|
314
|
+
*/
|
|
315
|
+
zzd: boolean;
|
|
316
|
+
/**
|
|
317
|
+
* 是否是微信
|
|
318
|
+
*/
|
|
319
|
+
wx: boolean;
|
|
320
|
+
/**
|
|
321
|
+
* 是否是支付宝
|
|
322
|
+
*/
|
|
323
|
+
zfb: boolean;
|
|
324
|
+
/**
|
|
325
|
+
* 是否是小程序
|
|
326
|
+
*/
|
|
327
|
+
mini: boolean;
|
|
328
|
+
name: detect_browser.Browser;
|
|
329
|
+
version: string;
|
|
330
|
+
os: detect_browser.OperatingSystem | null;
|
|
331
|
+
type: "browser";
|
|
332
|
+
} | {
|
|
333
|
+
/**
|
|
334
|
+
* 是否是浙里办
|
|
335
|
+
*/
|
|
336
|
+
zlb: boolean;
|
|
337
|
+
/**
|
|
338
|
+
* 是否是专有钉
|
|
339
|
+
*/
|
|
340
|
+
zyd: boolean;
|
|
341
|
+
/**
|
|
342
|
+
* 是否是浙政钉
|
|
343
|
+
*/
|
|
344
|
+
zzd: boolean;
|
|
345
|
+
/**
|
|
346
|
+
* 是否是微信
|
|
347
|
+
*/
|
|
348
|
+
wx: boolean;
|
|
349
|
+
/**
|
|
350
|
+
* 是否是支付宝
|
|
351
|
+
*/
|
|
352
|
+
zfb: boolean;
|
|
353
|
+
/**
|
|
354
|
+
* 是否是小程序
|
|
355
|
+
*/
|
|
356
|
+
mini: boolean;
|
|
357
|
+
name: detect_browser.Browser;
|
|
358
|
+
version: string;
|
|
359
|
+
os: detect_browser.OperatingSystem | null;
|
|
360
|
+
bot: string;
|
|
361
|
+
type: "bot-device";
|
|
362
|
+
} | {
|
|
363
|
+
/**
|
|
364
|
+
* 是否是浙里办
|
|
365
|
+
*/
|
|
366
|
+
zlb: boolean;
|
|
367
|
+
/**
|
|
368
|
+
* 是否是专有钉
|
|
369
|
+
*/
|
|
370
|
+
zyd: boolean;
|
|
371
|
+
/**
|
|
372
|
+
* 是否是浙政钉
|
|
373
|
+
*/
|
|
374
|
+
zzd: boolean;
|
|
375
|
+
/**
|
|
376
|
+
* 是否是微信
|
|
377
|
+
*/
|
|
378
|
+
wx: boolean;
|
|
379
|
+
/**
|
|
380
|
+
* 是否是支付宝
|
|
381
|
+
*/
|
|
382
|
+
zfb: boolean;
|
|
383
|
+
/**
|
|
384
|
+
* 是否是小程序
|
|
385
|
+
*/
|
|
386
|
+
mini: boolean;
|
|
387
|
+
type: "bot";
|
|
388
|
+
bot: true;
|
|
389
|
+
name: "bot";
|
|
390
|
+
version: null;
|
|
391
|
+
os: null;
|
|
392
|
+
} | {
|
|
393
|
+
/**
|
|
394
|
+
* 是否是浙里办
|
|
395
|
+
*/
|
|
396
|
+
zlb: boolean;
|
|
397
|
+
/**
|
|
398
|
+
* 是否是专有钉
|
|
399
|
+
*/
|
|
400
|
+
zyd: boolean;
|
|
401
|
+
/**
|
|
402
|
+
* 是否是浙政钉
|
|
403
|
+
*/
|
|
404
|
+
zzd: boolean;
|
|
405
|
+
/**
|
|
406
|
+
* 是否是微信
|
|
407
|
+
*/
|
|
408
|
+
wx: boolean;
|
|
409
|
+
/**
|
|
410
|
+
* 是否是支付宝
|
|
411
|
+
*/
|
|
412
|
+
zfb: boolean;
|
|
413
|
+
/**
|
|
414
|
+
* 是否是小程序
|
|
415
|
+
*/
|
|
416
|
+
mini: boolean;
|
|
417
|
+
version: string;
|
|
418
|
+
type: "node";
|
|
419
|
+
name: "node";
|
|
420
|
+
os: NodeJS.Platform;
|
|
421
|
+
} | {
|
|
422
|
+
/**
|
|
423
|
+
* 是否是浙里办
|
|
424
|
+
*/
|
|
425
|
+
zlb: boolean;
|
|
426
|
+
/**
|
|
427
|
+
* 是否是专有钉
|
|
428
|
+
*/
|
|
429
|
+
zyd: boolean;
|
|
430
|
+
/**
|
|
431
|
+
* 是否是浙政钉
|
|
432
|
+
*/
|
|
433
|
+
zzd: boolean;
|
|
434
|
+
/**
|
|
435
|
+
* 是否是微信
|
|
436
|
+
*/
|
|
437
|
+
wx: boolean;
|
|
438
|
+
/**
|
|
439
|
+
* 是否是支付宝
|
|
440
|
+
*/
|
|
441
|
+
zfb: boolean;
|
|
442
|
+
/**
|
|
443
|
+
* 是否是小程序
|
|
444
|
+
*/
|
|
445
|
+
mini: boolean;
|
|
446
|
+
type: "react-native";
|
|
447
|
+
name: "react-native";
|
|
448
|
+
version: null;
|
|
449
|
+
os: null;
|
|
450
|
+
};
|
|
451
|
+
|
|
242
452
|
/**
|
|
243
453
|
* Json字符串转对象
|
|
244
454
|
* @param str
|
|
245
455
|
* @param reviver
|
|
246
456
|
*/
|
|
247
|
-
declare const parseToJSON: <T = any>(str: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => T
|
|
457
|
+
declare const parseToJSON: <T = any>(str: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => Nullable<T>;
|
|
248
458
|
/**
|
|
249
459
|
* JSON.stringify() second param
|
|
250
460
|
* @param _
|
|
@@ -292,6 +502,18 @@ declare const isJSONStr: (str: string) => boolean;
|
|
|
292
502
|
* @param str
|
|
293
503
|
*/
|
|
294
504
|
declare const isArrStr: (str: string) => boolean;
|
|
505
|
+
/**
|
|
506
|
+
* 判断是否有效的key
|
|
507
|
+
* @param {string | number | symbol} key 键名
|
|
508
|
+
* @param {object} object 对象
|
|
509
|
+
* @example
|
|
510
|
+
*
|
|
511
|
+
* ```ts
|
|
512
|
+
* const obj = { a: 1, b: 2 }
|
|
513
|
+
* isValidKey('a', obj) // true
|
|
514
|
+
* ```
|
|
515
|
+
* @returns {boolean} boolean
|
|
516
|
+
*/
|
|
295
517
|
declare const isValidKey: (key: string | number | symbol, object: object) => key is never;
|
|
296
518
|
/**
|
|
297
519
|
* 是否是中国手机号
|
|
@@ -303,5 +525,35 @@ declare const isPhone: (val: NullOrUndefinable<Numeric>) => boolean;
|
|
|
303
525
|
* @param val
|
|
304
526
|
*/
|
|
305
527
|
declare const isTel: (val: NullOrUndefinable<Numeric>) => boolean;
|
|
528
|
+
/**
|
|
529
|
+
* 是否是邮箱
|
|
530
|
+
* @param val
|
|
531
|
+
*/
|
|
532
|
+
declare const isEmail: (val: NullOrUndefinable<string>) => boolean;
|
|
533
|
+
/**
|
|
534
|
+
* 是否是身份证
|
|
535
|
+
* @param val 身份证号
|
|
536
|
+
*/
|
|
537
|
+
declare const isIdCard: (val: NullOrUndefinable<string>) => boolean;
|
|
538
|
+
/**
|
|
539
|
+
* 包含非ASCII字符
|
|
540
|
+
* @param text
|
|
541
|
+
*/
|
|
542
|
+
declare const nonASCII: (text: string) => boolean;
|
|
543
|
+
/**
|
|
544
|
+
* 校验接口返回内容
|
|
545
|
+
* @param res
|
|
546
|
+
*/
|
|
547
|
+
declare const isValidRes: (res: Res) => boolean;
|
|
548
|
+
/**
|
|
549
|
+
* 校验接口数组返回内容
|
|
550
|
+
* @param res
|
|
551
|
+
*/
|
|
552
|
+
declare const isValidArrRes: (res: Res<any[]>) => boolean;
|
|
553
|
+
/**
|
|
554
|
+
* 校验接口分页返回内容
|
|
555
|
+
* @param res
|
|
556
|
+
*/
|
|
557
|
+
declare const isValidPageRes: (res: PageRes) => boolean;
|
|
306
558
|
|
|
307
|
-
export { NullOrUndefinable, Nullable, Numeric, Undefinable, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, isArrStr, isDef, isJSONStr, isNumeric, isPhone, isTel, isValidKey, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake };
|
|
559
|
+
export { NullOrUndefinable, Nullable, Numeric, PageRes, PageResData, Res, Undefinable, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, inBrowser, isArrStr, isDef, isEmail, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidKey, isValidPageRes, isValidRes, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, userAgent, waitTime };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { detect } from 'detect-browser';
|
|
2
|
+
|
|
1
3
|
const snake2Kebab = (str) => str.replace(/_([a-z])/g, (_, letter) => `-${letter.toLowerCase()}`);
|
|
2
4
|
const snake2Pascal = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^[a-z]/, (letter) => letter.toUpperCase());
|
|
3
5
|
const snake2Camel = (str) => str.replace(/(_([a-z]))/g, (match) => match[1].toUpperCase());
|
|
@@ -81,6 +83,23 @@ const isTel = (val) => {
|
|
|
81
83
|
return false;
|
|
82
84
|
return cnTelRE.test(val.toString());
|
|
83
85
|
};
|
|
86
|
+
const isEmail = (val) => {
|
|
87
|
+
if (!isDef(val))
|
|
88
|
+
return false;
|
|
89
|
+
const reg = /^[a-zA-Z\d](?:\w|-)+@[a-zA-Z\d]+\.[a-zA-Z]{2,5}$/;
|
|
90
|
+
return reg.test(val);
|
|
91
|
+
};
|
|
92
|
+
const isIdCard = (val) => {
|
|
93
|
+
if (!isDef(val))
|
|
94
|
+
return false;
|
|
95
|
+
const card15 = /^[1-9]\d{7}(?:0[1-9]|10|11|12)(?:[0-2][1-9]|10|20|30|31)\d{2}[\dXx]$/;
|
|
96
|
+
const card18 = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:[0-2][1-9]|10|20|30|31)\d{3}[\dXx]$/;
|
|
97
|
+
return card15.test(val) || card18.test(val);
|
|
98
|
+
};
|
|
99
|
+
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
100
|
+
const isValidRes = (res) => res.code === 200 && isDef(res.data);
|
|
101
|
+
const isValidArrRes = (res) => res.code === 200 && Array.isArray(res.data);
|
|
102
|
+
const isValidPageRes = (res) => res.code === 200 && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
84
103
|
|
|
85
104
|
const hidePhone = (str) => {
|
|
86
105
|
if (str) {
|
|
@@ -136,6 +155,61 @@ const hideThird = (str) => {
|
|
|
136
155
|
return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
|
|
137
156
|
};
|
|
138
157
|
|
|
158
|
+
const inBrowser = typeof window !== "undefined";
|
|
159
|
+
const waitTime = (time = 100) => {
|
|
160
|
+
return new Promise((resolve) => {
|
|
161
|
+
setTimeout(() => {
|
|
162
|
+
resolve(true);
|
|
163
|
+
}, time);
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
const fixiOSInputAutoZoomIn = () => {
|
|
167
|
+
if (CSS.supports("(font:-apple-system-body) and (-webkit-touch-callout:none) and (-webkit-tap-highlight-color:hotpink)")) {
|
|
168
|
+
const viewport = document.querySelector('meta[name="viewport"]');
|
|
169
|
+
if (viewport !== null) {
|
|
170
|
+
viewport.content = `${viewport.content}, user-scalable=no`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const userAgent = inBrowser ? window.navigator.userAgent : "";
|
|
175
|
+
const getHostEnv = () => {
|
|
176
|
+
const ua = userAgent.toLowerCase();
|
|
177
|
+
const baseInfo = detect();
|
|
178
|
+
const zlb = ua.includes("@zlb");
|
|
179
|
+
const zyd = ua.includes("saas");
|
|
180
|
+
const zzd = ua.includes("zhejiang") || ua.includes("tauruszjd");
|
|
181
|
+
const wx = ua.includes("micromessenger");
|
|
182
|
+
const zfb = ua.includes("alipay");
|
|
183
|
+
const mini = ua.includes("miniprogram");
|
|
184
|
+
return {
|
|
185
|
+
...baseInfo,
|
|
186
|
+
/**
|
|
187
|
+
* 是否是浙里办
|
|
188
|
+
*/
|
|
189
|
+
zlb,
|
|
190
|
+
/**
|
|
191
|
+
* 是否是专有钉
|
|
192
|
+
*/
|
|
193
|
+
zyd,
|
|
194
|
+
/**
|
|
195
|
+
* 是否是浙政钉
|
|
196
|
+
*/
|
|
197
|
+
zzd,
|
|
198
|
+
/**
|
|
199
|
+
* 是否是微信
|
|
200
|
+
*/
|
|
201
|
+
wx,
|
|
202
|
+
/**
|
|
203
|
+
* 是否是支付宝
|
|
204
|
+
*/
|
|
205
|
+
zfb,
|
|
206
|
+
/**
|
|
207
|
+
* 是否是小程序
|
|
208
|
+
*/
|
|
209
|
+
mini
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
|
|
139
213
|
const parseToJSON = (str, reviver2) => isJSONStr(str) ? JSON.parse(str, reviver2) : null;
|
|
140
214
|
const replacer = (_, value) => {
|
|
141
215
|
if (value instanceof Map) {
|
|
@@ -156,4 +230,4 @@ const reviver = (_, value) => {
|
|
|
156
230
|
};
|
|
157
231
|
const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
|
|
158
232
|
|
|
159
|
-
export { camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, isArrStr, isDef, isJSONStr, isNumeric, isPhone, isTel, isValidKey, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake };
|
|
233
|
+
export { camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, inBrowser, isArrStr, isDef, isEmail, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidKey, isValidPageRes, isValidRes, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, userAgent, waitTime };
|
package/package.json
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jhqn/utils-core",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1-beta.20",
|
|
3
5
|
"author": "jade-gjz <jiangang.zhang@jaderd.com>",
|
|
4
|
-
"
|
|
5
|
-
"keywords": [
|
|
6
|
-
"jade",
|
|
7
|
-
"utils"
|
|
8
|
-
],
|
|
6
|
+
"license": "MIT",
|
|
9
7
|
"homepage": "https://github.com/jaderd-jh/utils/tree/main/packages/core#readme",
|
|
10
8
|
"repository": {
|
|
11
9
|
"type": "git",
|
|
@@ -15,24 +13,31 @@
|
|
|
15
13
|
"bugs": {
|
|
16
14
|
"url": "https://github.com/jaderd-jh/utils/issues"
|
|
17
15
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"
|
|
16
|
+
"keywords": [
|
|
17
|
+
"jade",
|
|
18
|
+
"utils"
|
|
21
19
|
],
|
|
22
|
-
"
|
|
23
|
-
"module": "dist/index.mjs",
|
|
24
|
-
"types": "dist/index.d.ts",
|
|
20
|
+
"sideEffects": false,
|
|
25
21
|
"exports": {
|
|
26
22
|
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
27
24
|
"import": "./dist/index.mjs",
|
|
28
|
-
"require": "./dist/index.cjs"
|
|
29
|
-
"types": "./dist/index.d.ts"
|
|
25
|
+
"require": "./dist/index.cjs"
|
|
30
26
|
}
|
|
31
27
|
},
|
|
32
|
-
"
|
|
28
|
+
"main": "dist/index.cjs",
|
|
29
|
+
"module": "dist/index.mjs",
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"detect-browser": "^5.3.0"
|
|
36
|
+
},
|
|
33
37
|
"scripts": {
|
|
34
38
|
"test": "vitest",
|
|
35
39
|
"//build": "tsup",
|
|
36
|
-
"build": "unbuild"
|
|
40
|
+
"build": "unbuild",
|
|
41
|
+
"publint": "publint"
|
|
37
42
|
}
|
|
38
43
|
}
|