datasquirel/package-shared/utils/grab-db-full-name.ts
Benjamin Toby 761348de08 Updates
2025-06-04 08:43:16 +01:00

24 lines
586 B
TypeScript

type Param = {
dbName?: string;
userId?: string | number;
};
/**
* # Grab Database Full Name
*/
export default function grabDbFullName({ dbName, userId }: Param): string {
if (!dbName)
throw new Error(
`Database name not provided to db name parser funciton`
);
const sanitizedName = dbName.replace(/[^a-z0-9\_]/g, "");
const cleanedDbName = sanitizedName.replace(/datasquirel_user_\d+_/, "");
if (!userId) return cleanedDbName;
const dbNamePrefix = `datasquirel_user_${userId}_`;
return dbNamePrefix + cleanedDbName;
}