@shipfox/react-ui 0.0.1

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 (224) hide show
  1. package/.storybook/main.ts +18 -0
  2. package/.storybook/preview.tsx +48 -0
  3. package/.turbo/turbo-build.log +6 -0
  4. package/.turbo/turbo-check.log +6 -0
  5. package/.turbo/turbo-type.log +5 -0
  6. package/CHANGELOG.md +7 -0
  7. package/LICENSE +21 -0
  8. package/dist/colors.stories.conts.d.ts +33 -0
  9. package/dist/colors.stories.conts.d.ts.map +1 -0
  10. package/dist/colors.stories.conts.js +166 -0
  11. package/dist/colors.stories.conts.js.map +1 -0
  12. package/dist/colors.stories.js +61 -0
  13. package/dist/colors.stories.js.map +1 -0
  14. package/dist/components/button.d.ts +13 -0
  15. package/dist/components/button.d.ts.map +1 -0
  16. package/dist/components/button.js +51 -0
  17. package/dist/components/button.js.map +1 -0
  18. package/dist/components/button.stories.js +174 -0
  19. package/dist/components/button.stories.js.map +1 -0
  20. package/dist/components/icon/custom/badge.d.ts +4 -0
  21. package/dist/components/icon/custom/badge.d.ts.map +1 -0
  22. package/dist/components/icon/custom/badge.js +20 -0
  23. package/dist/components/icon/custom/badge.js.map +1 -0
  24. package/dist/components/icon/custom/check-circle-solid.d.ts +4 -0
  25. package/dist/components/icon/custom/check-circle-solid.d.ts.map +1 -0
  26. package/dist/components/icon/custom/check-circle-solid.js +34 -0
  27. package/dist/components/icon/custom/check-circle-solid.js.map +1 -0
  28. package/dist/components/icon/custom/circle-dotted-line.d.ts +4 -0
  29. package/dist/components/icon/custom/circle-dotted-line.d.ts.map +1 -0
  30. package/dist/components/icon/custom/circle-dotted-line.js +20 -0
  31. package/dist/components/icon/custom/circle-dotted-line.js.map +1 -0
  32. package/dist/components/icon/custom/component-fill.d.ts +4 -0
  33. package/dist/components/icon/custom/component-fill.d.ts.map +1 -0
  34. package/dist/components/icon/custom/component-fill.js +20 -0
  35. package/dist/components/icon/custom/component-fill.js.map +1 -0
  36. package/dist/components/icon/custom/component-line.d.ts +4 -0
  37. package/dist/components/icon/custom/component-line.d.ts.map +1 -0
  38. package/dist/components/icon/custom/component-line.js +20 -0
  39. package/dist/components/icon/custom/component-line.js.map +1 -0
  40. package/dist/components/icon/custom/ellipse-mini-solid.d.ts +4 -0
  41. package/dist/components/icon/custom/ellipse-mini-solid.d.ts.map +1 -0
  42. package/dist/components/icon/custom/ellipse-mini-solid.js +22 -0
  43. package/dist/components/icon/custom/ellipse-mini-solid.js.map +1 -0
  44. package/dist/components/icon/custom/index.d.ts +12 -0
  45. package/dist/components/icon/custom/index.d.ts.map +1 -0
  46. package/dist/components/icon/custom/index.js +13 -0
  47. package/dist/components/icon/custom/index.js.map +1 -0
  48. package/dist/components/icon/custom/info-tooltip-fill.d.ts +4 -0
  49. package/dist/components/icon/custom/info-tooltip-fill.d.ts.map +1 -0
  50. package/dist/components/icon/custom/info-tooltip-fill.js +22 -0
  51. package/dist/components/icon/custom/info-tooltip-fill.js.map +1 -0
  52. package/dist/components/icon/custom/resize.d.ts +4 -0
  53. package/dist/components/icon/custom/resize.d.ts.map +1 -0
  54. package/dist/components/icon/custom/resize.js +20 -0
  55. package/dist/components/icon/custom/resize.js.map +1 -0
  56. package/dist/components/icon/custom/spinner.d.ts +4 -0
  57. package/dist/components/icon/custom/spinner.d.ts.map +1 -0
  58. package/dist/components/icon/custom/spinner.js +145 -0
  59. package/dist/components/icon/custom/spinner.js.map +1 -0
  60. package/dist/components/icon/custom/thunder.d.ts +4 -0
  61. package/dist/components/icon/custom/thunder.d.ts.map +1 -0
  62. package/dist/components/icon/custom/thunder.js +20 -0
  63. package/dist/components/icon/custom/thunder.js.map +1 -0
  64. package/dist/components/icon/custom/x-circle-solid.d.ts +4 -0
  65. package/dist/components/icon/custom/x-circle-solid.d.ts.map +1 -0
  66. package/dist/components/icon/custom/x-circle-solid.js +34 -0
  67. package/dist/components/icon/custom/x-circle-solid.js.map +1 -0
  68. package/dist/components/icon/icon.d.ts +27 -0
  69. package/dist/components/icon/icon.d.ts.map +1 -0
  70. package/dist/components/icon/icon.js +27 -0
  71. package/dist/components/icon/icon.js.map +1 -0
  72. package/dist/components/icon/icon.stories.js +35 -0
  73. package/dist/components/icon/icon.stories.js.map +1 -0
  74. package/dist/components/icon/index.d.ts +2 -0
  75. package/dist/components/icon/index.d.ts.map +1 -0
  76. package/dist/components/icon/index.js +3 -0
  77. package/dist/components/icon/index.js.map +1 -0
  78. package/dist/components/index.d.ts +5 -0
  79. package/dist/components/index.d.ts.map +1 -0
  80. package/dist/components/index.js +6 -0
  81. package/dist/components/index.js.map +1 -0
  82. package/dist/components/theme-provider.d.ts +10 -0
  83. package/dist/components/theme-provider.d.ts.map +1 -0
  84. package/dist/components/theme-provider.js +32 -0
  85. package/dist/components/theme-provider.js.map +1 -0
  86. package/dist/components/typography/code.d.ts +11 -0
  87. package/dist/components/typography/code.d.ts.map +1 -0
  88. package/dist/components/typography/code.js +28 -0
  89. package/dist/components/typography/code.js.map +1 -0
  90. package/dist/components/typography/code.stories.js +54 -0
  91. package/dist/components/typography/code.stories.js.map +1 -0
  92. package/dist/components/typography/header.d.ts +10 -0
  93. package/dist/components/typography/header.d.ts.map +1 -0
  94. package/dist/components/typography/header.js +34 -0
  95. package/dist/components/typography/header.js.map +1 -0
  96. package/dist/components/typography/header.stories.js +34 -0
  97. package/dist/components/typography/header.stories.js.map +1 -0
  98. package/dist/components/typography/index.d.ts +4 -0
  99. package/dist/components/typography/index.d.ts.map +1 -0
  100. package/dist/components/typography/index.js +5 -0
  101. package/dist/components/typography/index.js.map +1 -0
  102. package/dist/components/typography/text.d.ts +12 -0
  103. package/dist/components/typography/text.d.ts.map +1 -0
  104. package/dist/components/typography/text.js +32 -0
  105. package/dist/components/typography/text.js.map +1 -0
  106. package/dist/components/typography/text.stories.js +105 -0
  107. package/dist/components/typography/text.stories.js.map +1 -0
  108. package/dist/hooks/index.d.ts +3 -0
  109. package/dist/hooks/index.d.ts.map +1 -0
  110. package/dist/hooks/index.js +4 -0
  111. package/dist/hooks/index.js.map +1 -0
  112. package/dist/hooks/useCopy.d.ts +1 -0
  113. package/dist/hooks/useCopy.d.ts.map +1 -0
  114. package/dist/hooks/useCopy.js +2 -0
  115. package/dist/hooks/useCopy.js.map +1 -0
  116. package/dist/hooks/useCopyToClipboard.d.ts +10 -0
  117. package/dist/hooks/useCopyToClipboard.d.ts.map +1 -0
  118. package/dist/hooks/useCopyToClipboard.js +16 -0
  119. package/dist/hooks/useCopyToClipboard.js.map +1 -0
  120. package/dist/hooks/useTheme.d.ts +2 -0
  121. package/dist/hooks/useTheme.d.ts.map +1 -0
  122. package/dist/hooks/useTheme.js +9 -0
  123. package/dist/hooks/useTheme.js.map +1 -0
  124. package/dist/index.d.ts +4 -0
  125. package/dist/index.d.ts.map +1 -0
  126. package/dist/index.js +5 -0
  127. package/dist/index.js.map +1 -0
  128. package/dist/state/theme.d.ts +7 -0
  129. package/dist/state/theme.d.ts.map +1 -0
  130. package/dist/state/theme.js +8 -0
  131. package/dist/state/theme.js.map +1 -0
  132. package/dist/utils/clipboard.d.ts +2 -0
  133. package/dist/utils/clipboard.d.ts.map +1 -0
  134. package/dist/utils/clipboard.js +6 -0
  135. package/dist/utils/clipboard.js.map +1 -0
  136. package/dist/utils/cn.d.ts +3 -0
  137. package/dist/utils/cn.d.ts.map +1 -0
  138. package/dist/utils/cn.js +7 -0
  139. package/dist/utils/cn.js.map +1 -0
  140. package/dist/utils/date.d.ts +16 -0
  141. package/dist/utils/date.d.ts.map +1 -0
  142. package/dist/utils/date.js +79 -0
  143. package/dist/utils/date.js.map +1 -0
  144. package/dist/utils/format/chart.d.ts +3 -0
  145. package/dist/utils/format/chart.d.ts.map +1 -0
  146. package/dist/utils/format/chart.js +14 -0
  147. package/dist/utils/format/chart.js.map +1 -0
  148. package/dist/utils/format/date.d.ts +10 -0
  149. package/dist/utils/format/date.d.ts.map +1 -0
  150. package/dist/utils/format/date.js +57 -0
  151. package/dist/utils/format/date.js.map +1 -0
  152. package/dist/utils/format/duration.d.ts +9 -0
  153. package/dist/utils/format/duration.d.ts.map +1 -0
  154. package/dist/utils/format/duration.js +71 -0
  155. package/dist/utils/format/duration.js.map +1 -0
  156. package/dist/utils/format/index.d.ts +5 -0
  157. package/dist/utils/format/index.d.ts.map +1 -0
  158. package/dist/utils/format/index.js +6 -0
  159. package/dist/utils/format/index.js.map +1 -0
  160. package/dist/utils/format/number.d.ts +7 -0
  161. package/dist/utils/format/number.d.ts.map +1 -0
  162. package/dist/utils/format/number.js +20 -0
  163. package/dist/utils/format/number.js.map +1 -0
  164. package/dist/utils/index.d.ts +5 -0
  165. package/dist/utils/index.d.ts.map +1 -0
  166. package/dist/utils/index.js +6 -0
  167. package/dist/utils/index.js.map +1 -0
  168. package/index.css +778 -0
  169. package/package.json +74 -0
  170. package/src/colors.stories.conts.ts +164 -0
  171. package/src/colors.stories.tsx +66 -0
  172. package/src/components/button.stories.tsx +126 -0
  173. package/src/components/button.tsx +63 -0
  174. package/src/components/icon/custom/badge.tsx +17 -0
  175. package/src/components/icon/custom/check-circle-solid.tsx +24 -0
  176. package/src/components/icon/custom/circle-dotted-line.tsx +17 -0
  177. package/src/components/icon/custom/component-fill.tsx +17 -0
  178. package/src/components/icon/custom/component-line.tsx +17 -0
  179. package/src/components/icon/custom/ellipse-mini-solid.tsx +17 -0
  180. package/src/components/icon/custom/index.ts +11 -0
  181. package/src/components/icon/custom/info-tooltip-fill.tsx +21 -0
  182. package/src/components/icon/custom/resize.tsx +17 -0
  183. package/src/components/icon/custom/spinner.tsx +98 -0
  184. package/src/components/icon/custom/thunder.tsx +17 -0
  185. package/src/components/icon/custom/x-circle-solid.tsx +24 -0
  186. package/src/components/icon/icon.stories.tsx +29 -0
  187. package/src/components/icon/icon.tsx +42 -0
  188. package/src/components/icon/index.ts +1 -0
  189. package/src/components/index.ts +4 -0
  190. package/src/components/renovate.json +23 -0
  191. package/src/components/theme-provider.tsx +50 -0
  192. package/src/components/typography/code.stories.tsx +36 -0
  193. package/src/components/typography/code.tsx +38 -0
  194. package/src/components/typography/header.stories.tsx +27 -0
  195. package/src/components/typography/header.tsx +41 -0
  196. package/src/components/typography/index.ts +3 -0
  197. package/src/components/typography/text.stories.tsx +67 -0
  198. package/src/components/typography/text.tsx +42 -0
  199. package/src/hooks/index.ts +2 -0
  200. package/src/hooks/useCopy.ts +0 -0
  201. package/src/hooks/useCopyToClipboard.ts +20 -0
  202. package/src/hooks/useTheme.ts +10 -0
  203. package/src/index.ts +3 -0
  204. package/src/state/theme.ts +15 -0
  205. package/src/utils/clipboard.ts +4 -0
  206. package/src/utils/cn.ts +6 -0
  207. package/src/utils/date.test.ts +119 -0
  208. package/src/utils/date.ts +99 -0
  209. package/src/utils/format/chart.ts +16 -0
  210. package/src/utils/format/date.test.ts +65 -0
  211. package/src/utils/format/date.ts +75 -0
  212. package/src/utils/format/duration.test.ts +58 -0
  213. package/src/utils/format/duration.ts +82 -0
  214. package/src/utils/format/index.ts +4 -0
  215. package/src/utils/format/number.test.ts +38 -0
  216. package/src/utils/format/number.ts +33 -0
  217. package/src/utils/index.ts +4 -0
  218. package/test/global.ts +3 -0
  219. package/test/setup.ts +9 -0
  220. package/tsconfig.build.json +13 -0
  221. package/tsconfig.json +11 -0
  222. package/tsconfig.test.json +12 -0
  223. package/vercel.json +8 -0
  224. package/vitest.config.ts +17 -0
