All Projects → sindresorhus → Decamelize

sindresorhus / Decamelize

Licence: mit
Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow

Programming Languages

javascript
184084 projects - #8 most used programming language

decamelize

Convert a camelized string into a lowercased one with a custom separator
Example: unicornRainbowunicorn_rainbow

Install

$ npm install decamelize

Usage

const decamelize = require('decamelize');

decamelize('unicornRainbow');
//=> 'unicorn_rainbow'

decamelize('unicornRainbow', {separator: '-'});
//=> 'unicorn-rainbow'

decamelize('testGUILabel', {preserveConsecutiveUppercase: true});
//=> 'test_GUI_label'

decamelize('testGUILabel', {preserveConsecutiveUppercase: false});
//=> 'test_gui_label'

API

decamelize(input, options?)

input

Type: string

options

Type: object

separator

Type: string
Default: '_'

Character or string inserted to separate words in string.

cosnt decamelize = require('decamelize');

decamelize('unicornRainbow');
//=> 'unicorn_rainbow'

decamelize('unicornRainbow', {separator: '-'});
//=> 'unicorn-rainbow'
preserveConsecutiveUppercase

Type: boolean
Default: false

Preserve sequences of uppercase characters.

const decamelize = require('decamelize');

decamelize('testGUILabel');
//=> 'test_gui_label'

decamelize('testGUILabel', {preserveConsecutiveUppercase: true});
//=> 'test_GUI_label'

Related

See camelcase for the inverse.


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].