Files
archived-linsa/web/lib/utils/index.ts
Aslam 3fe1f8012b feat: homepage font (#145)
* feat: new fonts file

* chore: apply geist

* chore: use relaway font for 'I want to learn'

* chore: config font geist

* feat(util): suffle array

* feat: add geist
2024-09-07 01:48:51 +07:00

40 lines
1001 B
TypeScript

import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export const randomId = () => {
return Math.random().toString(36).substring(7)
}
export const toTitleCase = (str: string): string => {
return str
.replace(/([A-Z])/g, " $1")
.replace(/^./, str => str.toUpperCase())
.trim()
}
function escapeRegExp(string: string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
}
export const searchSafeRegExp = (inputValue: string) => {
const escapedChars = inputValue.split("").map(escapeRegExp)
return new RegExp(escapedChars.join(".*"), "i")
}
export function shuffleArray<T>(array: T[]): T[] {
const shuffled = [...array]
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1))
;[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]
}
return shuffled
}
export * from "./urls"
export * from "./slug"
export * from "./keyboard"