Gathering detailed insights and metrics for case-anything
Gathering detailed insights and metrics for case-anything
Gathering detailed insights and metrics for case-anything
Gathering detailed insights and metrics for case-anything
copy-anything
An optimised way to copy'ing an object. A small and simple integration
merge-anything
Merge objects & other types recursively. A simple & small integration.
filter-anything
A simple (TypeScript) integration of "pick" and "omit" to filter props of an object
@angular-devkit/schematics-cli
Angular Schematics - CLI
camelCase, kebab-case, PascalCase... a simple integration with nano package size. (SMALL footprint!)
npm install case-anything
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
100 Stars
155 Commits
3 Forks
2 Watching
5 Branches
1 Contributors
Updated on 17 Nov 2024
TypeScript (99.85%)
JavaScript (0.15%)
Cumulative downloads
Total Downloads
Last day
-18.1%
114,274
Compared to previous day
Last week
-3.2%
656,477
Compared to previous week
Last month
3.7%
2,909,033
Compared to previous month
Last year
75.9%
38,466,988
Compared to previous year
5
1# npm 2npm i case-anything 3 4# deno 5deno add jsr:@mesqueeb/case-anything 6 7# jsr (use any of npx, yarn dlx, pnpm dlx, or bunx) 8npx jsr add @mesqueeb/case-anything
14 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...
Some features I focused on: |
Case anything is used in... |
case-anything supports tree-shaking and is side-effect free!
1// just import the functions you need like so: 2import { camelCase, kebabCase } from 'case-anything'
case-anything has different behaviour if the string you pass has spaces or not.
Name | Input example | Output example |
---|---|---|
🐪 camelCase | camelCase('$catDog') | catDog |
🐫 PascalCase UpperCamelCase | pascalCase('$catDog') upperCamelCase('$catDog') | 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 |
You can see that most functions by default remove special characters, and some functions keep special characters.
functions that remove special characters* | functions that keep special characters* |
---|---|
|
|
*You can control wether or not to keep or remove special characters like so:
1// default: 2camelCase('$catDog') === 'catDog' 3// force keeping special characters: 4camelCase('$catDog', { keepSpecialCharacters: true }) === '$catDog' 5 6// default: 7pathCase('$catDog') === '$cat/Dog' 8// force removing special characters: 9pathCase('$catDog', { keepSpecialCharacters: false }) === 'cat/Dog'
These cases do not change the casing of the words:
1// default: 2dotNotation('$catDog') === 'cat.Dog' 3// force lower case: 4dotNotation('$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("I'm O.K.!") | 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.
Instead of removing all special characters, you can opt to keep some special characters.
In the example below we see:
$cat-dog
$CatDog
1pascalCase('$cat-dog', { keepSpecialCharacters: false })
2// CatDog → not what we want
3
4pascalCase('$cat-dog', { keepSpecialCharacters: true })
5// $Cat-Dog → not what we want
6
7pascalCase('$cat-dog', { keep: ['$'] })
8// $CatDog → desired output
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! 😎
1// CONVERTS special characters: 2camelCase('Çâfé Ågård') === 'cafeAgard' 3pascalCase('Çâfé Ågård') === 'CafeAgard' 4kebabCase('Çâfé Ågård') === 'cafe-agard' 5snakeCase('Çâfé Ågård') === 'cafe_agard' 6constantCase('Çâfé Ågård') === 'CAFE_AGARD' 7trainCase('Çâfé Ågård') === 'Cafe-Agard' 8adaCase('Çâfé Ågård') === 'Cafe_Agard' 9cobolCase('Çâfé Ågård') === 'CAFE-AGARD' 10dotNotation('Çâfé Ågård') === 'Cafe.Agard' 11 12// DOES NOT convert special characters: 13spaceCase('Çâfé Ågård') === 'Çâfé Ågård' 14pathCase('Çâfé Ågård') === 'Çâfé/Ågård' 15lowerCase('Çâfé Ågård') === 'çâfé ågård' 16upperCase('Çâfé Ågård') === 'ÇÂFÉ ÅGÅRD' 17capitalCase('Çâfé Ågård') === 'Çâfé Ågård'
I have made sure there is great documentation available on hover!
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".
1// the source code is similar to: 2export function splitOnSpecialChars(string: string): any[] { 3 return string.match(/^[a-z]+|[A-Z][a-z]+|[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g) 4}
The actual regex used is a little bit more comprehensive and can be found here.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
4 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More