JSPM

nested-object-map

1.0.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 106
  • Score
    100M100P100Q69864F
  • License MIT

Deep convert a nested Object into a ES6 Map.

Package Exports

  • nested-object-map

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nested-object-map) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

NestedObjectMap Class

Deep convert a nested Object into a ES6 Map

Build Status Coverage Status Dependencies Status

npm install nested-object-map

Usage

Convert nested Object to Map

const NestedObjectMap = require('nested-object-map');

const config = new NestedObjectMap({
  api: {
    http: {
      auth: {
        token: 'secret'
      }
    }
  }
});

const authToken = config.get('api.http.auth.token');
const { token } = config.get('api.http.auth');

console.dir(authToken); // "secret"
console.dir(token); // "secret"

Add another object to Map

You could add (or "merge") another objects references to the Map.

config.addObject({
  api: {
    http: {
      port: 8080
    }
  }
});

console.dir(config.get('api.http.port')); // 3000
console.dir(config.get('api.http.auth.token')); // "secret"

Use case

if (object && object.api && object.api.http && object.api.http.auth) {
  const token = object.api.http.auth.token;
}

// VS

const config = new NestedObjectMap(object);
const token = config.get('api.http.auth.token');

There are similar modules for flat objects: