@tanwan/utils 1.0.0 → 1.2.0

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 (425) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/addClass.cjs +19 -0
  3. package/dist/addClass.d.cts +16 -0
  4. package/dist/addClass.d.ts +17 -0
  5. package/dist/addClass.js +19 -0
  6. package/dist/{string/camelCase.cjs → camelCase.cjs} +0 -1
  7. package/dist/{string/camelCase.d.cts → camelCase.d.cts} +1 -2
  8. package/dist/{string/camelCase.d.ts → camelCase.d.ts} +1 -2
  9. package/dist/{string/camelCase.js → camelCase.js} +0 -3
  10. package/dist/{string/capitalize.cjs → capitalize.cjs} +1 -1
  11. package/dist/{string/capitalize.d.cts → capitalize.d.cts} +2 -3
  12. package/dist/{string/capitalize.d.ts → capitalize.d.ts} +2 -3
  13. package/dist/{string/capitalize.js → capitalize.js} +1 -3
  14. package/dist/{array/chunk.cjs → chunk.cjs} +1 -1
  15. package/dist/{array/chunk.d.cts → chunk.d.cts} +2 -3
  16. package/dist/{array/chunk.d.ts → chunk.d.ts} +2 -3
  17. package/dist/{array/chunk.js → chunk.js} +1 -3
  18. package/dist/{number/clamp.cjs → clamp.cjs} +1 -1
  19. package/dist/{number/clamp.d.cts → clamp.d.cts} +2 -3
  20. package/dist/{number/clamp.d.ts → clamp.d.ts} +2 -3
  21. package/dist/{number/clamp.js → clamp.js} +1 -3
  22. package/dist/convertCurrencyToChinese.cjs +56 -0
  23. package/dist/convertCurrencyToChinese.d.cts +18 -0
  24. package/dist/convertCurrencyToChinese.d.ts +19 -0
  25. package/dist/convertCurrencyToChinese.js +56 -0
  26. package/dist/copyToClipboard.cjs +38 -0
  27. package/dist/copyToClipboard.d.cts +17 -0
  28. package/dist/copyToClipboard.d.ts +18 -0
  29. package/dist/copyToClipboard.js +38 -0
  30. package/dist/createElement.cjs +27 -0
  31. package/dist/createElement.d.cts +21 -0
  32. package/dist/createElement.d.ts +22 -0
  33. package/dist/createElement.js +27 -0
  34. package/dist/{function/debounce.cjs → debounce.cjs} +1 -1
  35. package/dist/{function/debounce.d.cts → debounce.d.cts} +2 -3
  36. package/dist/{function/debounce.d.ts → debounce.d.ts} +2 -3
  37. package/dist/{function/debounce.js → debounce.js} +1 -3
  38. package/dist/debounceSubmit.cjs +34 -0
  39. package/dist/debounceSubmit.d.cts +22 -0
  40. package/dist/debounceSubmit.d.ts +23 -0
  41. package/dist/debounceSubmit.js +34 -0
  42. package/dist/decodeBase64.cjs +19 -0
  43. package/dist/decodeBase64.d.cts +16 -0
  44. package/dist/decodeBase64.d.ts +17 -0
  45. package/dist/decodeBase64.js +19 -0
  46. package/dist/{base/deepClone.cjs → deepClone.cjs} +3 -3
  47. package/dist/{base/deepClone.d.cts → deepClone.d.cts} +2 -3
  48. package/dist/{base/deepClone.d.ts → deepClone.d.ts} +2 -3
  49. package/dist/{base/deepClone.js → deepClone.js} +1 -3
  50. package/dist/deepMerge.cjs +39 -0
  51. package/dist/deepMerge.d.cts +25 -0
  52. package/dist/deepMerge.d.ts +26 -0
  53. package/dist/deepMerge.js +39 -0
  54. package/dist/delay.cjs +8 -0
  55. package/dist/delay.d.cts +18 -0
  56. package/dist/delay.d.ts +19 -0
  57. package/dist/delay.js +8 -0
  58. package/dist/difference.cjs +24 -0
  59. package/dist/difference.d.cts +20 -0
  60. package/dist/difference.d.ts +21 -0
  61. package/dist/difference.js +24 -0
  62. package/dist/downloadFile.cjs +31 -0
  63. package/dist/downloadFile.d.cts +20 -0
  64. package/dist/downloadFile.d.ts +21 -0
  65. package/dist/downloadFile.js +31 -0
  66. package/dist/encodeBase64.cjs +20 -0
  67. package/dist/encodeBase64.d.cts +17 -0
  68. package/dist/encodeBase64.d.ts +18 -0
  69. package/dist/encodeBase64.js +20 -0
  70. package/dist/{array/flatten.cjs → flatten.cjs} +1 -1
  71. package/dist/{array/flatten.d.cts → flatten.d.cts} +2 -3
  72. package/dist/{array/flatten.d.ts → flatten.d.ts} +2 -3
  73. package/dist/{array/flatten.js → flatten.js} +1 -3
  74. package/dist/formatBankCard.cjs +19 -0
  75. package/dist/formatBankCard.d.cts +16 -0
  76. package/dist/formatBankCard.d.ts +17 -0
  77. package/dist/formatBankCard.js +19 -0
  78. package/dist/formatCurrency.cjs +7 -0
  79. package/dist/formatCurrency.d.cts +27 -0
  80. package/dist/formatCurrency.d.ts +28 -0
  81. package/dist/formatCurrency.js +7 -0
  82. package/dist/{date/formatDate.cjs → formatDate.cjs} +1 -1
  83. package/dist/{date/formatDate.d.cts → formatDate.d.cts} +2 -3
  84. package/dist/{date/formatDate.d.ts → formatDate.d.ts} +2 -3
  85. package/dist/{date/formatDate.js → formatDate.js} +1 -3
  86. package/dist/formatFileSize.cjs +33 -0
  87. package/dist/formatFileSize.d.cts +19 -0
  88. package/dist/formatFileSize.d.ts +20 -0
  89. package/dist/formatFileSize.js +33 -0
  90. package/dist/formatIdCard.cjs +21 -0
  91. package/dist/formatIdCard.d.cts +17 -0
  92. package/dist/formatIdCard.d.ts +18 -0
  93. package/dist/formatIdCard.js +21 -0
  94. package/dist/formatPhone.cjs +21 -0
  95. package/dist/formatPhone.d.cts +17 -0
  96. package/dist/formatPhone.d.ts +18 -0
  97. package/dist/formatPhone.js +21 -0
  98. package/dist/{number/formatThousands.cjs → formatThousands.cjs} +1 -1
  99. package/dist/{number/formatThousands.d.cts → formatThousands.d.cts} +2 -3
  100. package/dist/{number/formatThousands.d.ts → formatThousands.d.ts} +2 -3
  101. package/dist/{number/formatThousands.js → formatThousands.js} +1 -3
  102. package/dist/generateCode.cjs +29 -0
  103. package/dist/generateCode.d.cts +19 -0
  104. package/dist/generateCode.d.ts +20 -0
  105. package/dist/generateCode.js +29 -0
  106. package/dist/getAge.cjs +30 -0
  107. package/dist/getAge.d.cts +18 -0
  108. package/dist/getAge.d.ts +19 -0
  109. package/dist/getAge.js +30 -0
  110. package/dist/getByPath.cjs +29 -0
  111. package/dist/getByPath.d.cts +20 -0
  112. package/dist/getByPath.d.ts +21 -0
  113. package/dist/getByPath.js +29 -0
  114. package/dist/getCssVar.cjs +22 -0
  115. package/dist/getCssVar.d.cts +18 -0
  116. package/dist/getCssVar.d.ts +19 -0
  117. package/dist/getCssVar.js +22 -0
  118. package/dist/{date/getRelativeTime.cjs → getRelativeTime.cjs} +1 -1
  119. package/dist/{date/getRelativeTime.d.cts → getRelativeTime.d.cts} +2 -3
  120. package/dist/{date/getRelativeTime.d.ts → getRelativeTime.d.ts} +2 -3
  121. package/dist/{date/getRelativeTime.js → getRelativeTime.js} +1 -3
  122. package/dist/getScrollTop.cjs +28 -0
  123. package/dist/getScrollTop.d.cts +18 -0
  124. package/dist/getScrollTop.d.ts +19 -0
  125. package/dist/getScrollTop.js +28 -0
  126. package/dist/getStorage.cjs +27 -0
  127. package/dist/getStorage.d.cts +18 -0
  128. package/dist/getStorage.d.ts +19 -0
  129. package/dist/getStorage.js +27 -0
  130. package/dist/getStyle.cjs +20 -0
  131. package/dist/getStyle.d.cts +17 -0
  132. package/dist/getStyle.d.ts +18 -0
  133. package/dist/getStyle.js +20 -0
  134. package/dist/getTextWidth.cjs +26 -0
  135. package/dist/getTextWidth.d.cts +16 -0
  136. package/dist/getTextWidth.d.ts +17 -0
  137. package/dist/getTextWidth.js +26 -0
  138. package/dist/groupBy.cjs +36 -0
  139. package/dist/groupBy.d.cts +26 -0
  140. package/dist/groupBy.d.ts +27 -0
  141. package/dist/groupBy.js +36 -0
  142. package/dist/hasClass.cjs +19 -0
  143. package/dist/hasClass.d.cts +16 -0
  144. package/dist/hasClass.d.ts +17 -0
  145. package/dist/hasClass.js +19 -0
  146. package/dist/index.cjs +180 -36
  147. package/dist/index.d.cts +91 -19
  148. package/dist/index.d.ts +91 -19
  149. package/dist/index.iife.js +1 -1
  150. package/dist/index.js +91 -19
  151. package/dist/insertAfter.cjs +19 -0
  152. package/dist/insertAfter.d.cts +15 -0
  153. package/dist/insertAfter.d.ts +16 -0
  154. package/dist/insertAfter.js +19 -0
  155. package/dist/intersection.cjs +24 -0
  156. package/dist/intersection.d.cts +20 -0
  157. package/dist/intersection.d.ts +21 -0
  158. package/dist/intersection.js +24 -0
  159. package/dist/invert.cjs +21 -0
  160. package/dist/invert.d.cts +16 -0
  161. package/dist/invert.d.ts +17 -0
  162. package/dist/invert.js +21 -0
  163. package/dist/{base/isArray.cjs → isArray.cjs} +1 -1
  164. package/dist/{base/isArray.d.cts → isArray.d.cts} +2 -3
  165. package/dist/{base/isArray.d.ts → isArray.d.ts} +2 -3
  166. package/dist/{base/isArray.js → isArray.js} +1 -3
  167. package/dist/isBrowser.cjs +17 -0
  168. package/dist/isBrowser.d.cts +14 -0
  169. package/dist/isBrowser.d.ts +15 -0
  170. package/dist/isBrowser.js +17 -0
  171. package/dist/isDate.cjs +18 -0
  172. package/dist/isDate.d.cts +15 -0
  173. package/dist/isDate.d.ts +16 -0
  174. package/dist/isDate.js +18 -0
  175. package/dist/isEmpty.cjs +42 -0
  176. package/dist/isEmpty.d.cts +33 -0
  177. package/dist/isEmpty.d.ts +34 -0
  178. package/dist/isEmpty.js +42 -0
  179. package/dist/isFunction.cjs +19 -0
  180. package/dist/isFunction.d.cts +16 -0
  181. package/dist/isFunction.d.ts +17 -0
  182. package/dist/isFunction.js +19 -0
  183. package/dist/isInViewport.cjs +22 -0
  184. package/dist/isInViewport.d.cts +17 -0
  185. package/dist/isInViewport.d.ts +18 -0
  186. package/dist/isInViewport.js +22 -0
  187. package/dist/isNil.cjs +19 -0
  188. package/dist/isNil.d.cts +16 -0
  189. package/dist/isNil.d.ts +17 -0
  190. package/dist/isNil.js +19 -0
  191. package/dist/isNumber.cjs +19 -0
  192. package/dist/isNumber.d.cts +16 -0
  193. package/dist/isNumber.d.ts +17 -0
  194. package/dist/isNumber.js +19 -0
  195. package/dist/{base/isObject.cjs → isObject.cjs} +1 -1
  196. package/dist/{base/isObject.d.cts → isObject.d.cts} +2 -3
  197. package/dist/{base/isObject.d.ts → isObject.d.ts} +2 -3
  198. package/dist/{base/isObject.js → isObject.js} +1 -3
  199. package/dist/isPrimitive.cjs +21 -0
  200. package/dist/isPrimitive.d.cts +18 -0
  201. package/dist/isPrimitive.d.ts +19 -0
  202. package/dist/isPrimitive.js +21 -0
  203. package/dist/isPromise.cjs +18 -0
  204. package/dist/isPromise.d.cts +15 -0
  205. package/dist/isPromise.d.ts +16 -0
  206. package/dist/isPromise.js +18 -0
  207. package/dist/{base/isString.cjs → isString.cjs} +1 -1
  208. package/dist/{base/isString.d.cts → isString.d.cts} +2 -3
  209. package/dist/{base/isString.d.ts → isString.d.ts} +2 -3
  210. package/dist/{base/isString.js → isString.js} +1 -3
  211. package/dist/joinUrl.cjs +25 -0
  212. package/dist/joinUrl.d.cts +19 -0
  213. package/dist/joinUrl.d.ts +20 -0
  214. package/dist/joinUrl.js +25 -0
  215. package/dist/{string/kebabCase.d.cts → kebabCase.d.cts} +1 -2
  216. package/dist/{string/kebabCase.d.ts → kebabCase.d.ts} +1 -2
  217. package/dist/{string/kebabCase.js → kebabCase.js} +0 -2
  218. package/dist/lazyLoadImages.cjs +36 -0
  219. package/dist/lazyLoadImages.d.cts +19 -0
  220. package/dist/lazyLoadImages.d.ts +20 -0
  221. package/dist/lazyLoadImages.js +36 -0
  222. package/dist/listToTree.cjs +25 -0
  223. package/dist/listToTree.d.cts +32 -0
  224. package/dist/listToTree.d.ts +33 -0
  225. package/dist/listToTree.js +25 -0
  226. package/dist/mapValues.cjs +25 -0
  227. package/dist/mapValues.d.cts +20 -0
  228. package/dist/mapValues.d.ts +21 -0
  229. package/dist/mapValues.js +25 -0
  230. package/dist/maskString.cjs +28 -0
  231. package/dist/maskString.d.cts +24 -0
  232. package/dist/maskString.d.ts +25 -0
  233. package/dist/maskString.js +28 -0
  234. package/dist/memoize.cjs +32 -0
  235. package/dist/memoize.d.cts +22 -0
  236. package/dist/memoize.d.ts +23 -0
  237. package/dist/memoize.js +32 -0
  238. package/dist/off.cjs +22 -0
  239. package/dist/off.d.cts +19 -0
  240. package/dist/off.d.ts +20 -0
  241. package/dist/off.js +22 -0
  242. package/dist/omit.cjs +23 -0
  243. package/dist/omit.d.cts +17 -0
  244. package/dist/omit.d.ts +18 -0
  245. package/dist/omit.js +23 -0
  246. package/dist/on.cjs +21 -0
  247. package/dist/on.d.cts +18 -0
  248. package/dist/on.d.ts +19 -0
  249. package/dist/on.js +21 -0
  250. package/dist/once.cjs +31 -0
  251. package/dist/once.d.cts +20 -0
  252. package/dist/once.d.ts +21 -0
  253. package/dist/once.js +31 -0
  254. package/dist/parseQueryString.cjs +48 -0
  255. package/dist/parseQueryString.d.cts +21 -0
  256. package/dist/parseQueryString.d.ts +22 -0
  257. package/dist/parseQueryString.js +48 -0
  258. package/dist/pascalCase.cjs +18 -0
  259. package/dist/pascalCase.d.cts +15 -0
  260. package/dist/pascalCase.d.ts +16 -0
  261. package/dist/pascalCase.js +18 -0
  262. package/dist/pick.cjs +22 -0
  263. package/dist/pick.d.cts +17 -0
  264. package/dist/pick.d.ts +18 -0
  265. package/dist/pick.js +22 -0
  266. package/dist/{number/randomInt.cjs → randomInt.cjs} +1 -1
  267. package/dist/{number/randomInt.d.cts → randomInt.d.cts} +2 -3
  268. package/dist/{number/randomInt.d.ts → randomInt.d.ts} +2 -3
  269. package/dist/{number/randomInt.js → randomInt.js} +1 -3
  270. package/dist/range.cjs +27 -0
  271. package/dist/range.d.cts +20 -0
  272. package/dist/range.d.ts +21 -0
  273. package/dist/range.js +27 -0
  274. package/dist/removeClass.cjs +19 -0
  275. package/dist/removeClass.d.cts +16 -0
  276. package/dist/removeClass.d.ts +17 -0
  277. package/dist/removeClass.js +19 -0
  278. package/dist/removeElement.cjs +17 -0
  279. package/dist/removeElement.d.cts +14 -0
  280. package/dist/removeElement.d.ts +15 -0
  281. package/dist/removeElement.js +17 -0
  282. package/dist/removeStorage.cjs +19 -0
  283. package/dist/removeStorage.d.cts +14 -0
  284. package/dist/removeStorage.d.ts +15 -0
  285. package/dist/removeStorage.js +19 -0
  286. package/dist/retry.cjs +27 -0
  287. package/dist/retry.d.cts +17 -0
  288. package/dist/retry.d.ts +18 -0
  289. package/dist/retry.js +27 -0
  290. package/dist/sample.cjs +20 -0
  291. package/dist/sample.d.cts +16 -0
  292. package/dist/sample.d.ts +17 -0
  293. package/dist/sample.js +20 -0
  294. package/dist/scrollToElement.cjs +23 -0
  295. package/dist/scrollToElement.d.cts +16 -0
  296. package/dist/scrollToElement.d.ts +17 -0
  297. package/dist/scrollToElement.js +23 -0
  298. package/dist/setCssVar.cjs +22 -0
  299. package/dist/setCssVar.d.cts +18 -0
  300. package/dist/setCssVar.d.ts +19 -0
  301. package/dist/setCssVar.js +22 -0
  302. package/dist/setStorage.cjs +25 -0
  303. package/dist/setStorage.d.cts +17 -0
  304. package/dist/setStorage.d.ts +18 -0
  305. package/dist/setStorage.js +25 -0
  306. package/dist/setStyle.cjs +22 -0
  307. package/dist/setStyle.d.cts +19 -0
  308. package/dist/setStyle.d.ts +20 -0
  309. package/dist/setStyle.js +22 -0
  310. package/dist/{array/shuffle.cjs → shuffle.cjs} +1 -1
  311. package/dist/{array/shuffle.d.cts → shuffle.d.cts} +2 -3
  312. package/dist/{array/shuffle.d.ts → shuffle.d.ts} +2 -3
  313. package/dist/{array/shuffle.js → shuffle.js} +1 -3
  314. package/dist/snakeCase.cjs +18 -0
  315. package/dist/snakeCase.d.cts +15 -0
  316. package/dist/snakeCase.d.ts +16 -0
  317. package/dist/snakeCase.js +18 -0
  318. package/dist/sortBy.cjs +30 -0
  319. package/dist/sortBy.d.cts +20 -0
  320. package/dist/sortBy.d.ts +21 -0
  321. package/dist/sortBy.js +30 -0
  322. package/dist/stringifyQueryString.cjs +38 -0
  323. package/dist/stringifyQueryString.d.cts +21 -0
  324. package/dist/stringifyQueryString.d.ts +22 -0
  325. package/dist/stringifyQueryString.js +38 -0
  326. package/dist/{function/throttle.cjs → throttle.cjs} +1 -1
  327. package/dist/{function/throttle.d.cts → throttle.d.cts} +2 -3
  328. package/dist/{function/throttle.d.ts → throttle.d.ts} +2 -3
  329. package/dist/{function/throttle.js → throttle.js} +1 -3
  330. package/dist/toggleClass.cjs +22 -0
  331. package/dist/toggleClass.d.cts +19 -0
  332. package/dist/toggleClass.d.ts +20 -0
  333. package/dist/toggleClass.js +22 -0
  334. package/dist/treeFind.cjs +34 -0
  335. package/dist/treeFind.d.cts +25 -0
  336. package/dist/treeFind.d.ts +26 -0
  337. package/dist/treeFind.js +34 -0
  338. package/dist/treeToList.cjs +33 -0
  339. package/dist/treeToList.d.cts +24 -0
  340. package/dist/treeToList.d.ts +25 -0
  341. package/dist/treeToList.js +33 -0
  342. package/dist/truncate.cjs +23 -0
  343. package/dist/truncate.d.cts +19 -0
  344. package/dist/truncate.d.ts +20 -0
  345. package/dist/truncate.js +23 -0
  346. package/dist/uniqBy.cjs +30 -0
  347. package/dist/uniqBy.d.cts +20 -0
  348. package/dist/uniqBy.d.ts +21 -0
  349. package/dist/uniqBy.js +30 -0
  350. package/dist/{array/unique.cjs → unique.cjs} +1 -1
  351. package/dist/{array/unique.d.cts → unique.d.cts} +2 -3
  352. package/dist/{array/unique.d.ts → unique.d.ts} +2 -3
  353. package/dist/{array/unique.js → unique.js} +1 -3
  354. package/dist/uuid.cjs +23 -0
  355. package/dist/uuid.d.cts +16 -0
  356. package/dist/uuid.d.ts +17 -0
  357. package/dist/uuid.js +23 -0
  358. package/dist/validateEmail.cjs +19 -0
  359. package/dist/validateEmail.d.cts +16 -0
  360. package/dist/validateEmail.d.ts +17 -0
  361. package/dist/validateEmail.js +19 -0
  362. package/dist/validateIdCard.cjs +62 -0
  363. package/dist/validateIdCard.d.cts +15 -0
  364. package/dist/validateIdCard.d.ts +16 -0
  365. package/dist/validateIdCard.js +62 -0
  366. package/dist/validatePhone.cjs +19 -0
  367. package/dist/validatePhone.d.cts +16 -0
  368. package/dist/validatePhone.d.ts +17 -0
  369. package/dist/validatePhone.js +19 -0
  370. package/package.json +351 -58
  371. package/dist/array/chunk.d.cts.map +0 -1
  372. package/dist/array/chunk.d.ts.map +0 -1
  373. package/dist/array/chunk.js.map +0 -1
  374. package/dist/array/flatten.d.cts.map +0 -1
  375. package/dist/array/flatten.d.ts.map +0 -1
  376. package/dist/array/flatten.js.map +0 -1
  377. package/dist/array/shuffle.d.cts.map +0 -1
  378. package/dist/array/shuffle.d.ts.map +0 -1
  379. package/dist/array/shuffle.js.map +0 -1
  380. package/dist/array/unique.d.cts.map +0 -1
  381. package/dist/array/unique.d.ts.map +0 -1
  382. package/dist/array/unique.js.map +0 -1
  383. package/dist/base/deepClone.d.cts.map +0 -1
  384. package/dist/base/deepClone.d.ts.map +0 -1
  385. package/dist/base/deepClone.js.map +0 -1
  386. package/dist/base/isArray.d.cts.map +0 -1
  387. package/dist/base/isArray.d.ts.map +0 -1
  388. package/dist/base/isArray.js.map +0 -1
  389. package/dist/base/isObject.d.cts.map +0 -1
  390. package/dist/base/isObject.d.ts.map +0 -1
  391. package/dist/base/isObject.js.map +0 -1
  392. package/dist/base/isString.d.cts.map +0 -1
  393. package/dist/base/isString.d.ts.map +0 -1
  394. package/dist/base/isString.js.map +0 -1
  395. package/dist/date/formatDate.d.cts.map +0 -1
  396. package/dist/date/formatDate.d.ts.map +0 -1
  397. package/dist/date/formatDate.js.map +0 -1
  398. package/dist/date/getRelativeTime.d.cts.map +0 -1
  399. package/dist/date/getRelativeTime.d.ts.map +0 -1
  400. package/dist/date/getRelativeTime.js.map +0 -1
  401. package/dist/function/debounce.d.cts.map +0 -1
  402. package/dist/function/debounce.d.ts.map +0 -1
  403. package/dist/function/debounce.js.map +0 -1
  404. package/dist/function/throttle.d.cts.map +0 -1
  405. package/dist/function/throttle.d.ts.map +0 -1
  406. package/dist/function/throttle.js.map +0 -1
  407. package/dist/number/clamp.d.cts.map +0 -1
  408. package/dist/number/clamp.d.ts.map +0 -1
  409. package/dist/number/clamp.js.map +0 -1
  410. package/dist/number/formatThousands.d.cts.map +0 -1
  411. package/dist/number/formatThousands.d.ts.map +0 -1
  412. package/dist/number/formatThousands.js.map +0 -1
  413. package/dist/number/randomInt.d.cts.map +0 -1
  414. package/dist/number/randomInt.d.ts.map +0 -1
  415. package/dist/number/randomInt.js.map +0 -1
  416. package/dist/string/camelCase.d.cts.map +0 -1
  417. package/dist/string/camelCase.d.ts.map +0 -1
  418. package/dist/string/camelCase.js.map +0 -1
  419. package/dist/string/capitalize.d.cts.map +0 -1
  420. package/dist/string/capitalize.d.ts.map +0 -1
  421. package/dist/string/capitalize.js.map +0 -1
  422. package/dist/string/kebabCase.d.cts.map +0 -1
  423. package/dist/string/kebabCase.d.ts.map +0 -1
  424. package/dist/string/kebabCase.js.map +0 -1
  425. /package/dist/{string/kebabCase.cjs → kebabCase.cjs} +0 -0
@@ -0,0 +1,18 @@
1
+ //#region src/business/formatPhone/index.d.ts
2
+ /**
3
+ * 手机号格式化
4
+ *
5
+ * @param phone - 11 位手机号字符串
6
+ * @param mode - `'display'`(显示:188-1234-5678,默认)| `'mask'`(脱敏:188****5678)
7
+ * @returns 格式化后的手机号
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import formatPhone from '@tanwan/utils/formatPhone'
12
+ * formatPhone('18812345678') // '188-1234-5678'
13
+ * formatPhone('18812345678', 'mask') // '188****5678'
14
+ * ```
15
+ */
16
+ declare function formatPhone(phone: string, mode?: "display" | "mask"): string;
17
+ //#endregion
18
+ export { formatPhone as default };
@@ -0,0 +1,21 @@
1
+ //#region src/business/formatPhone/index.ts
2
+ /**
3
+ * 手机号格式化
4
+ *
5
+ * @param phone - 11 位手机号字符串
6
+ * @param mode - `'display'`(显示:188-1234-5678,默认)| `'mask'`(脱敏:188****5678)
7
+ * @returns 格式化后的手机号
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import formatPhone from '@tanwan/utils/formatPhone'
12
+ * formatPhone('18812345678') // '188-1234-5678'
13
+ * formatPhone('18812345678', 'mask') // '188****5678'
14
+ * ```
15
+ */
16
+ function formatPhone(phone, mode = "display") {
17
+ if (mode === "mask") return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
18
+ return phone.replace(/(\d{3})(\d{4})(\d{4})/, "$1-$2-$3");
19
+ }
20
+ //#endregion
21
+ export { formatPhone as default };
@@ -3,7 +3,7 @@
3
3
  * 千分位格式化数字
