recursive-trim
v1.0.1
Published
Recursively trims all string values in objects or arrays.
Maintainers
Readme
recursive-trim
Recursively trims whitespace from strings inside objects, arrays, or deeply nested structures.
Supports TypeScript and works with JSON-like data.
Great for sanitizing deeply nested input data before saving or sending to an API.
✨ Features
- Recursively cleans deeply nested objects/arrays
- Works with objects, arrays, and nested data
- Leaves non-string values untouched
- Safe for
nullandundefined - Zero dependencies
- ESM + TypeScript support
🚀 Installation
npm install recursive-trimor
yarn add recursive-trim📦 Usage
import recursiveTrim from "recursive-trim";
const data = {
name: " John Doe ",
address: {
city: " New York ",
streets: [" Main Street ", " 5th Avenue "],
},
tags: [" apple ", " banana "],
};
const cleaned = recursiveTrim(data);
console.log(cleaned);
/*
{
name: "John Doe",
address: {
city: "New York",
streets: ["Main Street", "5th Avenue"]
},
tags: ["apple", "banana"]
}
*/💡 Use Cases
- 🧼 Cleaning user input before saving to a database
- 📤 Sanitizing API payloads
- 🗄 Preparing data before comparing or storing
📄 License
MIT © Aravind Prabash
