Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/decamelize
Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow
https://github.com/sindresorhus/decamelize
Last synced: about 1 month ago
JSON representation
Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow
- Host: GitHub
- URL: https://github.com/sindresorhus/decamelize
- Owner: sindresorhus
- License: mit
- Created: 2015-01-24T10:57:45.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2022-10-30T10:53:22.000Z (about 2 years ago)
- Last Synced: 2024-04-14T11:09:11.074Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 39.1 KB
- Stars: 233
- Watchers: 9
- Forks: 25
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-nodejs - decamelize - Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow. (Repository / Text/String)
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