initial commit of v5

This commit is contained in:
Amruth Pillai
2026-01-19 23:31:54 +01:00
parent 55bdfd0067
commit cad390fa13
1132 changed files with 200807 additions and 165288 deletions
+60
View File
@@ -0,0 +1,60 @@
import _slugify from "@sindresorhus/slugify";
import { adjectives, animals, colors, uniqueNamesGenerator } from "unique-names-generator";
import { v7 as uuidv7 } from "uuid";
/**
* Generates a unique ID using the UUIDv7 algorithm.
* @returns The generated ID.
*/
export function generateId() {
return uuidv7();
}
/** Slugifies a string, with some pre-defined options.
*
* @param value - The value to slugify.
* @returns The slugified value.
*/
export function slugify(value: string) {
return _slugify(value, { decamelize: false });
}
/**
* Generates initials from a name.
* @param name - The name to generate initials from.
* @returns The initials.
*/
export function getInitials(name: string) {
return name
.split(" ")
.map((n) => n[0])
.slice(0, 2)
.join("")
.toUpperCase();
}
/**
* Transforms a string to a valid username (lowercase, no special characters except for dots, hyphens and underscores).
* @param value - The value to transform.
* @returns The transformed username.
*/
export function toUsername(value: string) {
return value
.trim()
.toLowerCase()
.replace(/[^a-z0-9._-]/g, "")
.slice(0, 64);
}
/**
* Generates a random name using the unique-names-generator library.
* @returns The random name.
*/
export function generateRandomName() {
return uniqueNamesGenerator({
dictionaries: [adjectives, colors, animals],
style: "capital",
separator: " ",
length: 3,
});
}