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

@munierujp/super-map

v1.1.1

Published

SuperMap class extends Map and add some methods, such as higher-order function.

Downloads

7

Readme

npm version JavaScript Style Guide

SuperMap.js

SuperMap class extends Map and add some methods, such as higher-order function.

Installation

$ npm i @munierujp/super-map

or

$ yarn add @munierujp/super-map

Use in your script

const SuperMap = require('@munierujp/super-map')

Definition

Entry

Entry is expressed as array which has two elements(0:key, 1:value).

const entry1 = ['foo', 'Foo']
const entry2 = ['bar', 'Bar']
const map = SuperMap.of(entry1, entry2)
console.log(map) // {"foo" => "Foo", "bar" => "Bar"}

Usage

You can use Map's self methods and below additional methods.

Creation

SuperMap.empty()

const map = SuperMap.empty()
console.log(map) // {}

SuperMap.of(...entries)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map) // { 'foo' => 'Foo', 'bar' => 'Bar' }

SuperMap.from(iterable)

const map = new Map([['foo', 'Foo'], ['bar', 'Bar']])
const superMap = SuperMap.from(map)
console.log(superMap) // { 'foo' => 'Foo', 'bar' => 'Bar' }

Intermediate operation

SuperMap.peek(callback)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const tmpMap = new Map()
const peekedMap = map.peek((v, k) => tmpMap.set(k, v))
console.log(peekedMap) // { 'foo' => 'Foo', 'bar' => 'Bar' }
console.log(tmpMap) // { 'foo' => 'Foo', 'bar' => 'Bar' }

SuperMap.peek(callback, thisArg)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const thisArg = 'baz'
const tmpMap = new Map()
const peekedMap = map.peek(function (v, k) {
  tmpMap.set(k, v + this)
}, thisArg)
console.log(peekedMap) // { 'foo' => 'Foo', 'bar' => 'Bar' }
console.log(tmpMap) // { 'foo' => 'Foobaz', 'bar' => 'Barbaz' }

SuperMap.filter(matcher)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const filteredMap = map.filter((v, k) => k.startsWith('f'))
console.log(filteredMap) // { 'foo' => 'Foo' }

SuperMap.map(mapper)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const mappedMap = map.map((v, k) => [k + '_', v + '-'])
console.log(mappedMap) // { 'foo_' => 'Foo-', 'bar_' => 'Bar-' }

SuperMap.mapEntry(mapper)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const mappedMap = map.mapEntry((v, k) => [k + '_', v + '-'])
console.log(mappedMap) // { 'foo_' => 'Foo-', 'bar_' => 'Bar-' }

SuperMap.mapKey(mapper)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const mappedMap = map.mapKey((v, k) => k + '_')
console.log(mappedMap) // { 'foo_' => 'Foo', 'bar_' => 'Bar' }

SuperMap.mapValue(mapper)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const mappedMap = map.mapValue((v, k) => v + '-')
console.log(mappedMap) // { 'foo' => 'Foo-', 'bar' => 'Bar-' }

Terminal operation

SuperMap.find(matcher)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const entry = map.find((v, k) => k.startsWith('f'))
console.log(entry) // [ 'foo', 'Foo' ]
const map = SuperMap.empty()
const entry = map.find((v, k) => k.startsWith('f'))
console.log(entry) // undefined

SuperMap.findEntry(matcher)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const entry = map.findEntry((v, k) => k.startsWith('f'))
console.log(entry) // [ 'foo', 'Foo' ]
const map = SuperMap.empty()
const entry = map.findEntry((v, k) => k.startsWith('f'))
console.log(entry) // undefined

SuperMap.findKey(matcher)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const key = map.findKey((v, k) => k.startsWith('f'))
console.log(key) // foo
const map = SuperMap.empty()
const key = map.findKey((v, k) => k.startsWith('f'))
console.log(key) // undefined

SuperMap.findValue(matcher)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const value = map.findValue((v, k) => k.startsWith('f'))
console.log(value) // Foo
const map = SuperMap.empty()
const value = map.findValue((v, k) => k.startsWith('f'))
console.log(value) // undefined

SuperMap.hasEntry(entry)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.hasEntry(['foo', 'Foo'])) // true
const map = SuperMap.empty()
console.log(map.hasEntry(['foo', 'Foo'])) // false

SuperMap.hasKey(key)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.hasKey('foo')) // true
const map = SuperMap.empty()
console.log(map.hasKey('foo')) // false

SuperMap.hasValue(value)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.hasValue('Foo')) // true
const map = SuperMap.empty()
console.log(map.hasValue('Foo')) // false

SuperMap.some(matcher)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.some((v, k) => k.startsWith('f'))) // true
const map = SuperMap.empty()
console.log(map.some((v, k) => k.startsWith('f'))) // false

SuperMap.every(matcher)

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.every((v, k) => k.length === 3)) // true
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.every((v, k) => k.startsWith('f'))) // false

SuperMap.isEmpty()

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.isEmpty()) // false
const map = SuperMap.empty()
console.log(map.isEmpty()) // true

SuperMap.isNotEmpty()

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.isNotEmpty()) // true
const map = SuperMap.empty()
console.log(map.isNotEmpty()) // false

SuperMap.toEntries()

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const entries = map.toEntries()
console.log(entries) // [ [ 'foo', 'Foo' ], [ 'bar', 'Bar' ] ]

SuperMap.toKeys()

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const keys = map.toKeys()
console.log(keys) // [ 'foo', 'bar' ]

SuperMap.toValues()

const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const values = map.toValues()
console.log(values) // [ 'Foo', 'Bar' ]

SuperMap.toMap()

const superMap = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const map = superMap.toMap()
console.log(map) // { 'foo' => 'Foo', 'bar' => 'Bar' }