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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cleaner-node-ts

v1.1.0

Published

TypeScript-first utility library for Node.js projects - making code more legible and maintainable

Downloads

10

Readme

cleaner-node-ts

npm version License Node.js Version TypeScript

TypeScript-first port of the popular cleaner-node utility library - making Node.js code more legible and maintainable.

Background

This is a complete TypeScript rewrite of the original cleaner-node package, maintaining 100% API compatibility while adding full type safety and modern JavaScript features.

There are several libraries out there designed to make life easier for developers (moment, lodash, underscore, etc.). However, for the most part, the goals of those utilities are to add on to what Node and JavaScript bring to the table. And, as Node and JavaScript mature, developers find them to be less of a necessity and end up removing them.

While cleaner-node-ts is also a helper package, and completely unnecessary, its goal is to abstract some of the more redundant and verbose syntaxes. The end result is a codebase that still functions as it would without cleaner-node-ts but is easier to read and maintain. Unlike those other libraries, which shrink over time, this library intends to grow for as long as Node exists, so developers don't have to write the same code again, and again, and again...

Installation

npm install cleaner-node-ts

Requirements

  • Node.js: >= 20.0.0
  • TypeScript: >= 5.0.0 (for TypeScript projects only)
  • Zero runtime dependencies (except Node.js built-ins)

Usage

JavaScript (CommonJS)

const _ = require('cleaner-node-ts').default;

// String manipulation
const cleaned = _.cleanString('  Hello World!  '); // "Hello World!"
const isValid = _.isValidString(cleaned); // true

// Array operations
const unique = _.unique([1, 2, 2, 3, 3, 3]); // [1, 2, 3]
const first = _.getFirst(['a', 'b', 'c']); // 'a'

// Validation
const isEmail = _.isEmail('[email protected]'); // true
const isGuid = _.isGuidFormat('550e8400-e29b-41d4-a716-446655440000'); // true

JavaScript (ESM)

import _ from 'cleaner-node-ts';

// All the same functions available
const tomorrow = _.addDays(new Date(), 1);
const guid = _.newGuid();

TypeScript

import _ from 'cleaner-node-ts';
// Or for specific imports:
// import { cleanString, isEmail, newGuid } from 'cleaner-node-ts';

// Full type safety and IntelliSense
const cleaned: string = _.cleanString('  Hello World!  ');
const isValid: boolean = _.isValidString(cleaned);

// Array operations with proper typing
const unique: number[] = _.unique([1, 2, 2, 3, 3, 3]);
const first: string | undefined = _.getFirst(['a', 'b', 'c']);

// Object manipulation with type inference
const cleaned = _.cleanObject({ name: 'John', age: undefined });
// Type: { name: string }

// Date utilities with Date type safety
const tomorrow: Date = _.addDays(new Date(), 1);
const timestamp: number = _.toEpoch(new Date());

Features

  • 🎯 TypeScript-first: Built with TypeScript from the ground up with full type definitions
  • 🔄 100% Compatible: Drop-in replacement for original cleaner-node package
  • 📦 Dual Package Support: Works with both CommonJS and ESM modules
  • 🌳 Tree-shakeable: Import only what you need with ESM
  • 🚀 203 Functions: Complete implementation of all original utilities
  • 🔒 Type-safe: Full type inference and strict mode support
  • 📚 Well-documented: Comprehensive JSDoc comments for all functions
  • Zero dependencies: Minimal footprint, only uses Node.js built-ins

Migration from cleaner-node

Migrating from the original cleaner-node package is straightforward:

# Uninstall original package
npm uninstall cleaner-node

# Install TypeScript version
npm install cleaner-node-ts
// Before (cleaner-node)
const _ = require('cleaner-node');

// After (cleaner-node-ts) - Updated for correct CommonJS usage
const _ = require('cleaner-node-ts').default;

All function signatures and behaviors are identical to the original package. The only difference is that you now get full TypeScript support if you're using TypeScript.

Complete Function Reference

The library includes 203 utility functions organized into the following categories:

