npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

purify-objects

v1.4.1

Published

A powerful TypeScript library for cleaning objects by removing empty values, with support for YAML and CSV formats

Downloads

578

Readme

purify-objects

npm version npm downloads npm bundle size License: MIT TypeScript PRs Welcome

A powerful TypeScript library for cleaning objects by removing empty values, with support for YAML and CSV formats.

Features

  • Clean objects by removing empty values (null, undefined, empty strings, empty arrays, empty objects)
  • Support for JSON, YAML, and CSV formats
  • Format conversion between JSON, YAML, and CSV
  • Command-line interface (CLI) for file processing
  • Safe mode to prevent accidental modifications
  • Compare mode to preview changes
  • Custom cleaning options
  • Automatic format detection based on file extension

Installation

npm install purify-objects

Usage

As a Library

import { cleanObject, parseContent, stringifyContent } from 'purify-objects';

const obj = {
  id: 1,
  name: "Turki",
  meta: {
    age: null,
    location: {
      city: "Riyadh",
      coords: undefined,
      district: "",
    },
    preferences: {},
  },
  roles: [],
  lastLogin: "2024-01-15",
  status: 0
};

const cleaned = cleanObject(obj);

const yaml = `
version: 2
config:
  user: Turki
  env: prod
  paths:
    root: /app
    temp: null
    logs:
  plugins: []
`;

const parsed = parseContent(yaml, 'yaml');
const result = cleanObject(parsed);
const output = stringifyContent(result, 'yaml');

const csv = `
id,name,department,salary,active
1,Turki,IT,15000,true
2,Ahmad,HR,,false
3,Mohammed,IT,12000,
4,,Finance,,true
`;

const data = parseContent(csv, 'csv', { headers: true });
const processed = data.map(row => cleanObject(row));
const final = stringifyContent(processed, 'csv', { headers: true });

Command Line Interface (CLI)

Basic usage:

npx purify-objects input.json
npx purify-objects input.yaml
npx purify-objects input.csv

Save output to a file:

npx purify-objects input.json --output cleaned.json

Format Conversion

Convert between formats:

# Convert JSON to YAML
npx purify-objects input.json --convert-to yaml

# Convert YAML to CSV
npx purify-objects input.yaml --convert-to csv

# Convert CSV to JSON
npx purify-objects input.csv --convert-to json

Convert without cleaning:

npx purify-objects input.yaml --convert-to json --noclean

CSV Options

# Use custom delimiter
npx purify-objects input.csv --delimiter ";"

# Disable headers
npx purify-objects input.csv --no-headers

Additional Options

# Preview changes without modifying the file
npx purify-objects input.json --compare

# Safe mode (creates new file instead of modifying)
npx purify-objects input.json --safe

# Remove zero values
npx purify-objects input.json --remove-zero-values

CLI Options

  • --output <file>: Save output to a file
  • --format <format>: Specify input format (json, yaml, csv)
  • --convert-to <format>: Convert to specified format
  • --noclean: Convert without cleaning data
  • --compare: Preview changes without modifying
  • --safe: Create new file instead of modifying
  • --delimiter <char>: CSV delimiter (default: ",")
  • --no-headers: Process CSV without headers
  • --remove-zero-values: Remove fields with zero values

API

function cleanObject<T extends object>(
  obj: T,
  customCleaner?: (key: string, value: any) => boolean,
  keepFields?: string[],
  options?: CleanerOptions
): T;

function parseContent(
  content: string,
  format: 'json' | 'yaml' | 'csv',
  options?: ParserOptions
): object | object[];

function stringifyContent(
  data: object | object[],
  format: 'json' | 'yaml' | 'csv',
  options?: ParserOptions
): string;

interface CleanerOptions {
  recursive?: boolean;
  safe?: boolean;
}

interface ParserOptions {
  delimiter?: string;
  headers?: boolean;
}

License

MIT