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.
change-case
Advanced tools
Transform a string between `camelCase`, `PascalCase`, `Capital Case`, `snake_case`, `kebab-case`, `CONSTANT_CASE` and others
The change-case package is a utility library that provides various functions to transform strings between different cases, such as camel case, snake case, kebab case, and more. It is useful for formatting strings in different coding conventions or textual formats.
camelCase
Converts a string to camel case.
const { camelCase } = require('change-case');
console.log(camelCase('test string')); // 'testString'
snakeCase
Converts a string to snake case.
const { snakeCase } = require('change-case');
console.log(snakeCase('test string')); // 'test_string'
kebabCase
Converts a string to kebab case.
const { kebabCase } = require('change-case');
console.log(kebabCase('test string')); // 'test-string'
titleCase
Converts a string to title case.
const { titleCase } = require('change-case');
console.log(titleCase('test string')); // 'Test String'
constantCase
Converts a string to constant case.
const { constantCase } = require('change-case');
console.log(constantCase('test string')); // 'TEST_STRING'
Lodash is a comprehensive utility library that includes methods for string case transformation, such as _.camelCase, _.snakeCase, and _.kebabCase. It offers a wider range of utilities beyond string case conversion, making it more versatile but also larger in size compared to change-case.
The 'case' package is another string case conversion library that supports various case transformations. It is similar to change-case but has a different API and may have different case conversion implementations.
String-case is a library that provides case conversion functions similar to change-case. It may offer a different set of features or API design, which could be preferred by some developers over change-case.
Transform a string between
camelCase
,PascalCase
,Capital Case
,snake_case
,kebab-case
,CONSTANT_CASE
and others.
npm install change-case --save
import * as changeCase from "change-case";
changeCase.camelCase("TEST_VALUE"); //=> "testValue"
Included case functions:
Method | Result |
---|---|
camelCase | twoWords |
capitalCase | Two Words |
constantCase | TWO_WORDS |
dotCase | two.words |
kebabCase | two-words |
noCase | two words |
pascalCase | TwoWords |
pascalSnakeCase | Two_Words |
pathCase | two/words |
sentenceCase | Two words |
snakeCase | two_words |
trainCase | Two-Words |
All methods accept an options
object as the second argument:
delimiter?: string
The character to use between words. Default depends on method, e.g. _
in snake case.locale?: string[] | string | false
Lower/upper according to specified locale, defaults to host environment. Set to false
to disable.split?: (value: string) => string[]
A function to define how the input is split into words. Defaults to split
.prefixCharacters?: string
Retain at the beginning of the string. Defaults to ""
. Example: use "_"
to keep the underscores in __typename
.suffixCharacters?: string
Retain at the end of the string. Defaults to ""
. Example: use "_"
to keep the underscore in type_
.By default, pascalCase
and snakeCase
separate ambiguous characters with _
. For example, V1.2
would become V1_2
instead of V12
. If you prefer them merged you can set mergeAmbiguousCharacters
to true
.
Change case exports a split
utility which can be used to build other case functions. It accepts a string and returns each "word" as an array. For example:
split("fooBar")
.map((x) => x.toLowerCase())
.join("_"); //=> "foo_bar"
import * as changeKeys from "change-case/keys";
changeKeys.camelCase({ TEST_KEY: true }); //=> { testKey: true }
Change case keys wraps around the core methods to transform object keys to any case.
1
.This package is a pure ESM package and ships with TypeScript definitions. It cannot be require
'd or used with CommonJS module resolution in TypeScript.
MIT
FAQs
Transform a string between `camelCase`, `PascalCase`, `Capital Case`, `snake_case`, `kebab-case`, `CONSTANT_CASE` and others
The npm package change-case receives a total of 4,908,362 weekly downloads. As such, change-case popularity was classified as popular.
We found that change-case demonstrated a healthy version release cadence and project activity because the last version was released less than 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.