Skip to content

useChangeCase

Category
Export Size
385 B
Package
@vueuse/integrations
Last Changed
11 months ago

Reactive wrapper for change-case.

Subsitutes useCamelCase, usePascalCase, useSnakeCase, useSentenceCase, useCapitalize, etc.

Demo

"helloWorld"
Available in the @vueuse/integrations add-on.

Install

bash
npm i change-case@^4

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 { ref } from 'vue'
import { useChangeCase } from '@vueuse/integrations/useChangeCase'

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
export type ChangeCaseType = keyof typeof changeCase
export declare function useChangeCase(
  input: MaybeRef<string>,
  type: ChangeCaseType,
  options?: Options | undefined,
): WritableComputedRef<string>
export declare function useChangeCase(
  input: MaybeRefOrGetter<string>,
  type: ChangeCaseType,
  options?: Options | undefined,
): ComputedRef<string>

Source

SourceDemoDocs

Contributors

Anthony Fu
Doctorwu
丶远方
Toni Engelhardt
sun0day
Curt Grimes
马灿

Changelog

v10.0.0-beta.5 on 4/13/2023
cb644 - refactor!: remove isFunction and isString utils
v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
0a72b - feat(toValue): rename resolveUnref to toValue

Released under the MIT License.