@fast-china/utils 1.0.4 → 1.0.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.global.js +147 -119
- package/dist/index.global.js.map +1 -1
- package/dist/index.global.min.js +5 -5
- package/dist/index.global.min.js.map +1 -1
- package/es/array/index.d.ts +19 -0
- package/es/array/index.mjs +33 -0
- package/es/array/index.mjs.map +1 -0
- package/es/base64/index.d.ts +9 -0
- package/es/base64/index.mjs +7 -1
- package/es/base64/index.mjs.map +1 -1
- package/es/click/index.d.ts +3 -0
- package/es/click/index.mjs.map +1 -1
- package/es/color/index.d.ts +3 -0
- package/es/color/index.mjs +8 -7
- package/es/color/index.mjs.map +1 -1
- package/es/console/index.mjs.map +1 -1
- package/es/date/index.d.ts +17 -0
- package/es/date/index.mjs +17 -0
- package/es/date/index.mjs.map +1 -1
- package/es/env/index.d.ts +25 -0
- package/es/env/index.mjs +38 -0
- package/es/env/index.mjs.map +1 -0
- package/es/identity/index.mjs +1 -1
- package/es/identity/index.mjs.map +1 -1
- package/es/index.d.ts +2 -0
- package/es/index.mjs +4 -0
- package/es/index.mjs.map +1 -1
- package/es/object/index.d.ts +0 -12
- package/es/object/index.mjs +0 -97
- package/es/object/index.mjs.map +1 -1
- package/es/storage/index.mjs +3 -2
- package/es/storage/index.mjs.map +1 -1
- package/es/string/index.d.ts +21 -0
- package/es/string/index.mjs +40 -3
- package/es/string/index.mjs.map +1 -1
- package/es/vue/props.mjs.map +1 -1
- package/es/vue/useRender.mjs +2 -1
- package/es/vue/useRender.mjs.map +1 -1
- package/lib/array/index.d.ts +19 -0
- package/lib/array/index.js +2 -0
- package/lib/array/index.js.map +1 -0
- package/lib/base64/index.d.ts +9 -0
- package/lib/base64/index.js +1 -1
- package/lib/base64/index.js.map +1 -1
- package/lib/click/index.d.ts +3 -0
- package/lib/click/index.js.map +1 -1
- package/lib/color/index.d.ts +3 -0
- package/lib/color/index.js +1 -1
- package/lib/color/index.js.map +1 -1
- package/lib/console/index.js.map +1 -1
- package/lib/date/index.d.ts +17 -0
- package/lib/date/index.js.map +1 -1
- package/lib/env/index.d.ts +25 -0
- package/lib/env/index.js +2 -0
- package/lib/env/index.js.map +1 -0
- package/lib/identity/index.js +1 -1
- package/lib/identity/index.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -1
- package/lib/object/index.d.ts +0 -12
- package/lib/object/index.js +1 -1
- package/lib/object/index.js.map +1 -1
- package/lib/storage/index.js +1 -1
- package/lib/storage/index.js.map +1 -1
- package/lib/string/index.d.ts +21 -0
- package/lib/string/index.js +1 -1
- package/lib/string/index.js.map +1 -1
- package/lib/vue/props.js.map +1 -1
- package/lib/vue/useRender.js +1 -1
- package/lib/vue/useRender.js.map +1 -1
- package/package.json +9 -8
package/lib/date/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/date/index.ts"],"sourcesContent":["/**\n * Date工具类\n */\nexport const dateUtil = {\n\t/**\n\t * 根据当前时间生成问候语\n\t */\n\tgetGreet(): string {\n\t\tconst now = new Date();\n\t\tconst hour = now.getHours();\n\t\tlet greet = \"\";\n\n\t\tif (hour < 5) {\n\t\t\tgreet = \"夜深了,注意身体哦!\";\n\t\t} else if (hour < 9) {\n\t\t\tgreet = \"早上好!\" + \"欢迎回来!\";\n\t\t} else if (hour < 12) {\n\t\t\tgreet = \"上午好!\" + \"欢迎回来!\";\n\t\t} else if (hour < 14) {\n\t\t\tgreet = \"中午好!\" + \"欢迎回来!\";\n\t\t} else if (hour < 18) {\n\t\t\tgreet = \"下午好!\" + \"欢迎回来!\";\n\t\t} else if (hour < 24) {\n\t\t\tgreet = \"晚上好!\" + \"欢迎回来!\";\n\t\t} else {\n\t\t\tgreet = \"您好!\" + \"欢迎回来!\";\n\t\t}\n\t\treturn greet;\n\t},\n\t/**\n\t * 时间处理翻译\n\t */\n\tdateTimeFix(date: string | Date | null | undefined): string {\n\t\tif (date !== null && date !== undefined && date) {\n\t\t\tif (typeof date === \"string\") {\n\t\t\t\tdate = new Date(date);\n\t\t\t}\n\n\t\t\t// 获取时间戳\n\t\t\tlet timestamp = date.getTime();\n\t\t\tif (timestamp.toString().length < 13) {\n\t\t\t\tconst arrTimestamp = timestamp.toString().split(\"\");\n\t\t\t\tfor (let start = 0; start < 13; start++) {\n\t\t\t\t\tif (!arrTimestamp[start]) {\n\t\t\t\t\t\tarrTimestamp[start] = \"0\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttimestamp = parseInt(arrTimestamp.join(\"\"));\n\t\t\t}\n\t\t\tconst minute = 1000 * 60;\n\t\t\tconst hour = minute * 60;\n\t\t\tconst day = hour * 24;\n\t\t\tconst month = day * 30;\n\t\t\t// 获取当前时间\n\t\t\tconst curTime = new Date().getTime();\n\t\t\t// 比较\n\t\t\tconst diffValue = curTime - timestamp;\n\n\t\t\t// 计算差异时间的量级\n\t\t\tconst monthC = diffValue / month;\n\t\t\tconst weekC = diffValue / (7 * day);\n\t\t\tconst dayC = diffValue / day;\n\t\t\tconst hourC = diffValue / hour;\n\t\t\tconst minC = diffValue / minute;\n\n\t\t\t// 如果本地时间反而小于变量时间\n\t\t\tif (diffValue < 0) {\n\t\t\t\tconst monthC1 = Math.abs(monthC);\n\t\t\t\tconst weekC1 = Math.abs(weekC);\n\t\t\t\tconst dayC1 = Math.abs(dayC);\n\t\t\t\tconst hourC1 = Math.abs(hourC);\n\t\t\t\tconst minC1 = Math.abs(minC);\n\n\t\t\t\tif (monthC1 > 12) {\n\t\t\t\t\t// 超过1年,直接显示 几 年前\n\t\t\t\t\treturn `${parseInt(`${monthC1 / 12}`)}年后`;\n\t\t\t\t} else if (monthC1 >= 6) {\n\t\t\t\t\treturn \"半年后\";\n\t\t\t\t} else if (monthC1 >= 1) {\n\t\t\t\t\treturn `${parseInt(`${monthC1}`)}月后`;\n\t\t\t\t} else if (weekC1 > 2) {\n\t\t\t\t\treturn \"半月后\";\n\t\t\t\t} else if (weekC1 >= 1) {\n\t\t\t\t\treturn `${parseInt(`${weekC1}`)}周后`;\n\t\t\t\t} else if (dayC1 >= 1) {\n\t\t\t\t\treturn `${parseInt(`${dayC1}`)}天后`;\n\t\t\t\t} else if (hourC1 >= 1) {\n\t\t\t\t\treturn `${parseInt(`${hourC1}`)}小时后`;\n\t\t\t\t} else if (minC1 >= 1) {\n\t\t\t\t\treturn `${parseInt(`${minC1}`)}分钟后`;\n\t\t\t\t}\n\t\t\t\treturn \"刚刚\";\n\t\t\t\t// return \"不久前\";\n\t\t\t}\n\n\t\t\t// 使用\n\t\t\tif (monthC > 12) {\n\t\t\t\t// 超过1年,直接显示 几 年前\n\t\t\t\treturn `${parseInt(`${monthC / 12}`)}年前`;\n\t\t\t} else if (monthC >= 6) {\n\t\t\t\treturn \"半年前\";\n\t\t\t} else if (monthC >= 1) {\n\t\t\t\treturn `${parseInt(`${monthC}`)}月前`;\n\t\t\t} else if (weekC > 2) {\n\t\t\t\treturn \"半月前\";\n\t\t\t} else if (weekC >= 1) {\n\t\t\t\treturn `${parseInt(`${weekC}`)}周前`;\n\t\t\t} else if (dayC >= 1) {\n\t\t\t\treturn `${parseInt(`${dayC}`)}天前`;\n\t\t\t} else if (hourC >= 1) {\n\t\t\t\treturn `${parseInt(`${hourC}`)}小时前`;\n\t\t\t} else if (minC >= 1) {\n\t\t\t\treturn `${parseInt(`${minC}`)}分钟前`;\n\t\t\t}\n\t\t\treturn \"刚刚\";\n\t\t} else {\n\t\t\treturn \"\";\n\t\t}\n\t},\n\tgetDefaultTime(): Date[] {\n\t\tconst end = new Date();\n\t\tconst start = new Date();\n\t\tstart.setMonth(start.getMonth() - 1);\n\t\tstart.setHours(0, 0, 0);\n\t\tend.setHours(23, 59, 59);\n\t\treturn [start, end];\n\t},\n\tgetSimpleTime(): Date {\n\t\tconst start = new Date();\n\t\tstart.setHours(0, 0, 0);\n\t\treturn start;\n\t},\n\tgetSimpleShortcuts(): {\n\t\ttext: string;\n\t\tvalue: () => Date;\n\t}[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\ttext: \"今天\",\n\t\t\t\tvalue: (): Date => {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdate.setHours(0, 0, 0);\n\t\t\t\t\treturn date;\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"昨天\",\n\t\t\t\tvalue: (): Date => {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdate.setDate(date.getDate() - 1);\n\t\t\t\t\tdate.setHours(0, 0, 0);\n\t\t\t\t\treturn date;\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"一周前\",\n\t\t\t\tvalue: (): Date => {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdate.setDate(date.getDate() - 7);\n\t\t\t\t\tdate.setHours(0, 0, 0);\n\t\t\t\t\treturn date;\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"一月前\",\n\t\t\t\tvalue: (): Date => {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdate.setMonth(date.getMonth() - 1);\n\t\t\t\t\tdate.setHours(0, 0, 0);\n\t\t\t\t\treturn date;\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"一年前\",\n\t\t\t\tvalue: (): Date => {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdate.setFullYear(date.getFullYear() - 1);\n\t\t\t\t\tdate.setHours(0, 0, 0);\n\t\t\t\t\treturn date;\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t},\n\tgetShortcuts(): {\n\t\ttext: string;\n\t\tvalue: () => Date[];\n\t}[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\ttext: \"近1天\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setDate(start.getDate() - 1);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近3天\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setDate(start.getDate() - 3);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近1周\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setDate(start.getDate() - 7);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近1月\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setMonth(start.getMonth() - 1);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近3月\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setMonth(start.getMonth() - 3);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近6月\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setMonth(start.getMonth() - 6);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近1年\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setFullYear(start.getFullYear() - 1);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t},\n\tgetDisabledDate(time: Date): boolean {\n\t\treturn time.getTime() > Date.now();\n\t},\n};\n"],"names":["dateUtil","getGreet","hour","Date","getHours","greet","dateTimeFix","date","timestamp","getTime","toString","length","arrTimestamp","split","start","parseInt","join","minute","day","month","diffValue","monthC","weekC","dayC","hourC","minC","monthC1","Math","abs","weekC1","dayC1","hourC1","minC1","getDefaultTime","end","setMonth","getMonth","setHours","getSimpleTime","getSimpleShortcuts","text","value","setDate","getDate","setFullYear","getFullYear","getShortcuts","getDisabledDate","time","now"],"mappings":"gFAGO,MAAMA,EAAW,CAIvB,QAAAC,GACO,MACAC,OADUC,MACCC,WACjB,IAAIC,EAAQ,GAiBL,OAdEA,EADLH,EAAO,EACF,aACEA,EAAO,EACT,YACEA,EAAO,GACT,YACEA,EAAO,GACT,YACEA,EAAO,GACT,YACEA,EAAO,GACT,YAEA,WAEFG,CACR,EAIA,WAAAC,CAAYC,GACX,GAAIA,SAAuCA,EAAM,CAC5B,iBAATA,IACHA,EAAA,IAAIJ,KAAKI,IAIb,IAAAC,EAAYD,EAAKE,UACrB,GAAID,EAAUE,WAAWC,OAAS,GAAI,CACrC,MAAMC,EAAeJ,EAAUE,WAAWG,MAAM,IAChD,IAAA,IAASC,EAAQ,EAAGA,EAAQ,GAAIA,IAC1BF,EAAaE,KACjBF,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AAOoB,EAAG,GAGpB,CACCM,KAAM,MACNC,MAAO,KACA,MAAAP,MAAU/B,KACVW,MAAYX,KAIX,OAHPW,EAAM4B,QAAQ5B,EAAM6B,UAAY,GAC1B7B,EAAAuB,SAAS,EAAG,EAAG,GACjBH,EAAAG,SAAS,GAAI,GAAI,IACd,CAACvB,EAAOoB,EAAG,GAGpB,CACCM,KAAM,MACNC,MAAO,KACA,MAAAP,MAAU/B,KACVW,MAAYX,KAIX,OAHPW,EAAMqB,SAASrB,EAAMsB,WAAa,GAC5BtB,EAAAuB,SAAS,EAAG,EAAG,GACjBH,EAAAG,SAAS,GAAI,GAAI,IACd,CAACvB,EAAOoB,EAAG,GAGpB,CACCM,KAAM,MACNC,MAAO,KACA,MAAAP,MAAU/B,KACVW,MAAYX,KAIX,OAHPW,EAAMqB,SAASrB,EAAMsB,WAAa,GAC5BtB,EAAAuB,SAAS,EAAG,EAAG,GACjBH,EAAAG,SAAS,GAAI,GAAI,IACd,CAACvB,EAAOoB,EAAG,GAGpB,CACCM,KAAM,MACNC,MAAO,KACA,MAAAP,MAAU/B,KACVW,MAAYX,KAIX,OAHPW,EAAMqB,SAASrB,EAAMsB,WAAa,GAC5BtB,EAAAuB,SAAS,EAAG,EAAG,GACjBH,EAAAG,SAAS,GAAI,GAAI,IACd,CAACvB,EAAOoB,EAAG,GAGpB,CACCM,KAAM,MACNC,MAAO,KACA,MAAAP,MAAU/B,KACVW,MAAYX,KAIX,OAHPW,EAAM8B,YAAY9B,EAAM+B,cAAgB,GAClC/B,EAAAuB,SAAS,EAAG,EAAG,GACjBH,EAAAG,SAAS,GAAI,GAAI,IACd,CAACvB,EAAOoB,EAAG,IAKtBa,gBAAgBC,GACRA,EAAKvC,UAAYN,KAAK8C"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/date/index.ts"],"sourcesContent":["/**\n * Date工具类\n */\nexport const dateUtil = {\n\t/**\n\t * 根据当前时间生成问候语\n\t */\n\tgetGreet(): string {\n\t\tconst now = new Date();\n\t\tconst hour = now.getHours();\n\t\tlet greet = \"\";\n\n\t\tif (hour < 5) {\n\t\t\tgreet = \"夜深了,注意身体哦!\";\n\t\t} else if (hour < 9) {\n\t\t\tgreet = \"早上好!\" + \"欢迎回来!\";\n\t\t} else if (hour < 12) {\n\t\t\tgreet = \"上午好!\" + \"欢迎回来!\";\n\t\t} else if (hour < 14) {\n\t\t\tgreet = \"中午好!\" + \"欢迎回来!\";\n\t\t} else if (hour < 18) {\n\t\t\tgreet = \"下午好!\" + \"欢迎回来!\";\n\t\t} else if (hour < 24) {\n\t\t\tgreet = \"晚上好!\" + \"欢迎回来!\";\n\t\t} else {\n\t\t\tgreet = \"您好!\" + \"欢迎回来!\";\n\t\t}\n\t\treturn greet;\n\t},\n\t/**\n\t * 时间处理翻译\n\t */\n\tdateTimeFix(date: string | Date | null | undefined): string {\n\t\tif (date !== null && date !== undefined && date) {\n\t\t\tif (typeof date === \"string\") {\n\t\t\t\tdate = new Date(date);\n\t\t\t}\n\n\t\t\t// 获取时间戳\n\t\t\tlet timestamp = date.getTime();\n\t\t\tif (timestamp.toString().length < 13) {\n\t\t\t\tconst arrTimestamp = timestamp.toString().split(\"\");\n\t\t\t\tfor (let start = 0; start < 13; start++) {\n\t\t\t\t\tif (!arrTimestamp[start]) {\n\t\t\t\t\t\tarrTimestamp[start] = \"0\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttimestamp = parseInt(arrTimestamp.join(\"\"));\n\t\t\t}\n\t\t\tconst minute = 1000 * 60;\n\t\t\tconst hour = minute * 60;\n\t\t\tconst day = hour * 24;\n\t\t\tconst month = day * 30;\n\t\t\t// 获取当前时间\n\t\t\tconst curTime = new Date().getTime();\n\t\t\t// 比较\n\t\t\tconst diffValue = curTime - timestamp;\n\n\t\t\t// 计算差异时间的量级\n\t\t\tconst monthC = diffValue / month;\n\t\t\tconst weekC = diffValue / (7 * day);\n\t\t\tconst dayC = diffValue / day;\n\t\t\tconst hourC = diffValue / hour;\n\t\t\tconst minC = diffValue / minute;\n\n\t\t\t// 如果本地时间反而小于变量时间\n\t\t\tif (diffValue < 0) {\n\t\t\t\tconst monthC1 = Math.abs(monthC);\n\t\t\t\tconst weekC1 = Math.abs(weekC);\n\t\t\t\tconst dayC1 = Math.abs(dayC);\n\t\t\t\tconst hourC1 = Math.abs(hourC);\n\t\t\t\tconst minC1 = Math.abs(minC);\n\n\t\t\t\tif (monthC1 > 12) {\n\t\t\t\t\t// 超过1年,直接显示 几 年前\n\t\t\t\t\treturn `${parseInt(`${monthC1 / 12}`)}年后`;\n\t\t\t\t} else if (monthC1 >= 6) {\n\t\t\t\t\treturn \"半年后\";\n\t\t\t\t} else if (monthC1 >= 1) {\n\t\t\t\t\treturn `${parseInt(`${monthC1}`)}月后`;\n\t\t\t\t} else if (weekC1 > 2) {\n\t\t\t\t\treturn \"半月后\";\n\t\t\t\t} else if (weekC1 >= 1) {\n\t\t\t\t\treturn `${parseInt(`${weekC1}`)}周后`;\n\t\t\t\t} else if (dayC1 >= 1) {\n\t\t\t\t\treturn `${parseInt(`${dayC1}`)}天后`;\n\t\t\t\t} else if (hourC1 >= 1) {\n\t\t\t\t\treturn `${parseInt(`${hourC1}`)}小时后`;\n\t\t\t\t} else if (minC1 >= 1) {\n\t\t\t\t\treturn `${parseInt(`${minC1}`)}分钟后`;\n\t\t\t\t}\n\t\t\t\treturn \"刚刚\";\n\t\t\t\t// return \"不久前\";\n\t\t\t}\n\n\t\t\t// 使用\n\t\t\tif (monthC > 12) {\n\t\t\t\t// 超过1年,直接显示 几 年前\n\t\t\t\treturn `${parseInt(`${monthC / 12}`)}年前`;\n\t\t\t} else if (monthC >= 6) {\n\t\t\t\treturn \"半年前\";\n\t\t\t} else if (monthC >= 1) {\n\t\t\t\treturn `${parseInt(`${monthC}`)}月前`;\n\t\t\t} else if (weekC > 2) {\n\t\t\t\treturn \"半月前\";\n\t\t\t} else if (weekC >= 1) {\n\t\t\t\treturn `${parseInt(`${weekC}`)}周前`;\n\t\t\t} else if (dayC >= 1) {\n\t\t\t\treturn `${parseInt(`${dayC}`)}天前`;\n\t\t\t} else if (hourC >= 1) {\n\t\t\t\treturn `${parseInt(`${hourC}`)}小时前`;\n\t\t\t} else if (minC >= 1) {\n\t\t\t\treturn `${parseInt(`${minC}`)}分钟前`;\n\t\t\t}\n\t\t\treturn \"刚刚\";\n\t\t} else {\n\t\t\treturn \"\";\n\t\t}\n\t},\n\t/**\n\t * 获取默认时间\n\t * @returns [00:00:00, 23:59:59]\n\t */\n\tgetDefaultTime(): Date[] {\n\t\tconst end = new Date();\n\t\tconst start = new Date();\n\t\tstart.setMonth(start.getMonth() - 1);\n\t\tstart.setHours(0, 0, 0);\n\t\tend.setHours(23, 59, 59);\n\t\treturn [start, end];\n\t},\n\t/**\n\t * 获取简单的日期时间\n\t * @returns xxxx-xx-xx 00:00:00\n\t */\n\tgetSimpleTime(): Date {\n\t\tconst start = new Date();\n\t\tstart.setHours(0, 0, 0);\n\t\treturn start;\n\t},\n\t/**\n\t * 获取简单的日期时间范围\n\t */\n\tgetSimpleShortcuts(): {\n\t\ttext: string;\n\t\tvalue: () => Date;\n\t}[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\ttext: \"今天\",\n\t\t\t\tvalue: (): Date => {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdate.setHours(0, 0, 0);\n\t\t\t\t\treturn date;\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"昨天\",\n\t\t\t\tvalue: (): Date => {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdate.setDate(date.getDate() - 1);\n\t\t\t\t\tdate.setHours(0, 0, 0);\n\t\t\t\t\treturn date;\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"一周前\",\n\t\t\t\tvalue: (): Date => {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdate.setDate(date.getDate() - 7);\n\t\t\t\t\tdate.setHours(0, 0, 0);\n\t\t\t\t\treturn date;\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"一月前\",\n\t\t\t\tvalue: (): Date => {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdate.setMonth(date.getMonth() - 1);\n\t\t\t\t\tdate.setHours(0, 0, 0);\n\t\t\t\t\treturn date;\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"一年前\",\n\t\t\t\tvalue: (): Date => {\n\t\t\t\t\tconst date = new Date();\n\t\t\t\t\tdate.setFullYear(date.getFullYear() - 1);\n\t\t\t\t\tdate.setHours(0, 0, 0);\n\t\t\t\t\treturn date;\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t},\n\t/**\n\t * 获取日期范围\n\t */\n\tgetShortcuts(): {\n\t\ttext: string;\n\t\tvalue: () => Date[];\n\t}[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\ttext: \"近1天\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setDate(start.getDate() - 1);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近3天\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setDate(start.getDate() - 3);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近1周\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setDate(start.getDate() - 7);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近1月\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setMonth(start.getMonth() - 1);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近3月\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setMonth(start.getMonth() - 3);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近6月\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setMonth(start.getMonth() - 6);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttext: \"近1年\",\n\t\t\t\tvalue: (): Date[] => {\n\t\t\t\t\tconst end = new Date();\n\t\t\t\t\tconst start = new Date();\n\t\t\t\t\tstart.setFullYear(start.getFullYear() - 1);\n\t\t\t\t\tstart.setHours(0, 0, 0);\n\t\t\t\t\tend.setHours(23, 59, 59);\n\t\t\t\t\treturn [start, end];\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\t},\n\t/**\n\t * 判断传入的时间是否大于当前时间\n\t */\n\tgetDisabledDate(time: Date): boolean {\n\t\treturn time.getTime() > Date.now();\n\t},\n};\n"],"names":["dateUtil","getGreet","hour","Date","getHours","greet","dateTimeFix","date","timestamp","getTime","toString","length","arrTimestamp","split","start","parseInt","join","minute","day","month","diffValue","monthC","weekC","dayC","hourC","minC","monthC1","Math","abs","weekC1","dayC1","hourC1","minC1","getDefaultTime","end","setMonth","getMonth","setHours","getSimpleTime","getSimpleShortcuts","text","value","setDate","getDate","setFullYear","getFullYear","getShortcuts","getDisabledDate","time","now"],"mappings":"gFAGO,MAAMA,EAAW,CAIvB,QAAAC,GACO,MACAC,OADUC,MACCC,WACjB,IAAIC,EAAQ,GAiBL,OAdEA,EADLH,EAAO,EACF,aACEA,EAAO,EACT,YACEA,EAAO,GACT,YACEA,EAAO,GACT,YACEA,EAAO,GACT,YACEA,EAAO,GACT,YAEA,WAEFG,CACR,EAIA,WAAAC,CAAYC,GACX,GAAIA,SAAuCA,EAAM,CAC5B,iBAATA,IACHA,EAAA,IAAIJ,KAAKI,IAIb,IAAAC,EAAYD,EAAKE,UACrB,GAAID,EAAUE,WAAWC,OAAS,GAAI,CACrC,MAAMC,EAAeJ,EAAUE,WAAWG,MAAM,IAChD,IAAA,IAASC,EAAQ,EAAGA,EAAQ,GAAIA,IAC1BF,EAAaE,KACjBF,EAAaE,GAAS,KAGxBN,EAAYO,SAASH,EAAaI,KAAK,IAAG,CAE3C,MAAMC,EAAS,IACTf,EAAgB,GAATe,EACPC,EAAa,GAAPhB,EACNiB,EAAc,GAAND,EAIRE,GAFU,IAAIjB,MAAOM,UAECD,EAGtBa,EAASD,EAAYD,EACrBG,EAAQF,GAAa,EAAIF,GACzBK,EAAOH,EAAYF,EACnBM,EAAQJ,EAAYlB,EACpBuB,EAAOL,EAAYH,EAGzB,GAAIG,EAAY,EAAG,CACZ,MAAAM,EAAUC,KAAKC,IAAIP,GACnBQ,EAASF,KAAKC,IAAIN,GAClBQ,EAAQH,KAAKC,IAAIL,GACjBQ,EAASJ,KAAKC,IAAIJ,GAClBQ,EAAQL,KAAKC,IAAIH,GAEvB,OAAIC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W,MAAYX,KAIX,OAHPW,EAAMqB,SAASrB,EAAMsB,WAAa,GAC5BtB,EAAAuB,SAAS,EAAG,EAAG,GACjBH,EAAAG,SAAS,GAAI,GAAI,IACd,CAACvB,EAAOoB,EAAG,GAGpB,CACCM,KAAM,MACNC,MAAO,KACA,MAAAP,MAAU/B,KACVW,MAAYX,KAIX,OAHPW,EAAMqB,SAASrB,EAAMsB,WAAa,GAC5BtB,EAAAuB,SAAS,EAAG,EAAG,GACjBH,EAAAG,SAAS,GAAI,GAAI,IACd,CAACvB,EAAOoB,EAAG,GAGpB,CACCM,KAAM,MACNC,MAAO,KACA,MAAAP,MAAU/B,KACVW,MAAYX,KAIX,OAHPW,EAAM8B,YAAY9B,EAAM+B,cAAgB,GAClC/B,EAAAuB,SAAS,EAAG,EAAG,GACjBH,EAAAG,SAAS,GAAI,GAAI,IACd,CAACvB,EAAOoB,EAAG,IAQtBa,gBAAgBC,GACRA,EAAKvC,UAAYN,KAAK8C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 环境工具类
|
|
3
|
+
*/
|
|
4
|
+
export declare const envUtil: {
|
|
5
|
+
/**
|
|
6
|
+
* 是否为 Uni 环境
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
isUni(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 是否为 Web 环境(浏览器环境)
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
isWeb(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* 是否为手机设备
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
isMobile(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* 是否为平板设备
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
isIpad(): boolean;
|
|
25
|
+
};
|
package/lib/env/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={isUni:()=>"undefined"!=typeof uni,isWeb:()=>"undefined"!=typeof window&&void 0!==window.document,isMobile(){if(!this.isWeb())return!1;const e=navigator.userAgent||"";return/Mobile|iPhone|Android.*Mobile|Windows Phone/i.test(e)},isIpad(){if(!this.isWeb())return!1;const e=navigator.userAgent||"";return/iPad|Android(?!.*Mobile)|Tablet/i.test(e)}};exports.envUtil=e;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/env/index.ts"],"sourcesContent":["/**\n * 环境工具类\n */\nexport const envUtil = {\n\t/**\n\t * 是否为 Uni 环境\n\t * @returns\n\t */\n\tisUni(): boolean {\n\t\treturn typeof uni !== \"undefined\";\n\t},\n\t/**\n\t * 是否为 Web 环境(浏览器环境)\n\t * @returns\n\t */\n\tisWeb(): boolean {\n\t\treturn typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\t},\n\t/**\n\t * 是否为手机设备\n\t * @returns\n\t */\n\tisMobile(): boolean {\n\t\tif (!this.isWeb()) return false;\n\t\tconst ua = navigator.userAgent || \"\";\n\t\t// Windows Phone 也归类为手机\n\t\treturn /Mobile|iPhone|Android.*Mobile|Windows Phone/i.test(ua);\n\t},\n\t/**\n\t * 是否为平板设备\n\t * @returns\n\t */\n\tisIpad(): boolean {\n\t\tif (!this.isWeb()) return false;\n\t\tconst ua = navigator.userAgent || \"\";\n\t\t// iPad 或 Android 平板通常不带 Mobile 字符串\n\t\treturn /iPad|Android(?!.*Mobile)|Tablet/i.test(ua);\n\t},\n};\n"],"names":["envUtil","isUni","uni","isWeb","window","document","isMobile","this","ua","navigator","userAgent","test","isIpad"],"mappings":"gFAGO,MAAMA,EAAU,CAKtBC,MAAiB,IACM,oBAARC,IAMfC,MAAiB,IACS,oBAAXC,aAAqD,IAApBA,OAAOC,SAMvD,QAAAC,GACC,IAAKC,KAAKJ,QAAgB,OAAA,EACpB,MAAAK,EAAKC,UAAUC,WAAa,GAE3B,MAAA,+CAA+CC,KAAKH,EAC5D,EAKA,MAAAI,GACC,IAAKL,KAAKJ,QAAgB,OAAA,EACpB,MAAAK,EAAKC,UAAUC,WAAa,GAE3B,MAAA,mCAAmCC,KAAKH,EAAE"}
|
package/lib/identity/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("../storage/index.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("../storage/index.js"),i=require("../string/index.js"),c=e.reactive({cacheKey:"__DEVICE_ID",deviceId:""}),r=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,d=()=>{if(c.deviceId&&r.test(c.deviceId))return t.Local.set(c.cacheKey,c.deviceId),c.deviceId;let e=t.Local.get(c.cacheKey);return e&&r.test(e)?(c.deviceId=e,e):(e=i.stringUtil.generateUUID(),t.Local.set(c.cacheKey,e),c.deviceId=e,e)};exports.useIdentity=()=>({...c,makeIdentity:d});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/identity/index.ts"],"sourcesContent":["import { reactive } from \"vue\";\nimport { Local } from \"../storage\";\nimport { stringUtil } from \"../string\";\n\nconst state = reactive({\n\tcacheKey: \"__DEVICE_ID\",\n\tdeviceId: \"\",\n});\n\nconst uuidRegExp = /^[0-9a-
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/identity/index.ts"],"sourcesContent":["import { reactive } from \"vue\";\nimport { Local } from \"../storage\";\nimport { stringUtil } from \"../string\";\n\nconst state = reactive({\n\tcacheKey: \"__DEVICE_ID\",\n\tdeviceId: \"\",\n});\n\nconst uuidRegExp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\n/**\n * 生成设备Id\n */\nconst makeIdentity = (): string => {\n\t// 判断是否存在\n\tif (state.deviceId && uuidRegExp.test(state.deviceId)) {\n\t\tLocal.set(state.cacheKey, state.deviceId);\n\t\treturn state.deviceId;\n\t}\n\t// 生成浏览器唯一 UUID\n\tlet deviceID = Local.get(state.cacheKey);\n\tif (deviceID && uuidRegExp.test(deviceID)) {\n\t\tstate.deviceId = deviceID;\n\t\treturn deviceID;\n\t}\n\tdeviceID = stringUtil.generateUUID();\n\tLocal.set(state.cacheKey, deviceID);\n\tstate.deviceId = deviceID;\n\treturn deviceID;\n};\n\nexport const useIdentity = (): typeof state & { makeIdentity: () => string } => {\n\treturn {\n\t\t...state,\n\t\tmakeIdentity,\n\t};\n};\n"],"names":["state","reactive","cacheKey","deviceId","uuidRegExp","makeIdentity","test","Local","set","deviceID","get","stringUtil","generateUUID"],"mappings":"wKAIMA,EAAQC,EAAAA,SAAS,CACtBC,SAAU,cACVC,SAAU,KAGLC,EAAa,kEAKbC,EAAe,KAEpB,GAAIL,EAAMG,UAAYC,EAAWE,KAAKN,EAAMG,UAE3C,OADAI,EAAAA,MAAMC,IAAIR,EAAME,SAAUF,EAAMG,UACzBH,EAAMG,SAGd,IAAIM,EAAWF,EAAAA,MAAMG,IAAIV,EAAME,UAC/B,OAAIO,GAAYL,EAAWE,KAAKG,IAC/BT,EAAMG,SAAWM,EACVA,IAEGE,EAAAA,aAAWC,eAChBL,EAAAA,MAAAC,IAAIR,EAAME,SAAUO,GAC1BT,EAAMG,SAAWM,EACVA,EAAA,sBAGmB,KACnB,IACHT,EACHK"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './array';
|
|
1
2
|
export * from './base64';
|
|
2
3
|
export * from './click';
|
|
3
4
|
export * from './color';
|
|
@@ -5,6 +6,7 @@ export * from './console';
|
|
|
5
6
|
export * from './crypto';
|
|
6
7
|
export * from './date';
|
|
7
8
|
export * from './dom';
|
|
9
|
+
export * from './env';
|
|
8
10
|
export * from './error';
|
|
9
11
|
export * from './identity';
|
|
10
12
|
export * from './object';
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./array/index.js"),r=require("./base64/index.js"),s=require("./click/index.js"),t=require("./color/index.js"),o=require("./console/index.js"),i=require("./crypto/index.js"),n=require("./date/index.js");require("./dom/index.js");const l=require("./env/index.js"),x=require("./error/index.js"),p=require("./identity/index.js"),u=require("./object/index.js"),c=require("./storage/index.js"),a=require("./string/index.js");require("./vue/index.js");const d=require("./dom/style.js"),j=require("./vue/expose.js"),q=require("./vue/func.js"),U=require("./vue/install.js"),E=require("./vue/props.js"),y=require("./vue/slots.js"),v=require("./vue/useRender.js"),I=require("./vue/with.js");exports.arrayUtil=e.arrayUtil,exports.base64Util=r.base64Util,exports.clickUtil=s.clickUtil,exports.colorUtil=t.colorUtil,exports.consoleDebug=o.consoleDebug,exports.consoleError=o.consoleError,exports.consoleLog=o.consoleLog,exports.consoleWarn=o.consoleWarn,exports.throwError=o.throwError,exports.cryptoUtil=i.cryptoUtil,exports.dateUtil=n.dateUtil,exports.envUtil=l.envUtil,exports.FastError=x.FastError,exports.useIdentity=p.useIdentity,exports.objectUtil=u.objectUtil,exports.CACHE_EXPIRE_SUFFIX=c.CACHE_EXPIRE_SUFFIX,exports.CACHE_PREFIX=c.CACHE_PREFIX,exports.Local=c.Local,exports.Session=c.Session,exports.useStorage=c.useStorage,exports.stringUtil=a.stringUtil,exports.addUnit=d.addUnit,exports.useExpose=j.useExpose,exports.execFunction=q.execFunction,exports.withInstall=U.withInstall,exports.withInstallDirective=U.withInstallDirective,exports.withNoopInstall=U.withNoopInstall,exports.definePropType=E.definePropType,exports.useProps=E.useProps,exports.makeSlots=y.makeSlots,exports.useRender=v.useRender,exports.withDefineType=I.withDefineType;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/object/index.d.ts
CHANGED
|
@@ -6,16 +6,4 @@ export declare const objectUtil: {
|
|
|
6
6
|
* 对象URL参数化
|
|
7
7
|
*/
|
|
8
8
|
objectToQueryString(obj: any): string;
|
|
9
|
-
/**
|
|
10
|
-
* 是否存在重复值
|
|
11
|
-
*/
|
|
12
|
-
hasDuplicateProperty<T>(arr: T[], prop: keyof T): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* 是否存在非重复值
|
|
15
|
-
*/
|
|
16
|
-
hasDifferentProperty<T>(arr: T[], prop: keyof T): boolean;
|
|
17
|
-
/**
|
|
18
|
-
* 时间处理翻译
|
|
19
|
-
*/
|
|
20
|
-
dateTimeFix(date: string | Date | null | undefined): string;
|
|
21
9
|
};
|
package/lib/object/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={objectToQueryString(e){let t="";for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(""!==t&&(t+="&"),t+=`${encodeURIComponent(o)}=${encodeURIComponent(e[o])}`);return t}};exports.objectUtil=e;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/object/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/object/index.ts"],"sourcesContent":["/**\n * 对象工具类\n */\nexport const objectUtil = {\n\t/**\n\t * 对象URL参数化\n\t */\n\tobjectToQueryString(obj: any): string {\n\t\tlet params = \"\";\n\t\tfor (const key in obj) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(obj, key)) {\n\t\t\t\tif (params !== \"\") {\n\t\t\t\t\tparams += \"&\";\n\t\t\t\t}\n\t\t\t\tparams += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;\n\t\t\t}\n\t\t}\n\t\treturn params;\n\t},\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/object/index.ts"],"sourcesContent":["/**\n * 对象工具类\n */\nexport const objectUtil = {\n\t/**\n\t * 对象URL参数化\n\t */\n\tobjectToQueryString(obj: any): string {\n\t\tlet params = \"\";\n\t\tfor (const key in obj) {\n\t\t\tif (Object.prototype.hasOwnProperty.call(obj, key)) {\n\t\t\t\tif (params !== \"\") {\n\t\t\t\t\tparams += \"&\";\n\t\t\t\t}\n\t\t\t\tparams += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;\n\t\t\t}\n\t\t}\n\t\treturn params;\n\t},\n};\n"],"names":["objectUtil","objectToQueryString","obj","params","key","Object","prototype","hasOwnProperty","call","encodeURIComponent"],"mappings":"gFAGO,MAAMA,EAAa,CAIzB,mBAAAC,CAAoBC,GACnB,IAAIC,EAAS,GACb,IAAA,MAAWC,KAAOF,EACbG,OAAOC,UAAUC,eAAeC,KAAKN,EAAKE,KAC9B,KAAXD,IACOA,GAAA,KAEDA,GAAA,GAAGM,mBAAmBL,MAAQK,mBAAmBP,EAAIE,OAG1D,OAAAD,CAAA"}
|
package/lib/storage/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),r=require("../base64/index.js"),o=require("../console/index.js"),i=e.reactive({prefix:"fast__",expireSuffix:"__Expire",crypto:!1}),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),r=require("../base64/index.js"),o=require("../console/index.js"),i=require("../error/index.js"),t=e.reactive({prefix:"fast__",expireSuffix:"__Expire",crypto:!1}),n=e.computed((()=>t.prefix)),s=e.computed((()=>t.expireSuffix)),f={set(e,r){"undefined"!=typeof uni?uni.setStorageSync(e,r):window.localStorage.setItem(e,r)},get:e=>"undefined"!=typeof uni?uni.getStorageSync(e):window.localStorage.getItem(e),remove(e){"undefined"!=typeof uni?uni.removeStorageSync(e):window.localStorage.removeItem(e)},clear(){"undefined"!=typeof uni?uni.clearStorageSync():window.localStorage.clear()},keys:()=>"undefined"!=typeof uni?uni.getStorageInfoSync().keys:window.localStorage},c={set(e,n,s,c){try{if(c??(c=t.crypto),s){if(isNaN(s)||s<1)throw new i.FastError("有效期应为一个有效数值");const r={time:Date.now(),expire:s},o=JSON.stringify(r);f.set(`${t.prefix}${e}${t.expireSuffix}`,o)}let o=JSON.stringify(n);c&&(o=r.base64Util.toBase64(o)),f.set(`${t.prefix}${e}`,o)}catch(p){o.consoleError("Local",p)}},get(e,i){try{i??(i=t.crypto);let o=f.get(`${t.prefix}${e}`);if(o){i&&(o=r.base64Util.base64ToStr(o));const n=f.get(`${t.prefix}${e}${t.expireSuffix}`);if(n){const r=JSON.parse(n);if(Date.now()>r.time+60*r.expire*1e3)return f.remove(`${t.prefix}${e}`),f.remove(`${t.prefix}${e}${t.expireSuffix}`),null}try{return JSON.parse(o)}catch{return o}}return null}catch(n){o.consoleError("Local",n)}},remove(e){try{f.remove(`${t.prefix}${e}`),f.remove(`${t.prefix}${e}${t.expireSuffix}`)}catch(r){o.consoleError("Local",r)}},removeByPrefix(e){try{for(const r in f.keys)-1!==r.indexOf(`${t.prefix}${e}`)&&f.remove(r)}catch(r){o.consoleError("Local",r)}},clear(){try{f.clear()}catch(e){o.consoleError("Local",e)}}},p={set(e,n,s,f){if("undefined"==typeof uni)try{if(f??(f=t.crypto),s){if(isNaN(s)||s<1)throw new i.FastError("有效期应为一个有效数值");const r={time:Date.now(),expire:s},o=JSON.stringify(r);window.sessionStorage.setItem(`${t.prefix}${e}${t.expireSuffix}`,o)}let o=JSON.stringify(n);f&&(o=r.base64Util.toBase64(o)),window.sessionStorage.setItem(`${t.prefix}${e}`,o)}catch(c){o.consoleError("Session",c)}else o.consoleError("Session","UniApp 环境下 [Session] 不可用。")},get(e,i){if("undefined"==typeof uni)try{i??(i=t.crypto);let o=window.sessionStorage.getItem(`${t.prefix}${e}`);if(o){i&&(o=r.base64Util.base64ToStr(o));const n=window.sessionStorage.getItem(`${t.prefix}${e}${t.expireSuffix}`);if(n){const r=JSON.parse(n);if(Date.now()>r.time+60*r.expire*1e3)return window.sessionStorage.removeItem(`${t.prefix}${e}`),window.sessionStorage.removeItem(`${t.prefix}${e}${t.expireSuffix}`),null}try{return JSON.parse(o)}catch{return o}}return null}catch(n){o.consoleError("Session",n)}else o.consoleError("Session","UniApp 环境下 [Session] 不可用。")},remove(e){if("undefined"==typeof uni)try{window.sessionStorage.removeItem(`${t.prefix}${e}`),window.sessionStorage.removeItem(`${t.prefix}${e}${t.expireSuffix}`)}catch(r){o.consoleError("Session",r)}else o.consoleError("Session","UniApp 环境下 [Session] 不可用。")},removeByPrefix(e){if("undefined"==typeof uni)try{for(const r in window.sessionStorage)-1!==r.indexOf(`${t.prefix}${e}`)&&window.sessionStorage.removeItem(r)}catch(r){o.consoleError("Session",r)}else o.consoleError("Session","UniApp 环境下 [Session] 不可用。")},clear(){if("undefined"==typeof uni)try{window.sessionStorage.clear()}catch(e){o.consoleError("Session",e)}else o.consoleError("Session","UniApp 环境下 [Session] 不可用。")}};exports.CACHE_EXPIRE_SUFFIX=s,exports.CACHE_PREFIX=n,exports.Local=c,exports.Session=p,exports.useStorage=()=>({prefix(e){t.prefix=e},expireSuffix(e){t.expireSuffix=e},crypto(e){t.crypto=e}});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/storage/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/storage/index.ts"],"sourcesContent":["import { computed, reactive } from \"vue\";\nimport { base64Util } from \"../base64\";\nimport { consoleError } from \"../console\";\n\nconst state = reactive({\n\tprefix: \"fast__\",\n\texpireSuffix: \"__Expire\",\n\tcrypto: false,\n});\n\n/**\n * 本地缓存前缀 Key\n */\nexport const CACHE_PREFIX = computed(() => state.prefix);\n\n/**\n * 本地缓存过期值后缀 Key\n */\nexport const CACHE_EXPIRE_SUFFIX = computed(() => state.expireSuffix);\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport const useStorage = () => {\n\treturn {\n\t\t/**\n\t\t * 设置缓存前缀 Key\n\t\t * @param key\n\t\t */\n\t\tprefix(key: string): void {\n\t\t\tstate.prefix = key;\n\t\t},\n\t\t/**\n\t\t * 缓存过期值后缀 Key\n\t\t * @param key\n\t\t */\n\t\texpireSuffix(key: string): void {\n\t\t\tstate.expireSuffix = key;\n\t\t},\n\t\t/**\n\t\t * 设置缓存是否加密\n\t\t * @param crypto\n\t\t */\n\t\tcrypto(crypto: boolean): void {\n\t\t\tstate.crypto = crypto;\n\t\t},\n\t};\n};\n\nconst storage = {\n\tset(key: string, val: any): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tuni.setStorageSync(key, val);\n\t\t} else {\n\t\t\twindow.localStorage.setItem(key, val);\n\t\t}\n\t},\n\tget(key: string): string | any | null {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\treturn uni.getStorageSync(key);\n\t\t} else {\n\t\t\treturn window.localStorage.getItem(key);\n\t\t}\n\t},\n\tremove(key: string): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tuni.removeStorageSync(key);\n\t\t} else {\n\t\t\twindow.localStorage.removeItem(key);\n\t\t}\n\t},\n\tclear(): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tuni.clearStorageSync();\n\t\t} else {\n\t\t\twindow.localStorage.clear();\n\t\t}\n\t},\n\tkeys(): string[] | Storage {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\treturn uni.getStorageInfoSync().keys;\n\t\t} else {\n\t\t\treturn window.localStorage;\n\t\t}\n\t},\n};\n\n/**\n * window.localStorage\n * - 如果是 UniApp 环境则使用的是 uni.xxxStorage\n */\nexport const Local = {\n\t/**\n\t * 设置\n\t * @param key 缓存的Key\n\t * @param val 缓存值\n\t * @param expire 过期时间,单位分钟\n\t * @param encrypt 是否对缓存的数据加密\n\t */\n\tset(key: string, val: any, expire?: number, encrypt?: boolean): void {\n\t\ttry {\n\t\t\tencrypt ??= state.crypto;\n\t\t\t// 判断是否存在缓存过期时间\n\t\t\tif (expire) {\n\t\t\t\tif (isNaN(expire) || expire < 1) {\n\t\t\t\t\tthrow new Error(\"有效期应为一个有效数值\");\n\t\t\t\t}\n\t\t\t\t// 设置过期时间的缓存\n\t\t\t\tconst expireData = {\n\t\t\t\t\ttime: Date.now(),\n\t\t\t\t\texpire,\n\t\t\t\t};\n\t\t\t\tconst expireJson = JSON.stringify(expireData);\n\t\t\t\tstorage.set(`${state.prefix}${key}${state.expireSuffix}`, expireJson);\n\t\t\t}\n\t\t\tlet valJson = JSON.stringify(val);\n\t\t\tif (encrypt) {\n\t\t\t\tvalJson = base64Util.toBase64(valJson);\n\t\t\t}\n\t\t\tstorage.set(`${state.prefix}${key}`, valJson);\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Local\", error);\n\t\t}\n\t},\n\t/**\n\t * 获取\n\t * @param key 缓存的Key\n\t * @param decrypt 是否对缓存的数据解密\n\t * @returns {T} 传入的对象类型,默认为 string\n\t */\n\tget<T = string>(key: string, decrypt?: boolean): T {\n\t\ttry {\n\t\t\tdecrypt ??= state.crypto;\n\t\t\t// 获取缓存 JSON 字符串\n\t\t\tlet valJson = storage.get(`${state.prefix}${key}`);\n\n\t\t\tif (valJson) {\n\t\t\t\t// 判断是否解密\n\t\t\t\tif (decrypt) {\n\t\t\t\t\tvalJson = base64Util.base64ToStr(valJson);\n\t\t\t\t}\n\t\t\t\t// 尝试获取缓存过期时间的 JSON 字符串\n\t\t\t\tconst expireJson = storage.get(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t\t\t// 判断是否存在过期时间\n\t\t\t\tif (expireJson) {\n\t\t\t\t\tconst expireData = JSON.parse(expireJson);\n\t\t\t\t\tif (Date.now() > expireData.time + expireData.expire * 60 * 1000) {\n\t\t\t\t\t\t// 过期了,删除对应的缓存数据\n\t\t\t\t\t\tstorage.remove(`${state.prefix}${key}`);\n\t\t\t\t\t\tstorage.remove(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\treturn JSON.parse(valJson) as T;\n\t\t\t\t} catch {\n\t\t\t\t\treturn valJson as T;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Local\", error);\n\t\t}\n\t},\n\t/**\n\t * 移除\n\t * @param key 缓存的Key\n\t */\n\tremove(key: string): void {\n\t\ttry {\n\t\t\tstorage.remove(`${state.prefix}${key}`);\n\t\t\tstorage.remove(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Local\", error);\n\t\t}\n\t},\n\t/**\n\t * 根据前缀移除\n\t * @param key 缓存的Key\n\t */\n\tremoveByPrefix(key: string): void {\n\t\ttry {\n\t\t\tfor (const itemKey in storage.keys) {\n\t\t\t\tif (itemKey.indexOf(`${state.prefix}${key}`) !== -1) {\n\t\t\t\t\tstorage.remove(itemKey);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Local\", error);\n\t\t}\n\t},\n\t/**\n\t * 移除全部\n\t */\n\tclear(): void {\n\t\ttry {\n\t\t\tstorage.clear();\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Local\", error);\n\t\t}\n\t},\n};\n\n/**\n * window.sessionStorage\n * - UniApp 环境下不可用\n */\nexport const Session = {\n\t/**\n\t * 设置会话缓存\n\t * @param key 缓存的Key\n\t * @param val 缓存值\n\t * @param expire 过期时间,单位分钟\n\t * @param encrypt 是否对缓存的数据加密\n\t */\n\tset(key: string, val: any, expire?: number, encrypt?: boolean): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tconsoleError(\"Session\", \"UniApp 环境下 [Session] 不可用。\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tencrypt ??= state.crypto;\n\t\t\t// 判断是否存在缓存过期时间\n\t\t\tif (expire) {\n\t\t\t\tif (isNaN(expire) || expire < 1) {\n\t\t\t\t\tthrow new Error(\"有效期应为一个有效数值\");\n\t\t\t\t}\n\t\t\t\t// 设置过期时间的缓存\n\t\t\t\tconst expireData = {\n\t\t\t\t\ttime: Date.now(),\n\t\t\t\t\texpire,\n\t\t\t\t};\n\t\t\t\tconst expireJson = JSON.stringify(expireData);\n\t\t\t\twindow.sessionStorage.setItem(`${state.prefix}${key}${state.expireSuffix}`, expireJson);\n\t\t\t}\n\t\t\tlet valJson = JSON.stringify(val);\n\t\t\tif (encrypt) {\n\t\t\t\tvalJson = base64Util.toBase64(valJson);\n\t\t\t}\n\t\t\twindow.sessionStorage.setItem(`${state.prefix}${key}`, valJson);\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Session\", error);\n\t\t}\n\t},\n\t/**\n\t * 获取会话缓存\n\t * @param key 缓存的Key\n\t * @param decrypt 是否对缓存的数据解密\n\t * @returns {T} 传入的对象类型,默认为 string\n\t */\n\tget<T = string>(key: string, decrypt?: boolean): T {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tconsoleError(\"Session\", \"UniApp 环境下 [Session] 不可用。\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tdecrypt ??= state.crypto;\n\t\t\t// 获取缓存 JSON 字符串\n\t\t\tlet valJson = window.sessionStorage.getItem(`${state.prefix}${key}`);\n\t\t\tif (valJson) {\n\t\t\t\t// 判断是否解密\n\t\t\t\tif (decrypt) {\n\t\t\t\t\tvalJson = base64Util.base64ToStr(valJson);\n\t\t\t\t}\n\t\t\t\t// 尝试获取缓存过期时间的 JSON 字符串\n\t\t\t\tconst expireJson = window.sessionStorage.getItem(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t\t\t// 判断是否存在过期时间\n\t\t\t\tif (expireJson) {\n\t\t\t\t\tconst expireData = JSON.parse(expireJson);\n\t\t\t\t\tif (Date.now() > expireData.time + expireData.expire * 60 * 1000) {\n\t\t\t\t\t\t// 过期了,删除对应的缓存数据\n\t\t\t\t\t\twindow.sessionStorage.removeItem(`${state.prefix}${key}`);\n\t\t\t\t\t\twindow.sessionStorage.removeItem(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\treturn JSON.parse(valJson) as T;\n\t\t\t\t} catch {\n\t\t\t\t\treturn valJson as T;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Session\", error);\n\t\t}\n\t},\n\t/**\n\t * 移除会话缓存\n\t * @param key 缓存的Key\n\t */\n\tremove(key: string): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tconsoleError(\"Session\", \"UniApp 环境下 [Session] 不可用。\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\twindow.sessionStorage.removeItem(`${state.prefix}${key}`);\n\t\t\twindow.sessionStorage.removeItem(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Session\", error);\n\t\t}\n\t},\n\t/**\n\t * 根据前缀移除会话缓存\n\t * @param key 缓存的Key\n\t */\n\tremoveByPrefix(key: string): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tconsoleError(\"Session\", \"UniApp 环境下 [Session] 不可用。\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tfor (const itemKey in window.sessionStorage) {\n\t\t\t\tif (itemKey.indexOf(`${state.prefix}${key}`) !== -1) {\n\t\t\t\t\twindow.sessionStorage.removeItem(itemKey);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Session\", error);\n\t\t}\n\t},\n\t/**\n\t * 移除全部会话缓存\n\t */\n\tclear(): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tconsoleError(\"Session\", \"UniApp 环境下 [Session] 不可用。\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\twindow.sessionStorage.clear();\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Session\", error);\n\t\t}\n\t},\n};\n"],"names":["state","reactive","prefix","expireSuffix","crypto","CACHE_PREFIX","computed","CACHE_EXPIRE_SUFFIX","storage","set","key","val","uni","setStorageSync","window","localStorage","setItem","get","getStorageSync","getItem","remove","removeStorageSync","removeItem","clear","clearStorageSync","keys","getStorageInfoSync","Local","expire","encrypt","isNaN","Error","expireData","time","Date","now","expireJson","JSON","stringify","valJson","base64Util","toBase64","error","index","consoleError","decrypt","base64ToStr","parse","removeByPrefix","itemKey","indexOf","Session","sessionStorage"],"mappings":"wKAIMA,EAAQC,EAAAA,SAAS,CACtBC,OAAQ,SACRC,aAAc,WACdC,QAAQ,IAMIC,EAAeC,EAAAA,UAAS,IAAMN,EAAME,SAKpCK,EAAsBD,EAAAA,UAAS,IAAMN,EAAMG,eA6BlDK,EAAU,CACf,GAAAC,CAAIC,EAAaC,GACG,oBAARC,IACNA,IAAAC,eAAeH,EAAKC,GAEjBG,OAAAC,aAAaC,QAAQN,EAAKC,EAEnC,EACAM,IAAIP,GACgB,oBAARE,IACHA,IAAIM,eAAeR,GAEnBI,OAAOC,aAAaI,QAAQT,GAGrC,MAAAU,CAAOV,GACa,oBAARE,IACVA,IAAIS,kBAAkBX,GAEfI,OAAAC,aAAaO,WAAWZ,EAEjC,EACA,KAAAa,GACoB,oBAARX,IACVA,IAAIY,mBAEJV,OAAOC,aAAaQ,OAEtB,EACAE,KAA2B,IACP,oBAARb,IACHA,IAAIc,qBAAqBD,KAEzBX,OAAOC,cASJY,EAAQ,CAQpB,GAAAlB,CAAIC,EAAaC,EAAUiB,EAAiBC,GACvC,IAGH,GAFAA,IAAAA,EAAY7B,EAAMI,QAEdwB,EAAQ,CACX,GAAIE,MAAMF,IAAWA,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EAAME,SAASQ,KAC5CI,OAAAsC,eAAe9B,WAAW,GAAGtB,EAAME,SAASQ,IAAMV,EAAMG,gBACxD,IACR,CAEG,IACI,OAAAkC,KAAKU,MAAMR,EAAO,CAClB,MACA,OAAAA,CAAA,CACR,CAEM,OAAA,WACCG,GACRC,EAAAC,aAAa,UAAWF,EAAK,MAhC7BC,EAAAC,aAAa,UAAW,4BAkC1B,EAKA,MAAAxB,CAAOV,GACF,GAAe,oBAARE,IAIP,IACHE,OAAOsC,eAAe9B,WAAW,GAAGtB,EAAME,SAASQ,KAC5CI,OAAAsC,eAAe9B,WAAW,GAAGtB,EAAME,SAASQ,IAAMV,EAAMG,sBACvDuC,GACRC,EAAAC,aAAa,UAAWF,EAAK,MAP7BC,EAAAC,aAAa,UAAW,4BAS1B,EAKA,cAAAI,CAAetC,GACV,GAAe,oBAARE,IAIP,IACQ,IAAA,MAAAqC,KAAWnC,OAAOsC,gBACyB,IAAjDH,EAAQC,QAAQ,GAAGlD,EAAME,SAASQ,MAC9BI,OAAAsC,eAAe9B,WAAW2B,SAG3BP,GACRC,EAAAC,aAAa,UAAWF,EAAK,MAV7BC,EAAAC,aAAa,UAAW,4BAY1B,EAIA,KAAArB,GACK,GAAe,oBAARX,IAIP,IACHE,OAAOsC,eAAe7B,cACdmB,GACRC,EAAAC,aAAa,UAAWF,EAAK,MAN7BC,EAAAC,aAAa,UAAW,4BAOzB,6GAvTwB,KAClB,CAKN,MAAA1C,CAAOQ,GACNV,EAAME,OAASQ,CAChB,EAKA,YAAAP,CAAaO,GACZV,EAAMG,aAAeO,CACtB,EAKA,MAAAN,CAAOA,GACNJ,EAAMI,OAASA,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/storage/index.ts"],"sourcesContent":["import { computed, reactive } from \"vue\";\nimport { base64Util } from \"../base64\";\nimport { consoleError } from \"../console\";\nimport { FastError } from \"../error\";\n\nconst state = reactive({\n\tprefix: \"fast__\",\n\texpireSuffix: \"__Expire\",\n\tcrypto: false,\n});\n\n/**\n * 本地缓存前缀 Key\n */\nexport const CACHE_PREFIX = computed(() => state.prefix);\n\n/**\n * 本地缓存过期值后缀 Key\n */\nexport const CACHE_EXPIRE_SUFFIX = computed(() => state.expireSuffix);\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport const useStorage = () => {\n\treturn {\n\t\t/**\n\t\t * 设置缓存前缀 Key\n\t\t * @param key\n\t\t */\n\t\tprefix(key: string): void {\n\t\t\tstate.prefix = key;\n\t\t},\n\t\t/**\n\t\t * 缓存过期值后缀 Key\n\t\t * @param key\n\t\t */\n\t\texpireSuffix(key: string): void {\n\t\t\tstate.expireSuffix = key;\n\t\t},\n\t\t/**\n\t\t * 设置缓存是否加密\n\t\t * @param crypto\n\t\t */\n\t\tcrypto(crypto: boolean): void {\n\t\t\tstate.crypto = crypto;\n\t\t},\n\t};\n};\n\nconst storage = {\n\tset(key: string, val: any): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tuni.setStorageSync(key, val);\n\t\t} else {\n\t\t\twindow.localStorage.setItem(key, val);\n\t\t}\n\t},\n\tget(key: string): string | any | null {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\treturn uni.getStorageSync(key);\n\t\t} else {\n\t\t\treturn window.localStorage.getItem(key);\n\t\t}\n\t},\n\tremove(key: string): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tuni.removeStorageSync(key);\n\t\t} else {\n\t\t\twindow.localStorage.removeItem(key);\n\t\t}\n\t},\n\tclear(): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tuni.clearStorageSync();\n\t\t} else {\n\t\t\twindow.localStorage.clear();\n\t\t}\n\t},\n\tkeys(): string[] | Storage {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\treturn uni.getStorageInfoSync().keys;\n\t\t} else {\n\t\t\treturn window.localStorage;\n\t\t}\n\t},\n};\n\n/**\n * window.localStorage\n * - 如果是 UniApp 环境则使用的是 uni.xxxStorage\n */\nexport const Local = {\n\t/**\n\t * 设置\n\t * @param key 缓存的Key\n\t * @param val 缓存值\n\t * @param expire 过期时间,单位分钟\n\t * @param encrypt 是否对缓存的数据加密\n\t */\n\tset(key: string, val: any, expire?: number, encrypt?: boolean): void {\n\t\ttry {\n\t\t\tencrypt ??= state.crypto;\n\t\t\t// 判断是否存在缓存过期时间\n\t\t\tif (expire) {\n\t\t\t\tif (isNaN(expire) || expire < 1) {\n\t\t\t\t\tthrow new FastError(\"有效期应为一个有效数值\");\n\t\t\t\t}\n\t\t\t\t// 设置过期时间的缓存\n\t\t\t\tconst expireData = {\n\t\t\t\t\ttime: Date.now(),\n\t\t\t\t\texpire,\n\t\t\t\t};\n\t\t\t\tconst expireJson = JSON.stringify(expireData);\n\t\t\t\tstorage.set(`${state.prefix}${key}${state.expireSuffix}`, expireJson);\n\t\t\t}\n\t\t\tlet valJson = JSON.stringify(val);\n\t\t\tif (encrypt) {\n\t\t\t\tvalJson = base64Util.toBase64(valJson);\n\t\t\t}\n\t\t\tstorage.set(`${state.prefix}${key}`, valJson);\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Local\", error);\n\t\t}\n\t},\n\t/**\n\t * 获取\n\t * @param key 缓存的Key\n\t * @param decrypt 是否对缓存的数据解密\n\t * @returns {T} 传入的对象类型,默认为 string\n\t */\n\tget<T = string>(key: string, decrypt?: boolean): T {\n\t\ttry {\n\t\t\tdecrypt ??= state.crypto;\n\t\t\t// 获取缓存 JSON 字符串\n\t\t\tlet valJson = storage.get(`${state.prefix}${key}`);\n\n\t\t\tif (valJson) {\n\t\t\t\t// 判断是否解密\n\t\t\t\tif (decrypt) {\n\t\t\t\t\tvalJson = base64Util.base64ToStr(valJson);\n\t\t\t\t}\n\t\t\t\t// 尝试获取缓存过期时间的 JSON 字符串\n\t\t\t\tconst expireJson = storage.get(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t\t\t// 判断是否存在过期时间\n\t\t\t\tif (expireJson) {\n\t\t\t\t\tconst expireData = JSON.parse(expireJson);\n\t\t\t\t\tif (Date.now() > expireData.time + expireData.expire * 60 * 1000) {\n\t\t\t\t\t\t// 过期了,删除对应的缓存数据\n\t\t\t\t\t\tstorage.remove(`${state.prefix}${key}`);\n\t\t\t\t\t\tstorage.remove(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\treturn JSON.parse(valJson) as T;\n\t\t\t\t} catch {\n\t\t\t\t\treturn valJson as T;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Local\", error);\n\t\t}\n\t},\n\t/**\n\t * 移除\n\t * @param key 缓存的Key\n\t */\n\tremove(key: string): void {\n\t\ttry {\n\t\t\tstorage.remove(`${state.prefix}${key}`);\n\t\t\tstorage.remove(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Local\", error);\n\t\t}\n\t},\n\t/**\n\t * 根据前缀移除\n\t * @param key 缓存的Key\n\t */\n\tremoveByPrefix(key: string): void {\n\t\ttry {\n\t\t\tfor (const itemKey in storage.keys) {\n\t\t\t\tif (itemKey.indexOf(`${state.prefix}${key}`) !== -1) {\n\t\t\t\t\tstorage.remove(itemKey);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Local\", error);\n\t\t}\n\t},\n\t/**\n\t * 移除全部\n\t */\n\tclear(): void {\n\t\ttry {\n\t\t\tstorage.clear();\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Local\", error);\n\t\t}\n\t},\n};\n\n/**\n * window.sessionStorage\n * - UniApp 环境下不可用\n */\nexport const Session = {\n\t/**\n\t * 设置会话缓存\n\t * @param key 缓存的Key\n\t * @param val 缓存值\n\t * @param expire 过期时间,单位分钟\n\t * @param encrypt 是否对缓存的数据加密\n\t */\n\tset(key: string, val: any, expire?: number, encrypt?: boolean): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tconsoleError(\"Session\", \"UniApp 环境下 [Session] 不可用。\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tencrypt ??= state.crypto;\n\t\t\t// 判断是否存在缓存过期时间\n\t\t\tif (expire) {\n\t\t\t\tif (isNaN(expire) || expire < 1) {\n\t\t\t\t\tthrow new FastError(\"有效期应为一个有效数值\");\n\t\t\t\t}\n\t\t\t\t// 设置过期时间的缓存\n\t\t\t\tconst expireData = {\n\t\t\t\t\ttime: Date.now(),\n\t\t\t\t\texpire,\n\t\t\t\t};\n\t\t\t\tconst expireJson = JSON.stringify(expireData);\n\t\t\t\twindow.sessionStorage.setItem(`${state.prefix}${key}${state.expireSuffix}`, expireJson);\n\t\t\t}\n\t\t\tlet valJson = JSON.stringify(val);\n\t\t\tif (encrypt) {\n\t\t\t\tvalJson = base64Util.toBase64(valJson);\n\t\t\t}\n\t\t\twindow.sessionStorage.setItem(`${state.prefix}${key}`, valJson);\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Session\", error);\n\t\t}\n\t},\n\t/**\n\t * 获取会话缓存\n\t * @param key 缓存的Key\n\t * @param decrypt 是否对缓存的数据解密\n\t * @returns {T} 传入的对象类型,默认为 string\n\t */\n\tget<T = string>(key: string, decrypt?: boolean): T {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tconsoleError(\"Session\", \"UniApp 环境下 [Session] 不可用。\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tdecrypt ??= state.crypto;\n\t\t\t// 获取缓存 JSON 字符串\n\t\t\tlet valJson = window.sessionStorage.getItem(`${state.prefix}${key}`);\n\t\t\tif (valJson) {\n\t\t\t\t// 判断是否解密\n\t\t\t\tif (decrypt) {\n\t\t\t\t\tvalJson = base64Util.base64ToStr(valJson);\n\t\t\t\t}\n\t\t\t\t// 尝试获取缓存过期时间的 JSON 字符串\n\t\t\t\tconst expireJson = window.sessionStorage.getItem(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t\t\t// 判断是否存在过期时间\n\t\t\t\tif (expireJson) {\n\t\t\t\t\tconst expireData = JSON.parse(expireJson);\n\t\t\t\t\tif (Date.now() > expireData.time + expireData.expire * 60 * 1000) {\n\t\t\t\t\t\t// 过期了,删除对应的缓存数据\n\t\t\t\t\t\twindow.sessionStorage.removeItem(`${state.prefix}${key}`);\n\t\t\t\t\t\twindow.sessionStorage.removeItem(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\treturn JSON.parse(valJson) as T;\n\t\t\t\t} catch {\n\t\t\t\t\treturn valJson as T;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Session\", error);\n\t\t}\n\t},\n\t/**\n\t * 移除会话缓存\n\t * @param key 缓存的Key\n\t */\n\tremove(key: string): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tconsoleError(\"Session\", \"UniApp 环境下 [Session] 不可用。\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\twindow.sessionStorage.removeItem(`${state.prefix}${key}`);\n\t\t\twindow.sessionStorage.removeItem(`${state.prefix}${key}${state.expireSuffix}`);\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Session\", error);\n\t\t}\n\t},\n\t/**\n\t * 根据前缀移除会话缓存\n\t * @param key 缓存的Key\n\t */\n\tremoveByPrefix(key: string): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tconsoleError(\"Session\", \"UniApp 环境下 [Session] 不可用。\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tfor (const itemKey in window.sessionStorage) {\n\t\t\t\tif (itemKey.indexOf(`${state.prefix}${key}`) !== -1) {\n\t\t\t\t\twindow.sessionStorage.removeItem(itemKey);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Session\", error);\n\t\t}\n\t},\n\t/**\n\t * 移除全部会话缓存\n\t */\n\tclear(): void {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\tconsoleError(\"Session\", \"UniApp 环境下 [Session] 不可用。\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\twindow.sessionStorage.clear();\n\t\t} catch (error) {\n\t\t\tconsoleError(\"Session\", error);\n\t\t}\n\t},\n};\n"],"names":["state","reactive","prefix","expireSuffix","crypto","CACHE_PREFIX","computed","CACHE_EXPIRE_SUFFIX","storage","set","key","val","uni","setStorageSync","window","localStorage","setItem","get","getStorageSync","getItem","remove","removeStorageSync","removeItem","clear","clearStorageSync","keys","getStorageInfoSync","Local","expire","encrypt","isNaN","FastError","expireData","time","Date","now","expireJson","JSON","stringify","valJson","base64Util","toBase64","error","index","consoleError","decrypt","base64ToStr","parse","removeByPrefix","itemKey","indexOf","Session","sessionStorage"],"mappings":"uMAKMA,EAAQC,EAAAA,SAAS,CACtBC,OAAQ,SACRC,aAAc,WACdC,QAAQ,IAMIC,EAAeC,EAAAA,UAAS,IAAMN,EAAME,SAKpCK,EAAsBD,EAAAA,UAAS,IAAMN,EAAMG,eA6BlDK,EAAU,CACf,GAAAC,CAAIC,EAAaC,GACG,oBAARC,IACNA,IAAAC,eAAeH,EAAKC,GAEjBG,OAAAC,aAAaC,QAAQN,EAAKC,EAEnC,EACAM,IAAIP,GACgB,oBAARE,IACHA,IAAIM,eAAeR,GAEnBI,OAAOC,aAAaI,QAAQT,GAGrC,MAAAU,CAAOV,GACa,oBAARE,IACVA,IAAIS,kBAAkBX,GAEfI,OAAAC,aAAaO,WAAWZ,EAEjC,EACA,KAAAa,GACoB,oBAARX,IACVA,IAAIY,mBAEJV,OAAOC,aAAaQ,OAEtB,EACAE,KAA2B,IACP,oBAARb,IACHA,IAAIc,qBAAqBD,KAEzBX,OAAOC,cASJY,EAAQ,CAQpB,GAAAlB,CAAIC,EAAaC,EAAUiB,EAAiBC,GACvC,IAG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KAA2B,GAApBD,EAAWJ,OAAc,IAIpD,OAFPd,OAAOsC,eAAe9B,WAAW,GAAGtB,EAAME,SAASQ,KAC5CI,OAAAsC,eAAe9B,WAAW,GAAGtB,EAAME,SAASQ,IAAMV,EAAMG,gBACxD,IACR,CAEG,IACI,OAAAkC,KAAKU,MAAMR,EAAO,CAClB,MACA,OAAAA,CAAA,CACR,CAEM,OAAA,WACCG,GACRC,EAAAC,aAAa,UAAWF,EAAK,MAhC7BC,EAAAC,aAAa,UAAW,4BAkC1B,EAKA,MAAAxB,CAAOV,GACF,GAAe,oBAARE,IAIP,IACHE,OAAOsC,eAAe9B,WAAW,GAAGtB,EAAME,SAASQ,KAC5CI,OAAAsC,eAAe9B,WAAW,GAAGtB,EAAME,SAASQ,IAAMV,EAAMG,sBACvDuC,GACRC,EAAAC,aAAa,UAAWF,EAAK,MAP7BC,EAAAC,aAAa,UAAW,4BAS1B,EAKA,cAAAI,CAAetC,GACV,GAAe,oBAARE,IAIP,IACQ,IAAA,MAAAqC,KAAWnC,OAAOsC,gBACyB,IAAjDH,EAAQC,QAAQ,GAAGlD,EAAME,SAASQ,MAC9BI,OAAAsC,eAAe9B,WAAW2B,SAG3BP,GACRC,EAAAC,aAAa,UAAWF,EAAK,MAV7BC,EAAAC,aAAa,UAAW,4BAY1B,EAIA,KAAArB,GACK,GAAe,oBAARX,IAIP,IACHE,OAAOsC,eAAe7B,cACdmB,GACRC,EAAAC,aAAa,UAAWF,EAAK,MAN7BC,EAAAC,aAAa,UAAW,4BAOzB,6GAvTwB,KAClB,CAKN,MAAA1C,CAAOQ,GACNV,EAAME,OAASQ,CAChB,EAKA,YAAAP,CAAaO,GACZV,EAAMG,aAAeO,CACtB,EAKA,MAAAN,CAAOA,GACNJ,EAAMI,OAASA,CAAA"}
|
package/lib/string/index.d.ts
CHANGED
|
@@ -10,6 +10,27 @@ export declare const stringUtil: {
|
|
|
10
10
|
* 是否为JSON字符串
|
|
11
11
|
*/
|
|
12
12
|
isJson(value: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 切割骆驼命名式字符串
|
|
15
|
+
*/
|
|
16
|
+
splitCamelCase(value: string): string[];
|
|
17
|
+
/**
|
|
18
|
+
* 将字符串转为 camelCase 格式,支持 - 或 _ 分隔的字符串
|
|
19
|
+
* 例如:'hello-world' 或 'hello_world' => 'helloWorld'
|
|
20
|
+
*/
|
|
21
|
+
toCamelCase(value: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* 字符串首字母大写
|
|
24
|
+
*/
|
|
25
|
+
firstCharToUpper(value: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* 字符串首字母小写
|
|
28
|
+
*/
|
|
29
|
+
firstCharToLower(value: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* 截取指定长度的字符串
|
|
32
|
+
*/
|
|
33
|
+
subStringWithEllipsis(value: string, length: number, suffix?: string): string;
|
|
13
34
|
/**
|
|
14
35
|
* 生成随机字符串
|
|
15
36
|
*/
|
package/lib/string/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("lodash-unified"),t={getUrlParams(e){const t=/[?&][^=?&]+=[^?&]+/g,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("lodash-unified"),t={getUrlParams(e){const t=/[?&][^=?&]+=[^?&]+/g,r={};let o;for(;null!==(o=t.exec(e));){const[e,t]=o[0].substring(1).split("=");r[e]=decodeURIComponent(t)}return r},isJson:r=>!!e.isString(r)&&(r=r.replace(/\s/g,"").replace(/\n|\r/,""),/^\{.*?\}$/.test(r)?/".*?":/.test(r):!!/^\[.*?\]$/.test(r)&&r.replace(/^\[/,"").replace(/\]$/,"").replace(/\},\{/g,"}\n{").split(/\n/).map((e=>t.isJson(e))).reduce(((e,t)=>!!t))),splitCamelCase:e=>e?1===e.length?[e]:e.split(new RegExp("(?=\\p{Lu}\\p{Ll})|(?<=\\p{Ll})(?=\\p{Lu})","u")).filter((e=>e.length>0)):[],toCamelCase:e=>e?e.replace(/[-_](\w)/g,((e,t)=>t?t.toUpperCase():"")):"",firstCharToUpper:e=>e?e.charAt(0).toUpperCase()+e.slice(1):"",firstCharToLower:e=>e?e.charAt(0).toLowerCase()+e.slice(1):"",subStringWithEllipsis:(e,t,r="...")=>e?e.length>t?e.substring(0,t)+r:e:"",generateRandomString(e){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let r="";for(let o=0;o<e;o++){const e=Math.floor(62*Math.random());r+=t.charAt(e)}return r},generateUUID(){let e="";for(let t=0;t<32;t++){const r=16*Math.random()|0;8!==t&&12!==t&&16!==t&&20!==t||(e+="-"),e+=(12===t?4:16===t?3&r|8:r).toString(16)}return e},async copy(e){if("undefined"!=typeof uni)return new Promise(((t,r)=>{uni.setClipboardData({data:e,success:()=>{t()},fail:()=>{r()}})}));if((null==navigator?void 0:navigator.clipboard)&&window.isSecureContext)await navigator.clipboard.writeText(e);else{const t=document.createElement("textarea");t.value=e,t.style.position="absolute",t.style.opacity="0",t.style.left="-999999px",t.style.top="-999999px",document.body.appendChild(t),t.focus(),t.select(),document.execCommand("copy"),t.remove()}}};exports.stringUtil=t;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/string/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/string/index.ts"],"sourcesContent":["import { isString } from \"lodash-unified\";\n\n/**\n * 字符串工具类\n */\nexport const stringUtil = {\n\t/**\n\t * 获取Url参数\n\t */\n\tgetUrlParams(url: string): Record<string, any> {\n\t\tconst regex = /[?&][^=?&]+=[^?&]+/g;\n\t\tconst params: Record<string, any> = {};\n\n\t\tlet match;\n\t\twhile ((match = regex.exec(url)) !== null) {\n\t\t\tconst [key, value] = match[0].substring(1).split(\"=\");\n\t\t\tparams[key] = decodeURIComponent(value);\n\t\t}\n\n\t\treturn params;\n\t},\n\t/**\n\t * 是否为JSON字符串\n\t */\n\tisJson(value: string): boolean {\n\t\tif (!isString(value)) return false;\n\n\t\tvalue = value.replace(/\\s/g, \"\").replace(/\\n|\\r/, \"\");\n\n\t\tif (/^\\{
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/string/index.ts"],"sourcesContent":["import { isString } from \"lodash-unified\";\n\n/**\n * 字符串工具类\n */\nexport const stringUtil = {\n\t/**\n\t * 获取Url参数\n\t */\n\tgetUrlParams(url: string): Record<string, any> {\n\t\tconst regex = /[?&][^=?&]+=[^?&]+/g;\n\t\tconst params: Record<string, any> = {};\n\n\t\tlet match;\n\t\twhile ((match = regex.exec(url)) !== null) {\n\t\t\tconst [key, value] = match[0].substring(1).split(\"=\");\n\t\t\tparams[key] = decodeURIComponent(value);\n\t\t}\n\n\t\treturn params;\n\t},\n\t/**\n\t * 是否为JSON字符串\n\t */\n\tisJson(value: string): boolean {\n\t\tif (!isString(value)) return false;\n\n\t\tvalue = value.replace(/\\s/g, \"\").replace(/\\n|\\r/, \"\");\n\n\t\tif (/^\\{.*?\\}$/.test(value)) return /\".*?\":/.test(value);\n\n\t\tif (/^\\[.*?\\]$/.test(value)) {\n\t\t\treturn value\n\t\t\t\t.replace(/^\\[/, \"\")\n\t\t\t\t.replace(/\\]$/, \"\")\n\t\t\t\t.replace(/\\},\\{/g, \"}\\n{\")\n\t\t\t\t.split(/\\n/)\n\t\t\t\t.map((s) => {\n\t\t\t\t\treturn stringUtil.isJson(s);\n\t\t\t\t})\n\t\t\t\t.reduce((prev, curr) => {\n\t\t\t\t\treturn !!curr;\n\t\t\t\t});\n\t\t}\n\n\t\treturn false;\n\t},\n\t/**\n\t * 切割骆驼命名式字符串\n\t */\n\tsplitCamelCase(value: string): string[] {\n\t\tif (!value) return [];\n\n\t\tif (value.length === 1) return [value];\n\n\t\treturn value.split(/(?=\\p{Lu}\\p{Ll})|(?<=\\p{Ll})(?=\\p{Lu})/u).filter((token) => token.length > 0);\n\t},\n\t/**\n\t * 将字符串转为 camelCase 格式,支持 - 或 _ 分隔的字符串\n\t * 例如:'hello-world' 或 'hello_world' => 'helloWorld'\n\t */\n\ttoCamelCase(value: string): string {\n\t\tif (!value) return \"\";\n\t\treturn value.replace(/[-_](\\w)/g, (_, c) => (c ? c.toUpperCase() : \"\"));\n\t},\n\t/**\n\t * 字符串首字母大写\n\t */\n\tfirstCharToUpper(value: string): string {\n\t\tif (!value) return \"\";\n\t\treturn value.charAt(0).toUpperCase() + value.slice(1);\n\t},\n\t/**\n\t * 字符串首字母小写\n\t */\n\tfirstCharToLower(value: string): string {\n\t\tif (!value) return \"\";\n\t\treturn value.charAt(0).toLowerCase() + value.slice(1);\n\t},\n\t/**\n\t * 截取指定长度的字符串\n\t */\n\tsubStringWithEllipsis(value: string, length: number, suffix = \"...\"): string {\n\t\tif (!value) return \"\";\n\t\treturn value.length > length ? value.substring(0, length) + suffix : value;\n\t},\n\t/**\n\t * 生成随机字符串\n\t */\n\tgenerateRandomString(length: number): string {\n\t\tconst characters = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\";\n\t\tlet randomString = \"\";\n\t\tfor (let i = 0; i < length; i++) {\n\t\t\tconst randomIndex = Math.floor(Math.random() * characters.length);\n\t\t\trandomString += characters.charAt(randomIndex);\n\t\t}\n\t\treturn randomString;\n\t},\n\t/**\n\t * @description 生成唯一 uuid\n\t */\n\tgenerateUUID(): string {\n\t\tlet uuid = \"\";\n\t\tfor (let i = 0; i < 32; i++) {\n\t\t\tconst random = (Math.random() * 16) | 0;\n\t\t\tif (i === 8 || i === 12 || i === 16 || i === 20) uuid += \"-\";\n\t\t\tuuid += (i === 12 ? 4 : i === 16 ? (random & 3) | 8 : random).toString(16);\n\t\t}\n\t\treturn uuid;\n\t},\n\t/**\n\t * 复制\n\t */\n\tasync copy(value: string): Promise<void> {\n\t\tif (typeof uni !== \"undefined\") {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tuni.setClipboardData({\n\t\t\t\t\tdata: value,\n\t\t\t\t\tsuccess: () => {\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t},\n\t\t\t\t\tfail: () => {\n\t\t\t\t\t\treject();\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t});\n\t\t} else {\n\t\t\t// navigator.clipboard 需要https等安全上下文\n\t\t\tif (navigator?.clipboard && window.isSecureContext) {\n\t\t\t\tawait navigator.clipboard.writeText(value);\n\t\t\t} else {\n\t\t\t\tconst textareaEl = document.createElement(\"textarea\");\n\t\t\t\ttextareaEl.value = value;\n\t\t\t\t// 使文本域不显示\n\t\t\t\ttextareaEl.style.position = \"absolute\";\n\t\t\t\ttextareaEl.style.opacity = \"0\";\n\t\t\t\ttextareaEl.style.left = \"-999999px\";\n\t\t\t\ttextareaEl.style.top = \"-999999px\";\n\t\t\t\tdocument.body.appendChild(textareaEl);\n\t\t\t\ttextareaEl.focus();\n\t\t\t\ttextareaEl.select();\n\t\t\t\tdocument.execCommand(\"copy\");\n\t\t\t\ttextareaEl.remove();\n\t\t\t}\n\t\t}\n\t},\n};\n"],"names":["stringUtil","getUrlParams","url","regex","params","match","exec","key","value","substring","split","decodeURIComponent","isJson","isString","replace","test","map","s","reduce","prev","curr","splitCamelCase","length","RegExp","filter","token","toCamelCase","_","c","toUpperCase","firstCharToUpper","charAt","slice","firstCharToLower","toLowerCase","subStringWithEllipsis","suffix","generateRandomString","characters","randomString","i","randomIndex","Math","floor","random","generateUUID","uuid","toString","copy","uni","Promise","resolve","reject","setClipboardData","data","success","fail","navigator","clipboard","window","isSecureContext","writeText","textareaEl","document","createElement","style","position","opacity","left","top","body","appendChild","focus","select","execCommand","remove"],"mappings":"kHAKaA,EAAa,CAIzB,YAAAC,CAAaC,GACZ,MAAMC,EAAQ,sBACRC,EAA8B,CAAC,EAEjC,IAAAC,EACJ,KAAqC,QAA7BA,EAAQF,EAAMG,KAAKJ,KAAgB,CACpC,MAACK,EAAKC,GA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5B,MAAMI,EAA0B,GAAhBF,KAAKE,SAAiB,EAC5B,IAANJ,GAAiB,KAANA,GAAkB,KAANA,GAAkB,KAANA,IAAkBM,GAAA,KAChDA,IAAM,KAANN,EAAW,EAAU,KAANA,EAAqB,EAATI,EAAc,EAAIA,GAAQG,SAAS,GAAE,CAEnE,OAAAD,CACR,EAIA,UAAME,CAAKxC,GACN,GAAe,oBAARyC,IACV,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC5BH,IAAII,iBAAiB,CACpBC,KAAM9C,EACN+C,QAAS,KACAJ,GAAA,EAETK,KAAM,KACEJ,GAAA,GAER,IAIE,IAAA,MAAAK,eAAA,EAAAA,UAAWC,YAAaC,OAAOC,sBAC5BH,UAAUC,UAAUG,UAAUrD,OAC9B,CACA,MAAAsD,EAAaC,SAASC,cAAc,YAC1CF,EAAWtD,MAAQA,EAEnBsD,EAAWG,MAAMC,SAAW,WAC5BJ,EAAWG,MAAME,QAAU,IAC3BL,EAAWG,MAAMG,KAAO,YACxBN,EAAWG,MAAMI,IAAM,YACdN,SAAAO,KAAKC,YAAYT,GAC1BA,EAAWU,QACXV,EAAWW,SACXV,SAASW,YAAY,QACrBZ,EAAWa,QAAO,CAEpB"}
|
package/lib/vue/props.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"props.js","sources":["../../../../src/vue/props.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"props.js","sources":["../../../../src/vue/props.ts"],"sourcesContent":["import { computed } from \"vue\";\nimport { omit, pick } from \"lodash-unified\";\nimport type { ComputedRef, PropType } from \"vue\";\n\nexport const definePropType = <T>(val: any): PropType<T> => val;\n\n/**\n * 构建 props\n * @param props props\n * @param rawProps 原生 props\n * @param ignoreRawProps 忽略 原生 props 的 key\n */\nexport const useProps = <T extends Record<string, unknown>, RT extends Record<string, unknown>>(\n\tprops: T,\n\trawProps?: RT,\n\tignoreRawProps?: (keyof RT)[]\n): ComputedRef<Record<string, unknown>> => {\n\tif (!props) return computed(() => ({}));\n\n\treturn computed<Record<string, unknown>>(() => {\n\t\tconst omittedRawProps = rawProps ? omit(rawProps, ignoreRawProps ?? []) : {};\n\t\treturn pick(props, Object.keys(omittedRawProps)) as Record<string, unknown>;\n\t});\n};\n"],"names":["val","props","rawProps","ignoreRawProps","computed","omittedRawProps","omit","pick","Object","keys"],"mappings":"0JAIkCA,GAA0BA,mBAQpC,CACvBC,EACAC,EACAC,IAEKF,EAEEG,YAAkC,KAClC,MAAAC,EAAkBH,EAAWI,EAAKA,KAAAJ,EAAUC,GAAkB,IAAM,CAAC,EAC3E,OAAOI,EAAKA,KAAAN,EAAOO,OAAOC,KAAKJ,GAAgB,IAJ7BD,YAAS,KAAA,CAAU"}
|
package/lib/vue/useRender.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue");exports.useRender=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),r=require("../error/index.js");exports.useRender=t=>{const n=e.getCurrentInstance();if(!n)throw new r.FastError("useRender must be called from inside a setup function");n.render=t};
|
|
2
2
|
//# sourceMappingURL=useRender.js.map
|
package/lib/vue/useRender.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRender.js","sources":["../../../../src/vue/useRender.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"useRender.js","sources":["../../../../src/vue/useRender.ts"],"sourcesContent":["import { getCurrentInstance } from \"vue\";\nimport { FastError } from \"../error\";\nimport type { VNode } from \"vue\";\n\n/**\n * 使用渲染\n * @description 为了解决使用 TSX 语法返回渲染函数,状态不会出现在 vue.js devtools 中\n */\nexport const useRender = (render: () => VNode): void => {\n\tconst vm = getCurrentInstance() as any;\n\tif (!vm) {\n\t\tthrow new FastError(\"useRender must be called from inside a setup function\");\n\t}\n\tvm.render = render;\n};\n"],"names":["render","vm","getCurrentInstance","FastError"],"mappings":"wJAQ0BA,IACnB,MAAAC,EAAKC,EAAAA,qBACX,IAAKD,EACE,MAAA,IAAIE,YAAU,yDAErBF,EAAGD,OAASA,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fast-china/utils",
|
|
3
3
|
"author": "小方",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.6",
|
|
5
5
|
"description": "Fast 工具库.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [
|
|
@@ -75,20 +75,21 @@
|
|
|
75
75
|
"./lib"
|
|
76
76
|
],
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"vue": "3.5.
|
|
78
|
+
"vue": "^3.5.0"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@types/crypto-js": "^4.2.0",
|
|
82
|
-
"@types/lodash": "
|
|
83
|
-
"@types/lodash-es": "
|
|
84
|
-
"crypto-js": "4.2.0",
|
|
82
|
+
"@types/lodash": "latest",
|
|
83
|
+
"@types/lodash-es": "latest",
|
|
84
|
+
"crypto-js": "^4.2.0",
|
|
85
85
|
"lodash": "^4.17.21",
|
|
86
86
|
"lodash-es": "^4.17.21",
|
|
87
87
|
"lodash-unified": "^1.0.3"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
|
-
"@dcloudio/types": "
|
|
91
|
-
"@
|
|
92
|
-
"
|
|
90
|
+
"@dcloudio/types": "latest",
|
|
91
|
+
"@fast-china/eslint-config": "^1.0.15",
|
|
92
|
+
"@types/node": "latest",
|
|
93
|
+
"vue": "^3.5.0"
|
|
93
94
|
}
|
|
94
95
|
}
|