uncase
Version:
Wrapper of change-case to create case converter, validator and etc.
149 lines (112 loc) • 2.78 kB
Markdown
//github.com/ntnyq/uncase/workflows/CI/badge.svg)](https://github.com/ntnyq/uncase/actions)
[](https://www.npmjs.com/package/uncase)
[](https://www.npmjs.com/package/uncase)
[](https://codecov.io/github/ntnyq/uncase)
[](https://github.com/ntnyq/uncase/blob/main/LICENSE)
Wrapper of [change-case](https://github.com/blakeembrey/change-case) to create case converter, validator and etc.
```shell
npm install uncase
```
```shell
yarn add uncase
```
```shell
pnpm add uncase
```
```ts
import { getCaseConverter } from 'uncase'
const result = getCaseConverter('camelCase')('hello-world')
console.log(result)
// => { input: 'hello-world', changed: true, output: 'helloWorld' }
```
```ts
import { isCamelCase, isPascalCase } from 'uncase/is'
console.log(isCamelCase('hello-world'))
// => false
console.log(isPascalCase('HelloWorld'))
// => true
```
- **Type**: `(caseType: CaseType, options: Options = {}) => CaseConverter`
Get a converter by caseType and convert the given input.
```ts
/**
* 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'
```
- `isCamelCase`
- `isCapitalCase`
- `isConstantCase`
- `isDotCase`
- `isKebabCase`
- `isNoCase`
- `isPascalCase`
- `isPascalSnakeCase`
- `isPathCase`
- `isSentenceCase`
- `isSnakeCase`
- `isTrainCase`
```ts
export type CaseValidator = (input: string) => boolean
```
Dynamic case convert. Useful to create ESLint case convention rules.
- [change-case](https://github.com/blakeembrey/change-case)
[ ](./LICENSE) License © 2025-PRESENT [ntnyq](https://github.com/ntnyq)
[![CI](https: