json-overrides
v1.1.3
Published
Creates name-specific manifests from a plain object. Overrides object properties with name-specific ones and removes the overrides property.
Downloads
12
Maintainers
Readme
json-overrides creates name-specific manifests from a plain object. Overrides object properties with name-specific ones and removes the overrides property.
Installation
$ npm install json-overrides
Usage
override(json: string | Overridable, name: string): Object
import override from "json-overrides";
let obj = {
a: "I'm a default value!",
b: "I'll never change!",
overrides: {
projectA: {
a: "I'm a default value for project A!"
},
projectB: {
a: "I'm a default value for project B!"
},
projectC: {
a: "I'm a default value for project B!",
b: "... or will I?"
}
}
};
override(obj, "projectA");
// {
// a: "I'm a default value for project A!",
// b: "I'll never change!"
// }
override(obj, "projectB");
// {
// a: "I'm a default value for project B!",
// b: "I'll never change!"
// }
override(obj, "projectC");
// {
// a: "I'm a default value for project C!",
// b: "... or will I?"
// }
override(obj, "projectD");
// Error: Overrides for projectD not found
override(123, "projectD");
// TypeError: Expected JSON to be an object (got number)
override(true, "projectD");
// TypeError: Expected JSON to be an object (got boolean)
Note: you can pass valid serialized objects as argument, e.g.
override(JSON.stringify(object), key");
.
Tests
$ npm test