Loading repository data…
Loading repository data…
idimetrix / repository
A collection of Vue.js case filters: `camelCase`, `PascalCase`, `Capital Case`, `Header-Case`, `Title Case`, `path/case`, `snake_case`, `param-case`, `dot.case`, `CONSTANT_CASE`, `lower case`, `lOWER CASE FIRST`, `UPPER CASE`, `Upper case first` and other
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
Features • Installation • Quick Start • API Reference • Examples • Documentation • Live Demo
⚠️ Version 2.0 - Complete rewrite for Vue 3 with full TypeScript support and 100% test coverage. For Vue 2, use version 1.x.
import { camelCase, pascalCase, snakeCase } from 'vue-case';
camelCase('hello world') // → 'helloWorld'
pascalCase('hello world') // → 'HelloWorld'
snakeCase('hello world') // → 'hello_world'
useCase()$methodsnpm
npm install vue-case
pnpm
pnpm add vue-case
yarn
yarn add vue-case
<!-- Vue 3 -->
<script src="https://unpkg.com/vue@3"></script>
<!-- vue-case -->
<script src="https://unpkg.com/vue-case@2"></script>
<script>
const { createApp } = Vue;
const app = createApp({
template: '<div>{{ $camelCase("hello world") }}</div>'
});
app.use(VueCase);
app.mount('#app');
</script>
<template>
<div class="converter">
<input v-model="text" placeholder="Enter text..." />
<div class="results">
<p>camelCase: <code>{{ camelCase(text) }}</code></p>
<p>PascalCase: <code>{{ pascalCase(text) }}</code></p>
<p>snake_case: <code>{{ snakeCase(text) }}</code></p>
<p>kebab-case: <code>{{ paramCase(text) }}</code></p>
</div>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { useCase } from 'vue-case';
const { camelCase, pascalCase, snakeCase, paramCase } = useCase();
const text = ref('Hello World');
</script>
<template>
<div>
<p>{{ $camelCase(username) }}</p>
<p>{{ $snakeCase(username) }}</p>
<p>{{ $truncate(description, 50) }}</p>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
data() {
return {
username: 'John Doe',
description: 'A very long description text...'
};
}
});
</script>
import { camelCase, pascalCase, snakeCase, constantCase } from 'vue-case';
// Use anywhere in your code
const apiEndpoint = camelCase('user profile'); // 'userProfile'
const className = pascalCase('my component'); // 'MyComponent'
const dbColumn = snakeCase('user name'); // 'user_name'
const envVar = constantCase('api key'); // 'API_KEY'
Setup in main.ts:
import { createApp } from 'vue';
import VueCase from 'vue-case';
import App from './App.vue';
const app = createApp(App);
// Install plugin globally
app.use(VueCase);
app.mount('#app');
Use in any component:
<template>
<div>
<!-- Available as $camelCase, $pascalCase, $snakeCase, etc. -->
<h1>{{ $titleCase(pageTitle) }}</h1>
<p>{{ $truncate(content, 100) }}</p>
</div>
</template>
useCase()<script setup lang="ts">
import { useCase } from 'vue-case';
import { ref, computed } from 'vue';
// Get all transformation methods
const { camelCase, pascalCase, snakeCase, constantCase, truncate } = useCase();
const inputText = ref('user profile settings');
// Use in computed properties
const apiRoute = computed(() => camelCase(inputText.value));
const component = computed(() => pascalCase(inputText.value));
const database = computed(() => snakeCase(inputText.value));
const environment = computed(() => constantCase(inputText.value));
</script>
<template>
<div>
<input v-model="inputText" />
<ul>
<li>API: {{ apiRoute }}</li>
<li>Component: {{ component }}</li>
<li>Database: {{ database }}</li>
<li>Environment: {{ environment }}</li>
</ul>
</div>
</template>
import type {
CaseMethods,
CaseTransformFn,
CaseCheckFn,
TruncateFn,
VueCaseOptions
} from 'vue-case';
import { camelCase, pascalCase, useCase } from 'vue-case';
// Type-safe function
const transformUserInput: CaseTransformFn = (input: string) => {
return camelCase(input);
};
// Type-safe composable usage
const caseMethods: CaseMethods = useCase();
// Use in classes
class StringTransformer {
private transform: CaseTransformFn;
constructor() {
this.transform = pascalCase;
}
process(input: string): string {
return this.transform(input);
}
}
| Method | Input | Output | Use Case |
|---|---|---|---|
camelCase | 'hello world' | 'helloWorld' | JavaScript variables, object keys |
pascalCase | 'hello world' | 'HelloWorld' | Component names, class names |
snakeCase | 'hello world' | 'hello_world' | Database columns, Python variables |
constantCase | 'hello world' | 'HELLO_WORLD' | Environment variables, constants |
paramCase | 'hello world' | 'hello-world' | URLs, CSS classes, file names |
dotCase | 'hello world' | 'hello.world' | Object paths, configuration keys |
pathCase | 'hello world' | 'hello/world' | File paths, routes |
headerCase | 'hello world' | 'Hello-World' | HTTP headers |
capitalCase | 'hello world' | 'Hello World' | Titles, display names |
titleCase | 'hello world' | 'Hello World' | Book titles, headings |
sentenceCase | 'HELLO WORLD' | 'Hello world' | Sentences, descriptions |
noCase | 'helloWorld' | 'hello world' | Remove formatting |
lowerCase | 'HELLO WORLD' | 'hello world' | Normalize to lowercase |
upperCase | 'hello world' | 'HELLO WORLD' | Normalize to uppercase |
lowerCaseFirst | 'Hello' | 'hello' | Lowercase first letter |
upperCaseFirst | 'hello' | 'Hello' | Capitalize first letter |
swapCase | 'Hello World' | 'hELLO wORLD' | Toggle case |
| Method | Signature | Description | Example |
|---|---|---|---|
truncate | (text: string, length?: number) | Truncate text with "..." | truncate('Hello World', 5) → 'Hello...' |
isLowerCase | (text: string): boolean | Check if lowercase | isLowerCase('hello') → true |
isUpperCase | (text: string): boolean | Check if uppercase | isUpperCase('HELLO') → true |
import { camelCase, snakeCase } from 'vue-case';
// Transform snake_case API responses to camelCase
function transformResponse<T extends Record<string, any>>(data: T): Record<string, any> {
return Object.entries(data).reduce((acc, [key, value]) => {
acc[camelCase(key)] = value;
return acc;
}, {} as Record<string, any>);
}
// Transform camelCase to snake_case for API requests
function transformRequest<T extends Record<string, any>>(data: T): Record<string, any> {
return Object.entries(data).reduce((acc, [key, value]) => {
acc[snakeCase(key)] = value;
return acc;
}, {} as Record<string, any>);
}
// Usage with Axios
import axios from 'axios';
const api = axios.create({
baseURL: 'https://api.example.com',
transformResponse: [(data) => {
const parsed = JSON.parse(data);
return transformResponse(parsed);
}],
transformRequest: [(data) => {
return JSON.stringify(transformRequest(data));
}]
});
// Now your API calls work seamlessly:
const response = await api.get('/user_profile'); // API returns user_name
console.log(response.data.userName); // Access as userName
<template>
<component
:is="getComponent(type)"
:class="getClassName(type)"
>
{{ content }}
</component>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { pascalCase, paramCase } from 'vue-case';
interface Props {
type: string;
content: string;
}
const props = defineProps<Props>();
// Convert 'user card' → 'UserCard' for component name
const getComponent = (type: string) => {
return pascalCase(type);
};
// Convert 'user card' → 'user-card' for CSS class
const getClassName = (type: string) => {
return `component-${paramCase(type)}`;
};
</script>
<template>
<form @submit.prevent="handleSubmit">
<div v-for="field in formFields" :key="field.name">
<label :for="field.id">{{ field.label }}</label>
<input
:id="field.id"
:name="field.name"
v-model="formData[field.name]"
/>
</div>
<button type="submit">Submit</button>
</form>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue';
import { camelCase, paramCase, capitalCase } from 'vue-case';
const fieldNames = ['user name', 'email address', 'phone number'];
const formFields = computed(() =>
fieldNames.map(name => ({
name: camelCase(name), // 'userName' for v-model
id: paramCase(name), // 'user-name' for id/for
label: capitalCase(name) // 'User Name' for display
}))
);
const formData = ref(
fieldNames.reduce((acc, name) => {
acc[camelCase(name)] = '';
return acc;
}, {} as Record<string, string>)
);
const handleSubmit = () => {
console.log(formData.value);
// { userName: '...', emailAddress: '...', phoneNumber: '...' }
};
</script>
<template>
<div class="blog-editor">
<input
v-model="title"
placeholder="Blog post title"
@input="generateSlug"
/>
<p class="slug-preview">
URL: <code>{{ baseUrl }}/{{ slug }}</code>
</p>
<button @click="copySlug">Copy URL</button>
</div>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue';
import { paramCase } from 'vue-case';
const title = ref('');
const baseUrl = 'https://myblog.com/posts';
const slug = computed(() => paramCase(title.value));
const generateSlug = () => {
// Automatically updates via computed property
};
const copySlug = async () => {
await navigator.clipboard.writeText(`${baseUrl}/${slug.value}`);
alert('URL copied!');
};
</script>