Skip to content
development
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

json-overrides

Default CI/CD Known Vulnerabilities npm package size npm version npm dependency Status 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: "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

$ npm test

About

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

Topics

Resources

License

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •