Convert string to machine name with selected separator:
Foo bar baz faz
→foo_bar_baz_faz
- To generate clean url alias for your articles from the title for example
const urlAlias = strToMachinename('My awesome article title', '-');
//=> my-awesome-article-title
- or to generate clean username from first name and last name of your user entity.
const username = strToMachinename('First name ' + 'Last Name', '_');
//=> first_name_last_name
$ npm install str-to-machinename
const strToMachinename = require('str-to-machinename');
strToMachinename("C'est une phrase française avec des accenté éàçàçéìù", '_');
//=> 'cest_une_phrase_francaise_avec_des_accente_eacaceiu'
strToMachinename("C'est une phrase française avec des accenté éàçàçéìù", '-');
//=> 'cest-une-phrase-francaise-avec-des-accente-eacaceiu'
strToMachinename("C'est une phrase française avec des accenté éàçàçéìù", '/');
//=> 'cest/une/phrase/francaise/avec/des/accente/eacaceiu'
Note: The following punctuations will be removed . , # ! $ % ^ & * ; : { } = ` ~ ( ) " '
Type: string
String to convert.
Type: '-' | '_' | '/'
Separator used for conversion.
Bug reports and pull requests are welcome on GitHub at https://github.com/berramou/str-to-machinename
This npm package is available under the terms of the MIT License.