Skip to content
On this page

useChangeCase

Category
Package
@vueuse/integrations
Last Changed
4 months ago

wrapper for change-case

Demo

"helloWorld"
available in add-on @vueuse/integrations

Install

npm i change-case
npm i change-case

Usage

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'
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

import { ref } from 'vue-demi'
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
import { ref } from 'vue-demi'
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

export declare type ChangeCaseType = keyof typeof changeCase
export declare function useChangeCase(
  input: MaybeRef<string>,
  type: ChangeCaseType,
  options?: Options | undefined
): WritableComputedRef<string>
export declare type ChangeCaseType = keyof typeof changeCase
export declare function useChangeCase(
  input: MaybeRef<string>,
  type: ChangeCaseType,
  options?: Options | undefined
): WritableComputedRef<string>

Source

SourceDemoDocs

Contributors

Anthony Fu
马灿

Changelog

v8.0.0-beta.3 on 3/8/2022
a98e5 - feat(integrations): add useChangeCase (#1371)
useChangeCase has loaded