Skip to content

Latest commit

 

History

History
89 lines (74 loc) · 3.71 KB

README.md

File metadata and controls

89 lines (74 loc) · 3.71 KB

Change Case

NPM version NPM downloads Bundle size

Convert text between camelCase, PascalCase, Capital Case, Header-Case, Title Case, path/case, snake_case, param-case, dot.case, no case, CONSTANT_CASE, lower case, lOWER CASE FIRST, UPPER CASE, Upper case first, sWaP cAsE -> SwAp CaSe, Sentence Case, isLowerCase, isUpperCase, and other

Installation

npm install text-case --save

Usage

import {
  camelCase, // `camelCase`
  pascalCase, // `PascalCase`
  capitalCase, // `Capital Case`
  headerCase, // `Header-Case`
  titleCase, // `Title Case`
  pathCase, // `path/case`
  snakeCase, // `snake_case`
  paramCase, // `param-case`
  dotCase, // `dot.case`
  noCase, // `no case`
  constantCase, // `CONSTANT_CASE`
  lowerCase, // `lower case`
  lowerCaseFirst, // `lOWER CASE FIRST`
  upperCase, // `UPPER CASE`
  upperCaseFirst, // `Upper case first`
  swapCase, // `sWaP cAsE` -> `SwAp CaSe`
  sentenceCase,
  isLowerCase,
  isUpperCase
} from "text-case";

Methods can also be installed independently. All functions also accept options as the second argument.

Options

  • splitRegexp RegExp used to split into word segments (see example).
  • stripRegexp RegExp used to remove extraneous characters (default: /[^A-Z0-9]/gi).
  • delimiter Value used between words (e.g. " ").
  • transform Used to transform each word segment (e.g. lowerCase).

Split Example

If you find the default split hard to use, you can provide a different one. The example below will change the behavior to expo2020 -> expo 2020 and WorldExpo -> world expo:

const options = {
  splitRegexp: /([a-z])([A-Z0-9])/g
};

License

MIT