# decamelize

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

Latest version **6.0.1** (published 2025-08-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install decamelize
pnpm add decamelize
yarn add decamelize
bun add decamelize
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 6.0.1 |
| Published | 2025-08-19 |
| First published | 2015-01-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 245 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | decamelize, decamelcase, camelcase, lowercase, case, dash, hyphen, string, text, convert |

## Links

- npm: https://www.npmjs.com/package/decamelize
- Repository: https://github.com/sindresorhus/decamelize
- Homepage: https://github.com/sindresorhus/decamelize#readme
- Issues: https://github.com/sindresorhus/decamelize/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/decamelize

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 6.0.1 (latest) — 2025-08-19
- 6.0.0 — 2021-10-01
- 5.0.1 — 2021-09-29
- 5.0.0 — 2021-01-11
- 4.0.0 — 2020-01-26
- 3.2.0 — 2019-04-05
- 3.1.1 — 2019-03-22
- 3.1.0 — 2019-03-21
- 3.0.0 — 2019-03-06
- 2.0.0 — 2018-01-08
- 1.2.0 — 2016-03-05
- 1.1.2 — 2015-12-23
- 1.1.1 — 2015-10-29
- 1.1.0 — 2015-10-25
- 1.0.0 — 2015-01-24

## README

# decamelize

> Convert a camelized string into a lowercased one with a custom separator\
> Example: `unicornRainbow` → `unicorn_rainbow`

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

## Install

```sh
npm install decamelize
```

*If you need Safari support, [stay on](https://github.com/sindresorhus/decamelize/issues/24) [version 3](https://github.com/sindresorhus/decamelize/issues/36) [until they implement](https://caniuse.com/js-regexp-lookbehind) regex lookbehinds.*

## Usage

```js
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: `'_'`

The character or string used to separate words.

```js
import decamelize from 'decamelize';

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

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

##### preserveConsecutiveUppercase

Type: `boolean`\
Default: `false`

Preserve sequences of uppercase characters.

```js
import decamelize from 'decamelize';

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

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

## Related

- [camelcase](https://github.com/sindresorhus/camelcase) - The inverse of this package
- [decamelize-keys](https://github.com/sindresorhus/decamelize-keys) - Convert object keys from camel case

---
_Source: https://npm.io/package/decamelize · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
