useChangeCase
Reactive wrapper for change-case
.
Subsitutes useCamelCase
, usePascalCase
, useSnakeCase
, useSentenceCase
, useCapitalize
, etc.
Demo
helloWorld
Install
bash
npm i change-case@^5
Usage
ts
import { useChangeCase } from '@vueuse/integrations/useChangeCase'
// `changeCase` will be a computed
const changeCase = useChangeCase('hello world', 'camelCase')
changeCase.value // helloWorld
changeCase.value = 'vue use'
changeCase.value // vueUse
// Supported methods
// export {
// camelCase,
// capitalCase,
// constantCase,
// dotCase,
// headerCase,
// noCase,
// paramCase,
// pascalCase,
// pathCase,
// sentenceCase,
// snakeCase,
// } from 'change-case'
or passing a ref
to it, the returned computed
will change along with the source ref's changes.
Can be passed into options
for customization
ts
import { useChangeCase } from '@vueuse/integrations/useChangeCase'
import { ref } from 'vue'
const input = ref('helloWorld')
const changeCase = useChangeCase(input, 'camelCase', {
delimiter: '-',
})
changeCase.value // hello-World
ref.value = 'vue use'
changeCase.value // vue-Use
Type Declarations
typescript
type EndsWithCase<T> = T extends `${infer _}Case` ? T : never
type FilterKeys<T> = {
[K in keyof T as K extends string ? K : never]: EndsWithCase<K>
}
type ChangeCaseKeys = FilterKeys<typeof changeCase>
export type ChangeCaseType = ChangeCaseKeys[keyof ChangeCaseKeys]
export declare function useChangeCase(
input: MaybeRef<string>,
type: MaybeRefOrGetter<ChangeCaseType>,
options?: MaybeRefOrGetter<Options> | undefined,
): WritableComputedRef<string>
export declare function useChangeCase(
input: MaybeRefOrGetter<string>,
type: MaybeRefOrGetter<ChangeCaseType>,
options?: MaybeRefOrGetter<Options> | undefined,
): ComputedRef<string>
Source
Contributors
Anthony Fu
Anthony Fu
David Vallejo
wheat
Doctorwu
丶远方
Toni Engelhardt
sun0day
Curt Grimes
马灿
Changelog
v12.0.0-beta.1
on 11/21/2024v11.0.0-beta.3
on 8/14/2024v11.0.0-beta.1
on 6/12/2024v10.0.0-beta.5
on 4/13/2023cb644
- refactor!: remove isFunction
and isString
utilsv10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
0a72b
- feat(toValue): rename resolveUnref
to toValue