
Research
Security News
The Landscape of Malicious Open Source Packages: 2025 Mid‑Year Threat Report
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
Uses binary search to insert a value into any sorted collection.
Requires Node.js 8.3.0 or above.
npm i binsert
The module exports a single function.
compare
(function, array, or any):
a
and b
, expected to return -1
if a
is less than b
, 1
if a
is greater than b
, and 0
if they are equal.get
(function): A callback that should return a value for a given index from 0
to length - 1
.insert
(function): A callback that accepts the index at which value
should be inserted. The callback is not expected to return anything. If insert
is omitted, it is assumed you will take care of insertion later using the index
return value.length
(positive integer): The length of the collection.multiple
(string): Only applies if unique
is false
or undefined. Specifies behavior in the event that more than one existing collection item is sort-equivalent with value
. If set to first
or last
, then value
will be inserted before/after the first/last sort-equivalent item, respectively. (This will slow down the insert operation.) Otherwise, value
will be inserted anywhere in the range of sort-equivalent items.set
(function): A callback that accepts the index at which an existing value should be overwritten with value
. This only applies if unique
is true
. The callback is not expected to return anything.unique
(bool): If set to true
, then no item in the collection may be sort-equivalent with another; so if an existing item is sort-equivalent with value
, it will either be overwritten with the set
callback (if one is provided) or else nothing will happen (if set
is not specified). If set to false
, multiple sort-equivalent items are allowed, so value
will always be inserted. Defaults to false
.value
(any): The value to insert.Returns an object:
found
(boolean): true
if compare
reported that the collection already contained a value with the same sort value as value
; false
otherwise.index
(positive integer): The index at which value
was (or should be) inserted.const binsert = require('binsert')
const arr = ['a', 'c', 'e']
binsert({get: i => arr[i], insert: (i, v) => { arr.splice(i, 0, v) }, length: arr.length, value: 'b'}) // {found: false, index: 1}
arr // ['a', 'b', 'c', 'e']
This module is part of the “b” family of binary search modules.
FAQs
Uses binary search to insert a value into any sorted collection.
The npm package binsert receives a total of 7 weekly downloads. As such, binsert popularity was classified as not popular.
We found that binsert demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A look at the top trends in how threat actors are weaponizing open source packages to deliver malware and persist across the software supply chain.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.