@via-cli/str-tools
v0.0.1
Published
字符串处理工具集合,包含字符串处理、正则匹配、日期处理、数字处理等工具
Readme
@via-cli/str-tools
字符串处理工具库 - 提供常用的字符串格式转换、验证、处理等功能
📦 安装
# 使用 npm
npm install @via-cli/str-tools
# 使用 pnpm
pnpm add @via-cli/str-tools
# 使用 yarn
yarn add @via-cli/str-tools🚀 快速开始
import { StrTools } from '@via-cli/str-tools'
// 命名格式转换
const pascalCase = StrTools.kebabToPascal('my-component-name') // 'MyComponentName'
const camelCase = StrTools.kebabToCamel('my-component-name') // 'myComponentName'
const kebabCase = StrTools.pascalToKebab('MyComponentName') // 'my-component-name'
// 字符串处理
const capitalized = StrTools.capitalize('hello world') // 'Hello world'
const titleCase = StrTools.toTitleCase('hello world') // 'Hello World'
const truncated = StrTools.truncate('long text', 5) // 'long...'
// 字符串验证
const isEmpty = StrTools.isEmpty(' ') // true
const isEmail = StrTools.isEmail('[email protected]') // true
const isNumeric = StrTools.isNumeric('123.45') // true
// 随机字符串生成
const randomStr = StrTools.generateRandomString(8) // 随机8位字母数字
const randomAlpha = StrTools.generateRandomAlpha(6) // 随机6位字母
const randomNum = StrTools.generateRandomNumeric(4) // 随机4位数字
// 字符串搜索和替换
const count = StrTools.countOccurrences('hello world hello', 'hello') // 2
const replaced = StrTools.replaceAll('hello world', 'hello', 'hi') // 'hi world'
// 字符串格式化
const formatted = StrTools.format('Hello {name}!', { name: 'World' }) // 'Hello World!'
const padded = StrTools.padLeft('123', 6, '0') // '000123'📖 API 文档
🤝 贡献
欢迎提交 Pull Request 或 Issue!
📄 许可证
MIT © 朝阳前端团队
