mirror of
https://github.com/Nezumi-2711/Sink.git
synced 2026-09-22 13:48:35 +00:00
feat: init
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { defu } from 'defu'
|
||||
import { toast } from 'vue-sonner'
|
||||
|
||||
export function useAPI(api: string, options?: object): Promise<unknown> {
|
||||
return $fetch(api, defu(options || {}, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${localStorage.getItem('SinkSiteToken') || ''}`,
|
||||
},
|
||||
})).catch((error) => {
|
||||
if (error?.data?.statusMessage) {
|
||||
toast(error?.data?.statusMessage)
|
||||
}
|
||||
return Promise.reject(error)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export function colorGradation(count: number) {
|
||||
return Array.from(Array(count).keys()).map(i => `hsl(var(--vis-secondary-color) / ${1 - (1 / count) * i})`)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
const EMOJI_FLAG_UNICODE_STARTING_POSITION = 127397
|
||||
|
||||
export function getFlag(countryCode: string) {
|
||||
const regex = /^[A-Z]{2}$/.test(countryCode)
|
||||
if (!countryCode || !regex)
|
||||
return void 0
|
||||
return String.fromCodePoint(...countryCode.split('').map(char => EMOJI_FLAG_UNICODE_STARTING_POSITION + char.charCodeAt(0)))
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { type ClassValue, clsx } from 'clsx'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export function formatNumber(number: number) {
|
||||
if (!number || typeof Intl === 'undefined')
|
||||
return number
|
||||
|
||||
return new Intl.NumberFormat('en').format(number)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { type DateValue, fromAbsolute, toCalendarDate } from '@internationalized/date'
|
||||
|
||||
export function getTimeZone() {
|
||||
if (typeof Intl === 'undefined')
|
||||
return 'Etc/UTC'
|
||||
|
||||
return Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||
}
|
||||
|
||||
export function getLocale() {
|
||||
if (typeof Intl === 'undefined')
|
||||
return navigator.language
|
||||
|
||||
return Intl.DateTimeFormat().resolvedOptions().locale
|
||||
}
|
||||
|
||||
export function shortDate(unix = 0) {
|
||||
const shortDate = new Intl.DateTimeFormat(undefined, {
|
||||
dateStyle: 'short',
|
||||
})
|
||||
return shortDate.format(unix * 1000)
|
||||
}
|
||||
|
||||
export function longDate(unix = 0) {
|
||||
return new Date(unix * 1000).toLocaleString()
|
||||
}
|
||||
|
||||
export function date2unix(dateValue: DateValue | Date, type: string) {
|
||||
const date = dateValue instanceof Date ? dateValue : dateValue.toDate(getTimeZone())
|
||||
if (type === 'start')
|
||||
return Math.floor(date.setHours(0, 0, 0) / 1000)
|
||||
|
||||
if (type === 'end')
|
||||
return Math.floor(date.setHours(23, 59, 59) / 1000)
|
||||
|
||||
return Math.floor(date.getTime() / 1000)
|
||||
}
|
||||
|
||||
export function unix2date(unix: number) {
|
||||
return toCalendarDate(fromAbsolute(unix * 1000, getTimeZone()))
|
||||
}
|
||||
Reference in New Issue
Block a user