@jhqn/utils-core 0.4.5 → 0.4.6

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.d.ts CHANGED
@@ -3,9 +3,7 @@
3
3
  /// <reference types="dayjs/plugin/relativeTime" />
4
4
  /// <reference types="dayjs/plugin/customParseFormat" />
5
5
  /// <reference types="dayjs/plugin/objectSupport" />
6
-
7
6
  import dayjs, { ConfigType, Dayjs } from "dayjs";
8
-
9
7
  //#region types/index.d.ts
10
8
  /**
11
9
  * 数字或字符串
@@ -538,16 +536,25 @@ declare const filterObj: (obj: Record<string, any>, keys: string[], reverse?: bo
538
536
  declare const toThousands: (num: number) => string;
539
537
  /**
540
538
  * 货币格式化
539
+ * @example
540
+ * ```ts
541
+ * currencyFmt(123456.789) // "¥123,456.79"
542
+ * ```
541
543
  * @param {number | string | bigint} currency - 金额
542
- * @param {number} [maximumFractionDigits] - 小数位数
544
+ * @param {number} [maximumFractionDigits] - 最多小数位数
543
545
  */
544
546
  declare const currencyFmt: (currency: UnDef<Numeric | bigint>, maximumFractionDigits?: number) => string;
545
547
  //#endregion
546
548
  //#region src/format/dayjs.d.ts
547
549
  /**
548
550
  * 格式化时间
551
+ * @example
552
+ * ```ts
553
+ * dateFmt(new Date(), 'date') // 2024-06-01
554
+ * dateFmt(dayjs(), 'datetime') // 2024-06-01 12:34:56
555
+ * ```
549
556
  * @param {import('dayjs').ConfigType} date 时间
550
- * @param {string} format 格式
557
+ * @param {string} [format = "datetime"] 格式化pattern
551
558
  * @returns {string} 格式化后的时间
552
559
  */
553
560
  declare const dateFmt: (date: ConfigType, format?: string | "date" | "datetime") => string;
@@ -718,6 +725,11 @@ declare const isArray: (val: any) => val is Array<any>;
718
725
  * @param {any} val 检测的目标
719
726
  */
720
727
  declare const isFunction: (val: any) => val is Function;
728
+ /**
729
+ * 是否是纯函数(不包含 Class,含原生构造函数如 Date、Array 等)
730
+ * @param {any} val 检测的目标
731
+ */
732
+ declare const isPureFunction: (val: any) => val is Function;
721
733
  /**
722
734
  * 是否是日期
723
735
  * @param {any} val 检测的目标
@@ -895,4 +907,4 @@ declare const isValidArrRes: (res: Res<any[]>, code?: number) => boolean;
895
907
  */
896
908
  declare const isValidPageRes: (res: PageRes, code?: number) => boolean;
897
909
  //#endregion
898
- export { type Dayjs, type Dict, type HostEnv, type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageReq, type PageRes, type PageResData, type PartialBy, type Res, type UnDef, type Undefinable, type VK, 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 };
910
+ export { type Dayjs, type Dict, type HostEnv, type MaybeArray, type NullOrUndefinable, type Nullable, type Numeric, type PageReq, type PageRes, type PageResData, type PartialBy, type Res, type UnDef, type Undefinable, type VK, 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, isPureFunction, 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/dist/index.js CHANGED
@@ -283,7 +283,18 @@ const isArray = (val) => Array.isArray(val);
283
283
  * 是否是函数,但也有可能是Class
284
284
  * @param {any} val 检测的目标
285
285
  */
286
- const isFunction = (val) => getVariableType(val) === "function";
286
+ const isFunction = (val) => typeof val === "function";
287
+ /**
288
+ * 是否是纯函数(不包含 Class,含原生构造函数如 Date、Array 等)
289
+ * @param {any} val 检测的目标
290
+ */
291
+ const isPureFunction = (val) => {
292
+ if (!isFunction(val)) return false;
293
+ const source = Function.prototype.toString.call(val);
294
+ if (source.startsWith("class")) return false;
295
+ if (source.includes("[native code]") && val.prototype !== void 0) return false;
296
+ return true;
297
+ };
287
298
  /**
288
299
  * 是否是日期
289
300
  * @param {any} val 检测的目标
@@ -821,8 +832,12 @@ const toThousands = (num) => {
821
832
  };
822
833
  /**
823
834
  * 货币格式化
835
+ * @example
836
+ * ```ts
837
+ * currencyFmt(123456.789) // "¥123,456.79"
838
+ * ```
824
839
  * @param {number | string | bigint} currency - 金额
825
- * @param {number} [maximumFractionDigits] - 小数位数
840
+ * @param {number} [maximumFractionDigits] - 最多小数位数
826
841
  */
827
842
  const currencyFmt = (currency, maximumFractionDigits = 2) => {
828
843
  if (!isDef(currency)) return "";
@@ -843,11 +858,16 @@ dayjs.extend(customParseFormat);
843
858
  dayjs.extend(objectSupport);
844
859
  /**
845
860
  * 格式化时间
861
+ * @example
862
+ * ```ts
863
+ * dateFmt(new Date(), 'date') // 2024-06-01
864
+ * dateFmt(dayjs(), 'datetime') // 2024-06-01 12:34:56
865
+ * ```
846
866
  * @param {import('dayjs').ConfigType} date 时间
847
- * @param {string} format 格式
867
+ * @param {string} [format = "datetime"] 格式化pattern
848
868
  * @returns {string} 格式化后的时间
849
869
  */
850
- const dateFmt = (date, format = "YYYY-MM-DD HH:mm:ss") => {
870
+ const dateFmt = (date, format = "datetime") => {
851
871
  const dd = dayjs(date);
852
872
  let fmt = format;
853
873
  if (!isDef(date) || !dd.isValid()) return "";
@@ -1063,4 +1083,4 @@ const getMockDataList = (data, total, code = 200, message = "success", options =
1063
1083
  };
1064
1084
  };
1065
1085
  //#endregion
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 };
1086
+ 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, isPureFunction, 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.5",
3
+ "version": "0.4.6",
4
4
  "keywords": [
5
5
  "jade",
6
6
  "utils"
@@ -33,7 +33,7 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "dayjs": "^1.11.20",
36
+ "dayjs": "^1.11.21",
37
37
  "detect-browser-es": "0.1.1"
38
38
  },
39
39
  "scripts": {