@frodoy/reusables
v1.0.0
Published
A TypeScript library that holds a couple of reusable utility functions.
Maintainers
Readme
@frodoy/reusables
A lightweight, type-safe utility library for JavaScript and TypeScript, providing clean, reusable helpers for strings, numbers, dates, and data manipulation.
✨ Features
- 🔒 Fully type-safe (TypeScript-first)
- ⚡ Lightweight and dependency-free
- 🧩 Modular utility functions
- 📚 Auto-documented with JSDoc + TypeDoc
- 🧠 Designed for real-world production use
📦 Installation
pnpm add @frodoy/reusables🚀 Usage
import {
slugify,
chunkArray,
addDays,
clamp,
percentageFrom,
} from "@frodoy/reusables";
slugify("Hello World!");
chunkArray([1, 2, 3, 4], 2);
addDays(new Date(), 5);
clamp(10, 0, 5);
percentageFrom(20, 200);📚 API Reference
📝 String Utilities
| Function | Description |
| ----------------- | ------------------------------------ |
| slugify | Converts string to URL-friendly slug |
| truncate | Shortens string with suffix |
| toCamelCase | Converts string to camelCase |
| capitalizeFirst | Capitalizes first letter |
| maskString | Masks sensitive parts of string |
| extractEmails | Extracts emails from text |
🔢 Number Utilities
| Function | Description |
| ---------------- | --------------------------------- |
| clamp | Restricts value within range |
| randomInt | Generates random integer |
| parseNumber | Safely parses numbers |
| percentageFrom | Calculates percentage from total |
| percentageOf | Calculates value from percentage |
| formatBytes | Converts bytes to readable format |
| roundTo | Rounds number precisely |
📅 Date Utilities
| Function | Description |
| ------------------ | ---------------------------------- |
| getStartOfMonth | Returns first day of month |
| isLeapYear | Determines leap year |
| isWeekend | Checks if weekend |
| addDays | Adds/subtracts days |
| timeAgo | Returns relative time string |
| daysBetweenDates | Calculates full days between dates |
🛠 Array/Object Utilities
| Function | Description |
| ------------ | ------------------------ |
| chunkArray | Splits array into chunks |
| groupBy | Groups objects by key |
📖 Documentation (Auto-generated)
This project uses JSDoc + TypeDoc.
Generate docs:
pnpm add -D typedoc
npx typedoc --out docs srcOpen:
docs/index.html🔗 Local Development
pnpm build
pnpm link ../reusables📁 Project Structure
src/
├──utils
├──utility_functions.ts
└──utility_types_and_variables.ts
├── string_utils.ts
├── number_utils.ts
├── date_utils.ts
├── array_obj_utils.ts
└── index.ts📌 Conventions
- Pure functions only
- No side effects
- Strong typing enforced
- Clean and readable implementations
🚀 Roadmap
- [ ] More object utilities
- [ ] Async helpers
- [ ] Performance benchmarks
- [ ] Full test coverage
📄 License
MIT
Built by Frodoy
