@jhqn/utils-core 0.0.1-beta.10 → 0.0.1-beta.11

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,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());
@@ -138,6 +140,60 @@ const hideThird = (str) => {
138
140
  return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
139
141
  };
140
142
 
143
+ const waitTime = (time = 100) => {
144
+ return new Promise((resolve) => {
145
+ setTimeout(() => {
146
+ resolve(true);
147
+ }, time);
148
+ });
149
+ };
150
+ const fixiOSInputAutoZoomIn = () => {
151
+ if (CSS.supports("(font:-apple-system-body) and (-webkit-touch-callout:none) and (-webkit-tap-highlight-color:hotpink)")) {
152
+ const viewport = document.querySelector('meta[name="viewport"]');
153
+ if (viewport !== null) {
154
+ viewport.content = `${viewport.content}, user-scalable=no`;
155
+ }
156
+ }
157
+ };
158
+ const { userAgent } = window.navigator;
159
+ const getHostEnv = () => {
160
+ const ua = userAgent.toLowerCase();
161
+ const baseInfo = detectBrowser.detect();
162
+ const zlb = ua.includes("@zlb");
163
+ const zyd = ua.includes("saas");
164
+ const zzd = ua.includes("zhejiang") || ua.includes("tauruszjd");
165
+ const wx = ua.includes("micromessenger");
166
+ const zfb = ua.includes("alipay");
167
+ const mini = ua.includes("miniprogram");
168
+ return {
169
+ ...baseInfo,
170
+ /**
171
+ * 是否是浙里办
172
+ */
173
+ zlb,
174
+ /**
175
+ * 是否是专有钉
176
+ */
177
+ zyd,
178
+ /**
179
+ * 是否是浙政钉
180
+ */
181
+ zzd,
182
+ /**
183
+ * 是否是微信
184
+ */
185
+ wx,
186
+ /**
187
+ * 是否是支付宝
188
+ */
189
+ zfb,
190
+ /**
191
+ * 是否是小程序
192
+ */
193
+ mini
194
+ };
195
+ };
196
+
141
197
  const parseToJSON = (str, reviver2) => isJSONStr(str) ? JSON.parse(str, reviver2) : null;
142
198
  const replacer = (_, value) => {
143
199
  if (value instanceof Map) {
@@ -164,6 +220,8 @@ exports.camel2Snake = camel2Snake;
164
220
  exports.camel2Title = camel2Title;
165
221
  exports.checkImg = checkImg;
166
222
  exports.filterObj = filterObj;
223
+ exports.fixiOSInputAutoZoomIn = fixiOSInputAutoZoomIn;
224
+ exports.getHostEnv = getHostEnv;
167
225
  exports.hideCardNo = hideCardNo;
168
226
  exports.hideMiddle = hideMiddle;
169
227
  exports.hideName = hideName;
@@ -206,3 +264,5 @@ exports.title2Camel = title2Camel;
206
264
  exports.title2Kebab = title2Kebab;
207
265
  exports.title2Pascal = title2Pascal;
208
266
  exports.title2Snake = title2Snake;
267
+ exports.userAgent = userAgent;
268
+ 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 字符串
@@ -239,6 +241,195 @@ declare const hideMiddle: (str: NullOrUndefinable<string>) => string;
239
241
  */
240
242
  declare const hideThird: (str: NullOrUndefinable<string>) => string;
241
243
 
244
+ /**
245
+ * 等待一段时间
246
+ * @param time
247
+ */
248
+ declare const waitTime: (time?: number) => Promise<unknown>;
249
+ /**
250
+ * 防止 iOS 因输入框字体小于16px 而在 focus 时页面缩放变大需要手动回正的情况。
251
+ * iOS 10+ 允许 pinch-zoom, 即使 viewport 是不可伸缩的。
252
+ * 只对这些浏览器添加额外规则
253
+ */
254
+ declare const fixiOSInputAutoZoomIn: () => void;
255
+ declare const userAgent: string;
256
+ /**
257
+ * 获取宿主环境信息
258
+ */
259
+ declare const getHostEnv: () => {
260
+ /**
261
+ * 是否是浙里办
262
+ */
263
+ zlb: boolean;
264
+ /**
265
+ * 是否是专有钉
266
+ */
267
+ zyd: boolean;
268
+ /**
269
+ * 是否是浙政钉
270
+ */
271
+ zzd: boolean;
272
+ /**
273
+ * 是否是微信
274
+ */
275
+ wx: boolean;
276
+ /**
277
+ * 是否是支付宝
278
+ */
279
+ zfb: boolean;
280
+ /**
281
+ * 是否是小程序
282
+ */
283
+ mini: boolean;
284
+ } | {
285
+ /**
286
+ * 是否是浙里办
287
+ */
288
+ zlb: boolean;
289
+ /**
290
+ * 是否是专有钉
291
+ */
292
+ zyd: boolean;
293
+ /**
294
+ * 是否是浙政钉
295
+ */
296
+ zzd: boolean;
297
+ /**
298
+ * 是否是微信
299
+ */
300
+ wx: boolean;
301
+ /**
302
+ * 是否是支付宝
303
+ */
304
+ zfb: boolean;
305
+ /**
306
+ * 是否是小程序
307
+ */
308
+ mini: boolean;
309
+ name: detect_browser.Browser;
310
+ version: string;
311
+ os: detect_browser.OperatingSystem | null;
312
+ type: "browser";
313
+ } | {
314
+ /**
315
+ * 是否是浙里办
316
+ */
317
+ zlb: boolean;
318
+ /**
319
+ * 是否是专有钉
320
+ */
321
+ zyd: boolean;
322
+ /**
323
+ * 是否是浙政钉
324
+ */
325
+ zzd: boolean;
326
+ /**
327
+ * 是否是微信
328
+ */
329
+ wx: boolean;
330
+ /**
331
+ * 是否是支付宝
332
+ */
333
+ zfb: boolean;
334
+ /**
335
+ * 是否是小程序
336
+ */
337
+ mini: boolean;
338
+ name: detect_browser.Browser;
339
+ version: string;
340
+ os: detect_browser.OperatingSystem | null;
341
+ bot: string;
342
+ type: "bot-device";
343
+ } | {
344
+ /**
345
+ * 是否是浙里办
346
+ */
347
+ zlb: boolean;
348
+ /**
349
+ * 是否是专有钉
350
+ */
351
+ zyd: boolean;
352
+ /**
353
+ * 是否是浙政钉
354
+ */
355
+ zzd: boolean;
356
+ /**
357
+ * 是否是微信
358
+ */
359
+ wx: boolean;
360
+ /**
361
+ * 是否是支付宝
362
+ */
363
+ zfb: boolean;
364
+ /**
365
+ * 是否是小程序
366
+ */
367
+ mini: boolean;
368
+ type: "bot";
369
+ bot: true;
370
+ name: "bot";
371
+ version: null;
372
+ os: null;
373
+ } | {
374
+ /**
375
+ * 是否是浙里办
376
+ */
377
+ zlb: boolean;
378
+ /**
379
+ * 是否是专有钉
380
+ */
381
+ zyd: boolean;
382
+ /**
383
+ * 是否是浙政钉
384
+ */
385
+ zzd: boolean;
386
+ /**
387
+ * 是否是微信
388
+ */
389
+ wx: boolean;
390
+ /**
391
+ * 是否是支付宝
392
+ */
393
+ zfb: boolean;
394
+ /**
395
+ * 是否是小程序
396
+ */
397
+ mini: boolean;
398
+ version: string;
399
+ type: "node";
400
+ name: "node";
401
+ os: NodeJS.Platform;
402
+ } | {
403
+ /**
404
+ * 是否是浙里办
405
+ */
406
+ zlb: boolean;
407
+ /**
408
+ * 是否是专有钉
409
+ */
410
+ zyd: boolean;
411
+ /**
412
+ * 是否是浙政钉
413
+ */
414
+ zzd: boolean;
415
+ /**
416
+ * 是否是微信
417
+ */
418
+ wx: boolean;
419
+ /**
420
+ * 是否是支付宝
421
+ */
422
+ zfb: boolean;
423
+ /**
424
+ * 是否是小程序
425
+ */
426
+ mini: boolean;
427
+ type: "react-native";
428
+ name: "react-native";
429
+ version: null;
430
+ os: null;
431
+ };
432
+
242
433
  /**
243
434
  * Json字符串转对象
244
435
  * @param str
@@ -304,4 +495,4 @@ declare const isPhone: (val: NullOrUndefinable<Numeric>) => boolean;
304
495
  */
305
496
  declare const isTel: (val: NullOrUndefinable<Numeric>) => boolean;
306
497
 
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 };
498
+ export { NullOrUndefinable, Nullable, Numeric, Undefinable, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, 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, 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());
@@ -136,6 +138,60 @@ const hideThird = (str) => {
136
138
  return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
137
139
  };
138
140
 
141
+ const waitTime = (time = 100) => {
142
+ return new Promise((resolve) => {
143
+ setTimeout(() => {
144
+ resolve(true);
145
+ }, time);
146
+ });
147
+ };
148
+ const fixiOSInputAutoZoomIn = () => {
149
+ if (CSS.supports("(font:-apple-system-body) and (-webkit-touch-callout:none) and (-webkit-tap-highlight-color:hotpink)")) {
150
+ const viewport = document.querySelector('meta[name="viewport"]');
151
+ if (viewport !== null) {
152
+ viewport.content = `${viewport.content}, user-scalable=no`;
153
+ }
154
+ }
155
+ };
156
+ const { userAgent } = window.navigator;
157
+ const getHostEnv = () => {
158
+ const ua = userAgent.toLowerCase();
159
+ const baseInfo = detect();
160
+ const zlb = ua.includes("@zlb");
161
+ const zyd = ua.includes("saas");
162
+ const zzd = ua.includes("zhejiang") || ua.includes("tauruszjd");
163
+ const wx = ua.includes("micromessenger");
164
+ const zfb = ua.includes("alipay");
165
+ const mini = ua.includes("miniprogram");
166
+ return {
167
+ ...baseInfo,
168
+ /**
169
+ * 是否是浙里办
170
+ */
171
+ zlb,
172
+ /**
173
+ * 是否是专有钉
174
+ */
175
+ zyd,
176
+ /**
177
+ * 是否是浙政钉
178
+ */
179
+ zzd,
180
+ /**
181
+ * 是否是微信
182
+ */
183
+ wx,
184
+ /**
185
+ * 是否是支付宝
186
+ */
187
+ zfb,
188
+ /**
189
+ * 是否是小程序
190
+ */
191
+ mini
192
+ };
193
+ };
194
+
139
195
  const parseToJSON = (str, reviver2) => isJSONStr(str) ? JSON.parse(str, reviver2) : null;
140
196
  const replacer = (_, value) => {
141
197
  if (value instanceof Map) {
@@ -156,4 +212,4 @@ const reviver = (_, value) => {
156
212
  };
157
213
  const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
158
214
 
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 };
215
+ export { camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, 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, userAgent, waitTime };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jhqn/utils-core",
3
3
  "type": "module",
4
- "version": "0.0.1-beta.10",
4
+ "version": "0.0.1-beta.11",
5
5
  "author": "jade-gjz <jiangang.zhang@jaderd.com>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/jaderd-jh/utils/tree/main/packages/core#readme",
@@ -31,6 +31,9 @@
31
31
  "files": [
32
32
  "dist"
33
33
  ],
34
+ "dependencies": {
35
+ "detect-browser": "^5.3.0"
36
+ },
34
37
  "scripts": {
35
38
  "test": "vitest",
36
39
  "//build": "tsup",