@fast-china/utils 1.0.2 → 1.0.4

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 (149) hide show
  1. package/dist/index.global.js +13172 -63953
  2. package/dist/index.global.js.map +1 -1
  3. package/dist/index.global.min.js +38 -73
  4. package/dist/index.global.min.js.map +1 -1
  5. package/es/base64/index.d.ts +12 -0
  6. package/es/base64/index.mjs +132 -0
  7. package/es/base64/index.mjs.map +1 -0
  8. package/es/click/index.d.ts +30 -0
  9. package/es/click/index.mjs +82 -0
  10. package/es/click/index.mjs.map +1 -0
  11. package/es/color/index.d.ts +30 -0
  12. package/es/color/index.mjs +60 -0
  13. package/es/color/index.mjs.map +1 -0
  14. package/es/console/index.d.ts +25 -0
  15. package/es/console/index.mjs +44 -0
  16. package/es/console/index.mjs.map +1 -0
  17. package/es/crypto/index.d.ts +46 -0
  18. package/es/crypto/index.mjs +106 -0
  19. package/es/crypto/index.mjs.map +1 -0
  20. package/es/date/index.d.ts +24 -0
  21. package/es/date/index.mjs +251 -0
  22. package/es/date/index.mjs.map +1 -0
  23. package/es/dom/index.d.ts +1 -0
  24. package/es/dom/index.mjs +5 -0
  25. package/es/dom/index.mjs.map +1 -0
  26. package/es/dom/style.d.ts +6 -0
  27. package/es/dom/style.mjs +21 -0
  28. package/es/dom/style.mjs.map +1 -0
  29. package/es/error/index.d.ts +3 -0
  30. package/es/error/index.mjs +10 -0
  31. package/es/error/index.mjs.map +1 -0
  32. package/es/identity/index.d.ts +8 -0
  33. package/es/identity/index.mjs +33 -0
  34. package/es/identity/index.mjs.map +1 -0
  35. package/es/index.d.ts +13 -0
  36. package/es/index.es.d.ts +2 -0
  37. package/es/index.mjs +54 -0
  38. package/es/index.mjs.map +1 -0
  39. package/es/object/index.d.ts +21 -0
  40. package/es/object/index.mjs +118 -0
  41. package/es/object/index.mjs.map +1 -0
  42. package/es/storage/index.d.ts +95 -0
  43. package/es/storage/index.mjs +306 -0
  44. package/es/storage/index.mjs.map +1 -0
  45. package/es/string/index.d.ts +25 -0
  46. package/es/string/index.mjs +94 -0
  47. package/es/string/index.mjs.map +1 -0
  48. package/es/vue/expose.d.ts +4 -0
  49. package/es/vue/expose.mjs +8 -0
  50. package/es/vue/expose.mjs.map +1 -0
  51. package/es/vue/func.d.ts +6 -0
  52. package/es/vue/func.mjs +26 -0
  53. package/es/vue/func.mjs.map +1 -0
  54. package/es/vue/index.d.ts +7 -0
  55. package/es/vue/index.mjs +20 -0
  56. package/es/vue/index.mjs.map +1 -0
  57. package/es/vue/install.d.ts +5 -0
  58. package/es/vue/install.mjs +31 -0
  59. package/es/vue/install.mjs.map +1 -0
  60. package/es/vue/props.d.ts +9 -0
  61. package/es/vue/props.mjs +15 -0
  62. package/es/vue/props.mjs.map +1 -0
  63. package/es/vue/slots.d.ts +11 -0
  64. package/es/vue/slots.mjs +7 -0
  65. package/es/vue/slots.mjs.map +1 -0
  66. package/es/vue/useRender.d.ts +6 -0
  67. package/es/vue/useRender.mjs +12 -0
  68. package/es/vue/useRender.mjs.map +1 -0
  69. package/es/vue/with.d.ts +5 -0
  70. package/es/vue/with.mjs +7 -0
  71. package/es/vue/with.mjs.map +1 -0
  72. package/lib/base64/index.d.ts +12 -0
  73. package/lib/base64/index.js +2 -0
  74. package/lib/base64/index.js.map +1 -0
  75. package/lib/click/index.d.ts +30 -0
  76. package/lib/click/index.js +2 -0
  77. package/lib/click/index.js.map +1 -0
  78. package/lib/color/index.d.ts +30 -0
  79. package/lib/color/index.js +2 -0
  80. package/lib/color/index.js.map +1 -0
  81. package/lib/console/index.d.ts +25 -0
  82. package/lib/console/index.js +2 -0
  83. package/lib/console/index.js.map +1 -0
  84. package/lib/crypto/index.d.ts +46 -0
  85. package/lib/crypto/index.js +2 -0
  86. package/lib/crypto/index.js.map +1 -0
  87. package/lib/date/index.d.ts +24 -0
  88. package/lib/date/index.js +2 -0
  89. package/lib/date/index.js.map +1 -0
  90. package/lib/dom/index.d.ts +1 -0
  91. package/lib/dom/index.js +2 -0
  92. package/lib/dom/index.js.map +1 -0
  93. package/lib/dom/style.d.ts +6 -0
  94. package/lib/dom/style.js +2 -0
  95. package/lib/dom/style.js.map +1 -0
  96. package/lib/error/index.d.ts +3 -0
  97. package/lib/error/index.js +2 -0
  98. package/lib/error/index.js.map +1 -0
  99. package/lib/identity/index.d.ts +8 -0
  100. package/lib/identity/index.js +2 -0
  101. package/lib/identity/index.js.map +1 -0
  102. package/lib/index.d.ts +13 -0
  103. package/lib/index.es.d.ts +2 -0
  104. package/lib/index.js +2 -0
  105. package/lib/index.js.map +1 -0
  106. package/lib/object/index.d.ts +21 -0
  107. package/lib/object/index.js +2 -0
  108. package/lib/object/index.js.map +1 -0
  109. package/lib/storage/index.d.ts +95 -0
  110. package/lib/storage/index.js +2 -0
  111. package/lib/storage/index.js.map +1 -0
  112. package/lib/string/index.d.ts +25 -0
  113. package/lib/string/index.js +2 -0
  114. package/lib/string/index.js.map +1 -0
  115. package/lib/vue/expose.d.ts +4 -0
  116. package/lib/vue/expose.js +2 -0
  117. package/lib/vue/expose.js.map +1 -0
  118. package/lib/vue/func.d.ts +6 -0
  119. package/lib/vue/func.js +2 -0
  120. package/lib/vue/func.js.map +1 -0
  121. package/lib/vue/index.d.ts +7 -0
  122. package/lib/vue/index.js +2 -0
  123. package/lib/vue/index.js.map +1 -0
  124. package/lib/vue/install.d.ts +5 -0
  125. package/lib/vue/install.js +2 -0
  126. package/lib/vue/install.js.map +1 -0
  127. package/lib/vue/props.d.ts +9 -0
  128. package/lib/vue/props.js +2 -0
  129. package/lib/vue/props.js.map +1 -0
  130. package/lib/vue/slots.d.ts +11 -0
  131. package/lib/vue/slots.js +2 -0
  132. package/lib/vue/slots.js.map +1 -0
  133. package/lib/vue/useRender.d.ts +6 -0
  134. package/lib/vue/useRender.js +2 -0
  135. package/lib/vue/useRender.js.map +1 -0
  136. package/lib/vue/with.d.ts +5 -0
  137. package/lib/vue/with.js +2 -0
  138. package/lib/vue/with.js.map +1 -0
  139. package/package.json +92 -81
  140. package/dist/index.cjs +0 -1294
  141. package/dist/index.cjs.map +0 -1
  142. package/dist/index.d.cts +0 -380
  143. package/dist/index.d.ts +0 -380
  144. package/dist/index.js +0 -1264
  145. package/dist/index.js.map +0 -1
  146. package/dist/index.min.cjs +0 -3
  147. package/dist/index.min.cjs.map +0 -1
  148. package/dist/index.min.js +0 -3
  149. package/dist/index.min.js.map +0 -1
