Recursively strip empty values from objects and arrays.
- TypeScript 100%
| dist | ||
| src | ||
| .gitignore | ||
| LICENSE | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
strip.ts
Recursively strip empty values from objects and arrays.
Install
npm install @0xA672/strip.ts
npm install github:0xA672/strip.ts
npm install github:0xA672/strip.ts#main
# or with bun
bun install github:0xA672/strip.ts
Usage
import { stripEmpties } from 'strip.ts';
const obj = {
name: 'test',
age: 0,
addr: '',
meta: {
tags: [],
extra: null,
note: 'hello',
},
};
console.log(stripEmpties(obj));
// => { name: 'test', meta: { note: 'hello' } }
console.log(stripEmpties(obj, { omitZero: true }));
// => { name: 'test', meta: { note: 'hello' } } (age removed)
Options
- omitZero (boolean): remove 0 values. Default false.