Function generateSlugName

  • Normalize a string into a slug-safe representation.

    This function:

    • Unescapes HTML entities
    • Converts to lowercase
    • Replaces ampersands, spaces, underscores, and slashes with hyphens
    • Removes specific punctuation characters that are problematic in URLs
    • Collapses multiple consecutive hyphens into one
    • Preserves non-ASCII Unicode characters (accented letters, Cyrillic, etc.)

    Parameters

    • str: string

      Source string to convert

    Returns string

    Slugified name suitable for URLs

    If string is not valid, empty, or would become a UUID

    generateSlugName('Hello World!') // returns 'hello-world!'
    generateSlugName('Café Münchën') // returns 'café-münchën'
    generateSlugName('B&B Hotel') // returns 'b-b-hotel'
    generateSlugName('foo & bar') // returns 'foo-bar'