@via-cli/path-utils
v0.0.2
Published
Path and URL utilities for CLI tools including path formatting and URL joining
Downloads
9
Maintainers
Readme
@via-cli/path-utils
路径和URL工具函数库,为CLI工具提供路径格式化和URL拼接等实用功能。
特性
- 🚀 现代化 ESM - 使用 ES 模块和 TypeScript
- 🛠️ 类型安全 - 完整的 TypeScript 类型定义
- 🧪 全面测试 - 使用 Vitest 进行单元测试
- 📦 轻量级 - 专注于路径和URL处理
- 🔧 CLI 友好 - 专为命令行工具设计
安装
npm install @via-cli/path-utils
# 或
pnpm add @via-cli/path-utils
# 或
yarn add @via-cli/path-utils使用
import { formatPath, urlJoin } from '@via-cli/path-utils';API 文档
路径工具
formatPath(filePath: string): string
格式化路径,将反斜杠转换为正斜杠。
console.log(formatPath('C:\\Users\\test')); // 'C:/Users/test'
console.log(formatPath('/home/user')); // '/home/user'URL工具
urlJoin(...paths: string[]): string
拼接URL路径,自动处理斜杠。
console.log(urlJoin('https://api.example.com', 'v1', 'users'));
// 'https://api.example.com/v1/users'
console.log(urlJoin('https://api.example.com/', '/v1/', '/users/'));
// 'https://api.example.com/v1/users/'开发
# 安装依赖
pnpm install
# 构建
pnpm build
# 开发模式(监听变化)
pnpm dev
# 运行测试
pnpm test
# 监听测试
pnpm test:watch
# 生成测试覆盖率报告
pnpm test:coverage
# 清理构建文件
pnpm clean技术栈
- TypeScript - 类型安全的开发体验
- ESM - 现代化的模块系统
- tsup - 快速的 TypeScript 构建工具
- Vitest - 快速的单元测试框架
- url-join - URL 拼接
许可证
MIT
