0.0.1 • Published 7 years ago

broccoli-json-transform v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

broccoli-json-transform

Broccoli plugin that allows for JSON files to be modified by using a transform.

Installation

npm install --save-dev broccoli-json-transform

Usage

var JsonTransform = require('broccoli-json-transform');

var tranformedJson = new JsonTransform(inputNode, options);
  • inputNode: A broccoli node

  • options: A hash of options

Options

  • transform: The function used to transform the JSON content. Should return an object.

  • space: Optional. String or number. Used when stringifying the JSON.

Example

If this is your example.json:

{
  "foo": "bar"
}

And this is your build pipeline:

var JsonTransform = require('broccoli-json-transform');

function capitalizeKeys(obj) {
  var result = {};
  var keys = Object.keys(obj);

  for(var i = 0; i < keys.length; ++i) {
    var key = keys[i];
    result[key.toUpperCase()] = obj[key];
  }

  return result;
}

var tranformedJson = new JsonTransform(inputNode, { transform: capitalizeKeys });

Then the output example.json will look like this:

{
  "FOO": "bar"
}

Contributing

Clone this repo and run the tests like so:

npm install
npm test