@@ -0,0 +1,57 @@
1
+ import { getYear } from 'date-fns';
2
+ import { isEndOfDay, isStartOfDay } from '../../utils/date.js';
3
+ const defaultOptions = {
4
+ year: 'numeric',
5
+ month: 'short',
6
+ day: 'numeric',
7
+ hour: 'numeric',
8
+ minute: '2-digit'
9
+ };
10
+ function getDateTimeFormatter({ locale, ...options } = {}) {
11
+ return new Intl.DateTimeFormat(locale, {
12
+ ...defaultOptions,
13
+ ...options
14
+ });
15
+ }
16
+ function areCurrentYear({ start, end }) {
17
+ const now = new Date();
18
+ return getYear(end) === getYear(now) && getYear(start) === getYear(now);
19
+ }
20
+ export function formatDateTime(date, options) {
21
+ const formatter = getDateTimeFormatter(options);
22
+ return formatter.format(date);
23
+ }
24
+ export function formatDateTimeRelativeToInterval(date, interval, options) {
25
+ const formatter = getDateTimeFormatter({
26
+ year: areCurrentYear(interval) ? undefined : defaultOptions.year,
27
+ ...options
28
+ });
29
+ return formatter.format(date);
30
+ }
31
+ export function formatDateTimeRange(interval, options) {
32
+ const { start, end } = interval;
33
+ const areFullDays = isStartOfDay(start) && isEndOfDay(end);
34
+ const formatter = getDateTimeFormatter({
35
+ year: areCurrentYear(interval) ? undefined : defaultOptions.year,
36
+ hour: areFullDays ? undefined : defaultOptions.hour,
37
+ minute: areFullDays ? undefined : defaultOptions.minute,
38
+ ...options
39
+ });
40
+ return formatter.formatRange(start, end);
41
+ }
42
+ export function formatTimeSeriesTick(date, { locale, ...options } = {}) {
43
+ const tickOptions = isStartOfDay(date) ? {
44
+ month: 'short',
45
+ day: 'numeric'
46
+ } : {
47
+ hour: 'numeric',
48
+ minute: '2-digit'
49
+ };
50
+ const formatter = new Intl.DateTimeFormat(locale, {
51
+ ...tickOptions,
52
+ ...options
53
+ });
54
+ return formatter.format(date);
55
+ }
56
+
57
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/format/date.ts"],"sourcesContent":["import {getYear, type NormalizedInterval} from 'date-fns';\nimport {isEndOfDay, isStartOfDay} from 'utils/date';\n\ninterface DateTimeFormatOptions extends Intl.DateTimeFormatOptions {\n locale?: string;\n}\n\nconst defaultOptions: DateTimeFormatOptions = {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n hour: 'numeric',\n minute: '2-digit',\n};\n\nfunction getDateTimeFormatter({\n locale,\n ...options\n}: DateTimeFormatOptions = {}): Intl.DateTimeFormat {\n return new Intl.DateTimeFormat(locale, {\n ...defaultOptions,\n ...options,\n });\n}\n\nfunction areCurrentYear({start, end}: NormalizedInterval): boolean {\n const now = new Date();\n return getYear(end) === getYear(now) && getYear(start) === getYear(now);\n}\n\nexport function formatDateTime(date: Date, options?: DateTimeFormatOptions): string {\n const formatter = getDateTimeFormatter(options);\n return formatter.format(date);\n}\n\nexport function formatDateTimeRelativeToInterval(\n date: Date,\n interval: NormalizedInterval,\n options?: DateTimeFormatOptions,\n) {\n const formatter = getDateTimeFormatter({\n year: areCurrentYear(interval) ? undefined : defaultOptions.year,\n ...options,\n });\n return formatter.format(date);\n}\n\nexport function formatDateTimeRange(\n interval: NormalizedInterval,\n options?: DateTimeFormatOptions,\n): string {\n const {start, end} = interval;\n const areFullDays = isStartOfDay(start) && isEndOfDay(end);\n const formatter = getDateTimeFormatter({\n year: areCurrentYear(interval) ? undefined : defaultOptions.year,\n hour: areFullDays ? undefined : defaultOptions.hour,\n minute: areFullDays ? undefined : defaultOptions.minute,\n ...options,\n });\n return formatter.formatRange(start, end);\n}\n\nexport function formatTimeSeriesTick(\n date: Date,\n {locale, ...options}: DateTimeFormatOptions = {},\n): string {\n const tickOptions: DateTimeFormatOptions = isStartOfDay(date)\n ? {month: 'short', day: 'numeric'}\n : {hour: 'numeric', minute: '2-digit'};\n const formatter = new Intl.DateTimeFormat(locale, {\n ...tickOptions,\n ...options,\n });\n return formatter.format(date);\n}\n"],"names":["getYear","isEndOfDay","isStartOfDay","defaultOptions","year","month","day","hour","minute","getDateTimeFormatter","locale","options","Intl","DateTimeFormat","areCurrentYear","start","end","now","Date","formatDateTime","date","formatter","format","formatDateTimeRelativeToInterval","interval","undefined","formatDateTimeRange","areFullDays","formatRange","formatTimeSeriesTick","tickOptions"],"mappings":"AAAA,SAAQA,OAAO,QAAgC,WAAW;AAC1D,SAAQC,UAAU,EAAEC,YAAY,QAAO,aAAa;AAMpD,MAAMC,iBAAwC;IAC5CC,MAAM;IACNC,OAAO;IACPC,KAAK;IACLC,MAAM;IACNC,QAAQ;AACV;AAEA,SAASC,qBAAqB,EAC5BC,MAAM,EACN,GAAGC,SACmB,GAAG,CAAC,CAAC;IAC3B,OAAO,IAAIC,KAAKC,cAAc,CAACH,QAAQ;QACrC,GAAGP,cAAc;QACjB,GAAGQ,OAAO;IACZ;AACF;AAEA,SAASG,eAAe,EAACC,KAAK,EAAEC,GAAG,EAAqB;IACtD,MAAMC,MAAM,IAAIC;IAChB,OAAOlB,QAAQgB,SAAShB,QAAQiB,QAAQjB,QAAQe,WAAWf,QAAQiB;AACrE;AAEA,OAAO,SAASE,eAAeC,IAAU,EAAET,OAA+B;IACxE,MAAMU,YAAYZ,qBAAqBE;IACvC,OAAOU,UAAUC,MAAM,CAACF;AAC1B;AAEA,OAAO,SAASG,iCACdH,IAAU,EACVI,QAA4B,EAC5Bb,OAA+B;IAE/B,MAAMU,YAAYZ,qBAAqB;QACrCL,MAAMU,eAAeU,YAAYC,YAAYtB,eAAeC,IAAI;QAChE,GAAGO,OAAO;IACZ;IACA,OAAOU,UAAUC,MAAM,CAACF;AAC1B;AAEA,OAAO,SAASM,oBACdF,QAA4B,EAC5Bb,OAA+B;IAE/B,MAAM,EAACI,KAAK,EAAEC,GAAG,EAAC,GAAGQ;IACrB,MAAMG,cAAczB,aAAaa,UAAUd,WAAWe;IACtD,MAAMK,YAAYZ,qBAAqB;QACrCL,MAAMU,eAAeU,YAAYC,YAAYtB,eAAeC,IAAI;QAChEG,MAAMoB,cAAcF,YAAYtB,eAAeI,IAAI;QACnDC,QAAQmB,cAAcF,YAAYtB,eAAeK,MAAM;QACvD,GAAGG,OAAO;IACZ;IACA,OAAOU,UAAUO,WAAW,CAACb,OAAOC;AACtC;AAEA,OAAO,SAASa,qBACdT,IAAU,EACV,EAACV,MAAM,EAAE,GAAGC,SAA+B,GAAG,CAAC,CAAC;IAEhD,MAAMmB,cAAqC5B,aAAakB,QACpD;QAACf,OAAO;QAASC,KAAK;IAAS,IAC/B;QAACC,MAAM;QAAWC,QAAQ;IAAS;IACvC,MAAMa,YAAY,IAAIT,KAAKC,cAAc,CAACH,QAAQ;QAChD,GAAGoB,WAAW;QACd,GAAGnB,OAAO;IACZ;IACA,OAAOU,UAAUC,MAAM,CAACF;AAC1B"}
@@ -0,0 +1,9 @@
1
+ import type { Duration as BaseDuration } from 'date-fns';
2
+ export interface Duration extends BaseDuration {
3
+ milliseconds?: number | bigint;
4
+ microseconds?: number | bigint;
5
+ nanoseconds?: number | bigint;
6
+ }
7
+ /** Format a duration in nanoseconds to a human readable string */
8
+ export declare function formatDuration(duration: Duration): string;
9
+ //# sourceMappingURL=duration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../../src/utils/format/duration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,QAAQ,IAAI,YAAY,EAAC,MAAM,UAAU,CAAC;AAGvD,MAAM,WAAW,QAAS,SAAQ,YAAY;IAC5C,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/B;AA6DD,kEAAkE;AAClE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAYzD"}
@@ -0,0 +1,71 @@
1
+ import { formatNumber } from './number.js';
2
+ const units = [
3
+ {
4
+ key: 'years',
5
+ symbol: 'y',
6
+ ns: 365 * 24 * 60 * 60 * 1000 * 1000 * 1000
7
+ },
8
+ {
9
+ key: 'months',
10
+ symbol: 'mo',
11
+ ns: 30 * 24 * 60 * 60 * 1000 * 1000 * 1000
12
+ },
13
+ {
14
+ key: 'weeks',
15
+ symbol: 'w',
16
+ ns: 7 * 24 * 60 * 60 * 1000 * 1000 * 1000
17
+ },
18
+ {
19
+ key: 'days',
20
+ symbol: 'd',
21
+ ns: 24 * 60 * 60 * 1000 * 1000 * 1000
22
+ },
23
+ {
24
+ key: 'hours',
25
+ symbol: 'h',
26
+ ns: 60 * 60 * 1000 * 1000 * 1000
27
+ },
28
+ {
29
+ key: 'minutes',
30
+ symbol: 'min',
31
+ ns: 60 * 1000 * 1000 * 1000
32
+ },
33
+ {
34
+ key: 'seconds',
35
+ symbol: 's',
36
+ ns: 1000 * 1000 * 1000
37
+ },
38
+ {
39
+ key: 'milliseconds',
40
+ symbol: 'ms',
41
+ ns: 1000 * 1000
42
+ },
43
+ {
44
+ key: 'microseconds',
45
+ symbol: 'μs',
46
+ ns: 1000
47
+ },
48
+ {
49
+ key: 'nanoseconds',
50
+ symbol: 'ns',
51
+ ns: 1
52
+ }
53
+ ];
54
+ /** Format a duration in nanoseconds to a human readable string */ export function formatDuration(duration) {
55
+ const nanoseconds = Object.entries(duration).reduce((acc, [key, value])=>{
56
+ const unit = units.find((u)=>u.key === key);
57
+ if (!unit) throw new Error(`Received unknown duration unit: ${key}`);
58
+ return acc + Number(value) * unit.ns;
59
+ }, 0);
60
+ for (const unit of units){
61
+ const value = nanoseconds / unit.ns;
62
+ if (value >= 1) return `${formatNumber(value, {
63
+ maximumFractionDigits: 1
64
+ })} ${unit.symbol}`;
65
+ }
66
+ return `${formatNumber(nanoseconds, {
67
+ maximumFractionDigits: 1
68
+ })} ns`;
69
+ }
70
+
71
+ //# sourceMappingURL=duration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/format/duration.ts"],"sourcesContent":["import type {Duration as BaseDuration} from 'date-fns';\nimport {formatNumber} from './number';\n\nexport interface Duration extends BaseDuration {\n milliseconds?: number | bigint;\n microseconds?: number | bigint;\n nanoseconds?: number | bigint;\n}\n\ninterface Unit {\n key: keyof Duration;\n symbol: string;\n ns: number;\n}\n\nconst units: Unit[] = [\n {\n key: 'years',\n symbol: 'y',\n ns: 365 * 24 * 60 * 60 * 1000 * 1000 * 1000,\n },\n {\n key: 'months',\n symbol: 'mo',\n ns: 30 * 24 * 60 * 60 * 1000 * 1000 * 1000,\n },\n {\n key: 'weeks',\n symbol: 'w',\n ns: 7 * 24 * 60 * 60 * 1000 * 1000 * 1000,\n },\n {\n key: 'days',\n symbol: 'd',\n ns: 24 * 60 * 60 * 1000 * 1000 * 1000,\n },\n {\n key: 'hours',\n symbol: 'h',\n ns: 60 * 60 * 1000 * 1000 * 1000,\n },\n {\n key: 'minutes',\n symbol: 'min',\n ns: 60 * 1000 * 1000 * 1000,\n },\n {\n key: 'seconds',\n symbol: 's',\n ns: 1000 * 1000 * 1000,\n },\n {\n key: 'milliseconds',\n symbol: 'ms',\n ns: 1000 * 1000,\n },\n {\n key: 'microseconds',\n symbol: 'μs',\n ns: 1000,\n },\n {\n key: 'nanoseconds',\n symbol: 'ns',\n ns: 1,\n },\n];\n\n/** Format a duration in nanoseconds to a human readable string */\nexport function formatDuration(duration: Duration): string {\n const nanoseconds = Object.entries(duration).reduce((acc, [key, value]) => {\n const unit = units.find((u) => u.key === key);\n if (!unit) throw new Error(`Received unknown duration unit: ${key}`);\n return acc + Number(value) * unit.ns;\n }, 0);\n\n for (const unit of units) {\n const value = nanoseconds / unit.ns;\n if (value >= 1) return `${formatNumber(value, {maximumFractionDigits: 1})} ${unit.symbol}`;\n }\n return `${formatNumber(nanoseconds, {maximumFractionDigits: 1})} ns`;\n}\n"],"names":["formatNumber","units","key","symbol","ns","formatDuration","duration","nanoseconds","Object","entries","reduce","acc","value","unit","find","u","Error","Number","maximumFractionDigits"],"mappings":"AACA,SAAQA,YAAY,QAAO,WAAW;AActC,MAAMC,QAAgB;IACpB;QACEC,KAAK;QACLC,QAAQ;QACRC,IAAI,MAAM,KAAK,KAAK,KAAK,OAAO,OAAO;IACzC;IACA;QACEF,KAAK;QACLC,QAAQ;QACRC,IAAI,KAAK,KAAK,KAAK,KAAK,OAAO,OAAO;IACxC;IACA;QACEF,KAAK;QACLC,QAAQ;QACRC,IAAI,IAAI,KAAK,KAAK,KAAK,OAAO,OAAO;IACvC;IACA;QACEF,KAAK;QACLC,QAAQ;QACRC,IAAI,KAAK,KAAK,KAAK,OAAO,OAAO;IACnC;IACA;QACEF,KAAK;QACLC,QAAQ;QACRC,IAAI,KAAK,KAAK,OAAO,OAAO;IAC9B;IACA;QACEF,KAAK;QACLC,QAAQ;QACRC,IAAI,KAAK,OAAO,OAAO;IACzB;IACA;QACEF,KAAK;QACLC,QAAQ;QACRC,IAAI,OAAO,OAAO;IACpB;IACA;QACEF,KAAK;QACLC,QAAQ;QACRC,IAAI,OAAO;IACb;IACA;QACEF,KAAK;QACLC,QAAQ;QACRC,IAAI;IACN;IACA;QACEF,KAAK;QACLC,QAAQ;QACRC,IAAI;IACN;CACD;AAED,gEAAgE,GAChE,OAAO,SAASC,eAAeC,QAAkB;IAC/C,MAAMC,cAAcC,OAAOC,OAAO,CAACH,UAAUI,MAAM,CAAC,CAACC,KAAK,CAACT,KAAKU,MAAM;QACpE,MAAMC,OAAOZ,MAAMa,IAAI,CAAC,CAACC,IAAMA,EAAEb,GAAG,KAAKA;QACzC,IAAI,CAACW,MAAM,MAAM,IAAIG,MAAM,CAAC,gCAAgC,EAAEd,KAAK;QACnE,OAAOS,MAAMM,OAAOL,SAASC,KAAKT,EAAE;IACtC,GAAG;IAEH,KAAK,MAAMS,QAAQZ,MAAO;QACxB,MAAMW,QAAQL,cAAcM,KAAKT,EAAE;QACnC,IAAIQ,SAAS,GAAG,OAAO,GAAGZ,aAAaY,OAAO;YAACM,uBAAuB;QAAC,GAAG,CAAC,EAAEL,KAAKV,MAAM,EAAE;IAC5F;IACA,OAAO,GAAGH,aAAaO,aAAa;QAACW,uBAAuB;IAAC,GAAG,GAAG,CAAC;AACtE"}
@@ -0,0 +1,5 @@
1
+ export * from './chart';
2
+ export * from './date';
3
+ export * from './duration';
4
+ export * from './number';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/format/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './chart.js';
2
+ export * from './date.js';
3
+ export * from './duration.js';
4
+ export * from './number.js';
5
+
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/format/index.ts"],"sourcesContent":["export * from './chart';\nexport * from './date';\nexport * from './duration';\nexport * from './number';\n"],"names":[],"mappings":"AAAA,cAAc,UAAU;AACxB,cAAc,SAAS;AACvB,cAAc,aAAa;AAC3B,cAAc,WAAW"}
@@ -0,0 +1,7 @@
1
+ export interface NumberFormatOptions extends Intl.NumberFormatOptions {
2
+ locale?: string;
3
+ }
4
+ export declare function formatNumber(value: number | bigint, { locale, ...options }?: NumberFormatOptions): string;
5
+ export declare function formatNumberCompact(value: number | bigint, options?: NumberFormatOptions): string;
6
+ export declare function formatPercent(value: number, { locale, ...options }?: NumberFormatOptions): string;
7
+ //# sourceMappingURL=number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../src/utils/format/number.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,mBAAmB;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,EAAC,MAAM,EAAE,GAAG,OAAO,EAAC,GAAE,mBAAwB,GAC7C,MAAM,CAGR;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,OAAO,GAAE,mBAAwB,GAChC,MAAM,CAOR;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,EAAC,MAAM,EAAE,GAAG,OAAO,EAAC,GAAE,mBAAwB,GAC7C,MAAM,CAKR"}
@@ -0,0 +1,20 @@
1
+ export function formatNumber(value, { locale, ...options } = {}) {
2
+ const formatter = new Intl.NumberFormat(locale, options);
3
+ return formatter.format(value);
4
+ }
5
+ export function formatNumberCompact(value, options = {}) {
6
+ return formatNumber(value, {
7
+ ...options,
8
+ style: 'decimal',
9
+ notation: 'compact',
10
+ compactDisplay: 'short'
11
+ });
12
+ }
13
+ export function formatPercent(value, { locale, ...options } = {}) {
14
+ return formatNumber(value, {
15
+ ...options,
16
+ style: 'percent'
17
+ });
18
+ }
19
+
20
+ //# sourceMappingURL=number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/format/number.ts"],"sourcesContent":["export interface NumberFormatOptions extends Intl.NumberFormatOptions {\n locale?: string;\n}\n\nexport function formatNumber(\n value: number | bigint,\n {locale, ...options}: NumberFormatOptions = {},\n): string {\n const formatter = new Intl.NumberFormat(locale, options);\n return formatter.format(value);\n}\n\nexport function formatNumberCompact(\n value: number | bigint,\n options: NumberFormatOptions = {},\n): string {\n return formatNumber(value, {\n ...options,\n style: 'decimal',\n notation: 'compact',\n compactDisplay: 'short',\n });\n}\n\nexport function formatPercent(\n value: number,\n {locale, ...options}: NumberFormatOptions = {},\n): string {\n return formatNumber(value, {\n ...options,\n style: 'percent',\n });\n}\n"],"names":["formatNumber","value","locale","options","formatter","Intl","NumberFormat","format","formatNumberCompact","style","notation","compactDisplay","formatPercent"],"mappings":"AAIA,OAAO,SAASA,aACdC,KAAsB,EACtB,EAACC,MAAM,EAAE,GAAGC,SAA6B,GAAG,CAAC,CAAC;IAE9C,MAAMC,YAAY,IAAIC,KAAKC,YAAY,CAACJ,QAAQC;IAChD,OAAOC,UAAUG,MAAM,CAACN;AAC1B;AAEA,OAAO,SAASO,oBACdP,KAAsB,EACtBE,UAA+B,CAAC,CAAC;IAEjC,OAAOH,aAAaC,OAAO;QACzB,GAAGE,OAAO;QACVM,OAAO;QACPC,UAAU;QACVC,gBAAgB;IAClB;AACF;AAEA,OAAO,SAASC,cACdX,KAAa,EACb,EAACC,MAAM,EAAE,GAAGC,SAA6B,GAAG,CAAC,CAAC;IAE9C,OAAOH,aAAaC,OAAO;QACzB,GAAGE,OAAO;QACVM,OAAO;IACT;AACF"}
@@ -0,0 +1,5 @@
1
+ export * from './clipboard';
2
+ export * from './cn';
3
+ export * from './date';
4
+ export * from './format';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,MAAM,CAAC;AACrB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './clipboard.js';
2
+ export * from './cn.js';
3
+ export * from './date.js';
4
+ export * from './format/index.js';
5
+
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from './clipboard';\nexport * from './cn';\nexport * from './date';\nexport * from './format';\n"],"names":[],"mappings":"AAAA,cAAc,cAAc;AAC5B,cAAc,OAAO;AACrB,cAAc,SAAS;AACvB,cAAc,WAAW"}