@fast-china/utils 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/index.global.js +138 -110
  2. package/dist/index.global.js.map +1 -1
  3. package/dist/index.global.min.js +5 -5
  4. package/dist/index.global.min.js.map +1 -1
  5. package/es/array/index.d.ts +19 -0
  6. package/es/array/index.mjs +33 -0
  7. package/es/array/index.mjs.map +1 -0
  8. package/es/base64/index.d.ts +9 -0
  9. package/es/base64/index.mjs +6 -0
  10. package/es/base64/index.mjs.map +1 -1
  11. package/es/click/index.d.ts +3 -0
  12. package/es/click/index.mjs.map +1 -1
  13. package/es/color/index.d.ts +3 -0
  14. package/es/color/index.mjs +5 -4
  15. package/es/color/index.mjs.map +1 -1
  16. package/es/date/index.d.ts +17 -0
  17. package/es/date/index.mjs +17 -0
  18. package/es/date/index.mjs.map +1 -1
  19. package/es/env/index.d.ts +25 -0
  20. package/es/env/index.mjs +38 -0
  21. package/es/env/index.mjs.map +1 -0
  22. package/es/index.d.ts +2 -0
  23. package/es/index.mjs +4 -0
  24. package/es/index.mjs.map +1 -1
  25. package/es/object/index.d.ts +0 -12
  26. package/es/object/index.mjs +0 -97
  27. package/es/object/index.mjs.map +1 -1
  28. package/es/storage/index.mjs +3 -2
  29. package/es/storage/index.mjs.map +1 -1
  30. package/es/string/index.d.ts +21 -0
  31. package/es/string/index.mjs +37 -0
  32. package/es/string/index.mjs.map +1 -1
  33. package/es/vue/useRender.mjs +2 -1
  34. package/es/vue/useRender.mjs.map +1 -1
  35. package/lib/array/index.d.ts +19 -0
  36. package/lib/array/index.js +2 -0
  37. package/lib/array/index.js.map +1 -0
  38. package/lib/base64/index.d.ts +9 -0
  39. package/lib/base64/index.js.map +1 -1
  40. package/lib/click/index.d.ts +3 -0
  41. package/lib/click/index.js.map +1 -1
  42. package/lib/color/index.d.ts +3 -0
  43. package/lib/color/index.js +1 -1
  44. package/lib/color/index.js.map +1 -1
  45. package/lib/date/index.d.ts +17 -0
  46. package/lib/date/index.js.map +1 -1
  47. package/lib/env/index.d.ts +25 -0
  48. package/lib/env/index.js +2 -0
  49. package/lib/env/index.js.map +1 -0
  50. package/lib/index.d.ts +2 -0
  51. package/lib/index.js +1 -1
  52. package/lib/object/index.d.ts +0 -12
  53. package/lib/object/index.js +1 -1
  54. package/lib/object/index.js.map +1 -1
  55. package/lib/storage/index.js +1 -1
  56. package/lib/storage/index.js.map +1 -1
  57. package/lib/string/index.d.ts +21 -0
  58. package/lib/string/index.js +1 -1
  59. package/lib/string/index.js.map +1 -1
  60. package/lib/vue/useRender.js +1 -1
  61. package/lib/vue/useRender.js.map +1 -1
  62. package/package.json +8 -8
