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

dictionaryjs

v1.0.10

Published

A simple dictionary wrapper for JavaScript providing hashmap functionality with the added benefit of accessing keys using box and dot operators!

Downloads

10,272

Readme

A simple dictionary wrapper for JavaScript providing hashmap functionality with the added benefit of accessing keys using box and dot operators!

Features

  • Typescript source-code.
  • Stores key/value pairs within a Associative Array like collections.
  • Use dot operator and brackets to access keys.
  • Remove key using the DELETE operator.
  • Iterator to support for..of looping.
  • Async/await support with Promises.
  • Set and Get methods for accessing keys.
  • GetDefault method with default value if value is not found.
  • Remove method to remove key from collection.
  • Size property to get total key count within collection.
  • Built-in forEach and asyncForEach methods for looping.
  • Empty and asyncEmpty to remove all entries from collection.
  • Has method checking if key is within collection.

install

Requirements

  • ECMAScript 2017 (ES2017)
  • Node.JS 8.x or later (tested on 8.1.3)

See branch "classic" for earlier versions of Node.JS.

API

Setup

To use simply include at the top of your script:

TypeScript example:

Set

Store values to a key:

Get

Get a value from a key:

Get Default

Get the value of a key or return the default value.

If key is not contained within dictionary then the default value will be returned.

Remove

Remove an entry by key:

Size

Determine how many entries are in the dictionary, returns an integer.

Has

Check if key is in the dictionary, returns boolean.

Contains

Check if value is in the dictionary, returns boolean.

Empty

Removes all dictionary entries. This method is blocking.

Async Empty

Removes all dictionary entries. This method is non-blocking.

Or as a promise:

For Each

To loop over each entry in the dictionary use: This method is blocking.

To break and end looping:

Async For Each

To loop over each entry in a non-blocking manner:

To break and end looping:

(Optional) You may also call a function once the asyncForEach loop is complete:

Or as a promise:

Using the (for ... of) loop:

Loop through all entries. This is blocking.

To loop through each key within the collection you may use the for...in loop. This is blocking.

Entries Iterator

Loop through all key and value pairs at once:

Get Keys

Returns an array of keys:

Get Values

Returns an array of values:

Initial Key/Values

Declare the Dictionary to have initial key/values with the constructor:

Caching Keys

An option in the constructor (defaults to false) allows you to have the keys cached so they are not recalculated each time you begin to iterate through the collection.

First enable caching by passing true in the constructor:

Then as you interact with the collection the cache will invalidate on its own as long as you use the methods built into the class. In other words using the dot or box operators to set or delete keys will not invalidate the key cache.

In the event you wish to still use the dot or box operators you can manually invalidate the cache yourself...