@semi-kit/utils 0.0.1 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semi-kit/utils",
3
- "version": "0.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "General-purpose tool function library",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -11,18 +11,18 @@
11
11
  "publishConfig": {
12
12
  "access": "public"
13
13
  },
14
- "main": "./dist/index.mjs",
15
- "module": "./dist/index.mjs",
16
- "types": "./dist/index.d.mts",
14
+ "main": "./lib/index.mjs",
15
+ "module": "./lib/index.mjs",
16
+ "types": "./lib/index.d.mts",
17
17
  "exports": {
18
- ".": "./dist/index.mjs",
19
- "./axios": "./dist/axios.mjs",
20
- "./color": "./dist/color.mjs",
21
- "./datetime": "./dist/datetime.mjs",
22
- "./device": "./dist/device.mjs",
23
- "./extra": "./dist/extra.mjs",
24
- "./localstorage": "./dist/localstorage.mjs",
25
- "./number": "./dist/number.mjs",
18
+ ".": "./lib/index.mjs",
19
+ "./axios": "./lib/axios.mjs",
20
+ "./color": "./lib/color.mjs",
21
+ "./datetime": "./lib/datetime.mjs",
22
+ "./device": "./lib/device.mjs",
23
+ "./extra": "./lib/extra.mjs",
24
+ "./localstorage": "./lib/localstorage.mjs",
25
+ "./number": "./lib/number.mjs",
26
26
  "./package.json": "./package.json"
27
27
  },
