refactor: group composables
parent
97983e6d11
commit
9e9f2bde09
|
@ -1,7 +0,0 @@
|
|||
import type { MastoClient } from 'masto'
|
||||
|
||||
export const useMasto = () => useNuxtApp().$masto.api as MastoClient
|
||||
|
||||
export const setMasto = (masto: MastoClient) => {
|
||||
useNuxtApp().$masto?.replace(masto)
|
||||
}
|
|
@ -12,7 +12,6 @@ const scopes = [
|
|||
'Navigation',
|
||||
'Preferences',
|
||||
'Account',
|
||||
|
||||
'Languages',
|
||||
'Switch account',
|
||||
] as const
|
||||
|
|
|
@ -1,5 +1,49 @@
|
|||
import type { MaybeRef } from '@vueuse/shared'
|
||||
import type { MaybeComputedRef, UseTimeAgoOptions } from '@vueuse/core'
|
||||
|
||||
const formatter = Intl.NumberFormat()
|
||||
|
||||
export const humanReadableNumber = (
|
||||
num: number,
|
||||
{ k, m }: { k: string; m: string } = { k: 'K', m: 'M' },
|
||||
useFormatter: Intl.NumberFormat = formatter,
|
||||
) => {
|
||||
if (num < 10000)
|
||||
return useFormatter.format(num)
|
||||
|
||||
if (num < 1000000)
|
||||
return `${Math.floor(num / 1000)}${k}`
|
||||
|
||||
return `${Math.floor(num / 1000000)}${m}`
|
||||
}
|
||||
|
||||
export const formattedNumber = (num: number, useFormatter: Intl.NumberFormat = formatter) => {
|
||||
return useFormatter.format(num)
|
||||
}
|
||||
|
||||
export const useHumanReadableNumber = () => {
|
||||
const i18n = useI18n()
|
||||
const numberFormatter = $computed(() => Intl.NumberFormat(i18n.locale.value))
|
||||
return {
|
||||
formatHumanReadableNumber: (num: MaybeRef<number>) => {
|
||||
return humanReadableNumber(
|
||||
unref(num),
|
||||
{ k: i18n.t('common.kiloSuffix'), m: i18n.t('common.megaSuffix') },
|
||||
numberFormatter,
|
||||
)
|
||||
},
|
||||
formatNumber: (num: MaybeRef<number>) => {
|
||||
return formattedNumber(
|
||||
unref(num),
|
||||
numberFormatter,
|
||||
)
|
||||
},
|
||||
forSR: (num: MaybeRef<number>) => {
|
||||
return unref(num) > 10000
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export const useFormattedDateTime = (
|
||||
value: MaybeComputedRef<string | Date | undefined | null>,
|
||||
options: Intl.DateTimeFormatOptions = { dateStyle: 'long', timeStyle: 'medium' },
|
|
@ -1,7 +1,13 @@
|
|||
import type { Ref } from 'vue'
|
||||
import type { Account, Relationship, Status } from 'masto'
|
||||
import type { Account, MastoClient, Relationship, Status } from 'masto'
|
||||
import { withoutProtocol } from 'ufo'
|
||||
|
||||
export const useMasto = () => useNuxtApp().$masto.api as MastoClient
|
||||
|
||||
export const setMasto = (masto: MastoClient) => {
|
||||
useNuxtApp().$masto?.replace(masto)
|
||||
}
|
||||
|
||||
// @unocss-include
|
||||
export const STATUS_VISIBILITIES = [
|
||||
{
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
import type { MaybeRef } from '@vueuse/shared'
|
||||
|
||||
const formatter = Intl.NumberFormat()
|
||||
|
||||
export const humanReadableNumber = (
|
||||
num: number,
|
||||
{ k, m }: { k: string; m: string } = { k: 'K', m: 'M' },
|
||||
useFormatter: Intl.NumberFormat = formatter,
|
||||
) => {
|
||||
if (num < 10000)
|
||||
return useFormatter.format(num)
|
||||
|
||||
if (num < 1000000)
|
||||
return `${Math.floor(num / 1000)}${k}`
|
||||
|
||||
return `${Math.floor(num / 1000000)}${m}`
|
||||
}
|
||||
|
||||
export const formattedNumber = (num: number, useFormatter: Intl.NumberFormat = formatter) => {
|
||||
return useFormatter.format(num)
|
||||
}
|
||||
|
||||
export const useHumanReadableNumber = () => {
|
||||
const i18n = useI18n()
|
||||
const numberFormatter = $computed(() => Intl.NumberFormat(i18n.locale.value))
|
||||
return {
|
||||
formatHumanReadableNumber: (num: MaybeRef<number>) => {
|
||||
return humanReadableNumber(
|
||||
unref(num),
|
||||
{ k: i18n.t('common.kiloSuffix'), m: i18n.t('common.megaSuffix') },
|
||||
numberFormatter,
|
||||
)
|
||||
},
|
||||
formatNumber: (num: MaybeRef<number>) => {
|
||||
return formattedNumber(
|
||||
unref(num),
|
||||
numberFormatter,
|
||||
)
|
||||
},
|
||||
forSR: (num: MaybeRef<number>) => {
|
||||
return unref(num) > 10000
|
||||
},
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
export const useIsMac = () => computed(() =>
|
||||
useRequestHeaders(['user-agent'])['user-agent']?.includes('Macintosh')
|
||||
?? navigator?.platform?.includes('Mac') ?? false)
|
|
@ -26,3 +26,6 @@ export function emojisArrayToObject(emojis: Emoji[]) {
|
|||
|
||||
export function noop() {}
|
||||
|
||||
export const useIsMac = () => computed(() =>
|
||||
useRequestHeaders(['user-agent'])['user-agent']?.includes('Macintosh')
|
||||
?? navigator?.platform?.includes('Mac') ?? false)
|
||||
|
|
Loading…
Reference in New Issue