@@ -0,0 +1,95 @@
1
+ /**
2
+ * 本地缓存前缀 Key
3
+ */
4
+ export declare const CACHE_PREFIX: import('vue').ComputedRef<string>;
5
+ /**
6
+ * 本地缓存过期值后缀 Key
7
+ */
8
+ export declare const CACHE_EXPIRE_SUFFIX: import('vue').ComputedRef<string>;
9
+ export declare const useStorage: () => {
10
+ /**
11
+ * 设置缓存前缀 Key
12
+ * @param key
13
+ */
14
+ prefix(key: string): void;
15
+ /**
16
+ * 缓存过期值后缀 Key
17
+ * @param key
18
+ */
19
+ expireSuffix(key: string): void;
20
+ /**
21
+ * 设置缓存是否加密
22
+ * @param crypto
23
+ */
24
+ crypto(crypto: boolean): void;
25
+ };
26
+ /**
27
+ * window.localStorage
28
+ * - 如果是 UniApp 环境则使用的是 uni.xxxStorage
29
+ */
30
+ export declare const Local: {
31
+ /**
32
+ * 设置
33
+ * @param key 缓存的Key
34
+ * @param val 缓存值
35
+ * @param expire 过期时间,单位分钟
36
+ * @param encrypt 是否对缓存的数据加密
37
+ */
38
+ set(key: string, val: any, expire?: number, encrypt?: boolean): void;
39
+ /**
40
+ * 获取
41
+ * @param key 缓存的Key
42
+ * @param decrypt 是否对缓存的数据解密
43
+ * @returns {T} 传入的对象类型,默认为 string
44
+ */
45
+ get<T = string>(key: string, decrypt?: boolean): T;
46
+ /**
47
+ * 移除
48
+ * @param key 缓存的Key
49
+ */
50
+ remove(key: string): void;
51
+ /**
52
+ * 根据前缀移除
53
+ * @param key 缓存的Key
54
+ */
55
+ removeByPrefix(key: string): void;
56
+ /**
57
+ * 移除全部
58
+ */
59
+ clear(): void;
60
+ };
61
+ /**
62
+ * window.sessionStorage
63
+ * - UniApp 环境下不可用
64
+ */
65
+ export declare const Session: {
66
+ /**
67
+ * 设置会话缓存
68
+ * @param key 缓存的Key
69
+ * @param val 缓存值
70
+ * @param expire 过期时间,单位分钟
71
+ * @param encrypt 是否对缓存的数据加密
72
+ */
73
+ set(key: string, val: any, expire?: number, encrypt?: boolean): void;
74
+ /**
75
+ * 获取会话缓存
76
+ * @param key 缓存的Key
77
+ * @param decrypt 是否对缓存的数据解密
78
+ * @returns {T} 传入的对象类型,默认为 string
79
+ */
80
+ get<T = string>(key: string, decrypt?: boolean): T;
81
+ /**
82
+ * 移除会话缓存
83
+ * @param key 缓存的Key
84
+ */
85
+ remove(key: string): void;
86
+ /**
87
+ * 根据前缀移除会话缓存
88
+ * @param key 缓存的Key
89
+ */
90
+ removeByPrefix(key: string): void;
91
+ /**
92
+ * 移除全部会话缓存
93
+ */
94
+ clear(): void;
95
+ };
@@ -0,0 +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}});
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,EAAS,EACvB,MAAA,IAAIG,MAAM,eAGjB,MAAMC,EAAa,CAClBC,KAAMC,KAAKC,MACXP,UAEKQ,EAAaC,KAAKC,UAAUN,GAC1BxB,EAAAC,IAAI,GAAGT,EAAME,SAASQ,IAAMV,EAAMG,eAAgBiC,EAAU,CAEjE,IAAAG,EAAUF,KAAKC,UAAU3B,GACzBkB,IACOW,EAAAA,EAAAA,WAAWC,SAASF,IAE/B/B,EAAQC,IAAI,GAAGT,EAAME,SAASQ,IAAO6B,SAC7BG,GACRC,EAAAC,aAAa,QAASF,EAAK,CAE7B,EAOA,GAAAzB,C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,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"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 字符串工具类
3
+ */
4
+ export declare const stringUtil: {
5
+ /**
6
+ * 获取Url参数
7
+ */
8
+ getUrlParams(url: string): Record<string, any>;
9
+ /**
10
+ * 是否为JSON字符串
11
+ */
12
+ isJson(value: string): boolean;
13
+ /**
14
+ * 生成随机字符串
15
+ */
16
+ generateRandomString(length: number): string;
17
+ /**
18
+ * @description 生成唯一 uuid
19
+ */
20
+ generateUUID(): string;
21
+ /**
22
+ * 复制
23
+ */
24
+ copy(value: string): Promise<void>;
25
+ };
@@ -0,0 +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;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,KA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
1
+ /**
2
+ * 构建 expose 和 vue.js devtools 状态查看
3
+ */
4
+ export declare const useExpose: <Exposed extends Record<string, any> = Record<string, any>>(expose: (exposed?: Exposed) => void, exposed?: Exposed) => Exposed;
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.useExpose=(e,t)=>(e(t),t);
2
+ //# sourceMappingURL=expose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expose.js","sources":["../../../../src/vue/expose.ts"],"sourcesContent":["/**\n * 构建 expose 和 vue.js devtools 状态查看\n */\nexport const useExpose = <Exposed extends Record<string, any> = Record<string, any>>(\n\texpose: (exposed?: Exposed) => void,\n\texposed?: Exposed\n): Exposed => {\n\texpose(exposed);\n\n\treturn exposed;\n};\n"],"names":["expose","exposed"],"mappings":"kGAGyB,CACxBA,EACAC,KAEAD,EAAOC,GAEAA"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 执行方法
3
+ * @param fn 要执行的方法
4
+ * @param args 参数
5
+ */
6
+ export declare const execFunction: <T = void>(fn: Function, ...args: any[]) => Promise<T>;
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../console/index.js");exports.execFunction=async(r,...t)=>{if(!r)return Promise.resolve(void 0);if("AsyncFunction"!==r.constructor.name)return new Promise(((n,o)=>{try{return n(r(...t))}catch(c){return e.consoleError("execFunction",c),o(c)}}));try{return await r(...t)}catch(n){return e.consoleError("execFunction",n),Promise.reject(n)}};
2
+ //# sourceMappingURL=func.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"func.js","sources":["../../../../src/vue/func.ts"],"sourcesContent":["/**\n * 执行方法\n * @param fn 要执行的方法\n * @param args 参数\n */\n\nimport { consoleError } from \"../console\";\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const execFunction = async <T = void>(fn: Function, ...args: any[]): Promise<T> => {\n\tif (!fn) return Promise.resolve(undefined);\n\t// 判断是否为异步方法\n\tif (fn.constructor.name === \"AsyncFunction\") {\n\t\t// 异步方法\n\t\ttry {\n\t\t\treturn await fn(...args);\n\t\t} catch (error) {\n\t\t\tconsoleError(\"execFunction\", error as any);\n\t\t\treturn Promise.reject(error);\n\t\t}\n\t} else {\n\t\t// 同步方法\n\t\treturn new Promise((resolve, reject) => {\n\t\t\ttry {\n\t\t\t\tconst res = fn(...args);\n\t\t\t\treturn resolve(res);\n\t\t\t} catch (error) {\n\t\t\t\tconsoleError(\"execFunction\", error as any);\n\t\t\t\treturn reject(error);\n\t\t\t}\n\t\t});\n\t}\n};\n"],"names":["async","fn","args","Promise","resolve","constructor","name","reject","error","index","consoleError"],"mappings":"4IAS4BA,MAAiBC,KAAiBC,KAC7D,IAAKD,EAAW,OAAAE,QAAQC,aAAQ,GAE5B,GAAwB,kBAAxBH,EAAGI,YAAYC,KAUlB,OAAO,IAAIH,SAAQ,CAACC,EAASG,KACxB,IAEH,OAAOH,EADKH,KAAMC,UAEVM,GAER,OADAC,EAAAC,aAAa,eAAgBF,GACtBD,EAAOC,EAAK,KAdjB,IACI,aAAMP,KAAMC,SACXM,GAED,OADPC,EAAAC,aAAa,eAAgBF,GACtBL,QAAQI,OAAOC,EAAK,CAY3B"}
@@ -0,0 +1,7 @@
1
+ export * from './expose';
2
+ export * from './func';
3
+ export * from './install';
4
+ export * from './props';
5
+ export * from './slots';
6
+ export * from './useRender';
7
+ export * from './with';
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./expose.js"),s=require("./func.js"),t=require("./install.js"),r=require("./props.js"),o=require("./slots.js"),i=require("./useRender.js"),p=require("./with.js");exports.useExpose=e.useExpose,exports.execFunction=s.execFunction,exports.withInstall=t.withInstall,exports.withInstallDirective=t.withInstallDirective,exports.withNoopInstall=t.withNoopInstall,exports.definePropType=r.definePropType,exports.useProps=r.useProps,exports.makeSlots=o.makeSlots,exports.useRender=i.useRender,exports.withDefineType=p.withDefineType;
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { Directive, Plugin } from 'vue';
2
+ export type TSXWithInstall<T> = T & Plugin;
3
+ export declare const withInstall: <T, E extends Record<string, any>>(main: T, extra?: E) => TSXWithInstall<T> & E;
4
+ export declare const withNoopInstall: <T>(component: T) => TSXWithInstall<T>;
5
+ export declare const withInstallDirective: <T extends Directive>(directive: T, name: string) => TSXWithInstall<T>;
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=()=>{};exports.withInstall=(t,e)=>{if(t.install=o=>{for(const s of[t,...Object.values(e??{})])o.component(s.name,s)},e)for(const[o,s]of Object.entries(e))t[o]=s;return t},exports.withInstallDirective=(t,e)=>(t.install=o=>{o.directive(e,t)},t),exports.withNoopInstall=e=>(e.install=t,e);
2
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.js","sources":["../../../../src/vue/install.ts"],"sourcesContent":["import type { App, Directive, Plugin } from \"vue\";\n\nexport type TSXWithInstall<T> = T & Plugin;\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nconst NOOP = (): void => {};\n\nexport const withInstall = <T, E extends Record<string, any>>(main: T, extra?: E): TSXWithInstall<T> & E => {\n\t(main as TSXWithInstall<T>).install = (app): void => {\n\t\tfor (const comp of [main, ...Object.values(extra ?? {})]) {\n\t\t\tapp.component(comp.name, comp);\n\t\t}\n\t};\n\n\tif (extra) {\n\t\tfor (const [key, comp] of Object.entries(extra)) {\n\t\t\t(main as any)[key] = comp;\n\t\t}\n\t}\n\treturn main as TSXWithInstall<T> & E;\n};\n\nexport const withNoopInstall = <T>(component: T): TSXWithInstall<T> => {\n\t(component as TSXWithInstall<T>).install = NOOP;\n\n\treturn component as TSXWithInstall<T>;\n};\n\nexport const withInstallDirective = <T extends Directive>(directive: T, name: string): TSXWithInstall<T> => {\n\t(directive as TSXWithInstall<T>).install = (app: App): void => {\n\t\tapp.directive(name, directive);\n\t};\n\n\treturn directive as TSXWithInstall<T>;\n};\n"],"names":["NOOP","main","extra","install","app","comp","Object","values","component","name","key","entries","directive"],"mappings":"gFAKA,MAAMA,EAAO,2BAEc,CAAmCC,EAASC,KAOtE,GAN4BD,EAAAE,QAAWC,IAC3B,IAAA,MAAAC,IAAQ,CAACJ,KAASK,OAAOC,OAAOL,GAAS,CAAE,IACjDE,EAAAI,UAAUH,EAAKI,KAAMJ,EAAI,EAI3BH,EACH,IAAA,MAAYQ,EAAKL,KAASC,OAAOK,QAAQT,GACvCD,EAAaS,GAAOL,EAGhB,OAAAJ,CAAA,+BAS4B,CAAsBW,EAAcH,KACtCG,EAAAT,QAAWC,IACvCA,EAAAQ,UAAUH,EAAMG,EAAS,EAGvBA,2BAX2BJ,IACjCA,EAAgCL,QAAUH,EAEpCQ"}
@@ -0,0 +1,9 @@
1
+ import { ComputedRef, PropType } from 'vue';
2
+ export declare const definePropType: <T>(val: any) => PropType<T>;
3
+ /**
4
+ * 构建 props
5
+ * @param props props
6
+ * @param rawProps 原生 props
7
+ * @param ignoreRawProps 忽略 原生 props 的 key
8
+ */
9
+ export declare const useProps: <T extends Record<string, unknown>, RT extends Record<string, unknown>>(props: T, rawProps?: RT, ignoreRawProps?: (keyof RT)[]) => ComputedRef<Record<string, unknown>>;
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("lodash-unified");exports.definePropType=e=>e,exports.useProps=(o,r,s)=>o?e.computed((()=>{const e=r?t.omit(r,s??[]):{};return t.pick(o,Object.keys(e))})):e.computed((()=>({})));
2
+ //# sourceMappingURL=props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"props.js","sources":["../../../../src/vue/props.ts"],"sourcesContent":["import type { ComputedRef, PropType } from \"vue\";\nimport { computed } from \"vue\";\nimport { omit, pick } from \"lodash-unified\";\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"}
@@ -0,0 +1,11 @@
1
+ import { SlotsType, VNode } from 'vue';
2
+ type RawSlots = Record<string, unknown>;
3
+ type VueSlots<T> = [T] extends [never] ? () => VNode[] : (arg: T) => VNode[];
4
+ type MakeSlots<T extends RawSlots> = {
5
+ [K in keyof T]: VueSlots<T[K]>;
6
+ };
7
+ /**
8
+ * 构建 slots
9
+ */
10
+ export declare const makeSlots: <Slots extends RawSlots>() => SlotsType<Partial<MakeSlots<Slots>>>;
11
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.makeSlots=()=>Object;
2
+ //# sourceMappingURL=slots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slots.js","sources":["../../../../src/vue/slots.ts"],"sourcesContent":["import type { SlotsType, VNode } from \"vue\";\n\ntype RawSlots = Record<string, unknown>;\n\ntype VueSlots<T> = [T] extends [never] ? () => VNode[] : (arg: T) => VNode[];\n\ntype MakeSlots<T extends RawSlots> = {\n\t[K in keyof T]: VueSlots<T[K]>;\n};\n\n/**\n * 构建 slots\n */\nexport const makeSlots = <Slots extends RawSlots>(): SlotsType<Partial<MakeSlots<Slots>>> => {\n\treturn Object as SlotsType<Partial<MakeSlots<Slots>>>;\n};\n"],"names":["Object"],"mappings":"kGAayB,IACjBA"}
@@ -0,0 +1,6 @@
1
+ import { VNode } from 'vue';
2
+ /**
3
+ * 使用渲染
4
+ * @description 为了解决使用 TSX 语法返回渲染函数,状态不会出现在 vue.js devtools 中
5
+ */
6
+ export declare const useRender: (render: () => VNode) => void;
@@ -0,0 +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};
2
+ //# sourceMappingURL=useRender.js.map
@@ -0,0 +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"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 定义类型数据
3
+ * @description 传入什么就返回什么,用来定义reactive或其他对象的响应式数据
4
+ */
5
+ export declare const withDefineType: <T>(data?: T) => T;
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.withDefineType=(e=void 0)=>e;
2
+ //# sourceMappingURL=with.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with.js","sources":["../../../../src/vue/with.ts"],"sourcesContent":["/**\n * 定义类型数据\n * @description 传入什么就返回什么,用来定义reactive或其他对象的响应式数据\n */\nexport const withDefineType = <T>(data: T = undefined): T => {\n\treturn data;\n};\n"],"names":["data"],"mappings":"uGAI8B,CAAIA,OAAU,IACpCA"}
package/package.json CHANGED
@@ -1,83 +1,94 @@
1
1
  {
2
- "name": "@fast-china/utils",
3
- "author": "小方",
4
- "version": "1.0.2",
5
- "description": "Fast 工具库.",
6
- "type": "module",
7
- "keywords": [
8
- "fast-china",
9
- "fast",
10
- "typescript",
11
- "utils"
12
- ],
13
- "license": "Apache-2.0",
14
- "publishConfig": {
15
- "access": "public"
16
- },
17
- "homepage": "https://fastdotnet.com",
18
- "repository": {
19
- "type": "git",
20
- "url": "https://gitee.com/China-xiaoFang/fast.utils"
21
- },
22
- "bugs": {
23
- "url": "https://gitee.com/China-xiaoFang/fast.utils/issues"
24
- },
25
- "scripts": {
26
- "check": "vue-tsc",
27
- "build": "vue-tsc && tsup",
28
- "lint:eslint": "eslint --max-warnings 0 \"src/**/*.{vue,js,ts,tsx}\" --fix",
29
- "lint:prettier": "prettier --write \"src/**/*.{vue,js,ts,jsx,tsx,md,json,css,scss,less,html}\"",
30
- "lint": "pnpm lint:eslint && pnpm lint:prettier"
31
- },
32
- "main": "./dist/index.js",
33
- "module": "./dist/index.js",
34
- "types": "./dist/index.d.ts",
35
- "exports": {
36
- ".": {
37
- "import": "./dist/index.js",
38
- "require": "./dist/index.cjs"
39
- }
40
- },
41
- "unpkg": "dist/index.global.min.js",
42
- "jsdelivr": "dist/index.global.min.js",
43
- "files": [
44
- "./Fast.png",
45
- "./LICENSE",
46
- "./README.md",
47
- "./README.zh.md",
48
- "./dist"
49
- ],
50
- "peerDependencies": {
51
- "vue": "^3.5.13"
52
- },
53
- "dependencies": {
54
- "@types/crypto-js": "^4.2.0",
55
- "@types/lodash": "^4.17.14",
56
- "@types/lodash-es": "^4.17.12",
57
- "crypto-js": "4.2.0",
58
- "lodash": "^4.17.21",
59
- "lodash-es": "^4.17.21",
60
- "lodash-unified": "^1.0.3"
61
- },
62
- "devDependencies": {
63
- "@dcloudio/types": "*",
64
- "@types/node": "*",
65
- "@typescript-eslint/eslint-plugin": "^8.19.1",
66
- "@typescript-eslint/parser": "^8.19.1",
67
- "@vue/tsconfig": "^0.7.0",
68
- "eslint": "^8.57.0",
69
- "eslint-config-prettier": "^9.1.0",
70
- "eslint-define-config": "^2.1.0",
71
- "eslint-plugin-import": "^2.30.0",
72
- "eslint-plugin-prettier": "^5.2.1",
73
- "eslint-plugin-vue": "^9.32.0",
74
- "prettier": "^3.3.3",
75
- "tsup": "^8.3.6",
76
- "typescript": "^5.7.3",
77
- "vue": "3.5.13",
78
- "vue-tsc": "^2.2.0"
79
- },
80
- "engines": {
81
- "node": ">=20.0.0"
82
- }
2
+ "name": "@fast-china/utils",
3
+ "author": "小方",
4
+ "version": "1.0.4",
5
+ "description": "Fast 工具库.",
6
+ "type": "module",
7
+ "keywords": [
8
+ "fast-china",
9
+ "fast",
10
+ "typescript",
11
+ "utils"
12
+ ],
13
+ "license": "Apache-2.0",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "homepage": "https://fastdotnet.com",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://gitee.com/China-xiaoFang/fast.utils"
21
+ },
22
+ "bugs": {
23
+ "url": "https://gitee.com/China-xiaoFang/fast.utils/issues"
24
+ },
25
+ "main": "lib/index.js",
26
+ "module": "es/index.mjs",
27
+ "types": "es/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./es/index.d.ts",
31
+ "import": "./es/index.mjs",
32
+ "require": "./lib/index.js"
33
+ },
34
+ "./es": {
35
+ "types": "./es/index.d.ts",
36
+ "import": "./es/index.mjs"
37
+ },
38
+ "./lib": {
39
+ "types": "./lib/index.d.ts",
40
+ "require": "./lib/index.js"
41
+ },
42
+ "./es/*.mjs": {
43
+ "types": "./es/*.d.ts",
44
+ "import": "./es/*.mjs"
45
+ },
46
+ "./es/*": {
47
+ "types": [
48
+ "./es/*.d.ts",
49
+ "./es/*/index.d.ts"
50
+ ],
51
+ "import": "./es/*.mjs"
52
+ },
53
+ "./lib/*.js": {
54
+ "types": "./lib/*.d.ts",
55
+ "require": "./lib/*.js"
56
+ },
57
+ "./lib/*": {
58
+ "types": [
59
+ "./lib/*.d.ts",
60
+ "./lib/*/index.d.ts"
61
+ ],
62
+ "require": "./lib/*.js"
63
+ },
64
+ "./*": "./*"
65
+ },
66
+ "unpkg": "dist/index.global.min.js",
67
+ "jsdelivr": "dist/index.global.min.js",
68
+ "files": [
69
+ "./Fast.png",
70
+ "./LICENSE",
71
+ "./README.md",
72
+ "./README.zh.md",
73
+ "./dist",
74
+ "./es",
75
+ "./lib"
76
+ ],
77
+ "peerDependencies": {
78
+ "vue": "3.5.13"
79
+ },
80
+ "dependencies": {
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",
85
+ "lodash": "^4.17.21",
86
+ "lodash-es": "^4.17.21",
87
+ "lodash-unified": "^1.0.3"
88
+ },
89
+ "devDependencies": {
90
+ "@dcloudio/types": "*",
91
+ "@types/node": "*",
92
+ "vue": "3.5.13"
93
+ }
83
94
  }