New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mafp

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mafp

`Map` object with native `filter`, `map`,`reduce`, `every`, and `some` methods. Zero Dependencies.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

nycrc config on GitHub GitHub issues GitHub forks GitHub stars GitHub license

MaFP

Map object with native filter, map,reduce, every, and some methods. Zero Dependencies.

https://www.npmjs.com/package/mafp

Motivation

Maps don’t have these methods natively. One would first need to copy an iterator into an array [...iterator] before using .map, .filter, .reduce. MaFP allows you to use those methods natively.

Installation

npm install mafp

OR

yarn add mafp

Initialize

Javascript

const MaFP = require("mafp").default;
const test = new MaFP([
  ["A", true],
  ["B", false],
  ["C", true],
  ["D", true],
]);

TypeScript

import MaFP from "mafp";

// Diamond notation needed if no arguments are provided
const test = new MaFP<string, boolean>();

// OR with arguments, types are inferred.
const test = new MaFP([
  ["A", true],
  ["B", false],
  ["C", true],
  ["D", true],
]);

Usage

test.filter(val => val);
// MaFP [Map] { 'A' => true, 'C' => true, 'D' => true }

test.filterToArray(val => val);
// [ 'A', true ], [ 'C', true ], [ 'D', true ] ]

test.map(val => !val);
// MaFP [Map] { 'A' => false, 'B' => true, 'C' => false, 'D' => false }

test.mapToArray(val => !val);
// [ [ 'A', false ], [ 'B', true ], [ 'C', false ], [ 'D', false ] ]

test.reduce((acc, curr) => acc + Number(curr), 0);
// 3

test.every(val => val);
// false

test.some(val => val);
// true

Also works with .keys() and .values():

test.keys().filter(key => key !== 'B');
// [ 'A', 'C', 'D' ]

// ETC...

Keywords

FAQs

Package last updated on 28 Apr 2020

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