
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
frequency-set
Advanced tools
An ES6 Set compliant structure that keeps the frequency of occurrences.
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i frequency-set
# or
$ yarn add frequency-set
const FrequencySet = require("frequency-set");
const MySet = new FrequencySet(["foo", "bar"]);
MySet.add("foo");
MySet.add("foo");
MySet.add("bar");
console.log([...MySet.entries()]); // [["foo", 3], ["bar", 2]]
const clone = new FrequencySet(MySet);
console.log(clone);
FrequencySet implements exactly the same interfaces as an ES6 Set. Except for the @@ Iteration Symbol and the entries(). Instead of returning the unique value as key and value, FrequencySet return the unique value as key and the count as value.
const mySet = new FrequencySet(["foo", "foo", "bar"]);
for (const [uniqueValue, count] of mySet) {
console.log([uniqueValue, count]); // [foo, 2] and [bar, 1]
}
Also the add method has been extended with a additional count
argument witch take a number.
const mySet = new FrequencySet().add("foo", 10);
console.log(mySet.toJSON()); // ["foo", 10]
FrequencySet implement a custom toJSON() method which will allow an automatic transformation into JSON.
const mySet = new FrequencySet(["foo", "foo", "bar"]);
console.log(mySet.toJSON()); // [foo, 2] and [bar, 1];
The toJSON method does not take into account functions and objects.
Thanks goes to these wonderful people (emoji key):
Gentilhomme 💻 🐛 👀 📖 🛡️ |
MIT
FAQs
A set that keeps the frequency of occurrences.
The npm package frequency-set receives a total of 665 weekly downloads. As such, frequency-set popularity was classified as not popular.
We found that frequency-set 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.