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

pushmap

v0.2.3

Published

Give power to any map. PushMap provides great methods for improving maps. Some examples are: .push() .all() .add()

Downloads

21

Readme

PushMap

Summary

  • Give power to any map. PushMap provides great methods for improving maps. Some examples are: .push() .all() .add().

  • Module developed by tnfAngel#8642.

Usage


let PushMap = require("pushmap")

let pmap = new PushMap()

Example


let PushMap = require("pushmap")

let pmap = new PushMap()

// Now we can use PushMap Methods on this map:

pmap.push('foo', 'bar') 

// Normal Map get method

pmap.get('foo') // ['bar']


Documentation

PushMap Methods

Pushmap includes all normal Map methods and:

  • Push | .push(key, element) -> updatedRow

Creates an array or push an element to original array of map.


pmap.push('foo', 'bar') 

pmap.get('foo') // ['bar']

pmap.push('foo', 'baz') 

pmap.get('foo') // ['bar', 'baz']
  • RemoveIndex | .removeIndex(key, index) -> updatedRow || false

Remove an element from an array by its index or return false if something went wrong.


pmap.push('foo', 'bar') // ['bar']

pmap.push('foo', 'baz') // ['bar', 'baz']

pmap.removeIndex('foo', 0) // Remove the element 0 of the array obtained by his key. 

pmap.get('foo') // ['baz']
  • FilterElement | .filterElement(key, callbackFn, [thisArg]) -> updatedRow || false

Same functionality as Array.prototype.filter(), but sets the result to the array. return false if something went wrong.


pmap.push('foo', 'bar') // ['bar']

pmap.push('foo', 'baz') // ['bar', 'baz']

pmap.filterElement('foo', x => x != 'baz') // Remove the element that has a value of baz.

// Also can be used with objects

pmap.push('qux', 'foo') // ['foo']

pmap.push('qux', {'bar': 'baz'}) // ['foo',  {'bar': 'baz'}]

pmap.filterElement('qux', x => !x.bar)

pmap.get('qux') // ['foo']
  • Shift | .shift() -> updatedRow

Same functionality as Array.prototype.shift(), but sets the result to the array.


pmap.push('foo', 'bar') // ['bar']

pmap.push('foo', 'baz') // ['bar', 'baz']

pmap.shift() // bar

pmap.get('foo') // ['baz']
  • All | .all() -> array

Returns all the elements of the map in an array of objects.


pmap.set('foo', 'bar') 

pmap.set('baz', 'qux') 

pmap.all() // [{key: 'foo', value: 'bar'}, {key: 'baz', value: 'qux'}]

// Also you can iterate the all method:

pmap.all().forEach(element => {
    console.log(element) // {key: x, value: x}
    console.log(element.key) // foo & baz
    console.log(element.value) // bar & qux
})

  • ToObject | .toObject() -> object

Same as all method but returns an object.


pmap.set('foo', 'bar') 

pmap.set('baz', 'qux') 

pmap.toObject() // {
                //    'foo': 'bar'
                //    'baz': 'qux'
                // {
  • Add | .add(key, number) -> updatedRow

Adds a number to a key in the map. (If no existing number, it will add to 0)


pmap.add('corge', 1) 

pmap.get('corge') // 1

pmap.add('corge', 2) 

pmap.get('corge') // 3

// You can't add to a value that is not a number

pmap.set('someString', 'someString') 

pmap.add('someString', 1) // PushMap error 
  • Subtract | .subtract(key, number) -> updatedRow

Subtracts a number to a key in the map. (If no existing number, it will subtract from 0)


pmap.subtract('grault', 1) 

pmap.get('grault') // -1

pmap.subtract('grault', 2) 

pmap.get('grault') // -3

// You can't subtract to a value that is not a number

pmap.set('someString', 'someString') 

pmap.subtract('someString', 1) // PushMap error 
  • Type | .type(key) -> typeof

Returns the type of a value in the map.


pmap.set('someString', 'someString') 

pmap.type('someString') // "string"

pmap.set('someObject', {foo: 'bar'}) 

pmap.type('someObject') // "object"

Normal Map Methods

Pushmap includes all normal Map methods.

  • Clear | .clear()

Removes all key-value pairs from the Map object.


pmap.clear()
  • Delete | .delete(key)

Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.


pmap.delete('foo')
  • Get | .get(key)

Returns the value associated to the key, or undefined if there is none.


pmap.get('foo')
  • Has | .has(key)

Returns a boolean asserting whether a value has been associated to the key in the Map object or not.


pmap.has('foo')
  • Set | .set(key, value)

Sets the value for the key in the Map object. Returns the Map object.


pmap.set('foo', 'bar')
  • Keys | .keys()

Returns a new Iterator object that contains the keys for each element in the Map object in insertion order.


pmap.keys()
  • Values | .values()

Returns a new Iterator object that contains the values for each element in the Map object in insertion order.


pmap.values()
  • Entries | .entries()

Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order.


pmap.entries()
  • ForEach | .forEach(callbackFn[, thisArg])

Calls callbackFn once for each key-value pair present in the Map object, in insertion order. If a thisArg parameter is provided to forEach, it will be used as the this value for each callback.


pmap.forEach(x => {
    console.log(x)
})

Instalation

If you have instalation issues, join our support server.

Linux & Windows

  1. Open: CMD
  2. Put: npm i pushmap@latest

Mac

  1. Install: XCode
  2. Put: npm i pushmap@latest