Skip to content

Instantly share code, notes, and snippets.

View ChristopherLMiller's full-sized avatar

Christopher Miller ChristopherLMiller

View GitHub Profile
@ChristopherLMiller
ChristopherLMiller / insert.ts
Created November 16, 2022 18:06
How to make slug unique while inserting... not generic
// we use this variable to keep track of the db insertion being successful or not
let result = null;
let counter = 0;
do {
try {
// Handle singular item
const title = newItems.title;
const slug = slugify(`${title}${counter ? '-' + counter : ''}`, {
lower: true,
strict: true,