{"id":10790,"library":"empty","title":"Empty Object/Function Utilities","description":"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.","status":"abandoned","version":"0.10.1","language":"javascript","source_language":"en","source_url":"https://github.com/iclanzan/empty","tags":["javascript","empty","noop"],"install":[{"cmd":"npm install empty","lang":"bash","label":"npm"},{"cmd":"yarn add empty","lang":"bash","label":"yarn"},{"cmd":"pnpm add empty","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library is CommonJS-only. Direct ESM import will fail without a bundler or compatibility layer.","wrong":"import empty from 'empty';","symbol":"empty","correct":"const empty = require('empty');"},{"note":"Individual empty utilities can be imported via named destructuring from the main export or directly via sub-path imports. Both are CommonJS only.","wrong":"import { object } from 'empty';","symbol":"empty.object","correct":"const { object } = require('empty');\n// or\nconst emptyObject = require('empty/object');"},{"note":"Similar to `object`, `func` and other named exports are available via CommonJS destructuring or sub-path imports.","wrong":"import { func } from 'empty';","symbol":"empty.func","correct":"const { func } = require('empty');\n// or\nconst emptyFunction = require('empty/function');"}],"quickstart":{"code":"const empty = require('empty');\n\n// Get a frozen empty object\nconst myEmptyObject = empty.object;\nconsole.log('Empty Object:', myEmptyObject, Object.isFrozen(myEmptyObject));\n\n// Get a frozen empty array\nconst myEmptyArray = empty.array;\nconsole.log('Empty Array:', myEmptyArray, Object.isFrozen(myEmptyArray));\n\n// Get a no-operation function\nconst noop = empty.func;\nconsole.log('No-op Function:', noop());\n\n// Get a function that returns a specific value\nconst returnFoo = empty.functionThatReturns('foo');\nconsole.log('Function that returns \"foo\":', returnFoo());\n\n// Demonstrating the NODE_ENV impact (typically set via environment variables)\n// For demonstration, simulating production behavior where objects might not be frozen\nconst originalNodeEnv = process.env.NODE_ENV;\nprocess.env.NODE_ENV = 'production';\nconst unfrozenEmptyObject = require('empty/object'); // Requires re-requiring the module\nconsole.log('Unfrozen Object (if NODE_ENV=production):', unfrozenEmptyObject, Object.isFrozen(unfrozenEmptyObject));\nprocess.env.NODE_ENV = originalNodeEnv; // Restore original env","lang":"javascript","description":"Demonstrates importing the `empty` library, accessing various empty types (object, array, function, functionThatReturns), and shows the potential impact of `NODE_ENV='production'` on immutability."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":">=0.1.0"},{"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'`.","message":"All 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"This 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`.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"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).","error":"ReferenceError: require is not defined in ES module scope"},{"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.","cause":"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).","error":"TypeError: Cannot assign to read only property 'foo' of object '#<Object>'"}],"ecosystem":"npm"}