Core Categories

  • Validation (46 functions) - Type checking, format validation, and data verification
  • String Manipulation (30+ functions) - Cleaning, formatting, and string operations
  • Array Operations (24+ functions) - Array utilities, unique values, and transformations
  • Object Operations (22+ functions) - Object manipulation, cleaning, and deep operations
  • File System (24 functions) - Synchronous file operations and path utilities
  • Date/Time (14 functions) - Date manipulation and formatting
  • Cryptography & JWT (18 functions) - Hashing, encryption, and JWT handling
  • HTTP Utilities (6 functions) - REST operations and request handling
  • Environment - Environment variable management
  • ID Generation - GUID, UID, and code generation

Popular Functions

String Operations

  • cleanString(value) - Clean and normalize strings
  • trimToNull(str) - Trim string or return null if empty
  • getEmail(text) - Extract first email from text
  • toCamelCase(str) / toKebabCase(str) / toPascalCase(str) / toSnakeCase(str) - Case conversion

Validation

  • isValidString(value) - Comprehensive string validation
  • isEmail(value) - Email address validation
  • isGuidFormat(str) - GUID format validation
  • isValidArray(arr) - Array validation with options
  • isNumber(value) - Flexible number checking

Arrays & Objects

  • unique(array) - Remove duplicates intelligently
  • getFirst(array) / getLast(array) - Safe array access
  • copyObject(obj) - Deep copy objects
  • cleanObject(obj) - Remove undefined values
  • removeProperty(obj, key) - Remove property recursively

File Operations

  • isFile(path) / isFolder(path) - Path existence checking
  • readFile(path) - Synchronous file reading
  • writeFile(path, content) - Write with directory creation
  • loadJson(path) / saveJson(path, obj) - JSON file operations

Date & Time

  • addDays(date, days) / addMonths(date, months) / addYears(date, years) - Date arithmetic
  • toEpoch(date) / fromEpoch(timestamp) - Unix timestamp conversion
  • getDuration(start, end) - Calculate time duration

ID Generation

  • newGuid() - Generate UUID v4
  • newUid() - Generate 32-character UID
  • newCode(length, chars) - Generate random codes

Aliases for Convenience

Many functions have shorter aliases for convenience:

  • _ - The default export containing all functions
  • firstgetFirst
  • lastgetLast
  • copycopyObject
  • countgetArrayCount
  • isCapsisUpperCase

JavaScript Compatibility

While this is a TypeScript-first library, it's fully compatible with JavaScript projects:

  • CommonJS: Works with require() in Node.js
  • ESM: Works with import in modern JavaScript
  • No TypeScript Required: JavaScript projects can use it without any TypeScript setup
  • Optional Types: TypeScript definitions are included but not required

Quick Examples

// Clean and validate data
const email = _.getEmail('Contact: [email protected]'); // '[email protected]'
if (_.isEmail(email)) {
  console.log('Valid email:', email);
}

// Work with arrays
const numbers = [1, 2, 2, 3, 3, 3];
const unique = _.unique(numbers); // [1, 2, 3]
const max = _.getMax(numbers); // 3
const sorted = _.sort(numbers); // [1, 2, 3]

// File operations
if (_.isFile('./config.json')) {
  const config = _.loadJson('./config.json');
  config.updated = _.now();
  _.saveJson('./config.json', config);
}

// Generate IDs
const userId = _.newGuid(); // '550e8400-e29b-41d4-a716-446655440000'
const sessionId = _.newUid(); // 'A1B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6'

// Date manipulation
const tomorrow = _.addDays(new Date(), 1);
const nextMonth = _.addMonths(new Date(), 1);
const timestamp = _.toEpoch(new Date());

// HTTP requests (async)
const data = await _.doGet('https://api.example.com/users');
const result = await _.doPost('https://api.example.com/users', {
  name: 'John Doe'
});

Development Status

COMPLETE - All 203 functions from the original cleaner-node package have been successfully implemented in TypeScript with:

  • Full type definitions
  • JSDoc documentation
  • Dual CJS/ESM builds
  • 100% API compatibility

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

# Clone the repository
git clone https://github.com/FredLackey/cleaner-node-ts.git
cd cleaner-node-ts

# Install dependencies
npm install

# Run tests
npm test

# Build the project
npm run build

# Run linting
npm run lint

License

Apache-2.0 - see LICENSE file for details.

Author

Fred Lackey
[email protected]
http://fredlackey.com


Links: