Package Exports
- uncase
- uncase/is
- uncase/package.json
Readme
uncase
Wrapper of change-case to create case converter, validator and etc.
Install
npm install uncaseyarn add uncasepnpm add uncaseUsage
case converter
import { getCaseConverter } from 'uncase'
const result = getCaseConverter('camelCase')('hello-world')
console.log(result)
// => { input: 'hello-world', changed: true, output: 'helloWorld' }case validator
import { isCamelCase, isPascalCase } from 'uncase/is'
console.log(isCamelCase('hello-world'))
// => false
console.log(isPascalCase('HelloWorld'))
// => trueAPI
Case converter
getCaseConverter
- Type: (caseType: CaseType, options: Options = {}) => CaseConverter
Get a converter by caseType and convert the given input.
Interface
/**
 * Case converter
 */
export type CaseConverter = (input: string) => CaseConvertResult
/**
 * Case convert result
 */
export type CaseConvertResult = {
  /**
   * whether output has changed from input
   */
  changed: boolean
  /**
   * input value
   */
  input: string
  /**
   * converted value
   */
  output: string
}
/**
 * All case converter names in raw and `camelCase`
 */
export type CaseType =
  | 'camelCase'
  | 'capitalCase'
  | 'Capital Case'
  | 'CONSTANT_CASE'
  | 'constantCase'
  | 'dot.case'
  | 'dotCase'
  | 'kebab-case'
  | 'kebabCase'
  | 'noCase'
  | 'no case'
  | 'Pascal_Snake_Case'
  | 'pascalCase'
  | 'PascalCase'
  | 'pascalSnakeCase'
  | 'path/case'
  | 'pathCase'
  | 'sentenceCase'
  | 'Sentence case'
  | 'snake_case'
  | 'snakeCase'
  | 'Train-Case'
  | 'trainCase'Case validator
- isCamelCase
- isCapitalCase
- isConstantCase
- isDotCase
- isKebabCase
- isNoCase
- isPascalCase
- isPascalSnakeCase
- isPathCase
- isSentenceCase
- isSnakeCase
- isTrainCase
Type
export type CaseValidator = (input: string) => booleanWhy this?
Dynamic case convert. Useful to create ESLint case convention rules.