This commit is contained in:
Nadar
2026-03-17 13:24:22 +03:00
commit 82e5ac9d81
554 changed files with 29637 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
export async function $copy(value: string | number) {
try {
await navigator.clipboard.writeText(value.toString())
}
catch {}
}

View File

@@ -0,0 +1,26 @@
export default (filename: string, content: string | File | Blob) => {
let blob: File | Blob
if (typeof content === 'string') {
blob = new File([content], filename, {
type: 'text/plain',
})
}
else {
blob = content
}
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.setAttribute(
'download',
filename,
)
document.body.appendChild(link)
link.click()
window.URL.revokeObjectURL(url)
document.body.removeChild(link)
}

View File

@@ -0,0 +1,8 @@
export default function hideEmail(email: string) {
const atIndex = email.indexOf('@')
const username = email.substring(0, atIndex)
const domain = email.substring(atIndex + 1)
const hiddenUsername = `${username.substring(0, 2)}**`
return `${hiddenUsername}@${domain}`
}

View File

@@ -0,0 +1,89 @@
import Decimal from 'decimal.js'
const CURRENCY_SYMBOL: Record<string, string> = {
RUB: '₽',
USD: '$',
EUR: '€',
}
const DEFAULT_FORMAT: string = '{amount} {currency}'
const CURRENCY_FORMAT: Record<string, string> = {
USD: '{currency}{amount}',
RUB: '{amount}{currency}',
EUR: '{currency}{amount}',
}
const DEFAULT_EXPONENT: number = 2
const CURRENCY_EXPONENT: Record<string, number> = {
BTC: 6,
USDT: 2,
}
function getSymbol(currency: string): string {
return CURRENCY_SYMBOL[currency] ?? currency
}
function getFormat(currency: string): string {
return CURRENCY_FORMAT[currency] ?? DEFAULT_FORMAT
}
function getExponent(currency: string): number {
return CURRENCY_EXPONENT[currency] ?? DEFAULT_EXPONENT
}
function format(value: Decimal.Value, currency: string): string {
const exponent = getExponent(currency)
try {
return new Decimal(value).toFixed(exponent)
}
catch {
return new Decimal(0).toFixed(exponent)
}
}
function fullFormat(value: Decimal.Value, currency: string, showCurrency = true, approximately = false): string {
let result = ''
let decimalValue: Decimal.Instance
const exponent = getExponent(currency)
try {
decimalValue = new Decimal(value)
}
catch {
decimalValue = new Decimal(0)
}
value = decimalValue.toFixed(exponent)
if (approximately && !decimalValue.isZero())
result = '~'
if (showCurrency) {
const symbol = getSymbol(currency)
const format = getFormat(currency)
result += format.replace('{amount}', value).replace('{currency}', symbol)
}
else {
result += value
}
return result
}
function convert(amount: Decimal.Value, rate: Decimal.Value, isTurnRate = true) {
if (isTurnRate)
return Decimal.mul(amount, rate)
else
return Decimal.div(amount, rate)
}
export const $money = {
getSymbol,
getFormat,
getExponent,
format,
fullFormat,
convert,
}