Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
d3-comparator
Advanced tools
A D3 generator for comparator functions. It can be used to easily sort arrays of objects by one or multiple dimensions.
If you want to sort by a single dimension, you end up writing comparators like function cmp(a, b) { return a.value - b.value; }
or function cmp(a, b) { return d3.ascending(a.value, b.value); }
. For sorting by two or more dimensions it gets ugly pretty fast. d3.comparator provides a simple API for generating those comparators.
d3.comparator()
Constructs a new comparator with the default return value 0. I.e. using it will not change sort order.
comparator(a, b)
The comparator can be used with the array sort method.
comparator.order(cmp, [accessor])
Adds a dimension to the comparator. The return value of accessor will be compared with cmp (which has to be a comparator function itself, e.g. d3.ascending). If accessor isn't specified, an identity function function(d) { return d; }
is used.
Dimensions are compared in order. As soon as cmp returns something other than 0
, subsequent dimensions are ignored.
Example using a single dimension:
var cmp = d3.comparator().order(d3.ascending, function(d) { return d.value; });
Example using two dimensions, roughly equivalent to SQL ORDER BY year DESC, value ASC
:
var cmp = d3.comparator()
.order(d3.descending, function(d) { return d.year; })
.order(d3.ascending, function(d) { return d.value; });
Note: These are just comparator functions. To acually sort an array use
someArray.sort(cmp);
Jeremy Stucki, Interactive Things
BSD, see LICENSE.txt
FAQs
Multi-dimensional comparator function generator for D3
The npm package d3-comparator receives a total of 1 weekly downloads. As such, d3-comparator popularity was classified as not popular.
We found that d3-comparator 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 threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.