@yelon/util 12.0.18 → 13.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (313) hide show
  1. package/{date-time/yelon-util-date-time.d.ts → array/array.d.ts} +1 -0
  2. package/array/array.service.d.ts +3 -0
  3. package/array/package.json +6 -7
  4. package/browser/browser.d.ts +1 -0
  5. package/browser/cookie.service.d.ts +3 -0
  6. package/browser/copy.d.ts +1 -1
  7. package/browser/package.json +5 -6
  8. package/browser/scroll.service.d.ts +3 -0
  9. package/config/abc/pdf.type.d.ts +1 -1
  10. package/config/abc/qr.type.d.ts +1 -1
  11. package/config/config.d.ts +5 -0
  12. package/config/config.service.d.ts +3 -0
  13. package/config/package.json +6 -7
  14. package/date-time/date-time.d.ts +5 -0
  15. package/date-time/package.json +6 -7
  16. package/decorator/decorator.d.ts +5 -0
  17. package/decorator/package.json +6 -7
  18. package/{esm2015/array/array-type.service.js → esm2020/array/array-type.service.mjs} +0 -0
  19. package/esm2020/array/array.mjs +5 -0
  20. package/esm2020/array/array.service.mjs +278 -0
  21. package/{esm2015/array/index.js → esm2020/array/index.mjs} +0 -0
  22. package/{esm2015/browser/browser.js → esm2020/browser/browser.mjs} +0 -0
  23. package/esm2020/browser/cookie.service.mjs +103 -0
  24. package/esm2020/browser/copy.mjs +9 -0
  25. package/{esm2015/browser/index.js → esm2020/browser/index.mjs} +0 -0
  26. package/{esm2015/browser/is-empty.js → esm2020/browser/is-empty.mjs} +0 -0
  27. package/esm2020/browser/scroll.service.mjs +88 -0
  28. package/{esm2015/browser/style.js → esm2020/browser/style.mjs} +2 -2
  29. package/{esm2015/config/abc/date-picker.type.js → esm2020/config/abc/date-picker.type.mjs} +0 -0
  30. package/{esm2015/config/abc/error-collect.type.js → esm2020/config/abc/error-collect.type.mjs} +0 -0
  31. package/{esm2015/config/abc/image.type.js → esm2020/config/abc/image.type.mjs} +0 -0
  32. package/{esm2015/config/abc/index.js → esm2020/config/abc/index.mjs} +0 -0
  33. package/{esm2015/config/abc/loading.type.js → esm2020/config/abc/loading.type.mjs} +0 -0
  34. package/{esm2015/config/abc/lodop.type.js → esm2020/config/abc/lodop.type.mjs} +0 -0
  35. package/{esm2015/config/abc/media.type.js → esm2020/config/abc/media.type.mjs} +0 -0
  36. package/{esm2015/config/abc/onboarding.type.js → esm2020/config/abc/onboarding.type.mjs} +0 -0
  37. package/{esm2015/config/abc/page-header.type.js → esm2020/config/abc/page-header.type.mjs} +0 -0
  38. package/esm2020/config/abc/pdf.type.mjs +2 -0
  39. package/esm2020/config/abc/qr.type.mjs +2 -0
  40. package/{esm2015/config/abc/se.type.js → esm2020/config/abc/se.type.mjs} +0 -0
  41. package/{esm2015/config/abc/sg.type.js → esm2020/config/abc/sg.type.mjs} +0 -0
  42. package/{esm2015/config/abc/st.type.js → esm2020/config/abc/st.type.mjs} +0 -0
  43. package/{esm2015/config/abc/sv.type.js → esm2020/config/abc/sv.type.mjs} +0 -0
  44. package/{esm2015/config/abc/xlsx.type.js → esm2020/config/abc/xlsx.type.mjs} +0 -0
  45. package/{esm2015/config/abc/zip.type.js → esm2020/config/abc/zip.type.mjs} +0 -0
  46. package/{esm2015/config/acl/acl.type.js → esm2020/config/acl/acl.type.mjs} +0 -0
  47. package/{esm2015/config/auth/auth.type.js → esm2020/config/auth/auth.type.mjs} +0 -0
  48. package/{esm2015/config/bis/bis.type.js → esm2020/config/bis/bis.type.mjs} +0 -0
  49. package/{esm2015/config/cache/cache.type.js → esm2020/config/cache/cache.type.mjs} +0 -0
  50. package/{esm2015/config/chart/chart.type.js → esm2020/config/chart/chart.type.mjs} +0 -0
  51. package/esm2020/config/config.mjs +5 -0
  52. package/esm2020/config/config.service.mjs +37 -0
  53. package/{esm2015/config/config.types.js → esm2020/config/config.types.mjs} +0 -0
  54. package/{esm2015/config/index.js → esm2020/config/index.mjs} +0 -0
  55. package/{esm2015/config/mock/mock.type.js → esm2020/config/mock/mock.type.mjs} +0 -0
  56. package/{esm2015/config/sf/sf.type.js → esm2020/config/sf/sf.type.mjs} +0 -0
  57. package/{esm2015/config/stomp/stomp.type.js → esm2020/config/stomp/stomp.type.mjs} +0 -0
  58. package/{esm2015/config/theme/http.type.js → esm2020/config/theme/http.type.mjs} +0 -0
  59. package/{esm2015/config/theme/i18n.type.js → esm2020/config/theme/i18n.type.mjs} +0 -0
  60. package/{esm2015/config/theme/index.js → esm2020/config/theme/index.mjs} +0 -0
  61. package/{esm2015/config/theme/responsive.type.js → esm2020/config/theme/responsive.type.mjs} +0 -0
  62. package/{esm2015/config/util/array.type.js → esm2020/config/util/array.type.mjs} +0 -0
  63. package/{esm2015/config/util/currency.type.js → esm2020/config/util/currency.type.mjs} +0 -0
  64. package/esm2020/date-time/date-time.mjs +5 -0
  65. package/{esm2015/date-time/index.js → esm2020/date-time/index.mjs} +0 -0
  66. package/esm2020/date-time/picker.mjs +116 -0
  67. package/{esm2015/date-time/time.js → esm2020/date-time/time.mjs} +6 -2
  68. package/esm2020/decorator/convert.mjs +58 -0
  69. package/esm2020/decorator/decorator.mjs +5 -0
  70. package/{esm2015/decorator/index.js → esm2020/decorator/index.mjs} +0 -0
  71. package/esm2020/decorator/zone-outside.mjs +57 -0
  72. package/esm2020/form/form.mjs +5 -0
  73. package/{esm2015/form/index.js → esm2020/form/index.mjs} +0 -0
  74. package/{esm2015/form/match-control.js → esm2020/form/match-control.mjs} +0 -0
  75. package/{esm2015/form/validators.js → esm2020/form/validators.mjs} +0 -0
  76. package/esm2020/format/currency.service.mjs +238 -0
  77. package/{esm2015/format/currency.types.js → esm2020/format/currency.types.mjs} +0 -0
  78. package/esm2020/format/format.mjs +5 -0
  79. package/{esm2015/format/index.js → esm2020/format/index.mjs} +0 -0
  80. package/esm2020/format/string.mjs +85 -0
  81. package/{esm2015/format/validate.js → esm2020/format/validate.mjs} +0 -0
  82. package/{esm2015/index.js → esm2020/index.mjs} +0 -0
  83. package/{esm2015/math/in-range.js → esm2020/math/in-range.mjs} +0 -0
  84. package/{esm2015/math/index.js → esm2020/math/index.mjs} +0 -0
  85. package/esm2020/math/math.mjs +5 -0
  86. package/{esm2015/math/round.js → esm2020/math/round.mjs} +0 -0
  87. package/{esm2015/other/assert.js → esm2020/other/assert.mjs} +0 -0
  88. package/{esm2015/other/deep.js → esm2020/other/deep.mjs} +0 -0
  89. package/{esm2015/other/index.js → esm2020/other/index.mjs} +3 -1
  90. package/esm2020/other/lazy.service.mjs +104 -0
  91. package/{esm2015/other/logger.js → esm2020/other/logger.mjs} +0 -0
  92. package/esm2020/other/other.mjs +5 -0
  93. package/esm2020/other/resize.mjs +4 -0
  94. package/esm2020/other/url.mjs +13 -0
  95. package/esm2020/pipes/currency/cny.pipe.mjs +23 -0
  96. package/{esm2015/pipes/currency/index.js → esm2020/pipes/currency/index.mjs} +2 -1
  97. package/esm2020/pipes/currency/mega.pipe.mjs +29 -0
  98. package/esm2020/pipes/currency/module.mjs +19 -0
  99. package/esm2020/pipes/currency/pipe-currency.mjs +5 -0
  100. package/esm2020/pipes/currency/price.pipe.mjs +27 -0
  101. package/esm2020/pipes/filter/filter.pipe.mjs +19 -0
  102. package/{esm2015/pipes/filter/index.js → esm2020/pipes/filter/index.mjs} +0 -0
  103. package/esm2020/pipes/filter/module.mjs +17 -0
  104. package/{esm2015/other/yelon-util-other.js → esm2020/pipes/filter/pipe-filter.mjs} +1 -1
  105. package/{esm2015/pipes/format/index.js → esm2020/pipes/format/index.mjs} +0 -0
  106. package/esm2020/pipes/format/mask.pipe.mjs +34 -0
  107. package/esm2020/pipes/format/module.mjs +17 -0
  108. package/{esm2015/array/yelon-util-array.js → esm2020/pipes/format/pipe-format.mjs} +1 -1
  109. package/{esm2015/pipes/index.js → esm2020/pipes/index.mjs} +0 -0
  110. package/esm2020/pipes/pipes.mjs +5 -0
  111. package/{esm2015/token/index.js → esm2020/token/index.mjs} +0 -0
  112. package/{esm2015/token/page-visibility.js → esm2020/token/page-visibility.mjs} +0 -0
  113. package/esm2020/token/token.mjs +5 -0
  114. package/{esm2015/token/window.js → esm2020/token/window.mjs} +0 -0
  115. package/{esm2015/yelon-util.js → esm2020/yelon-util.mjs} +0 -0
  116. package/fesm2015/{yelon-util-array.js → array.mjs} +8 -10
  117. package/fesm2015/array.mjs.map +1 -0
  118. package/fesm2015/{browser.js → browser.mjs} +28 -42
  119. package/fesm2015/browser.mjs.map +1 -0
  120. package/fesm2015/{yelon-util-config.js → config.mjs} +14 -8
  121. package/fesm2015/config.mjs.map +1 -0
  122. package/fesm2015/{yelon-util-date-time.js → date-time.mjs} +1 -1
  123. package/fesm2015/date-time.mjs.map +1 -0
  124. package/fesm2015/{yelon-util-decorator.js → decorator.mjs} +8 -4
  125. package/fesm2015/decorator.mjs.map +1 -0
  126. package/fesm2015/{yelon-util-form.js → form.mjs} +1 -1
  127. package/fesm2015/form.mjs.map +1 -0
  128. package/fesm2015/{yelon-util-format.js → format.mjs} +18 -14
  129. package/fesm2015/format.mjs.map +1 -0
  130. package/fesm2015/{yelon-util-math.js → math.mjs} +1 -1
  131. package/fesm2015/math.mjs.map +1 -0
  132. package/fesm2015/{yelon-util-other.js → other.mjs} +35 -30
  133. package/fesm2015/other.mjs.map +1 -0
  134. package/fesm2015/pipe-currency.mjs +96 -0
  135. package/fesm2015/pipe-currency.mjs.map +1 -0
  136. package/fesm2015/pipe-filter.mjs +40 -0
  137. package/fesm2015/pipe-filter.mjs.map +1 -0
  138. package/fesm2015/pipe-format.mjs +55 -0
  139. package/fesm2015/pipe-format.mjs.map +1 -0
  140. package/fesm2015/{yelon-util-pipes.js → pipes.mjs} +1 -1
  141. package/fesm2015/pipes.mjs.map +1 -0
  142. package/fesm2015/{yelon-util-token.js → token.mjs} +1 -1
  143. package/fesm2015/token.mjs.map +1 -0
  144. package/fesm2015/{yelon-util.js → yelon-util.mjs} +1 -1
  145. package/fesm2015/yelon-util.mjs.map +1 -0
  146. package/fesm2020/array.mjs +285 -0
  147. package/fesm2020/array.mjs.map +1 -0
  148. package/fesm2020/browser.mjs +260 -0
  149. package/fesm2020/browser.mjs.map +1 -0
  150. package/fesm2020/config.mjs +54 -0
  151. package/fesm2020/config.mjs.map +1 -0
  152. package/fesm2020/date-time.mjs +210 -0
  153. package/fesm2020/date-time.mjs.map +1 -0
  154. package/fesm2020/decorator.mjs +121 -0
  155. package/fesm2020/decorator.mjs.map +1 -0
  156. package/fesm2020/form.mjs +118 -0
  157. package/fesm2020/form.mjs.map +1 -0
  158. package/fesm2020/format.mjs +431 -0
  159. package/fesm2020/format.mjs.map +1 -0
  160. package/fesm2020/math.mjs +85 -0
  161. package/fesm2020/math.mjs.map +1 -0
  162. package/fesm2020/other.mjs +303 -0
  163. package/fesm2020/other.mjs.map +1 -0
  164. package/fesm2020/pipe-currency.mjs +94 -0
  165. package/fesm2020/pipe-currency.mjs.map +1 -0
  166. package/fesm2020/pipe-filter.mjs +40 -0
  167. package/fesm2020/pipe-filter.mjs.map +1 -0
  168. package/fesm2020/pipe-format.mjs +55 -0
  169. package/fesm2020/pipe-format.mjs.map +1 -0
  170. package/fesm2020/pipes.mjs +8 -0
  171. package/fesm2020/pipes.mjs.map +1 -0
  172. package/fesm2020/token.mjs +38 -0
  173. package/fesm2020/token.mjs.map +1 -0
  174. package/fesm2020/yelon-util.mjs +16 -0
  175. package/fesm2020/yelon-util.mjs.map +1 -0
  176. package/{array/yelon-util-array.d.ts → form/form.d.ts} +1 -0
  177. package/form/package.json +6 -7
  178. package/format/currency.service.d.ts +3 -0
  179. package/format/format.d.ts +5 -0
  180. package/format/package.json +6 -7
  181. package/{config/yelon-util-config.d.ts → math/math.d.ts} +1 -0
  182. package/math/package.json +6 -7
  183. package/other/index.d.ts +2 -0
  184. package/other/lazy.service.d.ts +3 -0
  185. package/{decorator/yelon-util-decorator.d.ts → other/other.d.ts} +1 -0
  186. package/other/package.json +6 -7
  187. package/other/resize.d.ts +1 -0
  188. package/other/url.d.ts +2 -0
  189. package/package.json +132 -8
  190. package/pipes/currency/cny.pipe.d.ts +3 -0
  191. package/pipes/currency/index.d.ts +1 -0
  192. package/pipes/currency/mega.pipe.d.ts +3 -0
  193. package/pipes/currency/module.d.ts +7 -0
  194. package/pipes/currency/package.json +6 -7
  195. package/pipes/currency/pipe-currency.d.ts +5 -0
  196. package/pipes/currency/price.pipe.d.ts +3 -0
  197. package/pipes/filter/filter.pipe.d.ts +3 -0
  198. package/pipes/filter/module.d.ts +5 -0
  199. package/pipes/filter/package.json +6 -7
  200. package/pipes/filter/pipe-filter.d.ts +5 -0
  201. package/pipes/format/mask.pipe.d.ts +3 -0
  202. package/pipes/format/module.d.ts +5 -0
  203. package/pipes/format/package.json +6 -7
  204. package/pipes/format/pipe-format.d.ts +5 -0
  205. package/pipes/package.json +6 -7
  206. package/pipes/pipes.d.ts +5 -0
  207. package/token/package.json +6 -7
  208. package/token/token.d.ts +5 -0
  209. package/yelon-util.d.ts +1 -0
  210. package/array/yelon-util-array.metadata.json +0 -1
  211. package/browser/browser.metadata.json +0 -1
  212. package/bundles/browser.umd.js +0 -325
  213. package/bundles/browser.umd.js.map +0 -1
  214. package/bundles/yelon-util-array.umd.js +0 -641
  215. package/bundles/yelon-util-array.umd.js.map +0 -1
  216. package/bundles/yelon-util-config.umd.js +0 -411
  217. package/bundles/yelon-util-config.umd.js.map +0 -1
  218. package/bundles/yelon-util-date-time.umd.js +0 -238
  219. package/bundles/yelon-util-date-time.umd.js.map +0 -1
  220. package/bundles/yelon-util-decorator.umd.js +0 -462
  221. package/bundles/yelon-util-decorator.umd.js.map +0 -1
  222. package/bundles/yelon-util-form.umd.js +0 -135
  223. package/bundles/yelon-util-form.umd.js.map +0 -1
  224. package/bundles/yelon-util-format.umd.js +0 -785
  225. package/bundles/yelon-util-format.umd.js.map +0 -1
  226. package/bundles/yelon-util-math.umd.js +0 -104
  227. package/bundles/yelon-util-math.umd.js.map +0 -1
  228. package/bundles/yelon-util-other.umd.js +0 -714
  229. package/bundles/yelon-util-other.umd.js.map +0 -1
  230. package/bundles/yelon-util-pipes-currency.umd.js +0 -108
  231. package/bundles/yelon-util-pipes-currency.umd.js.map +0 -1
  232. package/bundles/yelon-util-pipes-filter.umd.js +0 -374
  233. package/bundles/yelon-util-pipes-filter.umd.js.map +0 -1
  234. package/bundles/yelon-util-pipes-format.umd.js +0 -66
  235. package/bundles/yelon-util-pipes-format.umd.js.map +0 -1
  236. package/bundles/yelon-util-pipes.umd.js +0 -38
  237. package/bundles/yelon-util-pipes.umd.js.map +0 -1
  238. package/bundles/yelon-util-token.umd.js +0 -49
  239. package/bundles/yelon-util-token.umd.js.map +0 -1
  240. package/bundles/yelon-util.umd.js +0 -86
  241. package/bundles/yelon-util.umd.js.map +0 -1
  242. package/config/yelon-util-config.metadata.json +0 -1
  243. package/date-time/yelon-util-date-time.metadata.json +0 -1
  244. package/decorator/yelon-util-decorator.metadata.json +0 -1
  245. package/esm2015/array/array.service.js +0 -250
  246. package/esm2015/browser/cookie.service.js +0 -104
  247. package/esm2015/browser/copy.js +0 -27
  248. package/esm2015/browser/scroll.service.js +0 -89
  249. package/esm2015/config/abc/pdf.type.js +0 -2
  250. package/esm2015/config/abc/qr.type.js +0 -2
  251. package/esm2015/config/config.service.js +0 -34
  252. package/esm2015/config/yelon-util-config.js +0 -5
  253. package/esm2015/date-time/picker.js +0 -116
  254. package/esm2015/date-time/yelon-util-date-time.js +0 -5
  255. package/esm2015/decorator/convert.js +0 -56
  256. package/esm2015/decorator/yelon-util-decorator.js +0 -5
  257. package/esm2015/decorator/zone-outside.js +0 -55
  258. package/esm2015/form/yelon-util-form.js +0 -5
  259. package/esm2015/format/currency.service.js +0 -225
  260. package/esm2015/format/string.js +0 -76
  261. package/esm2015/format/yelon-util-format.js +0 -5
  262. package/esm2015/math/yelon-util-math.js +0 -5
  263. package/esm2015/other/lazy.service.js +0 -118
  264. package/esm2015/pipes/currency/cny.pipe.js +0 -22
  265. package/esm2015/pipes/currency/mega.pipe.js +0 -26
  266. package/esm2015/pipes/currency/module.js +0 -14
  267. package/esm2015/pipes/currency/price.pipe.js +0 -26
  268. package/esm2015/pipes/currency/yelon-util-pipes-currency.js +0 -6
  269. package/esm2015/pipes/filter/filter.pipe.js +0 -15
  270. package/esm2015/pipes/filter/module.js +0 -12
  271. package/esm2015/pipes/filter/yelon-util-pipes-filter.js +0 -5
  272. package/esm2015/pipes/format/mask.pipe.js +0 -30
  273. package/esm2015/pipes/format/module.js +0 -12
  274. package/esm2015/pipes/format/yelon-util-pipes-format.js +0 -5
  275. package/esm2015/pipes/yelon-util-pipes.js +0 -5
  276. package/esm2015/token/yelon-util-token.js +0 -5
  277. package/fesm2015/browser.js.map +0 -1
  278. package/fesm2015/yelon-util-array.js.map +0 -1
  279. package/fesm2015/yelon-util-config.js.map +0 -1
  280. package/fesm2015/yelon-util-date-time.js.map +0 -1
  281. package/fesm2015/yelon-util-decorator.js.map +0 -1
  282. package/fesm2015/yelon-util-form.js.map +0 -1
  283. package/fesm2015/yelon-util-format.js.map +0 -1
  284. package/fesm2015/yelon-util-math.js.map +0 -1
  285. package/fesm2015/yelon-util-other.js.map +0 -1
  286. package/fesm2015/yelon-util-pipes-currency.js +0 -87
  287. package/fesm2015/yelon-util-pipes-currency.js.map +0 -1
  288. package/fesm2015/yelon-util-pipes-filter.js +0 -32
  289. package/fesm2015/yelon-util-pipes-filter.js.map +0 -1
  290. package/fesm2015/yelon-util-pipes-format.js +0 -47
  291. package/fesm2015/yelon-util-pipes-format.js.map +0 -1
  292. package/fesm2015/yelon-util-pipes.js.map +0 -1
  293. package/fesm2015/yelon-util-token.js.map +0 -1
  294. package/fesm2015/yelon-util.js.map +0 -1
  295. package/form/yelon-util-form.d.ts +0 -4
  296. package/form/yelon-util-form.metadata.json +0 -1
  297. package/format/yelon-util-format.d.ts +0 -4
  298. package/format/yelon-util-format.metadata.json +0 -1
  299. package/math/yelon-util-math.d.ts +0 -4
  300. package/math/yelon-util-math.metadata.json +0 -1
  301. package/other/yelon-util-other.d.ts +0 -4
  302. package/other/yelon-util-other.metadata.json +0 -1
  303. package/pipes/currency/yelon-util-pipes-currency.d.ts +0 -5
  304. package/pipes/currency/yelon-util-pipes-currency.metadata.json +0 -1
  305. package/pipes/filter/yelon-util-pipes-filter.d.ts +0 -4
  306. package/pipes/filter/yelon-util-pipes-filter.metadata.json +0 -1
  307. package/pipes/format/yelon-util-pipes-format.d.ts +0 -4
  308. package/pipes/format/yelon-util-pipes-format.metadata.json +0 -1
  309. package/pipes/yelon-util-pipes.d.ts +0 -4
  310. package/pipes/yelon-util-pipes.metadata.json +0 -1
  311. package/token/yelon-util-token.d.ts +0 -4
  312. package/token/yelon-util-token.metadata.json +0 -1
  313. package/yelon-util.metadata.json +0 -1
