@useless-engineer/utils
v0.1.2
Published
repo for small, utility functions by useless engineer
Readme
🛠️ @useless-engineer/utils
Small, typed utilities distilled from real production bugs. One package. Multiple entry points. Only pay for what you import.
📦 Install · ⚡ Quick start · 📚 API · 🗺️ Roadmap · 📸 Follow
✨ Why this exists
Every utility here started as an Instagram post about a bug that actually shipped. The post explains the problem; this package is the fix, typed and tested, so you never copy-paste it again.
| | |
| ------------------------ | ------------------------------------------------------ |
| 🎯 Focused | Each function does one thing and has tests |
| 🌲 Tree-shakeable | sideEffects: false, import only what you use |
| 🧩 Split by platform | Core, React Native, and more, each its own import path |
| 🔒 Strictly typed | Written in TypeScript with strict mode on |
📦 Install
npm install @useless-engineer/utilspnpm add @useless-engineer/utils
yarn add @useless-engineer/utils
bun add @useless-engineer/utils⚡ Quick start
import { debounce, throttle } from "@useless-engineer/utils";
const onSearch = debounce((query: string) => fetchResults(query), 300);
const onScroll = throttle(() => updateHeader(), 100);import { isIOS, isAndroid } from "@useless-engineer/utils/react-native";
const padding = isIOS ? 20 : 16;💡
reactandreact-nativeare optional peer dependencies. If you only use the core entry, you never need to install either.
🧭 Entry points
| Import path | For | Status |
| -------------------------------------- | ------------------------- | ----------------------------------------------------------------------------- |
| @useless-engineer/utils | Platform-agnostic helpers | |
|
@useless-engineer/utils/react-native | React Native helpers | |
|
@useless-engineer/utils/react | React hooks | |
📚 API
Core
Waits for quiet. Every call resets the timer, and only the last call fires. Good for search inputs and autosave.
const save = debounce((text: string) => api.save(text), 500);
save("h");
save("he");
save("hello"); // only this one runs, 500ms after the last call
// In a React effect cleanup, so nothing fires after unmount:
save.cancel();| Param | Type | Description |
| ----------- | ------------------- | ----------------------------------- |
| fn | (...args) => void | Function to debounce |
| delay | number | Milliseconds of quiet before firing |
| returns | Debounced | Callable with a .cancel() method |
Keeps a steady beat. Runs at most once per interval, however often it's called. Good for scroll, drag, and resize.
const onScroll = throttle(() => updateHeader(), 100);
// Skip the immediate first call:
throttle(fn, 100, { leading: false });
// Skip the final catch-up call:
throttle(fn, 100, { trailing: false });| Option | Default | Description |
| ---------- | ------- | --------------------------------------------------- |
| leading | true | Fire right away on the first call of a burst |
| trailing | true | Fire once more at the end with the latest arguments |
Returns a function with .cancel().
| | debounce | throttle |
| ------------ | --------------------------------- | -------------------------------- |
| Fires | Once, after calls stop | On a fixed beat during calls |
| Use for | Search box, autosave, validation | Scroll, drag, resize |
| Ask yourself | "Do I only need the final state?" | "Does it need to stay live?" |
React Native
Plain booleans derived from Platform.OS.
import { isIOS, isAndroid } from "@useless-engineer/utils/react-native";
const behavior = isIOS ? "padding" : "height";🗺️ Roadmap
Released one or two at a time, each matching a post that's already live.
| Next up | Entry | Origin |
| ------------------------------------------------------------------------------------------------------------------------ | ------------ | ------------------------------------ |
| safeParseJSON, safeStringify, deepClone | core | JSON and shallow-copy gotchas |
|
getAccessibilityProps, createShadow | react-native | Accessibility and iOS-only shadows |
|
useInterval, useCountdown, useIsMounted | react | Stale closures and unmounted updates |
🤝 Contributing
Found a bug or have a post idea that deserves a utility? Open an issue.
npm install
npm test
npm run buildBuilt from real bugs, one post at a time.
MIT © Saurabh Bandkar
