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

@misec/lightmap

v0.1.4

Published

Extension of Map - adds iterative extensions to Map like map, filter, reduce, sort, etc.

Downloads

3

Readme

LightMap

LightMap is an extension of Map that adds iterative extensions to Map like map, filter, reduce, sort, etc.

NPM

Installation

npm i @misec/lightmap

Usage

Basic usage:

const LightMap = require( '@misec/lightmap' );

const x = new LightMap( [ [ 'a', 'hello' ], [ 'b', 'world' ] ] );
// LightMap { 'a' => 'hello', 'b' => 'world' }

Map usage:

For standard Map usage please refer to MDN Web Docs

.filter:

Filter LightMap based on keys and values based in. Comparisons can be made on the key and/or value.

const x = new LightMap( [ [ 'a', 'hello' ], [ 'b', 'world' ] ] );

x.filter( ( val, key ) => {
	return key === 'a';
} );
// LightMap { 'a' => 'hello' }

.map:

Map LightMap with new key and/or value. Return the new item in a "tuple" form matching the Map paradigm ([ x, y ]).

const x = new LightMap( [ [ 'a', 10 ], [ 'b', 20 ] ] );

x.map( ( val, key ) => {
	return [ key, val + 10 ];
} );
// LightMap { 'a' => 20, 'b' => 30 }

.reduce:

Reduce LightMap with new value. Must return the carriage value just like Array.reduce.

const x = new LightMap( [ [ 'a', 'hello' ], [ 'b', 'world' ] ] );

x.reduce( ( r, [ key, val ] ) => {
	r += val + ' ';
	return r;
}, '' );
// hello world 

.sortKeys:

Map LightMap with sorted key-value pairs.

const x = new LightMap( [ [ 'b', 'world' ], [ 'a', 'hello' ] ] );

x.sortKeys()
// LightMap { 'a' => 'hello', 'b' => 'world' }

.sortValues:

Map LightMap with sorted key-value pairs sorted by value.

const x = new LightMap( [ [ 'a', 10 ], [ 'b', 5 ], [ 'c', 1 ] ] );

x.sortValues( ( a, b ) => a >= b )
// LightMap { 'c' => 1, 'b' => 5, 'a' => 10 }

x.sortValues( ( a, b ) => a <= b )
// LightMap { 'a' => 10, 'b' => 5, 'c' => 1 }

.mapToArray:

maps a LightMap object to an array of arrays in the Map Pattern (re-constructable pattern)

const x = new LightMap( [ [ 'a', 0 ], [ 'b', 1 ] ] );

x.mapToArray();
// [ [ 'a', 0 ], [ 'b', 1 ] ]

.toJSON:

Native class override - returns .mapToArray method

const x = new LightMap( [ [ 'a', 0 ], [ 'b', 1 ] ] );

x.toJSON();
// [ [ 'a', 0 ], [ 'b', 1 ] ]

.toString:

Native class override - returns JSON stringified .mapToArray

const x = new LightMap( [ [ 'a', 0 ], [ 'b', 1 ] ] );

x.toString();
// [["a",0],["b",1]]

.indexOf:

returns the first index at which a given element can be found in the array, or -1 if it is not present

const x = new LightMap( [ [ 'a', 0 ], [ 'b', 1 ] ] );

x.indexOf( 'b' );
// 1

[ Symbol.replace ]:

symbol specifies the method that replaces matched substrings of a string

const x = new LightMap( [ [ '{{ a }}', 'hello' ], [ '{{ b }}', 'world' ] ] );

'{{ a }} {{ b }}'.replace( x );
// hello world

[ Symbol.toPrimitive( string ) ]:

symbol that specifies a function valued property that is called to convert an object to a primitive value

const x = new LightMap( [ [ 'a', 0 ], [ 'b', 1 ] ] );

'' + x;
// [["a",0],["b",1]]

[ Symbol.toPrimitive( number ) ]:

symbol that specifies a function valued property that is called to convert an object to a primitive value

const x = new LightMap( [ [ 'a', 0 ], [ 'b', 1 ] ] );

+x;
// 2 (size of the Map)