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
camelCase, kebab-case, PascalCase... 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.
case-anything supports tree-shaking.
import { camelCase, pascalCase, kebabCase, snakeCase, constantCase } from 'case-anything'
const testString = 'PonytaVaporeon_poliwrath-BUTTERFREE'
// or any variant on this
camelCase(testString)
=== 'ponytaVaporeonPoliwrathButterfree'
pascalCase(testString)
=== 'PonytaVaporeonPoliwrathButterfree'
kebabCase(testString)
=== 'ponyta-vaporeon-poliwrath-butterfree'
snakeCase(testString)
=== 'ponyta_vaporeon_poliwrath_butterfree'
constantCase(testString)
=== 'PONYTA_VAPOREON_POLIWRATH_BUTTERFREE'
pathCase(testString)
=== 'Ponyta/Vaporeon/Poliwrath/BUTTERFREE'
There is also spaceCase
and pathCase
, which does not convert the casing:
import { spaceCase, pathCase } from 'case-anything'
const testString = 'PonytaVaporeon_poliwrath-BUTTERFREE'
spaceCase(testString)
=== 'Ponyta Vaporeon poliwrath BUTTERFREE'
pathCase(testString)
=== 'Ponyta/Vaporeon/poliwrath/BUTTERFREE'
There is also upper, lower and capital case. These will all convert the casing & also add spaces in between:
import { upperCase, lowerCase, capitalCase } from 'case-anything'
const testString = 'PonytaVaporeon_poliwrath-BUTTERFREE'
upperCase(testString)
=== 'PONYTA VAPOREON POLIWRATH BUTTERFREE'
lowerCase(testString)
=== 'ponyta vaporeon poliwrath butterfree'
capitalCase(testString)
=== 'Ponyta Vaporeon Poliwrath Butterfree'
The split function used in case-anything will remove any special characters (besides numbers) as well. If however, you require a different split function, you can provide one yourself as second parameter.
This is possible for the capitalCase
, pascalCase
or camelCase
.
One use case example is when working with sentences. Eg. you want the capital case of this sentence: listen I'm O.K.!
. Let's see how this can be done:
const testString = "listen I'M O.K.!"
// capitalCase expected behaviour:
capitalCase(testString)
=== 'Listen I M O K'
// capitalCase with own split function:
capitalCase(testString, s => s.split(' '))
=== "Listen I'm O.k.!"
The reason this is only possible for three functions is because the logic behind the other functions is simple enough to implement yourself. Eg.:
// snakeCase with own split function:
testString.split(' ').join('_').toLowerCase()
=== "listen_i'm_o.k.!"
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) |
It is literally just this code:
function getParts (string) {
return string.match(/^[a-z]+|[A-Z][a-z]+|[A-Z]+|[a-z]+/g)
}
export function camelCase (string) {
return getParts(string)
.reduce((result, match, index) => {
return (index === 0)
? match.toLowerCase()
: result + match[0].toUpperCase() + match.slice(1).toLowerCase()
}, '')
}
export function kebabCase (string) {
return getParts(string)
.join('-').toLowerCase()
}
// etc...
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.