Socket
Socket
Sign inDemoInstall

decamelize

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

decamelize

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


Version published
Maintainers
1
Weekly downloads
32,261,620
increased by1.39%
Install size
7.70 kB

Weekly downloads

Package description

What is decamelize?

The decamelize npm package is used to convert a string from camelCase to a lower case string with a custom separator (defaulting to an underscore). It is useful for transforming variable names or keys in objects from camelCase to a format that is more common in other languages or contexts, such as snake_case for database fields or kebab-case for CSS class names.

What are decamelize's main functionalities?

Decamelize a string

Converts 'myCamelCaseString' to 'my_camel_case_string' using the default separator.

"myCamelCaseString".decamelize()

Decamelize with a custom separator

Converts 'myCamelCaseString' to 'my-camel-case-string' using a custom separator ('-').

"myCamelCaseString".decamelize('-')

Preserve consecutive uppercase characters

Converts 'myURLString' to 'my_url_string', preserving the consecutive uppercase characters.

"myURLString".decamelize('_', { preserveConsecutiveUppercase: true })

Other packages similar to decamelize

Readme

Source

decamelize

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

If you use this on untrusted user input, don't forget to limit the length to something reasonable.

Install

npm install decamelize

Usage

import decamelize from '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.

import decamelize from 'decamelize';

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

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

Type: boolean
Default: false

Preserve sequences of uppercase characters.

import decamelize from 'decamelize';

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

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

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.

Keywords

FAQs

Last updated on 01 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc