@jhqn/utils-core 0.4.4 → 0.4.5
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.js +5 -22
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import duration from "dayjs/plugin/duration.js";
|
|
|
5
5
|
import localeData from "dayjs/plugin/localeData.js";
|
|
6
6
|
import objectSupport from "dayjs/plugin/objectSupport.js";
|
|
7
7
|
import relativeTime from "dayjs/plugin/relativeTime.js";
|
|
8
|
-
|
|
9
8
|
//#region src/case.ts
|
|
10
9
|
/**
|
|
11
10
|
* snake2Kebab
|
|
@@ -150,7 +149,6 @@ const title2Pascal = (str) => str.replace(/ /g, "");
|
|
|
150
149
|
* @example title2Camel('Hello World') // Hello World => helloWorld
|
|
151
150
|
*/
|
|
152
151
|
const title2Camel = (str) => str.replace(/ /g, "").replace(/^[A-Z]/, (match) => match.toLowerCase());
|
|
153
|
-
|
|
154
152
|
//#endregion
|
|
155
153
|
//#region src/console/log-common.ts
|
|
156
154
|
const sharedStyle = "color: white; padding: 1px 2px;";
|
|
@@ -185,7 +183,7 @@ const jGroup = console.group.bind(console, "%c[%s]", `${sharedStyle} background:
|
|
|
185
183
|
/**
|
|
186
184
|
* jade console.groupCollapsed
|
|
187
185
|
*/
|
|
188
|
-
const jGroupC = console
|
|
186
|
+
const jGroupC = console?.groupCollapsed?.bind(console, "%c[%s]", `${sharedStyle} background: slateblue;`);
|
|
189
187
|
/**
|
|
190
188
|
* jade console.groupEnd
|
|
191
189
|
*/
|
|
@@ -194,17 +192,16 @@ const jGroupE = console.groupEnd.bind(console);
|
|
|
194
192
|
* jade console.time
|
|
195
193
|
* @param str
|
|
196
194
|
*/
|
|
197
|
-
const jTime = (str) => console
|
|
195
|
+
const jTime = (str) => console?.time(`[${str}]`);
|
|
198
196
|
/**
|
|
199
197
|
* jade console.timeEnd
|
|
200
198
|
* @param str
|
|
201
199
|
*/
|
|
202
|
-
const jTimeEnd = (str) => console
|
|
200
|
+
const jTimeEnd = (str) => console?.timeEnd(`[${str}]`);
|
|
203
201
|
/**
|
|
204
202
|
* jade console.clear
|
|
205
203
|
*/
|
|
206
|
-
const jClear = console
|
|
207
|
-
|
|
204
|
+
const jClear = console?.clear?.bind(console);
|
|
208
205
|
//#endregion
|
|
209
206
|
//#region src/console/log-dedupe.ts
|
|
210
207
|
let prevValue;
|
|
@@ -218,7 +215,6 @@ const jLogDedupe = (...args) => {
|
|
|
218
215
|
jLog(...args);
|
|
219
216
|
prevValue = args;
|
|
220
217
|
};
|
|
221
|
-
|
|
222
218
|
//#endregion
|
|
223
219
|
//#region src/console/log-once.ts
|
|
224
220
|
let logged = false;
|
|
@@ -231,7 +227,6 @@ const jLogOnce = (...args) => {
|
|
|
231
227
|
jLog(...args);
|
|
232
228
|
logged = true;
|
|
233
229
|
};
|
|
234
|
-
|
|
235
230
|
//#endregion
|
|
236
231
|
//#region src/validate/core.ts
|
|
237
232
|
/**
|
|
@@ -407,7 +402,6 @@ const isValidKey = (key, object) => key in object;
|
|
|
407
402
|
const isEmpty = (val) => {
|
|
408
403
|
return !isDef(val) || val === "" || isArray(val) && val.length === 0 || isObject(val) && Object.keys(val).length === 0 || isMap(val) && val.size === 0 || isSet(val) && val.size === 0;
|
|
409
404
|
};
|
|
410
|
-
|
|
411
405
|
//#endregion
|
|
412
406
|
//#region src/validate/form.ts
|
|
413
407
|
const cnPhoneRE = /^1[3-9]\d{9}$/;
|
|
@@ -508,7 +502,6 @@ const isValidFileType = (file, type) => {
|
|
|
508
502
|
if (typeArrStr.length > 1) return typeArrStr.some(validate);
|
|
509
503
|
return validate(type);
|
|
510
504
|
};
|
|
511
|
-
|
|
512
505
|
//#endregion
|
|
513
506
|
//#region src/validate/request.ts
|
|
514
507
|
/**
|
|
@@ -535,7 +528,6 @@ const isValidArrRes = (res, code) => isValidResCode(res, code) && isArray(res.da
|
|
|
535
528
|
* @param code
|
|
536
529
|
*/
|
|
537
530
|
const isValidPageRes = (res, code) => isValidResCode(res, code) && isDef(res.data) && isArray(res.data.list || res.data.records);
|
|
538
|
-
|
|
539
531
|
//#endregion
|
|
540
532
|
//#region src/desensitize.ts
|
|
541
533
|
/**
|
|
@@ -723,7 +715,6 @@ const hideBankCard = (bankCard) => {
|
|
|
723
715
|
}
|
|
724
716
|
return "";
|
|
725
717
|
};
|
|
726
|
-
|
|
727
718
|
//#endregion
|
|
728
719
|
//#region src/format/baseAttachUrl.ts
|
|
729
720
|
/**
|
|
@@ -743,7 +734,6 @@ function setBaseAttachUrl(baseUrl) {
|
|
|
743
734
|
function getBaseAttachUrl() {
|
|
744
735
|
return __BASE_ATTACH_URL__;
|
|
745
736
|
}
|
|
746
|
-
|
|
747
737
|
//#endregion
|
|
748
738
|
//#region src/format/core.ts
|
|
749
739
|
/**
|
|
@@ -817,7 +807,6 @@ function reviver(_key, value) {
|
|
|
817
807
|
* @param {boolean} reverse 为true时过滤取反
|
|
818
808
|
*/
|
|
819
809
|
const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
|
|
820
|
-
|
|
821
810
|
//#endregion
|
|
822
811
|
//#region src/format/currency.ts
|
|
823
812
|
/**
|
|
@@ -845,7 +834,6 @@ const currencyFmt = (currency, maximumFractionDigits = 2) => {
|
|
|
845
834
|
maximumFractionDigits
|
|
846
835
|
}).format(num);
|
|
847
836
|
};
|
|
848
|
-
|
|
849
837
|
//#endregion
|
|
850
838
|
//#region src/format/dayjs.ts
|
|
851
839
|
dayjs.extend(localeData).locale("zh-cn", zhCN);
|
|
@@ -887,7 +875,6 @@ const dateDuration = (start, end) => {
|
|
|
887
875
|
].join("");
|
|
888
876
|
return dd.format(format);
|
|
889
877
|
};
|
|
890
|
-
|
|
891
878
|
//#endregion
|
|
892
879
|
//#region src/format/resource.ts
|
|
893
880
|
/**
|
|
@@ -940,7 +927,6 @@ const attachFmt = (data) => {
|
|
|
940
927
|
else if (prototype === "[object Object]") attachList = [data];
|
|
941
928
|
return attachList.map(recoverFile);
|
|
942
929
|
};
|
|
943
|
-
|
|
944
930
|
//#endregion
|
|
945
931
|
//#region src/format/sort.ts
|
|
946
932
|
/**
|
|
@@ -977,7 +963,6 @@ const naturalSort = (arr) => {
|
|
|
977
963
|
const naturalSortBy = (arr, key) => {
|
|
978
964
|
return [...arr].sort((a, b) => naturalSort([a[key], b[key]])[0] === a[key] ? -1 : 1);
|
|
979
965
|
};
|
|
980
|
-
|
|
981
966
|
//#endregion
|
|
982
967
|
//#region src/dom.ts
|
|
983
968
|
/**
|
|
@@ -1056,7 +1041,6 @@ const getCodeOfDate = () => getCodeOfTime(dateFmt(/* @__PURE__ */ new Date(), "d
|
|
|
1056
1041
|
* 获取当月的时间戳的异或值的绝对值, 当月内获取的值是唯一的
|
|
1057
1042
|
*/
|
|
1058
1043
|
const getCodeOfMonth = () => getCodeOfTime(dateFmt(dayjs().endOf("month"), "date"));
|
|
1059
|
-
|
|
1060
1044
|
//#endregion
|
|
1061
1045
|
//#region src/mock.ts
|
|
1062
1046
|
const getMockData = (data, code = 200, message = "success") => {
|
|
@@ -1078,6 +1062,5 @@ const getMockDataList = (data, total, code = 200, message = "success", options =
|
|
|
1078
1062
|
message
|
|
1079
1063
|
};
|
|
1080
1064
|
};
|
|
1081
|
-
|
|
1082
1065
|
//#endregion
|
|
1083
|
-
export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, cnIdCard15Re, cnIdCard18Re, cnPhoneRE, cnTelRE, cnTelRE2, cnUSCIRE, currencyFmt, dateDuration, dateFmt, dayjs, emailRE, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getMockData, getMockDataList, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUSCI, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, naturalSort, naturalSortBy, nonASCII, parseJSON, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, stringifyJSON, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
|
1066
|
+
export { attachFmt, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, cnIdCard15Re, cnIdCard18Re, cnPhoneRE, cnTelRE, cnTelRE2, cnUSCIRE, currencyFmt, dateDuration, dateFmt, dayjs, emailRE, filterObj, fixiOSInputAutoZoomIn, getBaseAttachUrl, getCodeOfDate, getCodeOfHour, getCodeOfMonth, getHostEnv, getMockData, getMockDataList, getVariableType, hideBankCard, hideCardNo, hideEmail, hideFirstName, hideHead, hideMiddle, hidePhone, hideSurname, hideTail, hideThird, inBrowser, isArrStr, isArray, isBigInt, isBlob, isBoolean, isDate, isDef, isEmail, isEmpty, isError, isFile, isFunction, isIdCard, isJSONStr, isMap, isNull, isNumber, isNumeric, isObject, isPhone, isPromise, isRegExp, isSet, isString, isSymbol, isTel, isURL, isUSCI, isUndefined, isValidArrRes, isValidFileType, isValidKey, isValidPageRes, isValidRes, isValidResCode, isWeakMap, isWeakSet, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jLogDedupe, jLogOnce, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, naturalSort, naturalSortBy, nonASCII, parseJSON, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, recoverFile, replacer, resUrl, reviver, setBaseAttachUrl, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, stringifyJSON, title2Camel, title2Kebab, title2Pascal, title2Snake, toThousands, userAgent, waitTime };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jhqn/utils-core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"jade",
|
|
6
6
|
"utils"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"dayjs": "^1.11.
|
|
36
|
+
"dayjs": "^1.11.20",
|
|
37
37
|
"detect-browser-es": "0.1.1"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|