Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
A collection of binary search functions for sorted arrays.
Requires Node.js 8.3.0 or above.
npm i barr
The module exports an object with four function methods.
includes (arr, value, [options])
arr
(array): The sorted array which may or may not contain value
.value
(any): The value to look for in arr
.compare
(function, array, or any): Specifies how array elements will be compared:
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.compare
. If any two Map/object elements in arr
have values for that key that are equal, the next key in the compare
array is used, and so on. If any given element in a compare
array is itself an array, it is interpreted as a nested keychain.Returns true
if arr
contains an element that compare
says is sort-equivalent to value
.
const {includes} = require('barr')
includes([1, 2, 3], 2) // true
indexOf (arr, value, [options])
arr
(array): The sorted array which may or may not contain value
.value
(any): The value to look for in arr
.compare
(function, array, or any): Specifies how array elements will be compared. Refer above to this option’s definition under the documentation for includes
.multiple
(string): Specifies behavior in the event that more than one existing array element is sort-equivalent with value
. If set to first
or last
, the index of the first or last sort-equivalent element (respectively) will be returned. (Note that this will slow down the seek operation.) Otherwise, the index of whatever sort-equivalent item the algorithm comes across first will be returned.Returns the integer index if one is found; otherwise returns -1
.
insert (arr, value, [options])
arr
(array): The array into which to insert value
.value
(any): The value to insert into arr
.compare
(function, array, or any): Specifies how array elements will be compared. Refer above to this option’s definition under the documentation for includes
.multiple
(string): Only applies if unique
is false
or undefined. Specifies behavior in the event that more than one existing array element is sort-equivalent with value
. If set to first
or last
, then value
will be inserted before/after the first/last sort-equivalent element, respectively. (This will slow down the insert operation.) Otherwise, value
will be inserted anywhere in the range of sort-equivalent items.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 be overwritten. If set to false
, multiple sort-equivalent items are allowed, so value
will always be inserted. Defaults to false
.Returns an object:
found
(boolean): true
if compare
reported that arr
already contains a value with the same sort value as value
; false
otherwise.index
(positive integer): The index in arr
at which value
was inserted.const {insert} = require('barr')
const arr = ['a', 'c', 'e']
insert(arr, 'b') // {found: false, index: 1}
arr // ['a', 'b', 'c', 'e']
insert(arr, 'd') // {found: false, index: 3}
arr // ['a', 'b', 'c', 'd', 'e']
insert(arr, 'e', {multiple: 'last'}) // {found: true, index: 5}
arr // ['a', 'b', 'c', 'd', 'e', 'e']
// inserted here--^
insert(arr, 'e', {multiple: 'first'}) // {found: true, index: 4}
arr // ['a', 'b', 'c', 'd', 'e', 'e', 'e']
// inserted here--^
push (arr, ...values)
arr
(array): The array into which to insert value
.values
(one or more of: any): The values to insert into arr
.Returns the new length of arr
.
const {push} = require('barr')
const arr = ['a', 'c', 'e']
push(arr, 'b', 'd') // 5
arr // ['a', 'b', 'c', 'd', 'e']
This module is part of the “b” family of binary search modules.
FAQs
A collection of binary search functions for sorted arrays.
We found that barr 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.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.