Skip to content

feliperohdee/map-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CircleCI

Wht fuck is this

This is a MapMap data structure, is something like:

	const mapMap = new Map('key', new Map());

but better. It takes care to create MAPS automatically on set, and remove keys where the MAP is empty, it inherits MAP, so all MAP method are available, obviously.

Usage

	const MapMap = require('map-map');

	const mapMap = new MapMap('parentKey', 'key', 'value'); 
	console.log(mapMap.entries());
	// { [ 'parentKey', Map { 'key' => 'value' } ] }

	mapMap.set('parentKey', 'key-1', 'value-1');
	console.log(mapMap.entries());
	// [ 'parentKey', Map { 'key' => 'value', 'key-1' => 'value-1' } ] }
	
	console.log(mapMap.size()); // 1
	console.log(mapMap.size('parentKey')); // 2

	mapMap.clear('parentKey', 'key-1');
	console.log(mapMap.entries());
	// { [ 'parentKey', Map { 'key' => 'value' } ] }

	mapMap.clear('parentKey');
	console.log(mapMap.entries());
	// {}

	mapMap.clear();
	console.log(mapMap.entries());
	// {}

	console.log(mapMap.has('parentKey')); // true
	console.log(mapMap.has('parentKey-1')); // false
	console.log(mapMap.has('parentKey', 'value')); // true
	console.log(mapMap.has('parentKey', 'value-1')); // false

	mapMap.delete('parentKey');
	console.log(mapMap.entries());
	// {}

	mapMap.delete('parentKey', 'key-1');
	console.log(mapMap.entries());
	// { [ 'parentKey', Map { 'key' => 'value' } ] }

	mapMap.forEach(console.log);
	// Map { 'key' => 'value' }

	mapMap.forEach('parentKey', console.log);
	// 'value'
	// 'value-1'

Cool, no!!?

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published