https://github.com/bartozzz/json-overrides
Creates name-specific manifests from a plain object. Overrides object properties with name-specific ones and removes the overrides property.
https://github.com/bartozzz/json-overrides
extend json json-extend json-files object override
Last synced: 5 months ago
JSON representation
Creates name-specific manifests from a plain object. Overrides object properties with name-specific ones and removes the overrides property.
- Host: GitHub
- URL: https://github.com/bartozzz/json-overrides
- Owner: Bartozzz
- License: mit
- Created: 2016-06-06T19:08:48.000Z (about 10 years ago)
- Default Branch: development
- Last Pushed: 2023-01-07T03:55:55.000Z (over 3 years ago)
- Last Synced: 2025-03-13T21:06:56.981Z (about 1 year ago)
- Topics: extend, json, json-extend, json-files, object, override
- Language: JavaScript
- Homepage: https://npmjs.com/package/json-overrides
- Size: 1.84 MB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
json-overrides
[](https://github.com/Bartozzz/json-overrides/actions)
[](https://snyk.io/test/github/Bartozzz/json-overrides?targetFile=package.json)
[](https://www.npmjs.com/package/json-overrides)
[](https://www.npmjs.com/package/json-overrides)
[](https://www.npmjs.com/package/json-overrides)
[](https://www.npmjs.com/package/json-overrides)
**json-overrides** creates name-specific manifests from a plain object. Overrides object properties with name-specific ones and removes the overrides property.
## Installation
```bash
$ npm install json-overrides
```
## Usage
```
override(json: string | Overridable, name: string): Object
```
```javascript
import override from "json-overrides";
let obj = {
a: "Default a value",
b: "Default b value",
overrides: {
projectA: {
a: "a value for projectA",
},
projectB: {
a: "a value for projectB",
},
projectC: {
a: "a value for projectC",
b: "b value for projectC",
},
},
};
override(obj, "projectA");
// {
// a: "a value for projectA",
// b: "Default b value"
// }
override(obj, "projectB");
// {
// a: "a value for projectB",
// b: "Default b value"
// }
override(obj, "projectC");
// {
// a: "a value for projectC",
// b: "b value for projectC"
// }
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
```bash
$ npm test
```