@jhqn/utils-core 0.0.1-beta.18 → 0.0.1-beta.19
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 +5 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.mjs +5 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -99,9 +99,9 @@ const isIdCard = (val) => {
|
|
|
99
99
|
return card15.test(val) || card18.test(val);
|
|
100
100
|
};
|
|
101
101
|
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
102
|
-
const isValidRes = (res) => res.code === 200 && res.data;
|
|
102
|
+
const isValidRes = (res) => res.code === 200 && isDef(res.data);
|
|
103
103
|
const isValidArrRes = (res) => res.code === 200 && Array.isArray(res.data);
|
|
104
|
-
const isValidPageRes = (res) => res.code === 200 && res.data && Array.isArray(res.data.list || res.data.records);
|
|
104
|
+
const isValidPageRes = (res) => res.code === 200 && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
105
105
|
|
|
106
106
|
const hidePhone = (str) => {
|
|
107
107
|
if (str) {
|
|
@@ -157,6 +157,7 @@ const hideThird = (str) => {
|
|
|
157
157
|
return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
+
const inBrowser = typeof window !== "undefined";
|
|
160
161
|
const waitTime = (time = 100) => {
|
|
161
162
|
return new Promise((resolve) => {
|
|
162
163
|
setTimeout(() => {
|
|
@@ -172,7 +173,7 @@ const fixiOSInputAutoZoomIn = () => {
|
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
};
|
|
175
|
-
const userAgent =
|
|
176
|
+
const userAgent = inBrowser ? window.navigator.userAgent : "";
|
|
176
177
|
const getHostEnv = () => {
|
|
177
178
|
const ua = userAgent.toLowerCase();
|
|
178
179
|
const baseInfo = detectBrowser.detect();
|
|
@@ -244,6 +245,7 @@ exports.hideMiddle = hideMiddle;
|
|
|
244
245
|
exports.hideName = hideName;
|
|
245
246
|
exports.hidePhone = hidePhone;
|
|
246
247
|
exports.hideThird = hideThird;
|
|
248
|
+
exports.inBrowser = inBrowser;
|
|
247
249
|
exports.isArrStr = isArrStr;
|
|
248
250
|
exports.isDef = isDef;
|
|
249
251
|
exports.isEmail = isEmail;
|
package/dist/index.d.ts
CHANGED
|
@@ -253,6 +253,10 @@ declare const hideMiddle: (str: NullOrUndefinable<string>) => string;
|
|
|
253
253
|
*/
|
|
254
254
|
declare const hideThird: (str: NullOrUndefinable<string>) => string;
|
|
255
255
|
|
|
256
|
+
/**
|
|
257
|
+
* 判断是否是浏览器环境
|
|
258
|
+
*/
|
|
259
|
+
declare const inBrowser: boolean;
|
|
256
260
|
/**
|
|
257
261
|
* 等待一段时间
|
|
258
262
|
* @param time
|
|
@@ -264,6 +268,9 @@ declare const waitTime: (time?: number) => Promise<unknown>;
|
|
|
264
268
|
* 只对这些浏览器添加额外规则
|
|
265
269
|
*/
|
|
266
270
|
declare const fixiOSInputAutoZoomIn: () => void;
|
|
271
|
+
/**
|
|
272
|
+
* 用户代理
|
|
273
|
+
*/
|
|
267
274
|
declare const userAgent: string;
|
|
268
275
|
/**
|
|
269
276
|
* 获取宿主环境信息
|
|
@@ -447,7 +454,7 @@ declare const getHostEnv: () => {
|
|
|
447
454
|
* @param str
|
|
448
455
|
* @param reviver
|
|
449
456
|
*/
|
|
450
|
-
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>;
|
|
451
458
|
/**
|
|
452
459
|
* JSON.stringify() second param
|
|
453
460
|
* @param _
|
|
@@ -495,6 +502,18 @@ declare const isJSONStr: (str: string) => boolean;
|
|
|
495
502
|
* @param str
|
|
496
503
|
*/
|
|
497
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
|
+
*/
|
|
498
517
|
declare const isValidKey: (key: string | number | symbol, object: object) => key is never;
|
|
499
518
|
/**
|
|
500
519
|
* 是否是中国手机号
|
|
@@ -525,7 +544,7 @@ declare const nonASCII: (text: string) => boolean;
|
|
|
525
544
|
* 校验接口返回内容
|
|
526
545
|
* @param res
|
|
527
546
|
*/
|
|
528
|
-
declare const isValidRes: (res: Res) =>
|
|
547
|
+
declare const isValidRes: (res: Res) => boolean;
|
|
529
548
|
/**
|
|
530
549
|
* 校验接口数组返回内容
|
|
531
550
|
* @param res
|
|
@@ -537,4 +556,4 @@ declare const isValidArrRes: (res: Res<any[]>) => boolean;
|
|
|
537
556
|
*/
|
|
538
557
|
declare const isValidPageRes: (res: PageRes) => boolean;
|
|
539
558
|
|
|
540
|
-
export { NullOrUndefinable, Nullable, Numeric, PageRes, PageResData, Res, Undefinable, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, 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 };
|
|
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
|
@@ -97,9 +97,9 @@ const isIdCard = (val) => {
|
|
|
97
97
|
return card15.test(val) || card18.test(val);
|
|
98
98
|
};
|
|
99
99
|
const nonASCII = (text) => /[^\x20-\x7E]/.test(text);
|
|
100
|
-
const isValidRes = (res) => res.code === 200 && res.data;
|
|
100
|
+
const isValidRes = (res) => res.code === 200 && isDef(res.data);
|
|
101
101
|
const isValidArrRes = (res) => res.code === 200 && Array.isArray(res.data);
|
|
102
|
-
const isValidPageRes = (res) => res.code === 200 && res.data && Array.isArray(res.data.list || res.data.records);
|
|
102
|
+
const isValidPageRes = (res) => res.code === 200 && isDef(res.data) && Array.isArray(res.data.list || res.data.records);
|
|
103
103
|
|
|
104
104
|
const hidePhone = (str) => {
|
|
105
105
|
if (str) {
|
|
@@ -155,6 +155,7 @@ const hideThird = (str) => {
|
|
|
155
155
|
return str.slice(0, partLen) + "*".repeat(len - 2 * partLen) + str.slice(len - partLen);
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
+
const inBrowser = typeof window !== "undefined";
|
|
158
159
|
const waitTime = (time = 100) => {
|
|
159
160
|
return new Promise((resolve) => {
|
|
160
161
|
setTimeout(() => {
|
|
@@ -170,7 +171,7 @@ const fixiOSInputAutoZoomIn = () => {
|
|
|
170
171
|
}
|
|
171
172
|
}
|
|
172
173
|
};
|
|
173
|
-
const userAgent =
|
|
174
|
+
const userAgent = inBrowser ? window.navigator.userAgent : "";
|
|
174
175
|
const getHostEnv = () => {
|
|
175
176
|
const ua = userAgent.toLowerCase();
|
|
176
177
|
const baseInfo = detect();
|
|
@@ -229,4 +230,4 @@ const reviver = (_, value) => {
|
|
|
229
230
|
};
|
|
230
231
|
const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
|
|
231
232
|
|
|
232
|
-
export { camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, 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 };
|
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jhqn/utils-core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.19",
|
|
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",
|