uncase
Version:
Wrapper of change-case to create case converter, validator and etc.
58 lines (55 loc) • 1.88 kB
text/typescript
export { CaseValidator, isCamelCase, isCapitalCase, isConstantCase, isDotCase, isKebabCase, isNoCase, isPascalCase, isPascalSnakeCase, isPathCase, isSentenceCase, isSnakeCase, isTrainCase } from './is.mjs';
import { Options } from 'change-case';
export * from 'change-case';
/**
* Case converter
*/
type CaseConverter = (input: string) => CaseConvertResult;
/**
* Case convert result
*/
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`
*/
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';
/**
* CaseType to case converter map
*/
declare const convertersMap: Record<CaseType, (value: string, options?: Options) => string>;
/**
* Get a converter by caseType and convert the given input
*
* @param caseType - case utils name
* @param options - case utils options
* @returns case convert result {@link CaseConvertResult}
*
* @see {@link https://github.com/blakeembrey/change-case}
*
* @example
*
* ```ts
* import { getCaseConverter } from 'uncase'
*
* const result = getCaseConverter('camelCase')('hello-world')
*
* console.log(result)
* // => { input: 'hello-world', changed: true, output: 'helloWorld' }
* ```
*/
declare function getCaseConverter(caseType: CaseType, options?: Options): CaseConverter;
export { convertersMap, getCaseConverter };
export type { CaseConvertResult, CaseConverter, CaseType };