DEV Community

Dev Nestio
Dev Nestio

Posted on

Build a URL Slug Generator Supporting 8 Case Formats

I built a browser-only slug/identifier generator that converts any text into 8 different case formats.

Try it: https://devnestio.pages.dev/slug-generator/

Supported formats

kebab-case, snake_case, camelCase, PascalCase, dot.case, UPPER_SNAKE, Title Case, path/case

Core logic

const FORMATS = [
  { id: 'kebab', fn: words => words.join('-').toLowerCase() },
  { id: 'snake', fn: words => words.join('_').toLowerCase() },
  { id: 'camel', fn: words => words.map((w,i) =>
      i === 0 ? w.toLowerCase() : w.charAt(0).toUpperCase()+w.slice(1).toLowerCase()).join('')
  },
  { id: 'pascal', fn: words => words.map(w =>
      w.charAt(0).toUpperCase()+w.slice(1).toLowerCase()).join('')
  },
  // ...more formats
];
Enter fullscreen mode Exit fullscreen mode

Accent transliteration

const CHAR_MAP = { 'à':'a', 'ç':'c', 'ß':'ss', 'æ':'ae', '&':'and', '@':'at'... };

function transliterate(text) {
  return text.split('\).map(c => CHAR_MAP[c.toLowerCase()] ?? c).join('');
}
Enter fullscreen mode Exit fullscreen mode

Also uses normalize('NFD') to strip remaining diacritics.

Features

  • Max length with smart word-boundary truncation
  • Batch convert (one line per input)
  • Accent character map reference
  • Live preview with 150ms debounce

DevNestio — browser-only developer tools.

Top comments (0)