Package Exports
- str-to-machinename
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (str-to-machinename) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
StrToMachineNmae
Convert an string to machine name with selected separator:
Foo bar baz faz→foo_bar_baz_faz
Cases you may need this for:
- 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_nameInstallation
$ npm install str-to-machinenameUsage
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 . , # ! $ % ^ & * ; : { } = ` ~ ( ) " '
API
strToMachinename(input, separator)
input
Type: string
String to convert.
separator
Type: '-' | '_' | '/'
Separator used for conversion.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/berramou/str-to-machinename
License
This npm package is available under the terms of the MIT License.