@plutocms/utils 0.0.1-alpha.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.
- package/.editorconfig +12 -0
- package/.prettierrc +9 -0
- package/.vscode/extensions.json +14 -0
- package/.vscode/settings.json +47 -0
- package/.vscode/vue.code-snippets +16 -0
- package/app/components/NavbarAdminActionButton.vue +70 -0
- package/app/composables/navbar-admin-actions.ts +12 -0
- package/app/composables/sidebar-admin-actions.ts +18 -0
- package/bun.lock +2586 -0
- package/eslint.config.mjs +84 -0
- package/nuxt.config.ts +17 -0
- package/package.json +701 -0
- package/shared/types/navbar.ts +9 -0
- package/shared/utils/currency.ts +43 -0
- package/shared/utils/string.ts +21 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
currency?: 'USD' | 'BRL' | 'CAD'
|
|
3
|
+
spaceBetween?: boolean
|
|
4
|
+
prefix?: keyof Intl.NumberFormatOptionsCurrencyDisplayRegistry
|
|
5
|
+
trailingZero?: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Formats a number as a currency string.
|
|
10
|
+
* @param value - The numeric value to format.
|
|
11
|
+
* @param options - Formatting options including currency type, spacing, prefix style, and trailing zero preference.
|
|
12
|
+
* @returns The formatted currency string.
|
|
13
|
+
*/
|
|
14
|
+
export function formatCurrency(value: number, options?: Options): string {
|
|
15
|
+
const {
|
|
16
|
+
currency = 'USD',
|
|
17
|
+
spaceBetween = true,
|
|
18
|
+
prefix = 'symbol',
|
|
19
|
+
trailingZero = true,
|
|
20
|
+
} = options || {}
|
|
21
|
+
|
|
22
|
+
const currencyLocaleMap: Record<string, string> = {
|
|
23
|
+
USD: 'en-US',
|
|
24
|
+
BRL: 'pt-BR',
|
|
25
|
+
CAD: 'en-CA',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const formatter = new Intl.NumberFormat(currencyLocaleMap[currency], {
|
|
29
|
+
style: 'currency',
|
|
30
|
+
currency,
|
|
31
|
+
currencyDisplay: prefix,
|
|
32
|
+
minimumFractionDigits: trailingZero ? 2 : 0,
|
|
33
|
+
maximumFractionDigits: 2,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
let formattedValue = formatter.format(value)
|
|
37
|
+
|
|
38
|
+
if (spaceBetween) {
|
|
39
|
+
formattedValue = formattedValue.replace(/(\D)(\d)/, '$1 $2')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return formattedValue
|
|
43
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { kebabCase } from 'scule'
|
|
2
|
+
|
|
3
|
+
export function fileNameToKebabCase(name: string) {
|
|
4
|
+
const fileName = name.replace(/(.*)(\.\w+$)/, `$1`)
|
|
5
|
+
const fileExtension = name.replace(/(.*)(\.\w+$)/, `$2`)
|
|
6
|
+
|
|
7
|
+
return `${encodeURIComponent(kebabCase(fileName))}${fileExtension}`
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function slugify(text: string) {
|
|
11
|
+
return kebabCase(text.normalize('NFD').replace(/[\u0300-\u036F]/g, ''))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function domainFromUrl(url: string | null | undefined) {
|
|
15
|
+
if (!url) {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const match = url.match(/^(?:https?:\/\/)?(?:www\.)?([^/]+)/i)
|
|
20
|
+
return match ? match[1] : ''
|
|
21
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"references": [
|
|
3
|
+
{
|
|
4
|
+
"path": "./.nuxt/tsconfig.app.json"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"path": "./.nuxt/tsconfig.server.json"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"path": "./.nuxt/tsconfig.shared.json"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"path": "./.nuxt/tsconfig.node.json"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
// https://nuxt.com/docs/guide/concepts/typescript
|
|
17
|
+
"files": []
|
|
18
|
+
}
|