Lodash Internal `baseAssign` Utility
This package provides the internal `baseAssign` function from Lodash version 3.2.0, exporting it as a CommonJS module. `baseAssign` is a low-level utility responsible for shallowly assigning enumerable own properties from source objects to a destination object, serving as a building block for higher-level Lodash methods like `_.assign`. Published in 2015, this specific package is tied to an end-of-life major version of Lodash (v3.x, supported until January 2016). While Lodash (currently v4.x) remains actively maintained with a continuous release cadence, this individual internal module is not independently updated. Modern best practices for consuming Lodash functions involve importing directly from the main `lodash` package (e.g., `require('lodash/assign')` or `import assign from 'lodash/assign'`) or utilizing `lodash-es` with tree-shaking bundlers to optimize bundle size. Per-method packages like this one are discouraged and are slated for removal in Lodash v5.
Common errors
-
baseAssign is not a function
cause Attempting to use `import { baseAssign } from 'lodash._baseassign'` in an ES module environment, or `require` with a non-existent path. This package only exports `baseAssign` as a default CommonJS export.fixFor CommonJS, use `const baseAssign = require('lodash._baseassign');`. For ESM, you must use a CommonJS interop layer or, better yet, migrate to `import assign from 'lodash/assign'` from the main `lodash` package. -
TypeError: baseAssign is not a constructor
cause Trying to instantiate `baseAssign` with `new`, which is not a constructor function.fix`baseAssign` is a utility function and should be called directly, e.g., `baseAssign({}, source)`.
Warnings
- breaking This package is based on Lodash v3.2.0, an End-of-Life (EOL) version. Many APIs, behaviors, and internal structures changed significantly in Lodash v4.x, which was released in 2016. Code written for v3.x is unlikely to be directly compatible with v4.x equivalents without migration.
- deprecated Using granular internal modules like `lodash._baseassign` is strongly discouraged by the Lodash team. These packages are considered legacy, can increase `node_modules` size, and are planned for removal in Lodash v5.
- gotcha This package is CommonJS-only, meaning it cannot be directly imported using ES module `import` syntax (`import { baseAssign } from 'lodash._baseassign'`). Attempting to do so will result in runtime errors.
- breaking As an EOL version (v3.x), `lodash._baseassign` is no longer supported and will not receive security patches for newly discovered vulnerabilities. While the provided advisories mention v4.x vulnerabilities, similar issues could exist in older codebases.
Install
-
npm install lodash._baseassign -
yarn add lodash._baseassign -
pnpm add lodash._baseassign
Imports
- baseAssign
import { baseAssign } = from 'lodash._baseassign';const baseAssign = require('lodash._baseassign');
Quickstart
const baseAssign = require('lodash._baseassign');
const target = { a: 1 };
const source1 = { b: 2 };
const source2 = { c: 3, a: 4 }; // 'a' will be overwritten by source1 if applied first
// baseAssign is internal and typically takes a single source
const result = baseAssign(target, source1);
console.log('Result after baseAssign(target, source1):', result);
// Expected: { a: 1, b: 2 }
const anotherTarget = {};
const sourceObj = { propA: 1, propB: { nested: true } };
const assignedObj = baseAssign(anotherTarget, sourceObj);
console.log('Assigned object:', assignedObj);
console.log('Is it a shallow copy?', assignedObj.propB === sourceObj.propB); // Should be true
// Demonstrate its internal nature: it's not a public _.assign
// For multiple sources or customizers, use _.assign from the main lodash package.
const _ = require('lodash'); // Using the main lodash package for comparison
const finalObject = _.assign({}, {x: 1}, {y: 2}, {x: 3});
console.log('Result using _.assign from main lodash:', finalObject);