Fragmen
Copy‑paste TypeScript utilities into your project.
Browse 50+ focused fragments across 9 categories. Own the code, adapt it freely, and ship without extra dependencies.
npx fragmen add promise/delaySee It In Action
Real utilities solving real problems. Here's how chunk splits an array into smaller pieces.
Input Array
A list of 10 items to split
chunk(items, 3)
Split into groups of 3
Implementation
import { chunk } from '@/lib/chunk';
const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const chunks = chunk(items, 3);
console.log(chunks);
// [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
// Perfect for pagination
const paginatedData = chunk(allProducts, 20);
// Display page 1: paginatedData[0]Own Your Code
Utilities are copied into your codebase so you can inspect, adapt, and learn from them.
Zero Dependencies
Each fragment is self‑contained. Adding a utility won't bloat your project.
TypeScript First
Written in TypeScript with strong types and clear JSDoc.
Why Fragmen?
How Fragmen compares to other approaches
npm Packages
Install full libraries for small utilities
Stack Overflow
Copy-paste random code snippets
Fragmen
BestBattle-tested, typed utilities you own
Popular Utilities
Most commonly used utilities to solve everyday problems
debounce
Delay function execution until after wait time has elapsed since last call. Perfect for search inputs and resize handlers.
debounce(fn, 300)delay
Promise-based delay for async operations. Useful for rate limiting, animations, and testing scenarios.
await delay(1000)clone
Deep clone objects and arrays without reference issues. Essential for immutable state management.
clone(object)chunk
Split arrays into smaller chunks of specified size. Great for pagination and batch processing.
chunk(array, 3)slugify
Convert strings to URL-friendly slugs. Handles special characters, spaces, and case conversion.
slugify("Hello World")randomString
Generate cryptographically secure random strings. Perfect for tokens, IDs, and passwords.
randomString(16)Frequently Asked Questions
Everything you need to know about Fragmen
How is Fragmen different from lodash or other utility libraries?▼
Unlike traditional npm packages, Fragmen copies utilities directly into your codebase. This means you own the code completely, can modify it freely, and don't add dependencies to your project. Each utility is self-contained with no external dependencies.
Do I need to credit Fragmen in my project?▼
No attribution required! Fragmen is MIT licensed. Once you copy a utility, it's yours to use, modify, and distribute however you like. We only ask that you keep the MIT license notice in the code.
Can I modify the utilities after copying them?▼
Absolutely! That's the whole point. The code is now part of your project. Adapt it to your specific needs, add features, optimize for your use case, or learn from it. You have complete freedom.
How do updates work if I copy code into my project?▼
Since the code lives in your project, updates are manual. You can check the registry for improvements and copy new versions when needed. This gives you control over when and what to update, avoiding breaking changes.
Are the utilities tested?▼
Yes! Every utility has comprehensive test coverage with multiple test cases. You can view the tests in the registry alongside the source code. Tests are written using Vitest.
Can I use Fragmen in commercial projects?▼
Yes! Fragmen is MIT licensed, which means you can use it freely in both personal and commercial projects without any restrictions or fees.
Quick Start
Initialize
npx fragmen initBrowse Utilities
npx fragmen browseAdd to Your Project
npx fragmen add promise/delay string/capitalize