typepurify - Deep-clean any API response.
Preserve your types.
A comprehensive suite of zero-schema developer utilities designed to deeply strip null, undefined, and empty values while keeping your TypeScript types perfectly aligned.
Why typepurify?
When you receive messy data from an API, standard tools have major drawbacks. typepurify is built differently.
Safe API Fetching
Use the new @typepurify/fetch wrapper to automatically parse and deeply clean JSON responses straight from the network before they hit your app.
< 1 kB Size
Lightning-fast and incredibly small. Zero dependencies. Compare that to Zod's ~550 kB.
Perfect Type Inference
Automatically recalculates your TypeScript interfaces at compile-time. No manual schemas required.
Zero Boilerplate
Clean your nested data perfectly with a single line of code instead of writing hundreds of lines of validation schemas.
Extreme Speed
Use cleanInPlace() and cleanParse() for maximum performance and zero memory overhead when processing massive data payloads.
How to Use
Simple imports, powerful options, and fully inferred types.
1. Installation
npm install typepurify @typepurify/fetch2. Core Ecosystem Functions
tFetch(url, init?)
A drop-in replacement for the native fetch API. It automatically downloads the JSON response and runs it through the purification engine before returning it to you.
clean(payload, options?)
Deeply cleans the payload and returns a brand new, strictly typed object. It does not mutate the original data.
cleanInPlace(payload, options?)
Mutates the original object directly to remove empty values. Perfect for processing massive payloads with zero memory overhead.
cleanAsync(payload, options?)
Non-blocking, asynchronous variant of clean. Yields to the event loop to prevent UI freezing on massive datasets.
cleanParse(jsonString, options?)
A specialized JSON parser that deeply cleans a raw JSON string in a single pass. Saves up to 25% execution time and completely avoids intermediate object memory allocation for huge payloads.
import { clean, cleanInPlace, cleanAsync, cleanParse } from "typepurify"; import { tFetch } from "@typepurify/fetch"; // Safe Fetching from Network const safeApiData = await tFetch("https://api.example.com/data"); // Returns a new object const safeData = clean(dirtyApiData); // Mutates the original array/object directly for extreme performance cleanInPlace(massiveArrayPayload); // Non-blocking deep clean for massive datasets const asyncData = await cleanAsync(hugePayload); // Single-pass JSON string parsing and cleaning const parsedData = cleanParse(rawJsonString);
3. Configuration Props
You can pass an optional CleanOptions object as the second parameter to finely tune what gets stripped.
| Property | Type | Default | Description |
|---|---|---|---|
| stripEmptyStrings | boolean | false | Removes all empty strings `""` from the payload. |
| stripEmptyArrays | boolean | false | Removes all empty arrays `[]` from the payload. |
| stripEmptyObjects | boolean | false | Removes all empty objects `{}` from the payload. |
| trimStrings | boolean | false | Trims whitespace from strings before processing them. |
| stripWhen | (value: any) => boolean | undefined | Custom predicate function. If it returns true, the value is stripped. |
| transform | (value: any, key?: any) => any | undefined | Custom transform callback function to mutate or format values before cleaning. |

About the Author
Vallarasu Kanthasamy
I am a Bengaluru-based Software Developer and Next.js expert with over 3.5+ years of experience building scalable, user-friendly web applications. I specialize in frontend development, performance optimization, custom extension ecosystems, and full-stack automation with Node.js and Python.
Digital Ecosystem
Auto Console Log
VS Code ExtensionAutomatically wraps console logs in JSX and injects debug logs instantly.
Universal Spreadsheet
VS Code ExtensionSeamlessly edit and manage spreadsheet data directly in your editor.
ATS Resume Maker
Web ApplicationGenerate ATS friendly resumes that help you land your dream job faster.
Tech Stack Checker
Chrome ExtensionBrowser extensions for deep web analysis and productivity workflows.
Media Bucket Sync
WordPress PluginAdvanced plugin developed to solve complex AWS S3 media offloading issues.