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

axial-map

v1.0.7

Published

A wrapper for a JS native Map object to make traversing them a bit easier.

Downloads

38

Readme

Axial Map

A wrapper for a JS native Map object to make traversing them a bit easier.

Why

This is an effort to combine the features of a native Javascript Map object with a double-linked list. Data within the structure can be accessed using a key like any normal JS object but can also maintain an order and be traversed using next() and previous() methods. A cursor can be set to prevent the need to loop through an entire object.

In addition to the traversability of the object a user can directly set the cursor to a specific key. Other convenience methods like slice(), splice(), and each() have been added.

Rotating object store

The Axial Map can also be instantiated with a maxSize property. When the map is "full" and a new element is added to the map, the map will use an internal fifo() method (First In First Out) to remove the oldest element in the map. This is useful for keeping an ordered rotating map of data.

CodeSandbox Demo

To see an example and to try it out go to the codesandbox.io page.

Documentation

Table of Contents

constructor

Parameters

  • opts Object (optional, default {})

Returns void

add

Parameters

  • key (string | integer)
  • object any

Returns void

fifo

First in first out. Remove the oldest item from the map and the keys array

Returns void

remove

Removes and returns an element from the map given its key.

Parameters

Returns (Array | null)

firstKey

Returns the first key of the keys array or null.

Returns (string | null)

first

Returns the first item in the map.

Returns (any | null)

nthKey

Return the (n)th key of the keys array.

Parameters

  • n integer

Returns (string | null)

nth

Returns the (n)th item of the map or null.

Parameters

  • n any

Returns (any | null)

lastKey

Returns the last key of the keys array

Returns (string | null)

last

Returns the last item of the map or null.

Parameters

  • n any

Returns (any | null)

get

Get an item from the map given its key.

Parameters

Returns (any | null)

setCursor

Set the cursor to the position of key in the keys array.

Parameters

Returns void

current

Returns the item of the map that corresponds to the current cursor location.

Returns (any | null)

nextOrLast

Advances the cursor from its current position and returns the item of the map that corresponds with the new cursor position. If the cursor would advance out of bounds, then the current position (the last position) is maintained and that item is returned.

null is returned if the map is empty.

Returns (any | null)

next

Advances the cursor and returns the next item. If the "next" item is out of bounds null is returned.

Returns (any | null)

previousOrFirst

Rolls back the cursor 1 position from its current position and returns the item of the map that corresponds with the new cursor position. If the cursor would roll back out of bounds, then the current position (the first position) is maintained and that item is returned.

null is returned if the map is empty.

Returns (any | null)

previous

Rolls back the cursor 1 position and returns the next item. If the "previous" item is out of bounds null is returned.

Returns (any | null)

slice

Copies a selection of the map and returns a multidimensional array containing keys and items from start to end exclusive.

Parameters

  • start integer
  • end integer (optional, default Infinity)

Returns Array

splice

Removes a group of items from start to end exclusive. The removed items are returned as a multidimensional array containing keys and items.

Parameters

  • start integer
  • deleteCount integer (optional, default Infinity)

each

Will iterate over each item in the map invoking the provided callback. The callback is provided three arguments. The element itself, the key, and the iteration number (index).

Parameters

Returns void

reset

Reset the AxialMap to it's initial state. The maxSize property is maintained.