Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
decamelize
Advanced tools
Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow
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.
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 })
The snake-case package converts strings to snake_case. It is similar to decamelize but is specifically tailored to produce snake_case without providing options for custom separators.
The kebab-case package is designed to convert strings to kebab-case. While it serves a similar purpose in changing the case of strings, it is focused on kebab-case rather than providing a customizable separator.
The change-case package is a more comprehensive string transformation library that includes a variety of case conversion functions, including decamelize. It offers a broader set of functionalities compared to the single-purpose decamelize package.
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.
npm install decamelize
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'
Type: string
Type: object
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'
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.
FAQs
Convert a camelized string into a lowercased one with a custom separator: unicornRainbow → unicorn_rainbow
We found that decamelize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.