4
4
  * @example
5
5
  * ```ts
6
- * import formatThousands from '@tw/utils/formatThousands'
6
+ * import formatThousands from '@tanwan/utils/formatThousands'
7
7
  * formatThousands(1234567) // '1,234,567'
8
8
  * formatThousands(1234567.89) // '1,234,567.89'
9
9
  * ```
@@ -3,11 +3,10 @@
3
3
  * 千分位格式化数字
4
4
  * @example
5
5
  * ```ts
6
- * import formatThousands from '@tw/utils/formatThousands'
6
+ * import formatThousands from '@tanwan/utils/formatThousands'
7
7
  * formatThousands(1234567) // '1,234,567'
8
8
  * formatThousands(1234567.89) // '1,234,567.89'
9
9
  * ```
10
10
  */
11
11
  declare function formatThousands(num: number | string): string;
12
- export = formatThousands;
13
- //# sourceMappingURL=formatThousands.d.cts.map
12
+ export = formatThousands;
@@ -3,12 +3,11 @@
3
3
  * 千分位格式化数字
4
4
  * @example
5
5
  * ```ts
6
- * import formatThousands from '@tw/utils/formatThousands'
6
+ * import formatThousands from '@tanwan/utils/formatThousands'
7
7
  * formatThousands(1234567) // '1,234,567'
8
8
  * formatThousands(1234567.89) // '1,234,567.89'
9
9
  * ```
10
10
  */
11
11
  declare function formatThousands(num: number | string): string;
12
12
  //#endregion
13
- export { formatThousands as default };
14
- //# sourceMappingURL=formatThousands.d.ts.map
13
+ export { formatThousands as default };
@@ -3,7 +3,7 @@
3
3
  * 千分位格式化数字
4
4
  * @example
5
5
  * ```ts
6
- * import formatThousands from '@tw/utils/formatThousands'
6
+ * import formatThousands from '@tanwan/utils/formatThousands'
7
7
  * formatThousands(1234567) // '1,234,567'
8
8
  * formatThousands(1234567.89) // '1,234,567.89'
9
9
  * ```
@@ -15,5 +15,3 @@ function formatThousands(num) {
15
15
  }
16
16
  //#endregion
17
17
  export { formatThousands as default };
18
-
19
- //# sourceMappingURL=formatThousands.js.map
@@ -0,0 +1,29 @@
1
+ //#region src/business/generateCode/index.ts
2
+ /**
3
+ * 生成随机验证码
4
+ *
5
+ * @param length - 验证码长度,默认 6
6
+ * @param type - 类型:`'number'` | `'letter'` | `'mixed'`(默认)
7
+ * @returns 随机验证码字符串
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import generateCode from '@tanwan/utils/generateCode'
12
+ * generateCode() // 'a3Bk9M'(混合)
13
+ * generateCode(4) // 'G2xP'
14
+ * generateCode(6, 'number') // '382410'
15
+ * generateCode(6, 'letter') // 'aBcDeF'
16
+ * ```
17
+ */
18
+ function generateCode(length = 6, type = "mixed") {
19
+ const pool = {
20
+ number: "0123456789",
21
+ letter: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
22
+ mixed: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
23
+ }[type];
24
+ let result = "";
25
+ for (let i = 0; i < length; i++) result += pool[Math.floor(Math.random() * pool.length)];
26
+ return result;
27
+ }
28
+ //#endregion
29
+ module.exports = generateCode;
@@ -0,0 +1,19 @@
1
+ //#region src/business/generateCode/index.d.ts
2
+ /**
3
+ * 生成随机验证码
4
+ *
5
+ * @param length - 验证码长度,默认 6
6
+ * @param type - 类型:`'number'` | `'letter'` | `'mixed'`(默认)
7
+ * @returns 随机验证码字符串
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import generateCode from '@tanwan/utils/generateCode'
12
+ * generateCode() // 'a3Bk9M'(混合)
13
+ * generateCode(4) // 'G2xP'
14
+ * generateCode(6, 'number') // '382410'
15
+ * generateCode(6, 'letter') // 'aBcDeF'
16
+ * ```
17
+ */
18
+ declare function generateCode(length?: number, type?: "number" | "letter" | "mixed"): string;
19
+ export = generateCode;
@@ -0,0 +1,20 @@
1
+ //#region src/business/generateCode/index.d.ts
2
+ /**
3
+ * 生成随机验证码
4
+ *
5
+ * @param length - 验证码长度,默认 6
6
+ * @param type - 类型:`'number'` | `'letter'` | `'mixed'`(默认)
7
+ * @returns 随机验证码字符串
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import generateCode from '@tanwan/utils/generateCode'
12
+ * generateCode() // 'a3Bk9M'(混合)
13
+ * generateCode(4) // 'G2xP'
14
+ * generateCode(6, 'number') // '382410'
15
+ * generateCode(6, 'letter') // 'aBcDeF'
16
+ * ```
17
+ */
18
+ declare function generateCode(length?: number, type?: "number" | "letter" | "mixed"): string;
19
+ //#endregion
20
+ export { generateCode as default };
@@ -0,0 +1,29 @@
1
+ //#region src/business/generateCode/index.ts
2
+ /**
3
+ * 生成随机验证码
4
+ *
5
+ * @param length - 验证码长度,默认 6
6
+ * @param type - 类型:`'number'` | `'letter'` | `'mixed'`(默认)
7
+ * @returns 随机验证码字符串
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import generateCode from '@tanwan/utils/generateCode'
12
+ * generateCode() // 'a3Bk9M'(混合)
13
+ * generateCode(4) // 'G2xP'
14
+ * generateCode(6, 'number') // '382410'
15
+ * generateCode(6, 'letter') // 'aBcDeF'
16
+ * ```
17
+ */
18
+ function generateCode(length = 6, type = "mixed") {
19
+ const pool = {
20
+ number: "0123456789",
21
+ letter: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
22
+ mixed: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
23
+ }[type];
24
+ let result = "";
25
+ for (let i = 0; i < length; i++) result += pool[Math.floor(Math.random() * pool.length)];
26
+ return result;
27
+ }
28
+ //#endregion
29
+ export { generateCode as default };
@@ -0,0 +1,30 @@
1
+ //#region src/business/getAge/index.ts
2
+ /**
3
+ * 计算年龄
4
+ *
5
+ * @param source - 身份证号(18 位)或 `YYYY-MM-DD` 日期字符串
6
+ * @param baseDate - 计算的基准日期,默认为当天
7
+ * @returns 年龄(周岁)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getAge from '@tanwan/utils/getAge'
12
+ * getAge('1990-05-15') // 按当天计算
13
+ * getAge('110101199001011234') // 从身份证计算
14
+ * getAge('1990-05-15', '2024-01-01') // 按指定日期计算
15
+ * ```
16
+ */
17
+ function getAge(source, baseDate) {
18
+ let birthStr;
19
+ if (source.length === 18) birthStr = `${source.substring(6, 10)}-${source.substring(10, 12)}-${source.substring(12, 14)}`;
20
+ else birthStr = source;
21
+ const birth = new Date(birthStr);
22
+ const base = baseDate ? new Date(baseDate) : /* @__PURE__ */ new Date();
23
+ let age = base.getFullYear() - birth.getFullYear();
24
+ const monthDiff = base.getMonth() - birth.getMonth();
25
+ const dayDiff = base.getDate() - birth.getDate();
26
+ if (monthDiff < 0 || monthDiff === 0 && dayDiff < 0) age--;
27
+ return age;
28
+ }
29
+ //#endregion
30
+ module.exports = getAge;
@@ -0,0 +1,18 @@
1
+ //#region src/business/getAge/index.d.ts
2
+ /**
3
+ * 计算年龄
4
+ *
5
+ * @param source - 身份证号(18 位)或 `YYYY-MM-DD` 日期字符串
6
+ * @param baseDate - 计算的基准日期,默认为当天
7
+ * @returns 年龄(周岁)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getAge from '@tanwan/utils/getAge'
12
+ * getAge('1990-05-15') // 按当天计算
13
+ * getAge('110101199001011234') // 从身份证计算
14
+ * getAge('1990-05-15', '2024-01-01') // 按指定日期计算
15
+ * ```
16
+ */
17
+ declare function getAge(source: string, baseDate?: string | Date): number;
18
+ export = getAge;
@@ -0,0 +1,19 @@
1
+ //#region src/business/getAge/index.d.ts
2
+ /**
3
+ * 计算年龄
4
+ *
5
+ * @param source - 身份证号(18 位)或 `YYYY-MM-DD` 日期字符串
6
+ * @param baseDate - 计算的基准日期,默认为当天
7
+ * @returns 年龄(周岁)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getAge from '@tanwan/utils/getAge'
12
+ * getAge('1990-05-15') // 按当天计算
13
+ * getAge('110101199001011234') // 从身份证计算
14
+ * getAge('1990-05-15', '2024-01-01') // 按指定日期计算
15
+ * ```
16
+ */
17
+ declare function getAge(source: string, baseDate?: string | Date): number;
18
+ //#endregion
19
+ export { getAge as default };
package/dist/getAge.js ADDED
@@ -0,0 +1,30 @@
1
+ //#region src/business/getAge/index.ts
2
+ /**
3
+ * 计算年龄
4
+ *
5
+ * @param source - 身份证号(18 位)或 `YYYY-MM-DD` 日期字符串
6
+ * @param baseDate - 计算的基准日期,默认为当天
7
+ * @returns 年龄(周岁)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getAge from '@tanwan/utils/getAge'
12
+ * getAge('1990-05-15') // 按当天计算
13
+ * getAge('110101199001011234') // 从身份证计算
14
+ * getAge('1990-05-15', '2024-01-01') // 按指定日期计算
15
+ * ```
16
+ */
17
+ function getAge(source, baseDate) {
18
+ let birthStr;
19
+ if (source.length === 18) birthStr = `${source.substring(6, 10)}-${source.substring(10, 12)}-${source.substring(12, 14)}`;
20
+ else birthStr = source;
21
+ const birth = new Date(birthStr);
22
+ const base = baseDate ? new Date(baseDate) : /* @__PURE__ */ new Date();
23
+ let age = base.getFullYear() - birth.getFullYear();
24
+ const monthDiff = base.getMonth() - birth.getMonth();
25
+ const dayDiff = base.getDate() - birth.getDate();
26
+ if (monthDiff < 0 || monthDiff === 0 && dayDiff < 0) age--;
27
+ return age;
28
+ }
29
+ //#endregion
30
+ export { getAge as default };
@@ -0,0 +1,29 @@
1
+ //#region src/object/getByPath/index.ts
2
+ /**
3
+ * 通过路径字符串安全获取嵌套对象的值
4
+ *
5
+ * @param obj - 源对象
6
+ * @param path - 属性路径,支持点号分隔和方括号,如 `'a.b[0].c'`
7
+ * @param defaultValue - 路径不存在时的默认值
8
+ * @returns 路径对应的值,或默认值
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import getByPath from '@tanwan/utils/getByPath'
13
+ * const obj = { a: { b: [{ c: 42 }] } }
14
+ * getByPath(obj, 'a.b[0].c') // 42
15
+ * getByPath(obj, 'a.x.y') // undefined
16
+ * getByPath(obj, 'a.x.y', 'none') // 'none'
17
+ * ```
18
+ */
19
+ function getByPath(obj, path, defaultValue) {
20
+ const keys = path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
21
+ let current = obj;
22
+ for (const key of keys) {
23
+ if (current === null || current === void 0 || typeof current !== "object") return defaultValue;
24
+ current = current[key];
25
+ }
26
+ return current === void 0 ? defaultValue : current;
27
+ }
28
+ //#endregion
29
+ module.exports = getByPath;
@@ -0,0 +1,20 @@
1
+ //#region src/object/getByPath/index.d.ts
2
+ /**
3
+ * 通过路径字符串安全获取嵌套对象的值
4
+ *
5
+ * @param obj - 源对象
6
+ * @param path - 属性路径,支持点号分隔和方括号,如 `'a.b[0].c'`
7
+ * @param defaultValue - 路径不存在时的默认值
8
+ * @returns 路径对应的值,或默认值
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import getByPath from '@tanwan/utils/getByPath'
13
+ * const obj = { a: { b: [{ c: 42 }] } }
14
+ * getByPath(obj, 'a.b[0].c') // 42
15
+ * getByPath(obj, 'a.x.y') // undefined
16
+ * getByPath(obj, 'a.x.y', 'none') // 'none'
17
+ * ```
18
+ */
19
+ declare function getByPath<T = unknown>(obj: Record<string, unknown>, path: string, defaultValue?: T): T | undefined;
20
+ export = getByPath;
@@ -0,0 +1,21 @@
1
+ //#region src/object/getByPath/index.d.ts
2
+ /**
3
+ * 通过路径字符串安全获取嵌套对象的值
4
+ *
5
+ * @param obj - 源对象
6
+ * @param path - 属性路径,支持点号分隔和方括号,如 `'a.b[0].c'`
7
+ * @param defaultValue - 路径不存在时的默认值
8
+ * @returns 路径对应的值,或默认值
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import getByPath from '@tanwan/utils/getByPath'
13
+ * const obj = { a: { b: [{ c: 42 }] } }
14
+ * getByPath(obj, 'a.b[0].c') // 42
15
+ * getByPath(obj, 'a.x.y') // undefined
16
+ * getByPath(obj, 'a.x.y', 'none') // 'none'
17
+ * ```
18
+ */
19
+ declare function getByPath<T = unknown>(obj: Record<string, unknown>, path: string, defaultValue?: T): T | undefined;
20
+ //#endregion
21
+ export { getByPath as default };
@@ -0,0 +1,29 @@
1
+ //#region src/object/getByPath/index.ts
2
+ /**
3
+ * 通过路径字符串安全获取嵌套对象的值
4
+ *
5
+ * @param obj - 源对象
6
+ * @param path - 属性路径,支持点号分隔和方括号,如 `'a.b[0].c'`
7
+ * @param defaultValue - 路径不存在时的默认值
8
+ * @returns 路径对应的值,或默认值
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import getByPath from '@tanwan/utils/getByPath'
13
+ * const obj = { a: { b: [{ c: 42 }] } }
14
+ * getByPath(obj, 'a.b[0].c') // 42
15
+ * getByPath(obj, 'a.x.y') // undefined
16
+ * getByPath(obj, 'a.x.y', 'none') // 'none'
17
+ * ```
18
+ */
19
+ function getByPath(obj, path, defaultValue) {
20
+ const keys = path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
21
+ let current = obj;
22
+ for (const key of keys) {
23
+ if (current === null || current === void 0 || typeof current !== "object") return defaultValue;
24
+ current = current[key];
25
+ }
26
+ return current === void 0 ? defaultValue : current;
27
+ }
28
+ //#endregion
29
+ export { getByPath as default };
@@ -0,0 +1,22 @@
1
+ //#region src/dom/getCssVar/index.ts
2
+ /**
3
+ * 读取 CSS 自定义属性(CSS 变量)
4
+ *
5
+ * @param name - CSS 变量名(可带 `--` 前缀或省略)
6
+ * @param el - 指定元素,不传则读取 `document.documentElement`(`:root`)
7
+ * @returns CSS 变量值
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getCssVar from '@tanwan/utils/getCssVar'
12
+ * getCssVar('--color-primary')
13
+ * getCssVar('color-primary') // 自动补 -- 前缀
14
+ * getCssVar('--bg', document.getElementById('box'))
15
+ * ```
16
+ */
17
+ function getCssVar(name, el = document.documentElement) {
18
+ const varName = name.startsWith("--") ? name : `--${name}`;
19
+ return getComputedStyle(el).getPropertyValue(varName).trim();
20
+ }
21
+ //#endregion
22
+ module.exports = getCssVar;
@@ -0,0 +1,18 @@
1
+ //#region src/dom/getCssVar/index.d.ts
2
+ /**
3
+ * 读取 CSS 自定义属性(CSS 变量)
4
+ *
5
+ * @param name - CSS 变量名(可带 `--` 前缀或省略)
6
+ * @param el - 指定元素,不传则读取 `document.documentElement`(`:root`)
7
+ * @returns CSS 变量值
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getCssVar from '@tanwan/utils/getCssVar'
12
+ * getCssVar('--color-primary')
13
+ * getCssVar('color-primary') // 自动补 -- 前缀
14
+ * getCssVar('--bg', document.getElementById('box'))
15
+ * ```
16
+ */
17
+ declare function getCssVar(name: string, el?: Element): string;
18
+ export = getCssVar;
@@ -0,0 +1,19 @@
1
+ //#region src/dom/getCssVar/index.d.ts
2
+ /**
3
+ * 读取 CSS 自定义属性(CSS 变量)
4
+ *
5
+ * @param name - CSS 变量名(可带 `--` 前缀或省略)
6
+ * @param el - 指定元素,不传则读取 `document.documentElement`(`:root`)
7
+ * @returns CSS 变量值
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getCssVar from '@tanwan/utils/getCssVar'
12
+ * getCssVar('--color-primary')
13
+ * getCssVar('color-primary') // 自动补 -- 前缀
14
+ * getCssVar('--bg', document.getElementById('box'))
15
+ * ```
16
+ */
17
+ declare function getCssVar(name: string, el?: Element): string;
18
+ //#endregion
19
+ export { getCssVar as default };
@@ -0,0 +1,22 @@
1
+ //#region src/dom/getCssVar/index.ts
2
+ /**
3
+ * 读取 CSS 自定义属性(CSS 变量)
4
+ *
5
+ * @param name - CSS 变量名(可带 `--` 前缀或省略)
6
+ * @param el - 指定元素,不传则读取 `document.documentElement`(`:root`)
7
+ * @returns CSS 变量值
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getCssVar from '@tanwan/utils/getCssVar'
12
+ * getCssVar('--color-primary')
13
+ * getCssVar('color-primary') // 自动补 -- 前缀
14
+ * getCssVar('--bg', document.getElementById('box'))
15
+ * ```
16
+ */
17
+ function getCssVar(name, el = document.documentElement) {
18
+ const varName = name.startsWith("--") ? name : `--${name}`;
19
+ return getComputedStyle(el).getPropertyValue(varName).trim();
20
+ }
21
+ //#endregion
22
+ export { getCssVar as default };
@@ -3,7 +3,7 @@
3
3
  * 获取相对时间描述(如"3分钟前")
