@psenger/multivalue-map
v1.2.0
Published
Multi Value Map for NodeJS
Maintainers
Readme
@psenger/multivalue-map
An ES6 Map where each key holds a collection of values, not just one.
Installation • API • Usage • Contributing • Security
@psenger/multivalue-map is a lightweight ES6 Map extension where each key maps to a collection of values rather than a single one. Based on the Multimap abstract data type, it lets you set multiple values per key and get them back as an array. The collection type is pluggable: use ArrayCollection (default) to preserve duplicates, or SetCollection to enforce uniqueness among primitive values.
Table of contents
Installation Instructions
npm install @psenger/multivalue-map --saveor
yarn add @psenger/multivalue-mapAPI
Example Usage
const preData = [['A',['B','B','C']]]
const mvm = new MultiValueMap(preData,{ valueType: SetCollection })
mvm.set('D', 'E')
mvm.set('D', 'E')
const value = mvm.get('A')
console.log( value ) // [ 'B', 'C' ]
for (let [key, values] of mvm.entries()) {
console.log(key, values.getValue());
}
// A [ 'B', 'C' ]
// D [ 'E' ]Development
git clone https://github.com/psenger/multivalue-map.git
cd multivalue-map
nvm use
npm install
npm testSee CONTRIBUTING.md for the full development and contribution guide.
License
MIT License
Copyright (c) 2021 Philip A Senger
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
A multi-value map for Node.js — when one value per key is not enough.
