@danliyev/wishmap
v1.0.4
Published
An extended JavaScript Map with Array-like methods and event emission.
Readme
About
An extended Map with Array-like methods and event emission.
Links
Installation
Using NPM Registry
npm install @danliyev/wishmapUsing GitHub Packages Registry
Create a GitHub Personal Access Token with
read:packagesscopeAdd to your shell profile (
.bashrc,.zshrc, or.profile):
export GITHUB_TOKEN=your_token_here- In your project directory, create
.npmrc:
@danliyev:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}- Install:
npm install @danliyev/wishmapAlternative: npm login
Authenticate once with GitHub Packages:
npm login --registry=https://npm.pkg.github.com --scope=@danliyev
# Username: your-github-username
# Password: your-personal-access-token (with read:packages scope)
# Email: your-emailThen install normally:
npm install @danliyev/wishmapSee Working with the npm registry for more information.
Usage
import { WishMap } from '@danliyev/wishmap'
const map = new WishMap<string, number>()
// Listen to events
map.events.on('set', (key, value) => {
console.log(`Set ${key} = ${value}`)
})
map.events.on('delete', (key, value) => {
console.log(`Deleted ${key} (was ${value})`)
})
// Use like a regular Map
map.set('a', 1)
map.set('b', 2)
map.set('c', 3)
// Use Array-like methods
map.filter(v => v > 1) // WishMap { 'b' => 2, 'c' => 3 }
map.map(v => v * 2) // [2, 4, 6]
map.find(v => v === 2) // 2
map.every(v => v > 0) // true
map.some(v => v > 2) // true
map.reduce((acc, v) => acc + v, 0) // 6License
This project is licensed under the MIT License.
