Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including json-overrides with all npm packages installed. Try it out:

var jsonOverrides = require("json-overrides")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

json-overrides v1.1.3

Creates name-specific manifests from a plain object. Overrides object properties with name-specific ones and removes the overrides property.

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

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free