Socket
Socket
Sign inDemoInstall

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!)


Version published
Weekly downloads
691K
decreased by-1.33%
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'

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