What is change-case-all?
The change-case-all npm package is a utility library that provides a comprehensive set of functions for transforming the case of strings. It includes functionalities for converting strings to camel case, capital case, constant case, dot case, header case, no case, param case, pascal case, path case, sentence case, snake case, and swap case. This makes it a versatile tool for formatting strings in various coding and writing styles.
What are change-case-all's main functionalities?
Camel Case
Converts a string to camel case, which is a common case style in programming where the first letter of each word is capitalized except for the first word.
"use strict"; const { camelCase } = require('change-case-all'); console.log(camelCase('test string')); // 'testString'
Constant Case
Transforms a string to constant case, typically used for defining constants in programming, where all letters are uppercase and spaces are replaced by underscores.
"use strict"; const { constantCase } = require('change-case-all'); console.log(constantCase('test string')); // 'TEST_STRING'
Pascal Case
Converts a string to pascal case, similar to camel case but with the first letter of the first word also capitalized. Commonly used for class names in programming.
"use strict"; const { pascalCase } = require('change-case-all'); console.log(pascalCase('test string')); // 'TestString'
Snake Case
Transforms a string to snake case, where all letters are lowercase and spaces are replaced by underscores. Widely used in programming, especially in variable naming.
"use strict"; const { snakeCase } = require('change-case-all'); console.log(snakeCase('test string')); // 'test_string'
Other packages similar to change-case-all
lodash
Lodash is a comprehensive utility library that, among its wide range of functions, includes methods for changing the case of strings (e.g., _.camelCase, _.snakeCase). While lodash offers similar string case conversion functionalities, it is a much larger library aimed at providing a broad spectrum of utility functions beyond string case conversion.
case
The 'case' package is another npm library focused on string case conversion. It supports various case transformations similar to change-case-all. However, change-case-all provides a more extensive set of case conversion utilities, making it a more versatile choice for projects that require diverse string manipulation capabilities.
change-case-all
Change case functions for all cases in TypeScript and JavaScript.
Combined version of all change-case
methods, so you do not need to install them separately.
ESM and CJS bundles are included, also backwards compatible with change-case@4.1.0.
change-case-all@2.0.0
introduces a Case
helper class, which can be used to access all methods.
Usage
npm install --save change-case-all
Browser / ESM
import { Case } from 'change-case-all';
const camel = Case.camel('test string');
const upper = Case.upper('test string');
import { camelCase, upperCase, ... } from 'change-case-all';
const camel = camelCase('test string');
const upper = upperCase('test string');
Node.js
const { Case } = require('change-case-all');
const camel = Case.camel('foo-bar');
const snake = Case.snake('fooBar');
const { camelCase, snakeCase } = require('change-case-all');
const camel = camelCase('foo-bar');
const snake = snakeCase('fooBar');
Changelog
2.1.0
- Bundle dependencies in module to support Node.js
2.0.0
- Updated dependencies to
change-case@5.2.0
- ParamCase → now KebabCase
- HeaderCase → now TrainCase
- Create mjs and cjs bundles
- Introduce
Case
helper class: e.g. Case.camel('test string'); // testString
TitleCase@4.1.0
failing in tests, thus kept at 3.0.3
Links
Methods
Class based usage
import { Case } from 'change-case-all';
const str = 'test string';
camel = Case.camel(str);
capital = Case.capital(str);
constant = Case.constant(str);
dot = Case.dot(str);
no = Case.no(str);
pascal = Case.pascal(str);
path = Case.path(str);
sentence = Case.sentence(str);
snake = Case.snake(str);
train = Case.train(str);
kebap = Case.kebap(str);
sponge = Case.sponge(str);
swapCase = Case.swap(str);
title = Case.title(str);
uppper = Case.upper(str);
localeUpper = Case.localeUpper(str, 'en');
lower = Case.lower(str);
localeLower = Case.localeLower(str, 'en');
lowerFirst = Case.lowerFirst(str);
upperFirst = Case.upperFirst(str);
isUpper = Case.isUpper(str);
isLower = Case.isLower(str);
Function based usage
import { camelCase, upperCase, ... } from 'change-case-all';
const str = 'test string';
camel = camelCase(str);
capital = capitalCase(str);
constant = constantCase(str);
dot = dotCase(str);
no = noCase(str);
pascal = pascalCase(str);
path = pathCase(str);
sentence = sentenceCase(str);
snake = snakeCase(str);
train = trainCase(str);
kebap = kebapCase(str);
sponge = spongeCase(str);
swapCase = swapCase(str);
title = titleCase(str);
uppper = upperCase(str);
localeUpper = localeUpperCase(str, 'en');
lower = lowerCase(str);
localeLower = localeLowerCase(str, 'en');
lowerFirst = lowerCaseFirst(str);
upperFirst = upperCaseFirst(str);
isUpper = isUpperCase(str);
isLower = isLowerCase(str);