@@ -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\t/**\n\t * 是否存在重复值\n\t */\n\thasDuplicateProperty<T>(arr: T[], prop: keyof T): boolean {\n\t\tconst values = arr.map((obj) => obj[prop]);\n\t\tconst uniqueValues = new Set(values);\n\t\treturn values.length !== uniqueValues.size;\n\t},\n\t/**\n\t * 是否存在非重复值\n\t */\n\thasDifferentProperty<T>(arr: T[], prop: keyof T): boolean {\n\t\tconst valueSet = new Set<any>();\n\t\tfor (const obj of arr) {\n\t\t\tvalueSet.add(obj[prop]);\n\t\t\tif (valueSet.size > 1) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\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};\n"],"names":["objectUtil","objectToQueryString","obj","params","key","Object","prototype","hasOwnProperty","call","encodeURIComponent","hasDuplicateProperty","arr","prop","values","map","uniqueValues","Set","length","size","hasDifferentProperty","valueSet","add","dateTimeFix","date","Date","timestamp","getTime","toString","arrTimestamp","split","start","parseInt","join","minute","hour","day","month","diffValue","monthC","weekC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AAIN,GAClBQ,EAAQH,KAAKC,IAAIL,GACjBQ,EAASJ,KAAKC,IAAIJ,GAClBQ,EAAQL,KAAKC,IAAIH,GAEvB,OAAIC,EAAU,GAEN,GAAGZ,SAAS,GAAGY,EAAU,QACtBA,GAAW,EACd,MACGA,GAAW,EACd,GAAGZ,SAAS,GAAGY,SACZG,EAAS,EACZ,MACGA,GAAU,EACb,GAAGf,SAAS,GAAGe,SACZC,GAAS,EACZ,GAAGhB,SAAS,GAAGgB,SACZC,GAAU,EACb,GAAGjB,SAAS,GAAGiB,UACZC,GAAS,EACZ,GAAGlB,SAAS,GAAGkB,UAEhB,IAAA,CAKR,OAAIX,EAAS,GAEL,GAAGP,SAAS,GAAGO,EAAS,QACrBA,GAAU,EACb,MACGA,GAAU,EACb,GAAGP,SAAS,GAAGO,SACZC,EAAQ,EACX,MACGA,GAAS,EACZ,GAAGR,SAAS,GAAGQ,SACZC,GAAQ,EACX,GAAGT,SAAS,GAAGS,SACZC,GAAS,EACZ,GAAGV,SAAS,GAAGU,UACZC,GAAQ,EACX,GAAGX,SAAS,GAAGW,UAEhB,IAAA,CAEA,MAAA,EACR"}
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"}
@@ -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}),t=e.computed((()=>i.prefix)),n=e.computed((()=>i.expireSuffix)),s={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},f={set(e,t,n,f){try{if(f??(f=i.crypto),n){if(isNaN(n)||n<1)throw new Error("有效期应为一个有效数值");const r={time:Date.now(),expire:n},o=JSON.stringify(r);s.set(`${i.prefix}${e}${i.expireSuffix}`,o)}let o=JSON.stringify(t);f&&(o=r.base64Util.toBase64(o)),s.set(`${i.prefix}${e}`,o)}catch(c){o.consoleError("Local",c)}},get(e,t){try{t??(t=i.crypto);let o=s.get(`${i.prefix}${e}`);if(o){t&&(o=r.base64Util.base64ToStr(o));const n=s.get(`${i.prefix}${e}${i.expireSuffix}`);if(n){const r=JSON.parse(n);if(Date.now()>r.time+60*r.expire*1e3)return s.remove(`${i.prefix}${e}`),s.remove(`${i.prefix}${e}${i.expireSuffix}`),null}try{return JSON.parse(o)}catch{return o}}return null}catch(n){o.consoleError("Local",n)}},remove(e){try{s.remove(`${i.prefix}${e}`),s.remove(`${i.prefix}${e}${i.expireSuffix}`)}catch(r){o.consoleError("Local",r)}},removeByPrefix(e){try{for(const r in s.keys)-1!==r.indexOf(`${i.prefix}${e}`)&&s.remove(r)}catch(r){o.consoleError("Local",r)}},clear(){try{s.clear()}catch(e){o.consoleError("Local",e)}}},c={set(e,t,n,s){if("undefined"==typeof uni)try{if(s??(s=i.crypto),n){if(isNaN(n)||n<1)throw new Error("有效期应为一个有效数值");const r={time:Date.now(),expire:n},o=JSON.stringify(r);window.sessionStorage.setItem(`${i.prefix}${e}${i.expireSuffix}`,o)}let o=JSON.stringify(t);s&&(o=r.base64Util.toBase64(o)),window.sessionStorage.setItem(`${i.prefix}${e}`,o)}catch(f){o.consoleError("Session",f)}else o.consoleError("Session","UniApp 环境下 [Session] 不可用。")},get(e,t){if("undefined"==typeof uni)try{t??(t=i.crypto);let o=window.sessionStorage.getItem(`${i.prefix}${e}`);if(o){t&&(o=r.base64Util.base64ToStr(o));const n=window.sessionStorage.getItem(`${i.prefix}${e}${i.expireSuffix}`);if(n){const r=JSON.parse(n);if(Date.now()>r.time+60*r.expire*1e3)return window.sessionStorage.removeItem(`${i.prefix}${e}`),window.sessionStorage.removeItem(`${i.prefix}${e}${i.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(`${i.prefix}${e}`),window.sessionStorage.removeItem(`${i.prefix}${e}${i.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(`${i.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=n,exports.CACHE_PREFIX=t,exports.Local=f,exports.Session=c,exports.useStorage=()=>({prefix(e){i.prefix=e},expireSuffix(e){i.expireSuffix=e},crypto(e){i.crypto=e}});
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
@@ -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,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,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,IAA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Aa,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"}
@@ -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
  */
@@ -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,o={};let n;for(;null!==(n=t.exec(e));){const[e,t]=n[0].substring(1).split("=");o[e]=decodeURIComponent(t)}return o},isJson:o=>!!e.isString(o)&&(o=o.replace(/\s/g,"").replace(/\n|\r/,""),/^\{(.*?)\}$/.test(o)?/"(.*?)":(.*?)/g.test(o):!!/^\[(.*?)\]$/.test(o)&&o.replace(/^\[/,"").replace(/\]$/,"").replace(/},{/g,"}\n{").split(/\n/).map((e=>t.isJson(e))).reduce(((e,t)=>!!t))),generateRandomString(e){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let o="";for(let n=0;n<e;n++){const e=Math.floor(62*Math.random());o+=t.charAt(e)}return o},generateUUID(){let e="";for(let t=0;t<32;t++){const o=16*Math.random()|0;8!==t&&12!==t&&16!==t&&20!==t||(e+="-"),e+=(12===t?4:16===t?3&o|8:o).toString(16)}return e},async copy(e){if("undefined"!=typeof uni)return new Promise(((t,o)=>{uni.setClipboardData({data:e,success:()=>{t()},fail:()=>{o()}})}));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;
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)?/"(.*?)":(.*?)/g.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
@@ -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 (/^\\{(.*?)\\}$/.test(value)) return /\"(.*?)\":(.*?)/g.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\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","generateRandomString","length","characters","randomString","i","randomIndex","Math","floor","random","charAt","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,GAASH,EAAM,GAAGI,UAAU,GAAGC,MAAM,KAC1CN,EAAAG,GAAOI,mBAAmBH,EAAK,CAGhC,OAAAJ,CACR,EAIAQ,OAAOJ,KACDK,EAAAA,SAASL,KAEdA,EAAQA,EAAMM,QAAQ,MAAO,IAAIA,QAAQ,QAAS,IAE9C,cAAcC,KAAKP,GAAe,iBAAiBO,KAAKP,KAExD,cAAcO,KAAKP,IACfA,EACLM,QAAQ,MAAO,IACfA,QAAQ,MAAO,IACfA,QAAQ,OAAQ,QAChBJ,MAAM,MACNM,KAAKC,GACEjB,EAAWY,OAAOK,KAEzBC,QAAO,CAACC,EAAMC,MACLA,KASb,oBAAAC,CAAqBC,GACpB,MAAMC,EAAa,iEACnB,IAAIC,EAAe,GACnB,IAAA,IAASC,EAAI,EAAGA,EAAIH,EAAQG,IAAK,CAChC,MAAMC,EAAcC,KAAKC,MAAsBL,GAAhBI,KAAKE,UACpBL,GAAAD,EAAWO,OAAOJ,EAAW,CAEvC,OAAAF,CACR,EAIA,YAAAO,GACC,IAAIC,EAAO,GACX,IAAA,IAASP,EAAI,EAAGA,EAAI,GAAIA,IAAK,CAC5B,MAAMI,EAA0B,GAAhBF,KAAKE,SAAiB,EAC5B,IAANJ,GAAiB,KAANA,GAAkB,KAANA,GAAkB,KAANA,IAAkBO,GAAA,KAChDA,IAAM,KAANP,EAAW,EAAU,KAANA,EAAqB,EAATI,EAAc,EAAIA,GAAQI,SAAS,GAAE,CAEnE,OAAAD,CACR,EAIA,UAAME,CAAK1B,GACN,GAAe,oBAAR2B,IACV,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC5BH,IAAII,iBAAiB,CACpBC,KAAMhC,EACNiC,QAAS,KACAJ,GAAA,EAETK,KAAM,KACEJ,GAAA,GAER,IAIE,IAAA,MAAAK,eAAA,EAAAA,UAAWC,YAAaC,OAAOC,sBAC5BH,UAAUC,UAAUG,UAAUvC,OAC9B,CACA,MAAAwC,EAAaC,SAASC,cAAc,YAC1CF,EAAWxC,MAAQA,EAEnBwC,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"}
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 /\"(.*?)\":(.*?)/g.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,GAASH,EAAM,GAAGI,UAAU,GAAGC,MAAM,KAC1CN,EAAAG,GAAOI,mBAAmBH,EAAK,CAGhC,OAAAJ,CACR,EAIAQ,OAAOJ,KACDK,EAAAA,SAASL,KAEdA,EAAQA,EAAMM,QAAQ,MAAO,IAAIA,QAAQ,QAAS,IAE9C,cAAcC,KAAKP,GAAe,iBAAiBO,KAAKP,KAExD,cAAcO,KAAKP,IACfA,EACLM,QAAQ,MAAO,IACfA,QAAQ,MAAO,IACfA,QAAQ,OAAQ,QAChBJ,MAAM,MACNM,KAAKC,GACEjB,EAAWY,OAAOK,KAEzBC,QAAO,CAACC,EAAMC,MACLA,KASbC,eAAeb,GACTA,EAEgB,IAAjBA,EAAM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C,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"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue");exports.useRender=r=>{const t=e.getCurrentInstance();if(!t)throw new Error("useRender must be called from inside a setup function");t.render=r};
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
@@ -1 +1 @@
1
- {"version":3,"file":"useRender.js","sources":["../../../../src/vue/useRender.ts"],"sourcesContent":["import type { VNode } from \"vue\";\nimport { getCurrentInstance } 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 Error(\"useRender must be called from inside a setup function\");\n\t}\n\tvm.render = render;\n};\n"],"names":["render","vm","getCurrentInstance","Error"],"mappings":"yHAO0BA,IACnB,MAAAC,EAAKC,EAAAA,qBACX,IAAKD,EACE,MAAA,IAAIE,MAAM,yDAEjBF,EAAGD,OAASA,CAAA"}
1
+ {"version":3,"file":"useRender.js","sources":["../../../../src/vue/useRender.ts"],"sourcesContent":["import type { VNode } from \"vue\";\nimport { getCurrentInstance } from \"vue\";\nimport { FastError } from \"../error\";\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",
4
+ "version": "1.0.5",
5
5
  "description": "Fast 工具库.",
6
6
  "type": "module",
7
7
  "keywords": [
@@ -75,20 +75,20 @@
75
75
  "./lib"
76
76
  ],
77
77
  "peerDependencies": {
78
- "vue": "3.5.13"
78
+ "vue": "^3.5.0"
79
79
  },
80
80
  "dependencies": {
81
81
  "@types/crypto-js": "^4.2.0",
82
- "@types/lodash": "^4.17.14",
83
- "@types/lodash-es": "^4.17.12",
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
- "@types/node": "*",
92
- "vue": "3.5.13"
90
+ "@dcloudio/types": "latest",
91
+ "@types/node": "latest",
92
+ "vue": "^3.5.0"
93
93
  }
94
94
  }