Lodash Internal `baseAssign` Utility

3.2.0 · abandoned · verified Tue Apr 21

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

Warnings

Install

Imports

Quickstart

This code demonstrates how to `require` and use the `baseAssign` function for shallow property assignment. It also highlights that `baseAssign` is an internal, low-level utility, contrasting its usage with the public `_.assign` method from the main Lodash library.

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);

view raw JSON →