Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Count items and compare them against a reference
Simply install it via NPM (npm install countjs
) and require
it
in your code:
var Counter = require('countjs')
var c = new Counter()
countjs
is relatively simple -- just instantiate a counter and keep
adding stuff to it:
var c = new Counter()
c.add('a')
c.add('a')
c.add('b')
Then you can get how many items are there in the counter:
c.get('a') // 2
c.get('b') // 1
c.get() // {a: 2, b: 1}
You can also specify a custom quantity to add:
c.add('a', {qty: 3}) // 2
c.get('a') // 3
And create a diff between counters:
var c1 = new Counter({a: 1})
var c2 = new Counter({b: 1})
c1.diff(c2) // {a: 1, b: 0}
You can also use "references": if an item has qty X
in the reference, then your counter will not be able to
add more than X
qty of that item:
var ref = {a: 1, b: 2}
var c = new Counter({}, ref)
c.add('a') // true
c.add('a') // false
c.add('b', {qty: 3}) // false
c.add('b', {qty: 2}) // true
c.add('c') // false
c.get() // {a: 1, b: 2}
You can force the counter to accept the new value:
var ref = {a: 1}
var c = new Counter({}, ref)
c.add('a') // true
c.add('a') // false
c.add('a', {qty: 1, force: true}) // true
c.get() // {a: 2}
When using references, you can get a diff between the current counter and the reference. For example:
var ref = {a: 1}
var c = new Counter({}, ref)
c.add('a', {qty: 2, force: true}) // true
c.add('b', {qty: 3, force: true}) // true
c.diff() // {a: {mine: 2, other: 1, diff: 1}, b: {mine: 3, other: 0, diff: 3}}
Last but not least, you can get a full comparison between counters:
var c1 = new Counter({a: 1, b: 1, d: 3})
var c2 = new Counter({b: 2, c: 1, d: 3})
comparison = c1.compare(c2)
// {
// a: mine 1, other 0
// b: mine 1, other 2
// c: mine 0, other 1
// d: mine 3, other 3
// }
compare
is, basically, a #diff()
that also includes same values
between counters.
Just run npm test
and welcome to Greenland!
FAQs
A small utility to count things
The npm package countjs receives a total of 9 weekly downloads. As such, countjs popularity was classified as not popular.
We found that countjs 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.