Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

scule

unjs3.7mMIT1.3.0TypeScript support: included

String case utils

readme

🧵 Scule

npm version npm downloads bundle Codecov

Install

Install using npm or yarn:

npm i scule

Import:

// CommonJS
const { pascalCase } = require("scule");

// ESM
import { pascalCase } from "scule";

Notice: You may need to transpile package for legacy environments.

Utils

pascalCase(str, opts?: { normalize })

Splits string and joins by PascalCase convention:

pascalCase("foo-bar_baz");
// FooBarBaz

Notice: If an uppercase letter is followed by other uppercase letters (like FooBAR), they are preserved. You can use { normalize: true } for strictly following pascalCase convention.

camelCase(str, opts?: { normalize })

Splits string and joins by camelCase convention:

camelCase("foo-bar_baz");
// fooBarBaz

kebabCase(str)

Splits string and joins by kebab-case convention:

kebabCase("fooBar_Baz");
// foo-bar-baz

Notice: It does not preserve case.

snakeCase

Splits string and joins by snake_case convention:

snakeCase("foo-barBaz");
// foo_bar_baz

flatCase

Splits string and joins by flatcase convention:

flatCase("foo-barBaz");
// foobarbaz

trainCase(str, opts?: { normalize })

Split string and joins by Train-Case (a.k.a. HTTP-Header-Case) convention:

trainCase("FooBARb");
// Foo-Ba-Rb

Notice: If an uppercase letter is followed by other uppercase letters (like WWWAuthenticate), they are preserved (=> WWW-Authenticate). You can use { normalize: true } for strictly only having the first letter uppercased.

titleCase(str, opts?: { normalize })

With Title Case all words are capitalized, except for minor words. A compact regex of common minor words (such as a, for, to) is used to automatically keep them lower case.

titleCase("this-IS-aTitle");
// This is a Title

upperFirst(str)

Converts first character to upper case:

upperFirst("hello world!");
// Hello world!

lowerFirst(str)

Converts first character to lower case:

lowerFirst("Hello world!");
// hello world!

splitByCase(str, splitters?)

  • Splits string by the splitters provided (default: ['-', '_', '/', '.'])
  • Splits when case changes from lower to upper or upper to lower
  • Ignores numbers for case changes
  • Case is preserved in returned value
  • Is an irreversible function since 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

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

v1.3.0

compare changes

🚀 Enhancements

  • trainCase util (#74)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v1.2.0

compare changes

🚀 Enhancements

  • Add flatCase and trainCase (#68)

🩹 Fixes

  • isUppercase: Assume characters lowercase by default (#71)

🏡 Chore

✅ Tests

  • Add type tests for #71 (#71)

❤️ Contributors

v1.1.1

compare changes

🩹 Fixes

  • pascalCase, camelCase: Move normalize behind a flag (#63)

❤️ Contributors

  • Pooya Parsa (@pi0)

v1.1.0

compare changes

🚀 Enhancements

  • Export type helpers (#58)

🩹 Fixes

  • Move types filed to the top (4fd4a79)
  • pascalCase, camelCase: Lower rest of each segment (#62)

💅 Refactors

  • Simplify string variable name (abb2d2b)

📖 Documentation

  • Add missing quotation mark (#41)
  • Improve readme with code examples (21f19ba)

🏡 Chore

  • Update repo (#42)
  • Update lockfile and typescript (94bfc58)
  • Update release script (a52338f)
  • Update dependencies (3a5f1a6)
  • Add changelogen dev dependency (81365b8)

✅ Tests

  • Convert type tests to vitest syntax (#61)

🎨 Styles

  • Lint and format with prettier v3 (ba39ce6)

🤖 CI

❤️ Contributors

1.0.0 (2022-11-14)

Features

0.3.2 (2022-07-27)

Bug Fixes

  • ignore case changes for numbers (9927800)

0.3.1 (2022-07-27)

Bug Fixes

  • use stable toLowerCase (a0a6c06), closes #8

0.3.0 (2021-08-17)

⚠ BREAKING CHANGES

  • handle lower edges (resolves #4)

Bug Fixes

0.2.1 (2021-04-28)

0.2.0 (2021-04-22)

⚠ BREAKING CHANGES

  • add exports field

Features

0.1.1 (2021-02-16)

Features

  • add dot to default splitters (db5120f)

0.0.1 (2021-02-16)