Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reverse-iterable-map

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reverse-iterable-map

A reverse-iterable map implementation based on the built-in Map object

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-87.5%
Maintainers
1
Weekly downloads
 
Created
Source

reverse-iterable-map.js

A reverse-iterable map implementation based on the built-in Map object.

Table of Contents

Install

… for JavaScript

Downloads an ES module file.

curl -O https://github.com/kleinfreund/reverse-iterable-map.js/blob/master/src/reverse-iterable-map.js
import { ReverseIterableMap } from './src/reverse-iterable-map.js';

const map = new ReverseIterableMap();

… for Node.js (8.5+)

Installs the node package as a dependency. It doesn’t have any non-development dependencies itself.

npm install --save reverse-iterable-map
import { ReverseIterableMap } from 'reverse-iterable-map';

const map = new ReverseIterableMap();

Note, that Node.js version 8.5 or higher is required, as it comes with support for ES modules. If you don’t want to use it as an ES module, you will need to transpile the package yourself.

Examples

… on the website::

kleinfreund.github.io/reverse-iterable-map.js

Prints test results to the console.

… on a local HTTP server:

npm run example

Prints test results to the console.

Tests

… with Node’s experimental ES module feature:

npm test

Why?

Part of the additions to ECMAScript 2015 are the iteration protocols: Iterable and iterator. The former allows arbitrary objects to become iterable. Following the rules of the protocol gives one iteration capabilities via the following techniques:

However, only the iteration in one direction is considered by the specification at the time. This means that we only get forward-iteration by default.

Now, with the iteration protocols, we could redefine the iteration behavior for our purpose and make an object backwards-iterable. At the same time, this means losing the ability to iterate forwards.

If you need both a forwards- and backwards-iterable object, this implementation might be for you.

But why a map?

That’s what I needed. To be precise, I needed to access an iterator at a specific location in my data structure and be able to iterate in both directions.

I tried to stick to the Map interface as close as possible.

Implementing a reverse-iterable array, for example, can be accomplished by using the same techniques of this implementation.

Keywords

FAQs

Package last updated on 22 Dec 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc