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

[![npm version](https://badge.fury.io/js/%40js-commons%2Fsuper-map.svg)](https://badge.fury.io/js/%40js-commons%2Fsuper-map)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

# SuperMap
SuperMap class extends Map and add some methods, such as higher-order function.

## Installation
```sh
$ npm i @js-commons/super-map
```

or

```sh
$ yarn add @js-commons/super-map
```

## Use in your script
```js
const SuperMap = require('@js-commons/super-map')
```

or

```js
import SuperMap from '@js-commons/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"}
```

## API
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(callback)
```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(callback)
```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(callback)
```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(callback)
```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(callback)
```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(callback)
```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(callback)
```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(callback)
```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(callback)
```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(callback)
```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(callback)
```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' }
```