New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

map-object-facade

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

map-object-facade

Use map as object (e.g. map.a instead of map.get('a'))

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

map-object-facade

Use map as object (e.g. map.a instead of map.get('a'))

Features

  • Get and set values using the object dot notation.
  • Supports Object calls like Object.keys(map) and delete map[key].
  • Supports readonly (sealed) mode and noAdditions (frozen) mode.
  • Provides a single function for maps (mapAsObject).
  • Transparent: existing Map functionality is not changed.

Usage examples

import mapAsObject from 'map-object-facade'

let map = mapAsObject(new Map());
map.a = 1;
map['b'] = 2;
map.set('c', 3);

map.a === map.get('a');
map.size === 3
Object.keys(map) === map.keys() === ['a', 'b', 'c']

delete map.b
map.size === 2
map.b === map.get('b') === undefined
Object.keys(map) === map.keys() === ['a', 'c']

let readMap = mapAsObject(map, {readonly:true});

Readonly or noAdditions

Object.seal and Object.freeze cannot be set independently on a proxy (which is used in the implementation of objectFacade). Instead, options can be given in the mapAsObject(..) call.

Current supported options are:

  • noAdditions (alias: seal) that allows changing values, but no new keys (default: false)
  • readonly (alias: freeze) that allows no changes whatsoever (default: false)
  • throwOnIgnoredSet will throw if set is ignored due to noAdditions / readonly (default: false -- meaning sets will be silently ignored if not allowed).

For example:

mapAsObject(map, {noAdditions:true, throwOnIgnoredSet:true})

'seal' and 'freeze' are used as alias because they are known names (though not very descriptive).

Changelog

Install

$ npm install map-object-facade

License

MIT (C) Nicolas de Jong

Keywords

javascript

FAQs

Package last updated on 12 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts