通过您喜欢的包管理器将 @movk/core 添加到您的项目中。
pnpm add @movk/core
yarn add @movk/core
npm install @movk/core
@movk/core 是完全模块化的,支持按需导入,所有函数都支持 Tree-Shaking。import { camelCase, chunk, debounce, parseUrl } from '@movk/core'
// 数组操作
const items = [1, 2, 3, 4, 5, 6]
const chunked = chunk(items, 2) // => [[1, 2], [3, 4], [5, 6]]
// 异步控制
const handleSearch = debounce((query: string) => {
console.log('Search:', query)
}, 300)
// URL 处理
const url = parseUrl('https://example.com/path?foo=bar')
console.log(url.pathname) // => '/path'
// 字符串转换
const text = camelCase('hello-world') // => 'helloWorld'
在 Vue 项目中,除了通用工具函数外,还可以使用组合式函数:
<script setup lang="ts">
import { debounce, upperFirst, useAppStorage } from '@movk/core'
import { ref } from 'vue'
// 使用通用工具函数
const text = ref('hello world')
const capitalizedText = upperFirst(text.value) // => 'Hello world'
const handleInput = debounce(() => {
console.log('Debounced input')
}, 300)
// 使用 Vue 组合式函数
const appState = useAppStorage('app-state', {
theme: 'dark',
count: 0
})
function increment() {
appState.value.count++
}
</script>