The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
move to utils
Kiran K2a193c7fcde2
diff --git a/apps/web/lib/api/invoices/utils.ts b/apps/web/lib/api/invoices/utils.tsindex 65cd7b30dc..a139ea23ab 100644--- a/apps/web/lib/api/invoices/utils.ts+++ b/apps/web/lib/api/invoices/utils.ts@@ -1,5 +1,5 @@import { prisma } from "@dub/prisma";-import { randomBytes } from "crypto";+import { generateRandomString } from "@dub/utils";export async function generateInvoicePrefix() {const invoicePrefix = generateRandomString(8);@@ -16,18 +16,3 @@ export async function generateInvoicePrefix() {return invoicePrefix;}--// TODO:-// Move this to shared utils-function generateRandomString(length: number): string {- const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";- const randomBytesArray = randomBytes(length);- let result = "";-- for (let i = 0; i < length; i++) {- const randomIndex = randomBytesArray[i] % charset.length;- result += charset[randomIndex];- }-- return result;-}diff --git a/packages/utils/src/functions/random-value.ts b/packages/utils/src/functions/random-value.tsindex 7ace22e191..3b3cf6ee6f 100644--- a/packages/utils/src/functions/random-value.ts+++ b/packages/utils/src/functions/random-value.ts@@ -1,3 +1,18 @@+import { randomBytes } from "crypto";+export const randomValue = (values: any[]) => {return values[Math.floor(Math.random() * values.length)];};++export function generateRandomString(length: number): string {+ const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";+ const randomBytesArray = randomBytes(length);+ let result = "";++ for (let i = 0; i < length; i++) {+ const randomIndex = randomBytesArray[i] % charset.length;+ result += charset[randomIndex];+ }++ return result;+}