@jhqn/utils-core 0.0.1-beta.2 → 0.0.1-beta.21

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