omit.js is a lightweight JavaScript utility function designed to create a shallow copy of an object, excluding specified fields. The current stable version is 2.0.2. This package provides a straightforward API for basic object manipulation, returning a new object without mutating the original. Its release cadence has been very slow, with the last update in 2018. Key differentiators include its minimal footprint and singular focus on shallow property omission. It is not intended for deep cloning or complex data transformations, focusing purely on filtering top-level properties. Its utility can be partially superseded by native JavaScript spread syntax for simple cases, and TypeScript's built-in `Omit` utility type for type manipulation.
npm install omit.jsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use `omit.js` to filter properties from an object, creating a shallow copy. It shows omitting multiple and single fields, and highlights the non-mutating behavior on the top-level object, while also noting the shallow copy aspect for nested objects.
Review your module resolution settings, especially if you encountered issues upgrading from `1.x.x` to `2.x.x`. Ensure your bundler (Webpack, Rollup, etc.) or Node.js environment is configured to correctly resolve ES Modules if you are using `import` syntax.
If you require a deep copy, you must implement your own deep cloning logic (e.g., using `structuredClone` in modern environments, or a dedicated deep-cloning library like `lodash.clonedeep`) before or after using `omit.js`.
Consider refactoring to use native JavaScript for runtime omission (`const { excludedProp, ...rest } = myObject;`) and TypeScript's `Omit` utility type (`type NewType = Omit<OriginalType, 'prop1' | 'prop2'>;`) for compile-time type transformation. This can reduce dependency count and leverage language features.Evaluate if the benefits of a lightweight utility outweigh the risks of a minimally maintained package. For critical applications, consider using actively maintained alternatives or implementing the omission logic natively.
For ES Modules, use `import omit from 'omit.js';`. For CommonJS, use `const omit = require('omit.js');`.To omit nested properties, you need to either restructure your object before calling `omit.js` (e.g., flatten it) or use a different utility designed for deep property manipulation. For example, `omit(myObject, ['parent.nestedProp'])` will not work; `omit(myObject, ['parent'])` would remove `parent` entirely.
Ensure that the type of the variable receiving the result of `omit.js` (or `Omit<Type, Keys>`) correctly reflects the properties that have been removed. You might need to define a new type with `Omit<OriginalType, 'field1' | 'field2'>` or `Partial<OriginalType>`.
No dependency data recorded yet.