Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

case-anything

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

case-anything

camelCase, kebabCase, ... a simple integration with nano package size. (SMALL footprint!)

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
250K
decreased by-63.03%
Maintainers
1
Weekly downloads
 
Created
Source

Case anything 🐫

npm i case-anything

camelCase, kebabCase, ... a simple integration with nano package size. (SMALL footprint!)

Motivation

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.

Meet the family

  • merge-anything 🥡
  • filter-anything ⚔️
  • find-and-replace-anything 🎣
  • compare-anything 🛰
  • copy-anything 🎭
  • flatten-anything 🏏
  • is-what 🙉

Usage

case-anything supports tree-shaking.

import { camelCase, pascalCase, kebabCase, snakeCase, constantCase, pathCase } from 'case-anything'

const testString = 'PonytaVaporeon_Poliwrath-BUTTERFREE'
// or any variant on this

camelCase('ponyta-vaporeon-poliwrath-butterfree')
  === 'ponytaVaporeonPoliwrathButterfree'

pascalCase('ponytaVaporeonPoliwrathButterfree')
  === 'PonytaVaporeonPoliwrathButterfree'

kebabCase('ponytaVaporeonPoliwrathButterfree')
  === 'ponyta-vaporeon-poliwrath-butterfree'

snakeCase('ponytaVaporeonPoliwrathButterfree')
  === 'ponyta_vaporeon_poliwrath_butterfree'

constantCase('ponytaVaporeonPoliwrathButterfree')
  === 'PONYTA_VAPOREON_POLIWRATH_BUTTERFREE'

pathCase('ponytaVaporeonPoliwrathButterfree')
  === 'Ponyta/Vaporeon/Poliwrath/BUTTERFREE'

Package size

We'll compare this package with blakeembrey/change-case, a very famous package on npm.

case-anythingSecond Header
camelCase1.1K (572)27.2K (6K)
pascalCase1.1K (561)27.4K (6.1K)
kebabCase1.1K (541)26.8K (5.9K)
snakeCase1.1K (540)26.8K (5.9K)
constantCase1.1K (540)27.2K (6K)
pathCase1K (530)26.8K (5.9K)

Source code

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...

Keywords

FAQs

Package last updated on 02 Oct 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc