Registry / serialization / empty
library0.4.4jsnpmunverified

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.

npm install empty
INSTALL
IMPORT
SIG · EMPTY
E
empty
serializationjavascriptv0.4.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

empty
const empty = require('empty');
import empty from 'empty';
The library is CommonJS-only. Direct ESM import will fail without a bundler or compatibility layer.
empty.object
const { object } = require('empty'); // or const emptyObject = require('empty/object');
import { object } from 'empty';
Individual empty utilities can be imported via named destructuring from the main export or directly via sub-path imports. Both are CommonJS only.
empty.func
const { func } = require('empty'); // or const emptyFunction = require('empty/function');
import { func } from 'empty';
Similar to `object`, `func` and other named exports are available via CommonJS destructuring or sub-path imports.

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
Debug
Known issues
breakingThe library is exclusively CommonJS (CJS). Attempting to use `import` syntax in an ECMAScript Module (ESM) environment without a build step (like webpack or Rollup) or Node.js's CJS compatibility will result in errors.
fix
Use `const empty = require('empty');` for all imports. For ESM projects, consider a bundler to transpile, or use Node.js's CJS interoperability with `import empty from 'empty';` after ensuring `package.json` has `"type": "module"` and configuring a CJS default import wrapper.
affects: >=0.1.0
gotchaAll objects and functions returned by `empty` are `Object.freeze`d by default, making them immutable. However, if `process.env.NODE_ENV` is set to `'production'`, they are *not* frozen. This can lead to unexpected mutability if `NODE_ENV` is changed dynamically or is not consistently managed.
fix
Be aware of your `NODE_ENV` setting. If strict immutability is always required, ensure `NODE_ENV` is never `'production'` when using this library, or manually `Object.freeze` the results if `NODE_ENV` might be `'production'`.
affects: >=0.1.0
gotchaThis package is effectively abandoned, with the last publish over 7 years ago. It does not provide native TypeScript declarations, meaning consumers will either need to create their own `.d.ts` files or rely on `@ts-ignore`.
fix
Create a `declarations.d.ts` file with `declare module 'empty' { /* ... */ }` to provide type definitions, or consider using a more modern, maintained alternative with native TypeScript support.
affects: >=0.1.0
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
Attempting to use `require()` in a JavaScript file that is treated as an ES module (e.g., `"type": "module"` in `package.json` or `.mjs` extension).
fix
For ES Modules, you cannot directly use `require()`. You might need to use dynamic `import('empty')` or `import empty from 'empty';` if your environment supports CJS interop, or convert your module to CJS. The most reliable fix for this package is to ensure the consuming file is CJS or use a bundler.
TypeError: Cannot assign to read only property 'foo' of object '#<Object>'
Attempting to modify an object or array returned by `empty` when `Object.freeze` was applied. This happens when `process.env.NODE_ENV` is *not* `'production'` (the default frozen state).
fix
Do not attempt to mutate objects or arrays obtained from `empty` as they are immutable by design. If you need a mutable copy, create one using spread syntax (e.g., `{...empty.object}` or `[...empty.array]`). If you explicitly intend for them to be mutable, ensure `process.env.NODE_ENV` is set to `'production'` when the library is loaded.
Upgrade
Version history
0.4.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
empty — npm install empty · libregistry