Empty Object/Function Utilities

0.10.1 · abandoned · verified Sun Apr 19

The `empty` utility library, currently at version 0.10.1 (last published over 7 years ago), provides a collection of pre-defined empty objects, arrays, and no-operation functions. Its primary feature is enforcing immutability by applying `Object.freeze` to all returned entities by default. This behavior can be overridden if the `NODE_ENV` environment variable is set to `'production'`. The library was designed primarily for CommonJS environments, explicitly supporting Node.js and older browser bundling workflows via tools like Browserify. Due to its age and lack of recent updates, it does not support modern JavaScript module systems (ESM) or TypeScript natively, requiring manual declarations for type safety. Its key differentiator remains providing a consistent, immutable set of primitive empty values and noop functions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing the `empty` library, accessing various empty types (object, array, function, functionThatReturns), and shows the potential impact of `NODE_ENV='production'` on immutability.

const empty = require('empty');

// Get a frozen empty object
const myEmptyObject = empty.object;
console.log('Empty Object:', myEmptyObject, Object.isFrozen(myEmptyObject));

// Get a frozen empty array
const myEmptyArray = empty.array;
console.log('Empty Array:', myEmptyArray, Object.isFrozen(myEmptyArray));

// Get a no-operation function
const noop = empty.func;
console.log('No-op Function:', noop());

// Get a function that returns a specific value
const returnFoo = empty.functionThatReturns('foo');
console.log('Function that returns "foo":', returnFoo());

// Demonstrating the NODE_ENV impact (typically set via environment variables)
// For demonstration, simulating production behavior where objects might not be frozen
const originalNodeEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'production';
const unfrozenEmptyObject = require('empty/object'); // Requires re-requiring the module
console.log('Unfrozen Object (if NODE_ENV=production):', unfrozenEmptyObject, Object.isFrozen(unfrozenEmptyObject));
process.env.NODE_ENV = originalNodeEnv; // Restore original env

view raw JSON →