unich-ts-utils
v0.2.1
Published
Utility functions for JavaScript/TypeScript projects
Maintainers
Readme
unich-ts-utils
A comprehensive utility library for TypeScript/JavaScript projects, providing a collection of well-tested, type-safe utility functions organized by category to simplify your development workflow.
🚀 Quick Start
# npm
npm install unich-ts-utils
# yarn
yarn add unich-ts-utils
# pnpm
pnpm add unich-ts-utils// Import only what you need
import { formatCurrency, toPercentString } from 'unich-ts-utils';
// Format currency with options
formatCurrency(1234.567, { symbol: '$' }); // "$1,234.57"
// Format percentage
toPercentString(0.1234, { showPlusSign: true }); // "+12.34%"✨ Features
- 🎯 Type-safe - Full TypeScript support with proper type definitions
- 📦 Tree-shakeable - Import only what you need for optimal bundle size
- 🔄 Dual package - Supports both CommonJS and ESM
- 📝 Well-documented - Comprehensive documentation and examples
- ✅ Tested - Thoroughly tested with Jest
- 🧩 Modular - Organized by category for easy discovery and use
📚 Documentation
Interactive Documentation
The package includes comprehensive interactive documentation:
# Generate and open documentation in browser
npm run docs && npm run docs:open
# Open API documentation directly
npm run docs:api
# Generate markdown documentation
npm run docs:markdownDocumentation Guide
For a complete guide on how to navigate and use the documentation, see the DOCUMENTATION.md file.
🧰 Available Modules
📝 String Utilities
String manipulation functions for common text operations.
import { capitalize, truncate, toKebabCase } from 'unich-ts-utils';
capitalize('hello world'); // => "Hello world"
truncate('This is a long text', 10); // => "This is a..."
toKebabCase('helloWorld'); // => "hello-world"🔢 Array Utilities
Functions for array operations and transformations.
import { unique, groupBy, chunk } from 'unich-ts-utils';
unique([1, 2, 2, 3, 3, 4]); // => [1, 2, 3, 4]
chunk([1, 2, 3, 4, 5], 2); // => [[1, 2], [3, 4], [5]]💱 Numberish Utilities
Advanced utilities for formatting, parsing, and manipulating numbers.
import { formatCurrency, toPercentString, toApr } from 'unich-ts-utils';
formatCurrency(1234.567, { symbol: '$' }); // => "$1,234.57"
formatCurrency(1234567.89, { abbreviated: true }); // => "1.23M"
toPercentString(0.1234); // => "12.34%"
toPercentString(0.1234, { showPlusSign: true }); // => "+12.34%"
toApr(0.0567); // => "5.67%"🧩 Object Utilities
Functions for object manipulation and transformation.
import { deepClone, pick, omit } from 'unich-ts-utils';
const obj = { a: 1, b: { c: 2 } };
const clone = deepClone(obj);
pick({ id: 1, name: 'John', age: 30 }, ['name', 'age']); // => { name: 'John', age: 30 }
omit({ id: 1, name: 'John', age: 30 }, ['age']); // => { id: 1, name: 'John' }📅 Date Utilities
Functions for date formatting and manipulation.
import { formatDate, addDays } from 'unich-ts-utils';
const date = new Date('2024-03-05');
formatDate(date, 'YYYY-MM-DD'); // => "2024-03-05"
addDays(date, 1); // => Date object for March 6, 2024⚛️ React Utilities
Components and hooks for React applications.
import { mergeRef, pickChild } from 'unich-ts-utils';
// Merge multiple refs
const Component = React.forwardRef((props, ref) => {
const localRef = useRef(null);
const mergedRef = mergeRef(ref, localRef);
return <div ref={mergedRef} />;
});
// Pick child components by type
const header = pickChild(children, Header);🛠️ Development
Getting Started
# Clone the repository
git clone https://github.com/twan-unich/utils.git
# Install dependencies
npm install
# Run tests
npm test
# Build
npm run buildDocumentation Development
# Generate documentation
npm run docs
# Open documentation in browser
npm run docs:open
# Generate changelog
npm run changelog📄 License
👤 Author
Twan Unich
