npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

map-tree

v1.1.1

Published

Create Map trees usefull for property inheritance

Downloads

13

Readme

map-tree

npm Travis (.org) Codecov GitHub npm

MapTree structure, allows Maps to lookup elements in its Map children in a BFS way.

  • Solves Map inheritance
  • Allows overrides by setting keys on parents
  • Similar interface to the Map you love
  • Uses Map and Set under the hood to keep lookups and changes fast
  • Fundamental algorithm used is Breadth-first search (BSF)
  • Does not test for cycles, thus does not support graphs
  • Dependency free

Installation

npm install map-tree --save

Usage

const MapTree = require("map-tree");

const foodMap = new MapTree([["steak", {value: 1}]]);

const fruitMap = new MapTree();
fruitMap.set("banana", {value: 2});
fruitMap.set("apple", {value: 3});

foodMap.children.add(fruitMap);
foodMap.get("banana", true); // {value: 2}
foodMap.has("steak"); // true
foodMap.has("apple"); // false (not traversing)

for (let [key, value] of foodMap.entries(true)) {
    // will traverse children too!
}

Syntax

new MapTree([iterable [, children]]);
  • iterable : Array or iterable object of key-value pairs.

  • children : Array or iterable object of MapTree objects defining the children of the new object.

Properties

  • Map.prototype.size : Returns the number of key/value pairs in the MapTree object. It does not include children.

  • Map.prototype.children : Returns the MapTree children Set. The Set can be changed to add/remove/clear children. Property can be set provided an array or iterable object of MapTree objects to replace all children.

Methods

  • Map.prototype.clear() : Removes all key/value pairs from the MapTree object. Does not clear the children.

  • Map.prototype.delete(key) : Removes element from MapTree and returns true if the element did not exist, or false if the element did not. It will not delete from the children.

  • Map.prototype.entries([traverse]) : Returns a new Iterator object that contains an array of [key, value] for each element in the MapTree object in insertion order. If traverse is true, the Iterator will include children [key, value] in a BFS order.

  • Map.prototype.forEach(callbackFn [, traverse [, thisArg]]) : Calls callbackFn once for each key-value pair present in the MapTree object, in insertion order. If traverse is true, key-value pair present in children will be provided in BFS order. If a thisArg parameter is provided to forEach, it will be used as the this value for each callback.

  • Map.prototype.get(key[, traverse]) : Returns the value associated to the key, or undefined if there is none. If traverse is true, the key will be matched with children in BFS order.

  • Map.prototype.has(key[, traverse]) : Returns a boolean asserting whether a value has been associated to the key in the MapTree object or not. If traverse is true, the key will be matched with children in BFS order.

  • Map.prototype.keys([traverse]) : Returns a new Iterator object that contains the keys for each element in the MapTree object in insertion order. If traverse is true, the Iterator will include children keys in a BFS order.

  • Map.prototype.set(key, value) : Sets the value for the key in the MapTree object. Returns the MapTree object.

  • Map.prototype.values([traverse]) : Returns a new Iterator object that contains the values for each element in the MapTree object in insertion order. If traverse is true, the Iterator will include children values in a BFS order.

  • Map.prototype[@@iterator]() : Returns a new Iterator object that contains an array of [key, value] for each element in the MapTree object in insertion order. It does not include children.