Skip to content

Commit

Permalink
feat: add a simple tool
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdayo committed May 4, 2024
1 parent 53f27b1 commit e9004b5
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ export default defineConfigWithTheme<ThemeConfig>({

nav: [
{ text: '文章', link: '/posts/' },
{ text: '工具', link: '/tools/' },
{ text: '友链', link: '/links/' },
{ text: '关于', link: '/about/' },
],

sidebar: {
'/tools/': [{ text: '命名风格转换', link: '/tools/case-converter/' }],
},

socialLinks: [
{ icon: 'github', link: 'https://github.com/bsdayo' },
{ icon: 'x', link: 'https://twitter.com/konobsdayo' },
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dev": "vitepress dev . --host",
"build": "vitepress build .",
"preview": "vitepress preview .",
"new": "node tools/new-post.js"
"new": "node scripts/new-post.js"
},
"devDependencies": {
"@css-render/vue3-ssr": "^0.15.12",
Expand All @@ -17,6 +17,7 @@
"@types/markdown-it-container": "^2.0.10",
"@types/node": "^20.12.8",
"@types/webfontloader": "^1.6.38",
"js-convert-case": "^4.2.0",
"markdown-it-container": "^4.0.0",
"medium-zoom": "^1.1.0",
"naive-ui": "^2.38.2",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
55 changes: 55 additions & 0 deletions tools/case-converter/CaseConverter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<template>
<h2>输入</h2>
<n-input placeholder="输入" v-model:value="input" />

<h2>转换</h2>
<n-flex vertical>
<div v-for="(value, key) in values" :key="key">
<n-input-group>
<n-input :placeholder="key" :value="value" />
<n-button type="primary" @click="copyToClipboard(value)">复制</n-button>
</n-input-group>
</div>
</n-flex>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue'
import { NFlex, NInput, NInputGroup, NButton } from 'naive-ui'
import jsConvert from 'js-convert-case'
import { copyToClipboard } from '../utils'
const input = ref('')
const values = ref({
camelCase: '',
snake_case: '',
PascalCase: '',
'dot.case': '',
'path/case': '',
'text case': '',
'Sentence case': '',
'Header Case': '',
UPPERCASE: '',
lowercase: '',
'kebab-case': '',
})
watch(
() => input.value,
(val) => {
values.value['camelCase'] = jsConvert.toCamelCase(val)
values.value['snake_case'] = jsConvert.toSnakeCase(val)
values.value['PascalCase'] = jsConvert.toPascalCase(val)
values.value['dot.case'] = jsConvert.toDotCase(val)
values.value['path/case'] = jsConvert.toPathCase(val)
values.value['text case'] = jsConvert.toTextCase(val)
values.value['Sentence case'] = jsConvert.toSentenceCase(val)
values.value['Header Case'] = jsConvert.toHeaderCase(val)
values.value['UPPERCASE'] = jsConvert.toUpperCase(val)
values.value['lowercase'] = jsConvert.toLowerCase(val)
values.value['kebab-case'] = jsConvert.toKebabCase(val)
}
)
</script>

<style lang="scss" scoped></style>
7 changes: 7 additions & 0 deletions tools/case-converter/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 命名风格转换

<CaseConverter />

<script setup lang="ts">
import CaseConverter from './CaseConverter.vue'
</script>
3 changes: 3 additions & 0 deletions tools/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 工具

各种小工具!
12 changes: 12 additions & 0 deletions tools/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function copyToClipboard(text: string) {
if (navigator.clipboard) {
navigator.clipboard.writeText(text)
} else {
const input = document.createElement('input')
input.value = text
document.body.appendChild(input)
input.select()
document.execCommand('copy')
document.body.removeChild(input)
}
}

0 comments on commit e9004b5

Please sign in to comment.