
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
nested-object-map
Advanced tools
Deep convert a nested Object into a ES6 Map
npm install nested-object-map
The NestedObjectMap Class extends Map and behaves the same way with the difference that the passed objects field values will be mapped. If the object is nested (containing more instances of Object) references to those objects will be mapped as well. Sub-objects will be iterated and their fields will be mapped just the same but their field names will be prefixed with its path. Cyclic references and other objects (eg. arrays) will be mapped as reference. Scalar values are mapped as scalar values, setting them on the map will not change the original objects value.
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"
You can map another objects fields to the Map (similar to a "deep merge"). This is the same method the constructor calls.
config.mapObject({
api: {
http: {
port: 8080
}
}
});
console.dir(config.get('api.http.port')); // 3000
console.dir(config.get('api.http.auth.token')); // "secret"
It can help you to access values contained deep within nested objects more easily and without the need of too many safe guards. It's probably most useful when dealing with nested objects with unreliable structure.
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:
FAQs
Deep convert a nested Object into a ES6 Map.
The npm package nested-object-map receives a total of 139 weekly downloads. As such, nested-object-map popularity was classified as not popular.
We found that nested-object-map demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.