A collection of Vue.js case filters
Simply include vue-case
after Vue and it will install itself automatically:
<script src="vue.js"></script>
<script src="vue-case.min.js"></script>
<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-case"></script>
npm install vue-case
When used with a module system, you must explicitly install the filters via Vue.use()
:
import Vue from 'vue'
import VueCase from 'vue-case'
Vue.use(VueCase)
You don't need to do this when using global script tags.
npm install vue-case
When create file plugins/vue-case.js
:
import Vue from 'vue'
import VueCase from 'vue-case'
Vue.use(VueCase)
Then, add the file inside the plugins
key of nuxt.config.js
:
module.exports = {
//...
plugins: [
'~/plugins/vue-case'
],
//...
}
- camelCase
- pascalCase
- capitalCase
- headerCase
- titleCase
- pathCase
- paramCase
- dotCase
- snakeCase
- constantCase
- lowerCase
- lowerCaseFirst
- upperCase
- upperCaseFirst
- swapCase
- sentenceCase
- noCase
- isLowerCase
- isUpperCase
- truncate
-
Example:
{{ msg | camelCase }} // 'I LOVE vue-case' => 'iLoveVueCase'
-
Example:
{{ msg | pascalCase }} // 'I LOVE vue-case' => 'ILoveVueCase'
-
Example:
{{ msg | capitalCase }} // 'I LOVE vue-case' => ' I Love Vue Case'
-
Example:
{{ msg | headerCase }} // 'I LOVE vue-case' => 'I-Love-Vue-Case'
-
Example:
{{ msg | titleCase }} // 'I LOVE vue-case' => 'I LOVE Vue-Case'
-
Example:
{{ msg | pathCase }} // 'I LOVE vue-case' => 'i/love/vue/case'
-
Example:
{{ msg | paramCase }} // 'I LOVE vue-case' => 'i-love-vue-case'
-
Example:
{{ msg | dotCase }} // 'I LOVE vue-case' => 'i.love.vue.case'
-
Example:
{{ msg | snakeCase }} // 'I LOVE vue-case' => 'i_love_vue_case'
-
Example:
{{ msg | constantCase }} // 'I LOVE vue-case' => 'I_LOVE_VUE_CASE'
-
Example:
{{ msg | lowerCase }} // 'I LOVE vue-case' => 'i love vue-case'
-
Example:
{{ msg | lowerCaseFirst }} // 'I LOVE vue-case' => 'i LOVE vue-case'
-
Example:
{{ msg | upperCase }} // 'I LOVE vue-case' => 'I LOVE VUE-CASE'
-
Example:
{{ msg | upperCaseFirst }} // 'I LOVE vue-case' => 'I LOVE vue-case'
-
Example:
{{ msg | swapCase }} // 'I LOVE vue-case' => 'i love VUE-CASE'
-
Example:
{{ msg | sentenceCase }} // 'I LOVE vue-case' => 'I love vue case'
-
Example:
{{ msg | noCase }} // 'I LOVE vue-case' => 'i love vue case'
-
Example:
{{ msg | isLowerCase }} // 'I LOVE vue-case' => 'false'
-
Example:
{{ msg | isUpperCase }} // 'I LOVE vue-case' => 'false'
-
Example:
{{ msg | truncate(10) }} // 'I LOVE vue-case' => 'I LOVE vue...'
Aside from using filters inside templates you can do this programmatically using default filters object:
this.$options.filters.filterName(value)
For example, here's how you can use the truncate
filter:
this.$options.filters.truncate('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', 17) // => Lorem ipsum dolor...
If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.