grand commit
This commit is contained in:
15
lib/utils.ts
15
lib/utils.ts
@@ -1,9 +1,12 @@
|
||||
import {Prisma} from '@prisma/client'
|
||||
import bcrypt from 'bcryptjs'
|
||||
import {type ClassValue, clsx} from 'clsx'
|
||||
import {getLocale} from 'next-intl/server'
|
||||
import slugify from 'slugify'
|
||||
import {twMerge} from 'tailwind-merge'
|
||||
|
||||
import {i18nDefaultLocale} from '@/i18n-config'
|
||||
|
||||
/**
|
||||
* Just output dump using pretty output
|
||||
*
|
||||
@@ -16,6 +19,8 @@ export function dump(variable: any): [string, string] {
|
||||
]
|
||||
}
|
||||
|
||||
export const toPrice = (price: any) => parseFloat(price).toFixed(2)
|
||||
|
||||
/**
|
||||
* Create fallback avatar for showing during login process or in case if empty
|
||||
*
|
||||
@@ -118,6 +123,16 @@ export const toEmptyParams = (data: object | object[]) => {
|
||||
return result
|
||||
}
|
||||
|
||||
export const thisLocales = async (locales: any) => {
|
||||
const loc = await getLocale()
|
||||
return locales.filter((locale: any) => locale.lang === loc)
|
||||
}
|
||||
|
||||
export const thisLocale = async (locales: any) => {
|
||||
const loc = await getLocale()
|
||||
return locales.find((locale: any) => locale.lang === loc)
|
||||
}
|
||||
|
||||
export const dbErrorHandling = (e: unknown, message?: string | null) => {
|
||||
if (e instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
return {error: `${e.code}: ${e.message}`}
|
||||
|
||||
Reference in New Issue
Block a user