Skip to content

nyxblabs/magicase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

cover npm version npm downloads bundle License

๐Ÿช„ Magicase

๐Ÿ”ฎ Magical utility for string casing

๐Ÿ“ฅ Install:

# nyxi
nyxi magicase

# pnpm
pnpm add magicase

# npm
npm i magicase

# yarn
yarn add magicase

๐Ÿ”ฝ Import:

// CommonJS
const { pascalCase } = require('magicase')

// ESM
import { pascalCase } from 'magicase'

Notice: You may need to transpile the package for older environments.

๐Ÿงฐ Utils

๐Ÿช pascalCase(str)

Splits the string and joins it in PascalCase convention (foo-bar โžก๏ธ FooBar)

Remarks:

If an uppercase letter is followed by other uppercase letters (e.g., FooBAR), it is preserved.

๐Ÿซ camelCase

Splits the string and joins it in camelCase convention (foo-bar โžก๏ธ fooBar)

๐Ÿฅ™ kebabCase(str)

Splits the string and joins it in kebab-case convention (fooBar โžก๏ธ foo-bar)

Remarks:

  • It does not preserve case

๐Ÿ snakeCase

Splits the string and joins it in snake_case convention (foo-bar โžก๏ธ foo_bar)

๐Ÿ”  upperFirst(str)

Converts the first character to uppercase.

๐Ÿ”ก lowerFirst(str)

Converts the first character to lowercase.

๐Ÿงฉ splitByCase(str, splitters?)

  • ๐Ÿงฉ Splits the string by the provided splitters (default: ['-', '_', '/', '.']).
  • ๐Ÿ”„ Splits when there is a case change from lowercase to uppercase or uppercase to lowercase.
  • ๐Ÿ”ข Ignores numbers for case changes.
  • ๐Ÿ“ Case is preserved in the returned value.
  • โŒ This is an irreversible function since the splitters are omitted.

Development

  • ๐Ÿ™ Clone this repository
  • ๐Ÿ“ฅ Install latest LTS version of Node.js
  • ๐Ÿงฉ Enable Corepack using corepack enable
  • ๐Ÿ“ฆ Install dependencies using pnpm install
  • โ–ถ๏ธ Run interactive tests using pnpm dev

๐Ÿ“œ License

MIT - Made with ๐Ÿ’ž