@1001-digital/layers.base 0.0.8 → 0.0.9

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.
@@ -0,0 +1,27 @@
1
+ export const formatNumber = (num: number) => num?.toLocaleString('en-US')
2
+
3
+ export const roundAndFormatNumber = (num: number, decimals: number = 2) => {
4
+ const multiplier = Math.pow(10, decimals)
5
+ const rounded = Math.round(num * multiplier) / multiplier
6
+ return formatNumber(rounded === num ? num : rounded)
7
+ }
8
+
9
+ export const asPercentageOf = (num: number = 0, base: number = 1) => {
10
+ return formatNumber(Math.round((num / base) * 100))
11
+ }
12
+
13
+ export function formatUSD(value: string | number, fractionDigits: number = 0): string {
14
+ const numberValue = typeof value === 'string' ? parseFloat(value) : value
15
+
16
+ if (isNaN(numberValue)) {
17
+ throw new Error('Invalid number input')
18
+ }
19
+
20
+ return new Intl.NumberFormat('en-US', {
21
+ style: 'currency',
22
+ currency: 'USD',
23
+ minimumFractionDigits: fractionDigits,
24
+ maximumFractionDigits: fractionDigits,
25
+ }).format(numberValue)
26
+ }
27
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@1001-digital/layers.base",
3
3
  "type": "module",
4
- "version": "0.0.8",
4
+ "version": "0.0.9",
5
5
  "main": "./nuxt.config.ts",
6
6
  "devDependencies": {
7
7
  "@iconify-json/lucide": "^1.2.81",