npm package: @munierujp/super-map
Description: SuperMap class extends Map and add some methods, such as higher-order function.
Latest version: 1.1.1

[![npm version](https://badge.fury.io/js/%40munierujp%2Fsuper-map.svg)](https://badge.fury.io/js/%40munierujp%2Fsuper-map)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

# SuperMap.js
SuperMap class extends Map and add some methods, such as higher-order function.

## Installation
```sh
$ npm i @munierujp/super-map
```

or

```sh
$ yarn add @munierujp/super-map
```

## Use in your script
```js
const SuperMap = require('@munierujp/super-map')
```

## Definition
### Entry
Entry is expressed as array which has two elements(0:key, 1:value).

```js
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()
```js
const map = SuperMap.empty()
console.log(map) // {}
```

#### SuperMap.of(...entries)
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map) // { 'foo' => 'Foo', 'bar' => 'Bar' }
```

#### SuperMap.from(iterable)
```js
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)
```js
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)
```js
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)
```js
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)
```js
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)
```js
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)
```js
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)
```js
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)
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const entry = map.find((v, k) => k.startsWith('f'))
console.log(entry) // [ 'foo', 'Foo' ]
```

```js
const map = SuperMap.empty()
const entry = map.find((v, k) => k.startsWith('f'))
console.log(entry) // undefined
```

#### SuperMap.findEntry(matcher)
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const entry = map.findEntry((v, k) => k.startsWith('f'))
console.log(entry) // [ 'foo', 'Foo' ]
```

```js
const map = SuperMap.empty()
const entry = map.findEntry((v, k) => k.startsWith('f'))
console.log(entry) // undefined
```

#### SuperMap.findKey(matcher)
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const key = map.findKey((v, k) => k.startsWith('f'))
console.log(key) // foo
```

```js
const map = SuperMap.empty()
const key = map.findKey((v, k) => k.startsWith('f'))
console.log(key) // undefined
```

#### SuperMap.findValue(matcher)
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const value = map.findValue((v, k) => k.startsWith('f'))
console.log(value) // Foo
```

```js
const map = SuperMap.empty()
const value = map.findValue((v, k) => k.startsWith('f'))
console.log(value) // undefined
```

#### SuperMap.hasEntry(entry)
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.hasEntry(['foo', 'Foo'])) // true
```

```js
const map = SuperMap.empty()
console.log(map.hasEntry(['foo', 'Foo'])) // false
```

#### SuperMap.hasKey(key)
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.hasKey('foo')) // true
```

```js
const map = SuperMap.empty()
console.log(map.hasKey('foo')) // false
```

#### SuperMap.hasValue(value)
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.hasValue('Foo')) // true
```

```js
const map = SuperMap.empty()
console.log(map.hasValue('Foo')) // false
```

#### SuperMap.some(matcher)
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.some((v, k) => k.startsWith('f'))) // true
```

```js
const map = SuperMap.empty()
console.log(map.some((v, k) => k.startsWith('f'))) // false
```

#### SuperMap.every(matcher)
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.every((v, k) => k.length === 3)) // true
```

```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.every((v, k) => k.startsWith('f'))) // false
```

#### SuperMap.isEmpty()
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.isEmpty()) // false
```

```js
const map = SuperMap.empty()
console.log(map.isEmpty()) // true
```

#### SuperMap.isNotEmpty()
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
console.log(map.isNotEmpty()) // true
```

```js
const map = SuperMap.empty()
console.log(map.isNotEmpty()) // false
```

#### SuperMap.toEntries()
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const entries = map.toEntries()
console.log(entries) // [ [ 'foo', 'Foo' ], [ 'bar', 'Bar' ] ]
```

#### SuperMap.toKeys()
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const keys = map.toKeys()
console.log(keys) // [ 'foo', 'bar' ]
```

#### SuperMap.toValues()
```js
const map = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const values = map.toValues()
console.log(values) // [ 'Foo', 'Bar' ]
```

#### SuperMap.toMap()
```js
const superMap = SuperMap.of(['foo', 'Foo'], ['bar', 'Bar'])
const map = superMap.toMap()
console.log(map) // { 'foo' => 'Foo', 'bar' => 'Bar' }
```