@0xa672/strip.ts
v0.0.1
Published
Recursively strip empty values from objects and arrays.
Downloads
32
Readme
strip.ts
Recursively strip empty values from objects and arrays.
Install
npm install @0xA672/strip.tsnpm install github:0xA672/strip.tsnpm install github:0xA672/strip.ts#main# or with bun
bun install github:0xA672/strip.tsUsage
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.
