npm

Need private packages and team management tools?Check out npm Orgs. »

json-overrides

1.1.3 • Public • Published

json-overrides

Greenkeeper badge Build Status License NPM version NPM downloads

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

install

npm i json-overrides

Downloadsweekly downloads

0

version

1.1.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability