主题
useChangeCase
change-case
的反应式封装。
¥Reactive wrapper for change-case
.
替代 useCamelCase
、usePascalCase
、useSnakeCase
、useSentenceCase
、useCapitalize
等。
¥Subsitutes useCamelCase
, usePascalCase
, useSnakeCase
, useSentenceCase
, useCapitalize
, etc.
示例
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'
或者传递一个 ref
给它,返回的 computed
将随着源引用的变化而变化。
¥or passing a ref
to it, the returned computed
will change along with the source ref's changes.
可以传入 options
进行定制
¥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
类型声明
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>