What is pascal-case?
The pascal-case npm package is used to convert strings into PascalCase format, where the first letter of each word is capitalized and all words are concatenated without spaces. This is often used in programming to name classes, types, and other identifiers that require this specific casing convention.
What are pascal-case's main functionalities?
Convert string to PascalCase
This feature takes a string and converts it to PascalCase. The given code sample demonstrates how you might manually convert a string to PascalCase by splitting it into words, capitalizing the first letter of each word, and then joining them together without spaces.
"hello world".split(' ').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join('')
Other packages similar to pascal-case
camelcase
The camelcase package converts strings to camelCase. It is similar to pascal-case but the first letter of the result is in lowercase, which is the standard for naming variables and functions in many programming languages.
change-case
The change-case package is a more comprehensive string transformation library that includes pascalCase among many other case transformations. It provides a suite of utilities for various case conversions, making it more versatile than pascal-case if multiple case conversion functions are needed.
uppercamelcase
The uppercamelcase package is another alternative that converts strings to UpperCamelCase (or PascalCase). It is very similar to pascal-case but might have different handling of edge cases or additional options.
Pascal Case
Transform into a string of capitalized words without separators.
Installation
npm install pascal-case --save
Usage
import { pascalCase } from "pascal-case";
pascalCase("string");
pascalCase("dot.case");
pascalCase("PascalCase");
pascalCase("version 1.2.10");
The function also accepts options
.
Merge Numbers
If you'd like to remove the behavior prefixing _
before numbers, you can use pascalCaseTransformMerge
:
import { pascalCaseTransformMerge } from "pascal-case";
pascalCase("version 12", { transform: pascalCaseTransformMerge });
License
MIT