Skip to content
Creates name-specific manifests from a plain object. Overrides object properties with name-specific ones and removes the overrides property.
JavaScript
Branch: development
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
src
test
.babelrc
.editorconfig
.eslintignore
.eslintrc.json
.flowconfig
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
package-lock.json
package.json

README.md

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
You can’t perform that action at this time.