28
28
  "scripts": {
package/dist/axios.d.mts DELETED
@@ -1,18 +0,0 @@
1
- import { ParamsSerializerOptions } from "axios";
2
-
3
- //#region src/axios.d.ts
4
-
5
- /**
6
- * @description: 过滤请求参数:null undefined '' {} []
7
- * @param {object} data { name: 'Tom', age: null, link: '', address: undefined, items: [], info: {} }
8
- * @return {*} { name:'Tom' }
9
- */
10
- declare const useOmitNilRequestParams: (data: object) => object;
11
- /**
12
- * @description: Axios 参数序列化
13
- * @param {*} ParamsSerializerOptions
14
- * @return {*}
15
- */
16
- declare const useParamsSerializer: () => ParamsSerializerOptions;
17
- //#endregion
18
- export { useOmitNilRequestParams, useParamsSerializer };
package/dist/axios.mjs DELETED
@@ -1,22 +0,0 @@
1
- import { stringify } from "qs";
2
- import { isNil, omitBy } from "es-toolkit";
3
- import { isEmpty } from "es-toolkit/compat";
4
-
5
- //#region src/axios.ts
6
- /**
7
- * @description: 过滤请求参数:null undefined '' {} []
8
- * @param {object} data { name: 'Tom', age: null, link: '', address: undefined, items: [], info: {} }
9
- * @return {*} { name:'Tom' }
10
- */
11
- const useOmitNilRequestParams = (data) => omitBy(data, (e) => isNil(e) || e === "" || typeof e === "object" && isEmpty(e));
12
- /**
13
- * @description: Axios 参数序列化
14
- * @param {*} ParamsSerializerOptions
15
- * @return {*}
16
- */
17
- const useParamsSerializer = () => {
18
- return { serialize: (params) => stringify(params, { arrayFormat: "repeat" }) };
19
- };
20
-
21
- //#endregion
22
- export { useOmitNilRequestParams, useParamsSerializer };
package/dist/color.d.mts DELETED
@@ -1,10 +0,0 @@
1
- //#region src/color.d.ts
2
- declare const hexToRgb: (hex: string) => {
3
- r: number;
4
- g: number;
5
- b: number;
6
- };
7
- declare const rgbToHex: (r: number, g: number, b: number) => string;
8
- declare const randomHex: () => string;
9
- //#endregion
10
- export { hexToRgb, randomHex, rgbToHex };
package/dist/color.mjs DELETED
@@ -1,14 +0,0 @@
1
- //#region src/color.ts
2
- const hexToRgb = (hex) => {
3
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
4
- return {
5
- r: parseInt(result?.[1] ?? "0", 16),
6
- g: parseInt(result?.[2] ?? "0", 16),
7
- b: parseInt(result?.[3] ?? "0", 16)
8
- };
9
- };
10
- const rgbToHex = (r, g, b) => `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;
11
- const randomHex = () => `#${Math.floor(Math.random() * 16777215).toString(16).padEnd(6, "0")}`;
12
-
13
- //#endregion
14
- export { hexToRgb, randomHex, rgbToHex };
@@ -1,46 +0,0 @@
1
- import { DateLike } from "@vueuse/core";
2
-
3
- //#region src/datetime.d.ts
4
- interface FormatDateRangeParamsType {
5
- endTimeType?: "now" | "full";
6
- format?: string;
7
- }
8
- declare const getDayOfYear: (date?: DateLike) => number | undefined;
9
- declare const isWeekday: (date?: DateLike) => boolean;
10
- /**
11
- * @description: 时间转换为标准时间
12
- * @param {*} name:时间戳
13
- * @param {*} type:生成时间格式
14
- * @return {*} 14:25:59
15
- */
16
- declare const useFormatTime: (time?: DateLike, type?: string) => string;
17
- /**
18
- * @description: 时间转换为标准日期
19
- * @param {*} name:时间
20
- * @param {*} type:生成时间格式
21
- * @return {*} 2022-11-09
22
- */
23
- declare const useFormatDate: (time?: DateLike, type?: string) => string;
24
- /**
25
- * @description: 日期时间 -> 日期时间请求参数
26
- * @param {string} timestamp:时间数据
27
- * @param {*} field:日期时间字段名称
28
- * @param {*} start:开始字段名称
29
- * @param {*} end:结束字段名称
30
- * @return {*}
31
- */
32
- declare const useFormatDateTimeParams: (timestamp: string[] | null | undefined, field?: string, start?: string, end?: string) => {
33
- [x: string]: string | undefined;
34
- } | undefined;
35
- /**
36
- * @description: 转换为标准时间范围
37
- * @param {*} day 往前推*天数
38
- * @param {FormatDateRangeParamsType}
39
- * @return {*}
40
- */
41
- declare const useFormatDateRange: (day?: number, {
42
- endTimeType,
43
- format
44
- }?: FormatDateRangeParamsType) => string[];
45
- //#endregion
46
- export { FormatDateRangeParamsType, getDayOfYear, isWeekday, useFormatDate, useFormatDateRange, useFormatDateTimeParams, useFormatTime };
package/dist/datetime.mjs DELETED
@@ -1,64 +0,0 @@
1
- import { useDateFormat } from "@vueuse/core";
2
-
3
- //#region src/datetime.ts
4
- const getDayOfYear = (date = /* @__PURE__ */ new Date()) => {
5
- if (!date) return;
6
- const startOfYear = new Date(new Date(date).getFullYear(), 0, 0);
7
- const diff = new Date(date).getTime() - startOfYear.getTime();
8
- return Math.floor(diff / (1e3 * 60 * 60 * 24));
9
- };
10
- const isWeekday = (date = /* @__PURE__ */ new Date()) => {
11
- const day = new Date(date).getDay();
12
- return day !== 0 && day !== 6;
13
- };
14
- /**
15
- * @description: 时间转换为标准时间
16
- * @param {*} name:时间戳
17
- * @param {*} type:生成时间格式
18
- * @return {*} 14:25:59
19
- */
20
- const useFormatTime = (time = /* @__PURE__ */ new Date(), type = "HH:mm:ss") => useDateFormat(time, type).value;
21
- /**
22
- * @description: 时间转换为标准日期
23
- * @param {*} name:时间
24
- * @param {*} type:生成时间格式
25
- * @return {*} 2022-11-09
26
- */
27
- const useFormatDate = (time = /* @__PURE__ */ new Date(), type = "YYYY-MM-DD") => useDateFormat(time, type).value;
28
- /**
29
- * @description: 日期时间 -> 日期时间请求参数
30
- * @param {string} timestamp:时间数据
31
- * @param {*} field:日期时间字段名称
32
- * @param {*} start:开始字段名称
33
- * @param {*} end:结束字段名称
34
- * @return {*}
35
- */
36
- const useFormatDateTimeParams = (timestamp, field = "timestamp", start = "startTime", end = "endTime") => {
37
- if (!timestamp) return;
38
- const [startTime, endTime] = timestamp;
39
- return {
40
- [field]: void 0,
41
- [start]: startTime,
42
- [end]: endTime
43
- };
44
- };
45
- /**
46
- * @description: 转换为标准时间范围
47
- * @param {*} day 往前推*天数
48
- * @param {FormatDateRangeParamsType}
49
- * @return {*}
50
- */
51
- const useFormatDateRange = (day = 7, { endTimeType, format } = {
52
- endTimeType: "full",
53
- format: "YYYY-MM-DD HH:mm:ss"
54
- }) => {
55
- const time = +new Date((/* @__PURE__ */ new Date()).toLocaleDateString());
56
- const startTime = time - 3600 * 1e3 * 24 * (day - 1);
57
- const endTime = endTimeType === "full" ? time + 1440 * 60 * 1e3 - 1 : /* @__PURE__ */ new Date();
58
- const start = useDateFormat(startTime, format);
59
- const end = useDateFormat(endTime, format);
60
- return [start.value, end.value];
61
- };
62
-
63
- //#endregion
64
- export { getDayOfYear, isWeekday, useFormatDate, useFormatDateRange, useFormatDateTimeParams, useFormatTime };
package/dist/device.d.mts DELETED
@@ -1,8 +0,0 @@
1
- //#region src/device.d.ts
2
- declare const isAndroidMobile: () => boolean;
3
- declare const isAppleMobile: () => boolean;
4
- declare const isWeChatBrowser: () => boolean;
5
- declare const isQQBrowser: () => boolean;
6
- declare const isMobile: () => boolean;
7
- //#endregion
8
- export { isAndroidMobile, isAppleMobile, isMobile, isQQBrowser, isWeChatBrowser };
package/dist/device.mjs DELETED
@@ -1,9 +0,0 @@
1
- //#region src/device.ts
2
- const isAndroidMobile = () => /android/i.test(navigator.userAgent.toLowerCase());
3
- const isAppleMobile = () => /iphone|ipod|ipad|Macintosh/i.test(navigator.userAgent.toLowerCase());
4
- const isWeChatBrowser = () => /MicroMessenger/i.test(navigator.userAgent);
5
- const isQQBrowser = () => /MQQBrowser/i.test(navigator.userAgent);
6
- const isMobile = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
7
-
8
- //#endregion
9
- export { isAndroidMobile, isAppleMobile, isMobile, isQQBrowser, isWeChatBrowser };
package/dist/extra.d.mts DELETED
@@ -1,5 +0,0 @@
1
- //#region src/extra.d.ts
2
- declare const useOmitExtraParams: (sourceData: object, targetData: object) => Pick<object, never>;
3
- declare const __: undefined;
4
- //#endregion
5
- export { __, useOmitExtraParams };
package/dist/extra.mjs DELETED
@@ -1,8 +0,0 @@
1
- import { pick } from "es-toolkit";
2
-
3
- //#region src/extra.ts
4
- const useOmitExtraParams = (sourceData, targetData) => pick(sourceData, Object.keys(targetData));
5
- const __ = void 0;
6
-
7
- //#endregion
8
- export { __, useOmitExtraParams };
package/dist/index.d.mts DELETED
@@ -1,8 +0,0 @@
1
- import { useOmitNilRequestParams, useParamsSerializer } from "./axios.mjs";
2
- import { hexToRgb, randomHex, rgbToHex } from "./color.mjs";
3
- import { FormatDateRangeParamsType, getDayOfYear, isWeekday, useFormatDate, useFormatDateRange, useFormatDateTimeParams, useFormatTime } from "./datetime.mjs";
4
- import { isAndroidMobile, isAppleMobile, isMobile, isQQBrowser, isWeChatBrowser } from "./device.mjs";
5
- import { __, useOmitExtraParams } from "./extra.mjs";
6
- import { clearLocalStorage, getLocalStorage, removeLocalStorage, setLocalStorage } from "./localstorage.mjs";
7
- import { formatNumberWithCommas, formatPhoneNumber, getRandomNum, isEven, maskedPhoneNumber } from "./number.mjs";
8
- export { FormatDateRangeParamsType, __, clearLocalStorage, formatNumberWithCommas, formatPhoneNumber, getDayOfYear, getLocalStorage, getRandomNum, hexToRgb, isAndroidMobile, isAppleMobile, isEven, isMobile, isQQBrowser, isWeChatBrowser, isWeekday, maskedPhoneNumber, randomHex, removeLocalStorage, rgbToHex, setLocalStorage, useFormatDate, useFormatDateRange, useFormatDateTimeParams, useFormatTime, useOmitExtraParams, useOmitNilRequestParams, useParamsSerializer };
package/dist/index.mjs DELETED
@@ -1,9 +0,0 @@
1
- import { useOmitNilRequestParams, useParamsSerializer } from "./axios.mjs";
2
- import { hexToRgb, randomHex, rgbToHex } from "./color.mjs";
3
- import { getDayOfYear, isWeekday, useFormatDate, useFormatDateRange, useFormatDateTimeParams, useFormatTime } from "./datetime.mjs";
4
- import { isAndroidMobile, isAppleMobile, isMobile, isQQBrowser, isWeChatBrowser } from "./device.mjs";
5
- import { __, useOmitExtraParams } from "./extra.mjs";
6
- import { clearLocalStorage, getLocalStorage, removeLocalStorage, setLocalStorage } from "./localstorage.mjs";
7
- import { formatNumberWithCommas, formatPhoneNumber, getRandomNum, isEven, maskedPhoneNumber } from "./number.mjs";
8
-
9
- export { __, clearLocalStorage, formatNumberWithCommas, formatPhoneNumber, getDayOfYear, getLocalStorage, getRandomNum, hexToRgb, isAndroidMobile, isAppleMobile, isEven, isMobile, isQQBrowser, isWeChatBrowser, isWeekday, maskedPhoneNumber, randomHex, removeLocalStorage, rgbToHex, setLocalStorage, useFormatDate, useFormatDateRange, useFormatDateTimeParams, useFormatTime, useOmitExtraParams, useOmitNilRequestParams, useParamsSerializer };
@@ -1,7 +0,0 @@
1
- //#region src/localstorage.d.ts
2
- declare const setLocalStorage: (key: string, value: any) => void;
3
- declare const getLocalStorage: <T>(key: string) => T | null;
4
- declare const removeLocalStorage: (key: string) => void;
5
- declare const clearLocalStorage: () => void;
6
- //#endregion
7
- export { clearLocalStorage, getLocalStorage, removeLocalStorage, setLocalStorage };
@@ -1,12 +0,0 @@
1
- //#region src/localstorage.ts
2
- const setLocalStorage = (key, value) => localStorage.setItem(key, JSON.stringify(value));
3
- const getLocalStorage = (key) => {
4
- const data = localStorage.getItem(key);
5
- if (data) return JSON.parse(data);
6
- return null;
7
- };
8
- const removeLocalStorage = (key) => localStorage.removeItem(key);
9
- const clearLocalStorage = () => localStorage.clear();
10
-
11
- //#endregion
12
- export { clearLocalStorage, getLocalStorage, removeLocalStorage, setLocalStorage };
package/dist/number.d.mts DELETED
@@ -1,8 +0,0 @@
1
- //#region src/number.d.ts
2
- declare const formatNumberWithCommas: (val: number) => string;
3
- declare const getRandomNum: (min: number, max: number) => number;
4
- declare const maskedPhoneNumber: (phone: string | number) => string;
5
- declare const formatPhoneNumber: (phone: string, separator?: string) => string;
6
- declare const isEven: (val: number) => boolean;
7
- //#endregion
8
- export { formatNumberWithCommas, formatPhoneNumber, getRandomNum, isEven, maskedPhoneNumber };
package/dist/number.mjs DELETED
@@ -1,9 +0,0 @@
1
- //#region src/number.ts
2
- const formatNumberWithCommas = (val) => val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
3
- const getRandomNum = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
4
- const maskedPhoneNumber = (phone) => phone?.toString()?.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
5
- const formatPhoneNumber = (phone, separator = "-") => phone.replace(/(\W|\s)/g, "").split(/^(\d{3})(\d{4})(\d{4})$/).filter((item) => item).join(separator);
6
- const isEven = (val) => val % 2 === 0;
7
-
8
- //#endregion
9
- export { formatNumberWithCommas, formatPhoneNumber, getRandomNum, isEven, maskedPhoneNumber };