4
4
  * @example
5
5
  * ```ts
6
- * import getRelativeTime from '@tw/utils/getRelativeTime'
6
+ * import getRelativeTime from '@tanwan/utils/getRelativeTime'
7
7
  * getRelativeTime(Date.now() - 60000) // '1分钟前'
8
8
  * getRelativeTime(Date.now() - 3600000) // '1小时前'
9
9
  * ```
@@ -3,11 +3,10 @@
3
3
  * 获取相对时间描述(如"3分钟前")
4
4
  * @example
5
5
  * ```ts
6
- * import getRelativeTime from '@tw/utils/getRelativeTime'
6
+ * import getRelativeTime from '@tanwan/utils/getRelativeTime'
7
7
  * getRelativeTime(Date.now() - 60000) // '1分钟前'
8
8
  * getRelativeTime(Date.now() - 3600000) // '1小时前'
9
9
  * ```
10
10
  */
11
11
  declare function getRelativeTime(date: number | string | Date, now?: Date): string;
12
- export = getRelativeTime;
13
- //# sourceMappingURL=getRelativeTime.d.cts.map
12
+ export = getRelativeTime;
@@ -3,12 +3,11 @@
3
3
  * 获取相对时间描述(如"3分钟前")
4
4
  * @example
5
5
  * ```ts
6
- * import getRelativeTime from '@tw/utils/getRelativeTime'
6
+ * import getRelativeTime from '@tanwan/utils/getRelativeTime'
7
7
  * getRelativeTime(Date.now() - 60000) // '1分钟前'
8
8
  * getRelativeTime(Date.now() - 3600000) // '1小时前'
9
9
  * ```
