Search code examples
javascriptangularjsslug

How to convert "slugified-title" to "Slugified Title"


I'm using angular-slugify to make a slug out of a title input. But is there any way to restore it back to title? Im new to angularjs and there is seem no resource for title restoration.

UPDATE

How can to convert this-is-a-slug-title to This Is A Slug Title in angularjs or javascript? It may be advanced for me as a beginner but your help is much appreciated.


Solution

  • I wrote a simple custom function to convert the slugified string back to normal by splitting the string to array and make each item to have a first char uppercase and joins the array back as string.

    function inverse_slugify(s) {
        return s.toLowerCase()
                .split('-')
                .map(i => i[0].toUpperCase() + i.substr(1))
                .join(' ');
    }
    

    DEMO