@@ -0,0 +1,431 @@
1
+ import { deepGet } from '@yelon/util/other';
2
+ import { CurrencyPipe, formatNumber } from '@angular/common';
3
+ import * as i0 from '@angular/core';
4
+ import { LOCALE_ID, DEFAULT_CURRENCY_CODE, Injectable, Inject } from '@angular/core';
5
+ import * as i1 from '@yelon/util/config';
6
+
7
+ /**
8
+ * String formatting
9
+ *
10
+ * 字符串格式化
11
+ * ```
12
+ * format('this is ${name}', { name: 'asdf' })
13
+ * // output: this is asdf
14
+ * format('this is ${user.name}', { user: { name: 'asdf' } }, true)
15
+ * // output: this is asdf
16
+ * ```
17
+ */
18
+ function format(str, obj, needDeepGet = false) {
19
+ return (str || '').replace(/\${([^}]+)}/g, (_work, key) => needDeepGet ? deepGet(obj, key.split('.'), '') : (obj || {})[key] || '');
20
+ }
21
+ /**
22
+ * Format mask
23
+ *
24
+ * 格式化掩码
25
+ *
26
+ * | 字符 | 描述 |
27
+ * | --- | --- |
28
+ * | `0` | 任意数字,若该位置字符不符合,则默认为 `0` 填充 |
29
+ * | `9` | 任意数字 |
30
+ * | `#` | 任意字符 |
31
+ * | `U` | 转换大写 |
32
+ * | `L` | 转换小写 |
33
+ * | `*` | 转换为 `*` 字符 |
34
+ *
35
+ * ```ts
36
+ * formatMask('123', '(###)') => (123)
37
+ * formatMask('15900000000', '999****9999') => 159****0000
38
+ * ```
39
+ */
40
+ function formatMask(value, option) {
41
+ if (!value) {
42
+ return '';
43
+ }
44
+ const opt = {
45
+ ...(typeof option === 'string' ? { mask: option } : option)
46
+ };
47
+ const tokens = {
48
+ '0': { pattern: /\d/, default: '0' },
49
+ '9': { pattern: /\d/ },
50
+ '#': { pattern: /[a-zA-Z0-9]/ },
51
+ U: {
52
+ pattern: /[a-zA-Z]/,
53
+ transform: char => char.toLocaleUpperCase()
54
+ },
55
+ L: {
56
+ pattern: /[a-zA-Z]/,
57
+ transform: char => char.toLocaleLowerCase()
58
+ },
59
+ '*': {
60
+ pattern: /.*/,
61
+ transform: _ => `*`
62
+ },
63
+ ...opt.tokens
64
+ };
65
+ const splitValue = value.split('');
66
+ return opt.mask
67
+ .split('')
68
+ .reduce((res, cur) => {
69
+ const token = tokens[cur];
70
+ if (!token) {
71
+ res.push(cur);
72
+ return res;
73
+ }
74
+ const value = splitValue.shift() ?? '';
75
+ if (!token.pattern.test(value)) {
76
+ if (token.default)
77
+ res.push(token.default);
78
+ return res;
79
+ }
80
+ if (typeof token.transform === 'function') {
81
+ res.push(token.transform(value));
82
+ }
83
+ else {
84
+ res.push(value);
85
+ }
86
+ return res;
87
+ }, [])
88
+ .join('');
89
+ }
90
+
91
+ const REGEX_STR = {
92
+ num: `((-?\\d+\\.\\d+)|(-?\\d+)|(-?\\.\\d+))`,
93
+ idCard: `(^\\d{15}$)|(^\\d{17}(?:[0-9]|X)$)`,
94
+ mobile: `^(0|\\+?86|17951)?1[0-9]{10}$`,
95
+ url: `(((^https?:(?:\/\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+(?::\\d+)?|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:\/[\\+~%\\/.\\w-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)`,
96
+ ip: `(?:^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$)|(?:^(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?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$)`,
97
+ color: `(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\\b|(?:rgb|hsl)a?\\([^\\)]*\\)`,
98
+ chinese: `[\u4e00-\u9fa5]+`
99
+ };
100
+ function genRegex(str, flags) {
101
+ return new RegExp(`^${str}$`, flags);
102
+ }
103
+ const REGEX = {
104
+ num: genRegex(REGEX_STR.num),
105
+ idCard: genRegex(REGEX_STR.idCard, 'i'),
106
+ mobile: genRegex(REGEX_STR.mobile),
107
+ url: genRegex(REGEX_STR.url),
108
+ ip: genRegex(REGEX_STR.ip),
109
+ color: genRegex(REGEX_STR.color),
110
+ chinese: genRegex(REGEX_STR.chinese)
111
+ };
112
+ /**
113
+ * Wheter is number
114
+ *
115
+ * 是否为数字
116
+ */
117
+ function isNum(value) {
118
+ return REGEX.num.test(value.toString());
119
+ }
120
+ /**
121
+ * Wheter is integer
122
+ *
123
+ * 是否为整数
124
+ */
125
+ function isInt(value) {
126
+ return isNum(value) && parseInt(value.toString(), 10).toString() === value.toString();
127
+ }
128
+ /**
129
+ * Wheter is decimal
130
+ *
131
+ * 是否为小数点数值
132
+ */
133
+ function isDecimal(value) {
134
+ return isNum(value) && !isInt(value);
135
+ }
136
+ /**
137
+ * Wheter is People's Republic of China identity card
138
+ *
139
+ * 是否为中华人民共和国居民身份证
140
+ */
141
+ function isIdCard(value) {
142
+ return REGEX.idCard.test(value);
143
+ }
144
+ /**
145
+ * Wheter is china mobile (China)
146
+ *
147
+ * 是否为手机号(中国)
148
+ */
149
+ function isMobile(value) {
150
+ return REGEX.mobile.test(value);
151
+ }
152
+ /**
153
+ * Wheter is url address
154
+ *
155
+ * 是否URL地址
156
+ */
157
+ function isUrl(url) {
158
+ return REGEX.url.test(url);
159
+ }
160
+ /**
161
+ * Wheter is IPv4 address (Support v4, v6)
162
+ *
163
+ * 是否IP4地址(支持v4、v6)
164
+ */
165
+ function isIp(ip) {
166
+ return REGEX.ip.test(ip);
167
+ }
168
+ /**
169
+ * Wheter is color
170
+ *
171
+ * 是否颜色代码值
172
+ */
173
+ function isColor(color) {
174
+ return REGEX.color.test(color);
175
+ }
176
+ /**
177
+ * Wheter is chinese
178
+ *
179
+ * 是否中文
180
+ */
181
+ function isChinese(value) {
182
+ return REGEX.chinese.test(value);
183
+ }
184
+
185
+ const CurrencyMega_Powers = [
186
+ { unit: 'Q', value: Math.pow(10, 15) },
187
+ { unit: 'T', value: Math.pow(10, 12) },
188
+ { unit: 'B', value: Math.pow(10, 9) },
189
+ { unit: 'M', value: Math.pow(10, 6) },
190
+ { unit: 'K', value: 1000 }
191
+ ];
192
+
193
+ class CurrencyService {
194
+ constructor(cog, locale, _defaultCurrencyCode = 'USD') {
195
+ this.locale = locale;
196
+ this.currencyPipe = new CurrencyPipe(locale, _defaultCurrencyCode);
197
+ this.c = cog.merge('utilCurrency', {
198
+ startingUnit: 'yuan',
199
+ megaUnit: { Q: '京', T: '兆', B: '亿', M: '万', K: '千' },
200
+ precision: 2,
201
+ ignoreZeroPrecision: true
202
+ });
203
+ }
204
+ /**
205
+ * Format a number with commas as thousands separators
206
+ *
207
+ * 格式化货币,用逗号将数字格式化为千位分隔符
208
+ * ```ts
209
+ * 10000 => `10,000`
210
+ * 10000.567 => `10,000.57`
211
+ * ```
212
+ */
213
+ format(value, options) {
214
+ options = {
215
+ startingUnit: this.c.startingUnit,
216
+ precision: this.c.precision,
217
+ ignoreZeroPrecision: this.c.ignoreZeroPrecision,
218
+ ngCurrency: this.c.ngCurrency,
219
+ ...options
220
+ };
221
+ let truthValue = Number(value);
222
+ if (value == null || isNaN(truthValue)) {
223
+ return '';
224
+ }
225
+ if (options.startingUnit === 'cent') {
226
+ truthValue = truthValue / 100;
227
+ }
228
+ if (options.ngCurrency != null) {
229
+ const cur = options.ngCurrency;
230
+ return this.currencyPipe.transform(truthValue, cur.currencyCode, cur.display, cur.digitsInfo, cur.locale || this.locale);
231
+ }
232
+ const res = formatNumber(truthValue, this.locale, `.${options.ignoreZeroPrecision ? 1 : options.precision}-${options.precision}`);
233
+ return options.ignoreZeroPrecision ? res.replace(/(?:\.[0]+)$/g, '') : res;
234
+ }
235
+ /**
236
+ * Large number format filter
237
+ *
238
+ * 大数据格式化
239
+ * ```ts
240
+ * 1000 => { value: '1', unit: 'K', unitI18n: '千' }
241
+ * 12456 => { value: '12.46', unit: 'K', unitI18n: '千' }
242
+ * ```
243
+ */
244
+ mega(value, options) {
245
+ options = { precision: this.c.precision, unitI18n: this.c.megaUnit, startingUnit: this.c.startingUnit, ...options };
246
+ let num = Number(value);
247
+ const res = { raw: value, value: '', unit: '', unitI18n: '' };
248
+ if (isNaN(num) || num === 0) {
249
+ res.value = value.toString();
250
+ return res;
251
+ }
252
+ if (options.startingUnit === 'cent') {
253
+ num = num / 100;
254
+ }
255
+ let abs = Math.abs(+num);
256
+ const rounder = Math.pow(10, options.precision);
257
+ const isNegative = num < 0;
258
+ for (const p of CurrencyMega_Powers) {
259
+ let reduced = abs / p.value;
260
+ reduced = Math.round(reduced * rounder) / rounder;
261
+ if (reduced >= 1) {
262
+ abs = reduced;
263
+ res.unit = p.unit;
264
+ break;
265
+ }
266
+ }
267
+ res.value = (isNegative ? '-' : '') + abs;
268
+ res.unitI18n = options.unitI18n[res.unit];
269
+ return res;
270
+ }
271
+ /**
272
+ * Converted into RMB notation.
273
+ *
274
+ * 转化成人民币表示法
275
+ */
276
+ cny(value, options) {
277
+ options = {
278
+ inWords: true,
279
+ minusSymbol: '负',
280
+ startingUnit: this.c.startingUnit,
281
+ ...options
282
+ };
283
+ value = Number(value);
284
+ if (isNaN(value)) {
285
+ return '';
286
+ }
287
+ if (options.startingUnit === 'cent') {
288
+ value = value / 100;
289
+ }
290
+ value = value.toString();
291
+ let integer;
292
+ let decimal;
293
+ [integer, decimal] = value.split('.');
294
+ let symbol = '';
295
+ if (integer.startsWith('-')) {
296
+ symbol = options.minusSymbol;
297
+ integer = integer.substring(1);
298
+ }
299
+ if (/^-?\d+$/.test(value)) {
300
+ decimal = null;
301
+ }
302
+ integer = (+integer).toString();
303
+ const inWords = options.inWords;
304
+ const unit = {
305
+ num: inWords
306
+ ? ['', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '点']
307
+ : ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '点'],
308
+ radice: inWords
309
+ ? [
310
+ '',
311
+ '拾',
312
+ '佰',
313
+ '仟',
314
+ '万',
315
+ '拾',
316
+ '佰',
317
+ '仟',
318
+ '亿',
319
+ '拾',
320
+ '佰',
321
+ '仟',
322
+ '万亿',
323
+ '拾',
324
+ '佰',
325
+ '仟',
326
+ '兆',
327
+ '拾',
328
+ '佰',
329
+ '仟'
330
+ ]
331
+ : [
332
+ '',
333
+ '十',
334
+ '百',
335
+ '千',
336
+ '万',
337
+ '十',
338
+ '百',
339
+ '千',
340
+ '亿',
341
+ '十',
342
+ '百',
343
+ '千',
344
+ '万亿',
345
+ '十',
346
+ '百',
347
+ '千',
348
+ '兆',
349
+ '十',
350
+ '百',
351
+ '千'
352
+ ],
353
+ dec: ['角', '分', '厘', '毫']
354
+ };
355
+ if (inWords) {
356
+ value = (+value).toFixed(5).toString();
357
+ }
358
+ let integerRes = '';
359
+ const integerCount = integer.length;
360
+ if (integer === '0' || integerCount === 0) {
361
+ integerRes = '零';
362
+ }
363
+ else {
364
+ let cnDesc = '';
365
+ for (let i = 0; i < integerCount; i++) {
366
+ const n = +integer[i];
367
+ const j = integerCount - i - 1;
368
+ const isZero = i > 1 && n !== 0 && integer[i - 1] === '0';
369
+ const cnZero = isZero ? '零' : '';
370
+ const isEmpptyUnit = (n === 0 && j % 4 !== 0) || integer.substring(i - 3, i - 3 + 4) === '0000';
371
+ const descMark = cnDesc;
372
+ let cnNum = unit.num[n];
373
+ cnDesc = isEmpptyUnit ? '' : unit.radice[j];
374
+ // 第一位是一十
375
+ if (i === 0 && cnNum === '一' && cnDesc === '十')
376
+ cnNum = '';
377
+ const isChangeEr = n > 1 &&
378
+ cnNum === '二' && // 去除首位
379
+ ['', '十', '百'].indexOf(cnDesc) === -1 && // 不读两\两十\两百
380
+ descMark !== '十'; // 不读十两
381
+ if (isChangeEr)
382
+ cnNum = '两';
383
+ integerRes += cnZero + cnNum + cnDesc;
384
+ }
385
+ }
386
+ // 小数部分拼接
387
+ let decimalRes = '';
388
+ const decimalCount = decimal ? decimal.toString().length : 0;
389
+ if (decimal === null) {
390
+ decimalRes = inWords ? '整' : '';
391
+ }
392
+ else if (decimal === '0') {
393
+ decimalRes = '零';
394
+ }
395
+ else {
396
+ for (let i = 0; i < decimalCount; i++) {
397
+ if (inWords && i > unit.dec.length - 1)
398
+ break;
399
+ const n = decimal[i];
400
+ const cnZero = n === '0' ? '零' : '';
401
+ const cnNum = unit.num[+n];
402
+ const cnDesc = inWords ? unit.dec[i] : '';
403
+ decimalRes += cnZero + cnNum + cnDesc;
404
+ }
405
+ }
406
+ const ret = symbol +
407
+ (inWords
408
+ ? integerRes + (decimalRes === '零' ? '元整' : `元${decimalRes}`)
409
+ : integerRes + (decimalRes === '' ? '' : `点${decimalRes}`));
410
+ return ret;
411
+ }
412
+ }
413
+ CurrencyService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.3", ngImport: i0, type: CurrencyService, deps: [{ token: i1.YunzaiConfigService }, { token: LOCALE_ID }, { token: DEFAULT_CURRENCY_CODE }], target: i0.ɵɵFactoryTarget.Injectable });
414
+ CurrencyService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.3", ngImport: i0, type: CurrencyService, providedIn: 'root' });
415
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.3", ngImport: i0, type: CurrencyService, decorators: [{
416
+ type: Injectable,
417
+ args: [{ providedIn: 'root' }]
418
+ }], ctorParameters: function () { return [{ type: i1.YunzaiConfigService }, { type: undefined, decorators: [{
419
+ type: Inject,
420
+ args: [LOCALE_ID]
421
+ }] }, { type: undefined, decorators: [{
422
+ type: Inject,
423
+ args: [DEFAULT_CURRENCY_CODE]
424
+ }] }]; } });
425
+
426
+ /**
427
+ * Generated bundle index. Do not edit.
428
+ */
429
+
430
+ export { CurrencyMega_Powers, CurrencyService, REGEX, REGEX_STR, format, formatMask, isChinese, isColor, isDecimal, isIdCard, isInt, isIp, isMobile, isNum, isUrl };
431
+ //# sourceMappingURL=format.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.mjs","sources":["../../../../packages/util/format/string.ts","../../../../packages/util/format/validate.ts","../../../../packages/util/format/currency.types.ts","../../../../packages/util/format/currency.service.ts","../../../../packages/util/format/format.ts"],"sourcesContent":["import type { NzSafeAny } from 'ng-zorro-antd/core/types';\n\nimport { deepGet } from '@yelon/util/other';\n\n/**\n * String formatting\n *\n * 字符串格式化\n * ```\n * format('this is ${name}', { name: 'asdf' })\n * // output: this is asdf\n * format('this is ${user.name}', { user: { name: 'asdf' } }, true)\n * // output: this is asdf\n * ```\n */\nexport function format(\n str: string | null | undefined,\n obj: NzSafeAny | null | undefined,\n needDeepGet: boolean = false\n): string {\n return (str || '').replace(/\\${([^}]+)}/g, (_work: string, key: string) =>\n needDeepGet ? deepGet(obj, key.split('.'), '') : (obj || {})[key] || ''\n );\n}\n\nexport interface FormatMaskOption {\n mask: string;\n tokens?: { [key: string]: FormatMaskToken };\n}\n\nexport interface FormatMaskToken {\n pattern: RegExp;\n default?: NzSafeAny;\n transform?: (char: string) => string;\n}\n\n/**\n * Format mask\n *\n * 格式化掩码\n *\n * | 字符 | 描述 |\n * | --- | --- |\n * | `0` | 任意数字,若该位置字符不符合,则默认为 `0` 填充 |\n * | `9` | 任意数字 |\n * | `#` | 任意字符 |\n * | `U` | 转换大写 |\n * | `L` | 转换小写 |\n * | `*` | 转换为 `*` 字符 |\n *\n * ```ts\n * formatMask('123', '(###)') => (123)\n * formatMask('15900000000', '999****9999') => 159****0000\n * ```\n */\nexport function formatMask(value: string, option: string | FormatMaskOption): string {\n if (!value) {\n return '';\n }\n const opt: FormatMaskOption = {\n ...(typeof option === 'string' ? { mask: option } : option)\n };\n const tokens: { [key: string]: FormatMaskToken } = {\n '0': { pattern: /\\d/, default: '0' },\n '9': { pattern: /\\d/ },\n '#': { pattern: /[a-zA-Z0-9]/ },\n U: {\n pattern: /[a-zA-Z]/,\n transform: char => char.toLocaleUpperCase()\n },\n L: {\n pattern: /[a-zA-Z]/,\n transform: char => char.toLocaleLowerCase()\n },\n '*': {\n pattern: /.*/,\n transform: _ => `*`\n },\n ...opt.tokens\n };\n\n const splitValue = value.split('');\n return opt.mask\n .split('')\n .reduce((res, cur) => {\n const token = tokens[cur];\n if (!token) {\n res.push(cur);\n return res;\n }\n\n const value = splitValue.shift() ?? '';\n if (!token.pattern.test(value)) {\n if (token.default) res.push(token.default);\n return res;\n }\n\n if (typeof token.transform === 'function') {\n res.push(token.transform(value));\n } else {\n res.push(value);\n }\n return res;\n }, [] as string[])\n .join('');\n}\n","export const REGEX_STR = {\n num: `((-?\\\\d+\\\\.\\\\d+)|(-?\\\\d+)|(-?\\\\.\\\\d+))`,\n idCard: `(^\\\\d{15}$)|(^\\\\d{17}(?:[0-9]|X)$)`,\n mobile: `^(0|\\\\+?86|17951)?1[0-9]{10}$`,\n url: `(((^https?:(?:\\/\\/)?)(?:[-;:&=\\\\+\\\\$,\\\\w]+@)?[A-Za-z0-9.-]+(?::\\\\d+)?|(?:www.|[-;:&=\\\\+\\\\$,\\\\w]+@)[A-Za-z0-9.-]+)((?:\\/[\\\\+~%\\\\/.\\\\w-_]*)?\\\\??(?:[-\\\\+=&;%@.\\\\w_]*)#?(?:[\\\\w]*))?)`,\n ip: `(?:^(?:25[0-5]|2[0-4]\\\\d|1\\\\d\\\\d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1-9]\\\\d|\\\\d)){3}|(?::[a-fA-F\\\\d]{1,4}){1,5}|:)|(?:[a-fA-F\\\\d]{1,4}:){1}(?:(?::[a-fA-F\\\\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\\\\d|1\\\\d\\\\d|[1-9]\\\\d|\\\\d)(?:\\\\.(?:25[0-5]|2[0-4]\\\\d|1\\\\d\\\\d|[1-9]\\\\d|\\\\d)){3}|(?::[a-fA-F\\\\d]{1,4}){1,6}|:)|(?::(?:(?::[a-fA-F\\\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\\\d|1\\\\d\\\\d|[1-9]\\\\d|\\\\d)(?:\\\\.(?:25[0-5]|2[0-4]\\\\d|1\\\\d\\\\d|[1-9]\\\\d|\\\\d)){3}|(?::[a-fA-F\\\\d]{1,4}){1,7}|:)))(?:%[0-9a-zA-Z]{1,})?$)`,\n color: `(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\\\\b|(?:rgb|hsl)a?\\\\([^\\\\)]*\\\\)`,\n chinese: `[\\u4e00-\\u9fa5]+`\n};\n\nfunction genRegex(str: string, flags?: string): RegExp {\n return new RegExp(`^${str}$`, flags);\n}\n\nexport const REGEX = {\n num: genRegex(REGEX_STR.num),\n idCard: genRegex(REGEX_STR.idCard, 'i'),\n mobile: genRegex(REGEX_STR.mobile),\n url: genRegex(REGEX_STR.url),\n ip: genRegex(REGEX_STR.ip),\n color: genRegex(REGEX_STR.color),\n chinese: genRegex(REGEX_STR.chinese)\n};\n\n/**\n * Wheter is number\n *\n * 是否为数字\n */\nexport function isNum(value: string | number): boolean {\n return REGEX.num.test(value.toString());\n}\n\n/**\n * Wheter is integer\n *\n * 是否为整数\n */\nexport function isInt(value: string | number): boolean {\n return isNum(value) && parseInt(value.toString(), 10).toString() === value.toString();\n}\n\n/**\n * Wheter is decimal\n *\n * 是否为小数点数值\n */\nexport function isDecimal(value: string | number): boolean {\n return isNum(value) && !isInt(value);\n}\n\n/**\n * Wheter is People's Republic of China identity card\n *\n * 是否为中华人民共和国居民身份证\n */\nexport function isIdCard(value: string): boolean {\n return REGEX.idCard.test(value);\n}\n\n/**\n * Wheter is china mobile (China)\n *\n * 是否为手机号(中国)\n */\nexport function isMobile(value: string): boolean {\n return REGEX.mobile.test(value);\n}\n\n/**\n * Wheter is url address\n *\n * 是否URL地址\n */\nexport function isUrl(url: string): boolean {\n return REGEX.url.test(url);\n}\n\n/**\n * Wheter is IPv4 address (Support v4, v6)\n *\n * 是否IP4地址(支持v4、v6)\n */\nexport function isIp(ip: string): boolean {\n return REGEX.ip.test(ip);\n}\n\n/**\n * Wheter is color\n *\n * 是否颜色代码值\n */\nexport function isColor(color: string): boolean {\n return REGEX.color.test(color);\n}\n\n/**\n * Wheter is chinese\n *\n * 是否中文\n */\nexport function isChinese(value: string): boolean {\n return REGEX.chinese.test(value);\n}\n","export type CurrencyStartingUnit = 'yuan' | 'cent';\n\nexport interface CurrencyStartingUnitOptions {\n /**\n * The starting unit of the value, `yuan` means 元, `cent` means 分, default: `yuan`\n *\n * 值的起始单位,`yuan` 元,`cent` 分,默认:`yuan`\n */\n startingUnit?: CurrencyStartingUnit;\n}\n\nexport interface CurrencyFormatOptions extends CurrencyStartingUnitOptions {\n /**\n * Using `DEFAULT_CURRENCY_CODE` when value is `true\n *\n * 是否使用 `CurrencyPipe` 来替代\n */\n useAngular?: boolean;\n /**\n * 精度,默认:`2`\n */\n precision?: number;\n /**\n * 是否忽略精度 `.0` 或 `.00` 结尾的字符,默认:`true`\n */\n ignoreZeroPrecision?: boolean;\n\n /**\n * Use anguar `currency` pipe parse when is set, pls refer to [document](https://angular.io/api/common/CurrencyPipe)\n *\n * 若指定则表示使用 Angular 自带的 `currency` 管道来解析,见[文档](https://angular.cn/api/common/CurrencyPipe)\n */\n ngCurrency?: {\n display: 'code' | 'symbol' | 'symbol-narrow';\n currencyCode?: string;\n digitsInfo?: string;\n locale?: string;\n };\n}\n\nexport interface CurrencyMegaOptions extends CurrencyStartingUnitOptions {\n /**\n * 精度,默认:`2`\n */\n precision?: number;\n\n /**\n * 单位国际化,默认:`{Q: '京', T: '兆', B: '亿', M: '万', K: '千',}`\n */\n unitI18n?: CurrencyMegaUnitI18n;\n}\n\nexport interface CurrencyMegaResult {\n raw: number | string;\n value: string;\n unit: string;\n unitI18n: string;\n}\n\nexport const CurrencyMega_Powers = [\n { unit: 'Q', value: Math.pow(10, 15) },\n { unit: 'T', value: Math.pow(10, 12) },\n { unit: 'B', value: Math.pow(10, 9) },\n { unit: 'M', value: Math.pow(10, 6) },\n { unit: 'K', value: 1000 }\n];\n\nexport interface CurrencyMegaUnitI18n {\n Q: string;\n T: string;\n B: string;\n M: string;\n K: string;\n}\n\nexport interface CurrencyCNYOptions extends CurrencyStartingUnitOptions {\n /**\n * Whether to return to uppercase notation, default: `true`\n *\n * 是否返回大写表示法,默认:`true`\n */\n inWords?: boolean;\n /**\n * Specify negative sign, default: `negative`\n *\n * 指定负数符号,默认:`负`\n */\n minusSymbol?: string;\n}\n","import { CurrencyPipe, formatNumber } from '@angular/common';\nimport { DEFAULT_CURRENCY_CODE, Inject, Injectable, LOCALE_ID } from '@angular/core';\n\nimport { YunzaiConfigService, YunzaiUtilCurrencyConfig } from '@yelon/util/config';\nimport type { NzSafeAny } from 'ng-zorro-antd/core/types';\n\nimport {\n CurrencyCNYOptions,\n CurrencyFormatOptions,\n CurrencyMegaOptions,\n CurrencyMegaResult,\n CurrencyMega_Powers\n} from './currency.types';\n\n@Injectable({ providedIn: 'root' })\nexport class CurrencyService {\n private c: YunzaiUtilCurrencyConfig;\n private readonly currencyPipe: CurrencyPipe;\n\n constructor(\n cog: YunzaiConfigService,\n @Inject(LOCALE_ID) private locale: string,\n @Inject(DEFAULT_CURRENCY_CODE) _defaultCurrencyCode: string = 'USD'\n ) {\n this.currencyPipe = new CurrencyPipe(locale, _defaultCurrencyCode);\n this.c = cog.merge('utilCurrency', {\n startingUnit: 'yuan',\n megaUnit: { Q: '京', T: '兆', B: '亿', M: '万', K: '千' },\n precision: 2,\n ignoreZeroPrecision: true\n })!;\n }\n\n /**\n * Format a number with commas as thousands separators\n *\n * 格式化货币,用逗号将数字格式化为千位分隔符\n * ```ts\n * 10000 => `10,000`\n * 10000.567 => `10,000.57`\n * ```\n */\n format(value: number | string, options?: CurrencyFormatOptions): string {\n options = {\n startingUnit: this.c.startingUnit,\n precision: this.c.precision,\n ignoreZeroPrecision: this.c.ignoreZeroPrecision,\n ngCurrency: this.c.ngCurrency,\n ...options\n };\n let truthValue = Number(value);\n if (value == null || isNaN(truthValue)) {\n return '';\n }\n if (options.startingUnit === 'cent') {\n truthValue = truthValue / 100;\n }\n if (options.ngCurrency != null) {\n const cur = options.ngCurrency!;\n return this.currencyPipe.transform(\n truthValue,\n cur.currencyCode,\n cur.display,\n cur.digitsInfo,\n cur.locale || this.locale\n )!;\n }\n const res = formatNumber(\n truthValue,\n this.locale,\n `.${options.ignoreZeroPrecision ? 1 : options.precision}-${options.precision}`\n );\n return options.ignoreZeroPrecision ? res.replace(/(?:\\.[0]+)$/g, '') : res;\n }\n\n /**\n * Large number format filter\n *\n * 大数据格式化\n * ```ts\n * 1000 => { value: '1', unit: 'K', unitI18n: '千' }\n * 12456 => { value: '12.46', unit: 'K', unitI18n: '千' }\n * ```\n */\n mega(value: number | string, options?: CurrencyMegaOptions): CurrencyMegaResult {\n options = { precision: this.c.precision, unitI18n: this.c.megaUnit, startingUnit: this.c.startingUnit, ...options };\n let num = Number(value);\n const res: CurrencyMegaResult = { raw: value, value: '', unit: '', unitI18n: '' };\n if (isNaN(num) || num === 0) {\n res.value = value.toString();\n return res;\n }\n if (options.startingUnit === 'cent') {\n num = num / 100;\n }\n let abs = Math.abs(+num);\n const rounder = Math.pow(10, options.precision!);\n const isNegative = num < 0;\n for (const p of CurrencyMega_Powers) {\n let reduced = abs / p.value;\n\n reduced = Math.round(reduced * rounder) / rounder;\n\n if (reduced >= 1) {\n abs = reduced;\n res.unit = p.unit;\n break;\n }\n }\n\n res.value = (isNegative ? '-' : '') + abs;\n res.unitI18n = (options.unitI18n as { [key: string]: NzSafeAny })[res.unit];\n return res;\n }\n\n /**\n * Converted into RMB notation.\n *\n * 转化成人民币表示法\n */\n cny(value: number | string, options?: CurrencyCNYOptions): string {\n options = {\n inWords: true,\n minusSymbol: '负',\n startingUnit: this.c.startingUnit,\n ...options\n };\n\n value = Number(value);\n if (isNaN(value)) {\n return '';\n }\n if (options.startingUnit === 'cent') {\n value = value / 100;\n }\n value = value.toString();\n let integer: number | string;\n let decimal: number | string | null;\n [integer, decimal] = value.split('.');\n let symbol = '';\n if (integer.startsWith('-')) {\n symbol = options.minusSymbol!;\n integer = integer.substring(1);\n }\n if (/^-?\\d+$/.test(value)) {\n decimal = null;\n }\n integer = (+integer).toString();\n const inWords = options.inWords;\n const unit: { [key: string]: string[] } = {\n num: inWords\n ? ['', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '点']\n : ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '点'],\n radice: inWords\n ? [\n '',\n '拾',\n '佰',\n '仟',\n '万',\n '拾',\n '佰',\n '仟',\n '亿',\n '拾',\n '佰',\n '仟',\n '万亿',\n '拾',\n '佰',\n '仟',\n '兆',\n '拾',\n '佰',\n '仟'\n ]\n : [\n '',\n '十',\n '百',\n '千',\n '万',\n '十',\n '百',\n '千',\n '亿',\n '十',\n '百',\n '千',\n '万亿',\n '十',\n '百',\n '千',\n '兆',\n '十',\n '百',\n '千'\n ],\n dec: ['角', '分', '厘', '毫']\n };\n if (inWords) {\n value = (+value).toFixed(5).toString();\n }\n let integerRes = '';\n const integerCount = integer.length;\n if (integer === '0' || integerCount === 0) {\n integerRes = '零';\n } else {\n let cnDesc = '';\n for (let i = 0; i < integerCount; i++) {\n const n = +integer[i];\n const j = integerCount - i - 1;\n const isZero = i > 1 && n !== 0 && integer[i - 1] === '0';\n const cnZero = isZero ? '零' : '';\n const isEmpptyUnit = (n === 0 && j % 4 !== 0) || integer.substring(i - 3, i - 3 + 4) === '0000';\n const descMark = cnDesc;\n let cnNum = unit.num[n];\n\n cnDesc = isEmpptyUnit ? '' : unit.radice[j];\n // 第一位是一十\n if (i === 0 && cnNum === '一' && cnDesc === '十') cnNum = '';\n const isChangeEr =\n n > 1 &&\n cnNum === '二' && // 去除首位\n ['', '十', '百'].indexOf(cnDesc) === -1 && // 不读两\\两十\\两百\n descMark !== '十'; // 不读十两\n if (isChangeEr) cnNum = '两';\n integerRes += cnZero + cnNum + cnDesc;\n }\n }\n\n // 小数部分拼接\n let decimalRes = '';\n const decimalCount = decimal ? decimal.toString().length : 0;\n if (decimal === null) {\n decimalRes = inWords ? '整' : '';\n } else if (decimal === '0') {\n decimalRes = '零';\n } else {\n for (let i = 0; i < decimalCount; i++) {\n if (inWords && i > unit.dec.length - 1) break;\n const n = decimal[i];\n const cnZero = n === '0' ? '零' : '';\n const cnNum = unit.num[+n];\n const cnDesc = inWords ? unit.dec[i] : '';\n decimalRes += cnZero + cnNum + cnDesc;\n }\n }\n const ret =\n symbol +\n (inWords\n ? integerRes + (decimalRes === '零' ? '元整' : `元${decimalRes}`)\n : integerRes + (decimalRes === '' ? '' : `点${decimalRes}`));\n return ret;\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAIA;;;;;;;;;;;SAWgB,MAAM,CACpB,GAA8B,EAC9B,GAAiC,EACjC,cAAuB,KAAK;IAE5B,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,KAAa,EAAE,GAAW,KACpE,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,GAAG,CAAC,IAAI,EAAE,CACxE,CAAC;AACJ,CAAC;AAaD;;;;;;;;;;;;;;;;;;;SAmBgB,UAAU,CAAC,KAAa,EAAE,MAAiC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AG,CAAC,KAAK,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;gBACpC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC3B,MAAM,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;gBAC1C,UAAU,IAAI,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;aACvC;SACF;QACD,MAAM,GAAG,GACP,MAAM;aACL,OAAO;kBACJ,UAAU,IAAI,UAAU,KAAK,GAAG,GAAG,IAAI,GAAG,IAAI,UAAU,EAAE,CAAC;kBAC3D,UAAU,IAAI,UAAU,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,UAAU,EAAE,CAAC,CAAC,CAAC;QAChE,OAAO,GAAG,CAAC;KACZ;;4GA/OU,eAAe,qDAMhB,SAAS,aACT,qBAAqB;gHAPpB,eAAe,cADF,MAAM;2FACnB,eAAe;kBAD3B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;0BAO7B,MAAM;2BAAC,SAAS;;0BAChB,MAAM;2BAAC,qBAAqB;;;ACtBjC;;;;;;"}
@@ -0,0 +1,85 @@
1
+ import { assertNumber } from '@yelon/util/other';
2
+
3
+ /**
4
+ * Checks if `value` is between `start` and `end` to, but not including `end`. If `end` is not specified, it's set to start with `start` then set to `0`. If `start` is greater than `end` the params are swapped to support negative ranges.
5
+ *
6
+ * 检查 `value` 是否在 `start` 与 `end` 之间,但不包括 `end`。 如果 `end` 没有指定,那么 `start` 设置为 `0`。 如果 `start` 大于 `end`,那么参数会交换以便支持负范围。
7
+ * ```ts
8
+ * inRange(3, 2, 4); // true
9
+ * inRange(4, 8); // true
10
+ * inRange(4, 2); // false
11
+ * inRange(2, 2); // false
12
+ * inRange(1.2, 2); // true
13
+ * inRange(-3, -2, -6); // true
14
+ * ```
15
+ */
16
+ function inRange(value, start, end) {
17
+ if (end === undefined) {
18
+ end = start;
19
+ start = 0;
20
+ }
21
+ assertNumber(value);
22
+ assertNumber(start);
23
+ assertNumber(end);
24
+ return value >= Math.min(start, end) && value < Math.max(start, end);
25
+ }
26
+
27
+ /**
28
+ * Computes `number` rounded up to `precision`.
29
+ *
30
+ * 根据 `precision`(精度) 向上舍入 `number`。
31
+ * ```ts
32
+ * ceil(4.006); // 5
33
+ * ceil(6.004, 2); // 6.01
34
+ * ceil(6040, -2); // 6100
35
+ * ```
36
+ */
37
+ function ceil(number, precision = 0) {
38
+ return createRound(number, precision, 'ceil');
39
+ }
40
+ /**
41
+ * Computes `number` rounded down to `precision`.
42
+ *
43
+ * 根据 `precision`(精度) 向下舍入 `number`。
44
+ * ```ts
45
+ * floor(4.006); // 4
46
+ * floor(0.046, 2); // 0.04
47
+ * floor(4060, -2); // 4000
48
+ * ```
49
+ */
50
+ function floor(number, precision = 0) {
51
+ return createRound(number, precision, 'floor');
52
+ }
53
+ /**
54
+ * Computes `number` rounded to `precision`.
55
+ *
56
+ * 根据 `precision`(精度) 四舍五入 `number`。
57
+ * ```ts
58
+ * round(4.006); // 4
59
+ * round(4.006, 2); // 4.01
60
+ * round(4060, -2); // 4100
61
+ * ```
62
+ */
63
+ function round(number, precision = 0) {
64
+ return createRound(number, precision, 'round');
65
+ }
66
+ function createRound(number, precision, methodName) {
67
+ const func = Math[methodName];
68
+ precision = precision == null ? 0 : Math.min(precision, 292);
69
+ if (!precision) {
70
+ return func(number);
71
+ }
72
+ // Shift with exponential notation to avoid floating-point issues.
73
+ // See [MDN](https://mdn.io/round#Examples) for more details.
74
+ let pair = `${number}e`.split('e');
75
+ const value = func(Number(`${pair[0]}e${Number(pair[1]) + precision}`));
76
+ pair = `${value}e`.split('e');
77
+ return Number(`${pair[0]}e${Number(pair[1]) - precision}`);
78
+ }
79
+
80
+ /**
81
+ * Generated bundle index. Do not edit.
82
+ */
83
+
84
+ export { ceil, floor, inRange, round };
85
+ //# sourceMappingURL=math.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.mjs","sources":["../../../../packages/util/math/in-range.ts","../../../../packages/util/math/round.ts","../../../../packages/util/math/math.ts"],"sourcesContent":["import { assertNumber } from '@yelon/util/other';\n\n/**\n * Checks if `value` is between `start` and `end` to, but not including `end`. If `end` is not specified, it's set to start with `start` then set to `0`. If `start` is greater than `end` the params are swapped to support negative ranges.\n *\n * 检查 `value` 是否在 `start` 与 `end` 之间,但不包括 `end`。 如果 `end` 没有指定,那么 `start` 设置为 `0`。 如果 `start` 大于 `end`,那么参数会交换以便支持负范围。\n * ```ts\n * inRange(3, 2, 4); // true\n * inRange(4, 8); // true\n * inRange(4, 2); // false\n * inRange(2, 2); // false\n * inRange(1.2, 2); // true\n * inRange(-3, -2, -6); // true\n * ```\n */\nexport function inRange(value: number, start: number, end?: number): boolean {\n if (end === undefined) {\n end = start;\n start = 0;\n }\n assertNumber(value);\n assertNumber(start);\n assertNumber(end);\n return value >= Math.min(start, end) && value < Math.max(start, end);\n}\n","/**\n * Computes `number` rounded up to `precision`.\n *\n * 根据 `precision`(精度) 向上舍入 `number`。\n * ```ts\n * ceil(4.006); // 5\n * ceil(6.004, 2); // 6.01\n * ceil(6040, -2); // 6100\n * ```\n */\nexport function ceil(number: number, precision: number = 0): number {\n return createRound(number, precision, 'ceil');\n}\n\n/**\n * Computes `number` rounded down to `precision`.\n *\n * 根据 `precision`(精度) 向下舍入 `number`。\n * ```ts\n * floor(4.006); // 4\n * floor(0.046, 2); // 0.04\n * floor(4060, -2); // 4000\n * ```\n */\nexport function floor(number: number, precision: number = 0): number {\n return createRound(number, precision, 'floor');\n}\n\n/**\n * Computes `number` rounded to `precision`.\n *\n * 根据 `precision`(精度) 四舍五入 `number`。\n * ```ts\n * round(4.006); // 4\n * round(4.006, 2); // 4.01\n * round(4060, -2); // 4100\n * ```\n */\nexport function round(number: number, precision: number = 0): number {\n return createRound(number, precision, 'round');\n}\n\nfunction createRound(number: number, precision: number, methodName: keyof Math): number {\n const func = Math[methodName] as (x: number) => number;\n\n precision = precision == null ? 0 : Math.min(precision, 292);\n if (!precision) {\n return func(number);\n }\n // Shift with exponential notation to avoid floating-point issues.\n // See [MDN](https://mdn.io/round#Examples) for more details.\n let pair = `${number}e`.split('e');\n const value = func(Number(`${pair[0]}e${Number(pair[1]) + precision}`));\n pair = `${value}e`.split('e');\n return Number(`${pair[0]}e${Number(pair[1]) - precision}`);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;SAagB,OAAO,CAAC,KAAa,EAAE,KAAa,EAAE,GAAY;IAChE,IAAI,GAAG,KAAK,SAAS,EAAE;QACrB,GAAG,GAAG,KAAK,CAAC;QACZ,KAAK,GAAG,CAAC,CAAC;KACX;IACD,YAAY,CAAC,KAAK,CAAC,CAAC;IACpB,YAAY,CAAC,KAAK,CAAC,CAAC;IACpB,YAAY,CAAC,GAAG,CAAC,CAAC;IAClB,OAAO,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACvE;;ACxBA;;;;;;;;;;SAUgB,IAAI,CAAC,MAAc,EAAE,YAAoB,CAAC;IACxD,OAAO,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;;;;;SAUgB,KAAK,CAAC,MAAc,EAAE,YAAoB,CAAC;IACzD,OAAO,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;;SAUgB,KAAK,CAAC,MAAc,EAAE,YAAoB,CAAC;IACzD,OAAO,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,WAAW,CAAC,MAAc,EAAE,SAAiB,EAAE,UAAsB;IAC5E,MAAM,IAAI,GAA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