Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
case-anything
Advanced tools
camelCase, kebab-case, PascalCase... a simple integration with nano package size. (SMALL footprint!)
npm i case-anything
10 case changing functions: camelCase, kebab-case, PascalCase and more...
A simple integration with nano package size. (SMALL footprint!)
I created this package because most other packages that do simple case changing are so big...
I wanted to try my hand at the smallest iteration possible. (and it's 12+ times smaller than the next popular case changing package!!)
There's also a Better Touch Tool preset with keyboard shortcuts to convert selected text system wide!
case-anything supports tree-shaking and is side-effect free!
Name | Input example | Output example |
---|---|---|
🐪 camelCase | camelCase('$catDog') | catDog |
🐫 PascalCase UpperCamelCase | pascalCase('$catDog') upperCamelCase | CatDog |
🥙 kebab-case | kebabCase('$catDog') | cat-dog |
🐍 snake_case | snakeCase('$catDog') | cat_dog |
📣 CONSTANT_CASE | constantCase('$catDog') | CAT_DOG |
🚂 Train-Case | trainCase('$catDog') | Cat-Dog |
🕊 Ada_Case | adaCase('$catDog') | Cat_Dog |
👔 COBOL-CASE | cobolCase('$catDog') | CAT-DOG |
📍 Dot.notation | dotNotation('$catDog') | cat.Dog |
📂 Path/case | pathCase('$catDog') | $cat/Dog |
🛰 Space case | spaceCase('$catDog') | $cat Dog |
🏛 Capital Case | capitalCase('$catDog') | $Cat Dog |
🔡 lower case | lowerCase('$catDog') | $cat dog |
🔠 UPPER CASE | upperCase('$catDog') | $CAT DOG |
functions that strip away special characters* | functions that keep special characters* |
---|---|
|
|
*You can control wether or not to keep or remove special characters like so:
camelCase('$catDog') === 'catDog'
// force keeping special characters:
camelCase('$catDog', { keepSpecialCharacters: true }) === '$catDog'
pathCase('$catDog') === '$cat/Dog'
// force removing special characters:
pathCase('$catDog', { keepSpecialCharacters: false }) === 'cat/Dog'
These cases do not change the casing of the words:
dotNotation('$catDog') === 'cat.Dog'
// force lower case:
dotNotation('$catDog').toLowerCase() === 'cat.dog'
As soon as there is a space in the target string, it will regard the input as a sentence and only split each part at the spaces.
Name | Input example | Output example |
---|---|---|
🐪 camelCase | camelCase("I'm O.K.!") | imOk |
🐫 PascalCase UpperCamelCase | pascalCase("I'm O.K.!") upperCamelCase | ImOk |
🥙 kebab-case | kebabCase("I'm O.K.!") | im-ok |
🐍 snake_case | snakeCase("I'm O.K.!") | im_ok |
📣 CONSTANT_CASE | constantCase("I'm O.K.!") | IM_OK |
🚂 Train-Case | trainCase("I'm O.K.!") | Im-Ok |
🕊 Ada_Case | adaCase("I'm O.K.!") | Im_Ok |
👔 COBOL-CASE | cobolCase("I'm O.K.!") | IM-OK |
📍 Dot.notation | dotNotation("I'm O.K.!") | Im.OK |
📂 Path/case | pathCase("I'm O.K.!") | I\'m/O.K.! |
🛰 Space case | spaceCase("I'm O.K.!") | I\'m O.K.! |
🏛 Capital Case | capitalCase("I'm O.K.!") | I\'m O.k.! |
🔡 lower case | lowerCase("I'm O.K.!") | i\'m o.k.! |
🔠 UPPER CASE | upperCase("I'm O.K.!") | I\'M O.K.! |
Also note, that multiple sequential spaces are treated as one space.
I have extended regular alphabet with the most common Latin-1 Supplement special characters.
The coolest thing about this library is that it will "convert" special characters into regular alphabet for the cases used as variable names! 😎
// CONVERTS special characters:
camelCase('Çâfé Ågård') === 'cafeAgard'
pascalCase('Çâfé Ågård') === 'CafeAgard'
kebabCase('Çâfé Ågård') === 'cafe-agard'
snakeCase('Çâfé Ågård') === 'cafe_agard'
constantCase('Çâfé Ågård') === 'CAFE_AGARD'
trainCase('Çâfé Ågård') === 'Cafe-Agard'
adaCase('Çâfé Ågård') === 'Cafe_Agard'
cobolCase('Çâfé Ågård') === 'CAFE-AGARD'
dotNotation('Çâfé Ågård') === 'Cafe.Agard'
// DOES NOT convert special characters:
spaceCase('Çâfé Ågård') === 'Çâfé Ågård'
pathCase('Çâfé Ågård') === 'Çâfé/Ågård'
lowerCase('Çâfé Ågård') === 'çâfé ågård'
upperCase('Çâfé Ågård') === 'ÇÂFÉ ÅGÅRD'
capitalCase('Çâfé Ågård') === 'Çâfé Ågård'
With Better Touch Tool you can set up keyboard shortcuts to convert selected text with JavaScript. This repo provides an easy to install preset that has shortcuts for pascal, kebab and camel case! (thanks to @AndrewKoch) It even supports multi-cursors in VSCode!
Here is an example triggering keyboard shortcuts to convert the selected text to PascalCase; kebab-case; camelCase:
You can download the BTT preset from the source code: case-anything.bttpreset.
We'll compare this package with blakeembrey/change-case, a very famous package on npm.
case-anything | change-case | |
---|---|---|
camelCase | 1.1K (572) | 27.2K (6K) |
pascalCase | 1.1K (561) | 27.4K (6.1K) |
kebabCase | 1.1K (541) | 26.8K (5.9K) |
snakeCase | 1.1K (540) | 26.8K (5.9K) |
constantCase | 1.1K (540) | 27.2K (6K) |
pathCase | 1K (530) | 26.8K (5.9K) |
What keeps my package small, is that literally just uses a regex to separate "words".
// the source code is similar to:
export function splitOnSpecialChars(string: string): any[] {
return string.match(/^[a-z]+|[A-Z][a-z]+|[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g)
}
The actual regex used is a little bit more comprehensive and can be found here.
FAQs
camelCase, kebab-case, PascalCase... a simple integration with nano package size. (SMALL footprint!)
The npm package case-anything receives a total of 669,359 weekly downloads. As such, case-anything popularity was classified as popular.
We found that case-anything 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
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.