1.0.0 • Published 4 years ago

mafp v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

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...
1.0.0

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago