str-to-machinename

1.0.0 • Public • Published

StrToMachineNmae

Convert an string to machine name with selected separator: Foo bar baz fazfoo_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_name

Installation

$ npm install str-to-machinename

Usage

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.

/str-to-machinename/

    Package Sidebar

    Install

    npm i str-to-machinename

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.36 kB

    Total Files

    4

    Last publish

    Collaborators

    • berramou