10
10
  */
11
11
  declare function getRelativeTime(date: number | string | Date, now?: Date): string;
12
12
  //#endregion
13
- export { getRelativeTime as default };
14
- //# sourceMappingURL=getRelativeTime.d.ts.map
13
+ export { getRelativeTime as default };
@@ -3,7 +3,7 @@
3
3
  * 获取相对时间描述(如"3分钟前")
4
4
  * @example
5
5
  * ```ts
6
- * import getRelativeTime from '@tw/utils/getRelativeTime'
6
+ * import getRelativeTime from '@tanwan/utils/getRelativeTime'
7
7
  * getRelativeTime(Date.now() - 60000) // '1分钟前'
8
8
  * getRelativeTime(Date.now() - 3600000) // '1小时前'
9
9
  * ```
@@ -27,5 +27,3 @@ function getRelativeTime(date, now = /* @__PURE__ */ new Date()) {
27
27
  }
28
28
  //#endregion
29
29
  export { getRelativeTime as default };
30
-
31
- //# sourceMappingURL=getRelativeTime.js.map
@@ -0,0 +1,28 @@
1
+ //#region src/dom/getScrollTop/index.ts
2
+ /**
3
+ * 获取或设置页面/元素的垂直滚动位置
4
+ *
5
+ * @param value - 设置滚动位置(传数字),不传则返回当前滚动位置
6
+ * @param el - 指定元素,不传则使用全局滚动
7
+ * @returns 当前滚动位置(仅 get 模式)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getScrollTop from '@tanwan/utils/getScrollTop'
12
+ * getScrollTop() // 获取全局滚动位置
13
+ * getScrollTop(100) // 设置全局滚动位置为 100
14
+ * getScrollTop(0, el) // 设置元素滚动位置为 0
15
+ * ```
16
+ */
17
+ function getScrollTop(value, el) {
18
+ if (value === void 0) {
19
+ const target = el || window;
20
+ if (target === window) return window.scrollY || document.documentElement.scrollTop;
21
+ return target.scrollTop;
22
+ }
23
+ const target = el || window;
24
+ if (target === window) window.scrollTo({ top: value });
25
+ else target.scrollTop = value;
26
+ }
27
+ //#endregion
28
+ module.exports = getScrollTop;
@@ -0,0 +1,18 @@
1
+ //#region src/dom/getScrollTop/index.d.ts
2
+ /**
3
+ * 获取或设置页面/元素的垂直滚动位置
4
+ *
5
+ * @param value - 设置滚动位置(传数字),不传则返回当前滚动位置
6
+ * @param el - 指定元素,不传则使用全局滚动
7
+ * @returns 当前滚动位置(仅 get 模式)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getScrollTop from '@tanwan/utils/getScrollTop'
12
+ * getScrollTop() // 获取全局滚动位置
13
+ * getScrollTop(100) // 设置全局滚动位置为 100
14
+ * getScrollTop(0, el) // 设置元素滚动位置为 0
15
+ * ```
16
+ */
17
+ declare function getScrollTop(value?: number, el?: Element | Window): number | void;
18
+ export = getScrollTop;
@@ -0,0 +1,19 @@
1
+ //#region src/dom/getScrollTop/index.d.ts
2
+ /**
3
+ * 获取或设置页面/元素的垂直滚动位置
4
+ *
5
+ * @param value - 设置滚动位置(传数字),不传则返回当前滚动位置
6
+ * @param el - 指定元素,不传则使用全局滚动
7
+ * @returns 当前滚动位置(仅 get 模式)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getScrollTop from '@tanwan/utils/getScrollTop'
12
+ * getScrollTop() // 获取全局滚动位置
13
+ * getScrollTop(100) // 设置全局滚动位置为 100
14
+ * getScrollTop(0, el) // 设置元素滚动位置为 0
15
+ * ```
16
+ */
17
+ declare function getScrollTop(value?: number, el?: Element | Window): number | void;
18
+ //#endregion
19
+ export { getScrollTop as default };
@@ -0,0 +1,28 @@
1
+ //#region src/dom/getScrollTop/index.ts
2
+ /**
3
+ * 获取或设置页面/元素的垂直滚动位置
4
+ *
5
+ * @param value - 设置滚动位置(传数字),不传则返回当前滚动位置
6
+ * @param el - 指定元素,不传则使用全局滚动
7
+ * @returns 当前滚动位置(仅 get 模式)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import getScrollTop from '@tanwan/utils/getScrollTop'
12
+ * getScrollTop() // 获取全局滚动位置
13
+ * getScrollTop(100) // 设置全局滚动位置为 100
14
+ * getScrollTop(0, el) // 设置元素滚动位置为 0
15
+ * ```
16
+ */
17
+ function getScrollTop(value, el) {
18
+ if (value === void 0) {
19
+ const target = el || window;
20
+ if (target === window) return window.scrollY || document.documentElement.scrollTop;
21
+ return target.scrollTop;
22
+ }
23
+ const target = el || window;
24
+ if (target === window) window.scrollTo({ top: value });
25
+ else target.scrollTop = value;
26
+ }
27
+ //#endregion
28
+ export { getScrollTop as default };