Registry / database / lodash-joins

lodash-joins

JSON →
library3.1.1jsnpmunverified

A JavaScript library providing SQL-style join algorithms for arrays of objects, built as an extension to Lodash. Current stable version 3.1.1, released in 2022, with low release cadence. Key differentiators: supports multiple join algorithms (nested loop, hash, sorted merge) and many join types (inner, left/right outer, full outer, left/right semi, left/right anti). Ships TypeScript types. Only dependency is Lodash. Coercive key comparisons support Dates and similar types.

npm install lodash-joins
INSTALL
IMPORT
SIG · LODASH-JOINS
L
lodash-joins
databasejavascriptv3.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

_
✓ import _ from 'lodash'; import 'lodash-joins';
✗ import { hashInnerJoin } from 'lodash-joins';
lodash-joins mutates Lodash's _ object; you must import Lodash first, then import the library for side effects.
hashInnerJoin
✓ _.hashInnerJoin(left, leftKey, right, rightKey, merger);
✗ hashInnerJoin(left, leftKey, right, rightKey, merger);
All join functions are attached to Lodash's _ object, not exported as named exports.
nestedLoopInnerJoin
✓ _.nestedLoopInnerJoin(left, leftKey, right, rightKey, merger);
✗ import { nestedLoopInnerJoin } from 'lodash-joins';
Same as other join functions; attached to _.

Demonstrates basic usage of hashInnerJoin with two arrays, key accessor strings, and a merger function.

const _ = require('lodash'); require('lodash-joins'); const employees = [ { id: 1, name: 'Alice', deptId: 10 }, { id: 2, name: 'Bob', deptId: 20 }, ]; const departments = [ { id: 10, name: 'Engineering' }, { id: 30, name: 'Marketing' }, ]; // Inner join on deptId const result = _.hashInnerJoin( employees, 'deptId', departments, 'id', (left, right) => ({ employeeName: left.name, departmentName: right ? right.name : null, }) ); console.log(result); // Output: [ { employeeName: 'Alice', departmentName: 'Engineering' } ]
Debug
Known issues
gotchaLibrary mutates Lodash's _ object via side effects; importing for side effects is required.
fix
Always import lodash-joins as a side-effect import: require('lodash-joins') or import 'lodash-joins'; do not attempt to destructure functions from it.
affects: >=1.0.0
gotchaAccessor functions can be strings (property name) or functions; strings are used directly as pluck, not deep paths like 'a.b'.
fix
Use a string for simple property access, or provide a function to extract nested values.
affects: >=1.0.0
breakingIn v3, the order of parameters in sorted merge join changed: leftKeyAccessor and rightKeyAccessor are now swapped to match other joins.
fix
Update calls to sortedMerge* joins to match the new parameter order: (leftArray, leftKeyAccessor, rightArray, rightKeyAccessor, merger).
affects: >=3.0.0
deprecated_.pluck is deprecated in Lodash; accessor strings are used directly instead.
fix
Do not use _.pluck; pass property name strings as accessors.
affects: >=2.0.0
gotchaMerger function receives null for left or right row in outer joins; must handle null gracefully.
fix
In merger, check that left or right is not null before accessing properties; use conditional operators.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught TypeError: _.hashInnerJoin is not a function
lodash-joins not imported properly; functions are attached to Lodash's _ object.
fix
Ensure you require or import lodash-joins after lodash: const _ = require('lodash'); require('lodash-joins'); Then use _.hashInnerJoin(...).
TypeError: Cannot read properties of undefined (reading 'name')
Merger function called with null for right row in outer join.
fix
In the merger, check for null: (left, right) => ({ name: left ? left.name : null, ... })
Error: sortedMergeInnerJoin no longer supports old parameter order
Parameter order changed in v3.
fix
Update to new order: (leftArray, leftKeyAccessor, rightArray, rightKeyAccessor, merger).
Upgrade
Version history
3.1.1latest on npm
Audit
Dependencies
lodashrequiredAll join functions are attached to Lodash's _ object; library extends Lodash
Agent activity
4 hits · last 30 days
node
4
Resources
lodash-joins — npm install lodash-joins · libregistry