Recursively strip empty values from objects and arrays.
  • TypeScript 100%
Find a file
2026-04-24 19:23:22 +08:00
dist build: update compiled output 2026-04-18 22:44:28 +08:00
src Implement stripEmpties function to remove empty values 2026-04-18 20:30:51 +08:00
.gitignore y 2026-04-24 19:23:22 +08:00
LICENSE Initial commit 2026-04-18 20:28:02 +08:00
package-lock.json y 2026-04-24 19:23:22 +08:00
package.json y 2026-04-24 19:23:22 +08:00
README.md y 2026-04-24 19:23:22 +08:00
tsconfig.json y 2026-04-24 19:23:22 +08:00

strip.ts

Recursively strip empty values from objects and arrays.

TypeScript JavaScript License: MIT

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.