@cgboiler/shared

v1.1.2

Published

一个现代化的 TypeScript 工具库,提供常用的工具函数集合。

Readme

@cgboiler/core

一个现代化的 TypeScript 工具库,提供常用的工具函数集合。

特性

  • 🚀 使用 TypeScript 编写,提供完整的类型定义
  • 📦 支持 Tree Shaking,只打包使用的代码
  • 🔧 支持 ESM 和 CommonJS 两种模块格式
  • 📚 详细的文档和类型注释
  • ✅ 完整的测试覆盖

安装

npm install @cgboiler/core

# 或者使用 yarn
yarn add @cgboiler/core

# 或者使用 pnpm
pnpm add @cgboiler/core

使用

import { capitalize, unique, deepClone } from '@cgboiler/core';

// 字符串操作
console.log(capitalize('hello')); // 'Hello'

// 数组操作
console.log(unique([1, 1, 2, 2, 3])); // [1, 2, 3]

// 对象操作
const obj = { a: 1, b: { c: 2 } };
const cloned = deepClone(obj);

API 文档

字符串工具

  • capitalize(str: string): string - 将字符串的首字母转换为大写
  • camelToKebab(str: string): string - 将驼峰命名转换为短横线命名
  • kebabToCamel(str: string): string - 将短横线命名转换为驼峰命名

数组工具

  • unique<T>(arr: T[]): T[] - 数组去重
  • groupBy<T>(arr: T[], key: keyof T): Record<string, T[]> - 数组分组
  • flatten<T>(arr: (T | T[])[]): T[] - 数组扁平化

对象工具

  • deepClone<T>(obj: T): T - 深拷贝对象
  • flattenObject(obj: Record<string, any>, prefix?: string): Record<string, any> - 对象扁平化
  • pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> - 选择对象中的指定属性

开发

# 安装依赖
pnpm install

# 开发模式
pnpm dev

# 构建
pnpm build

# 运行测试
pnpm test

# 代码格式化
pnpm format

# 代码检查
pnpm lint

License

MIT