view-json

0.1.0 • Public • Published

view-json NPM version Build Status

View plugin for templates.js, assemble or verb, that calls JSON.parse on .json files and keeps file.content in sync with file.json.data.

Install

Install with npm:

$ npm i view-json --save

The use case for this is to be able to easily update values on a JSON file as it progresses through a plugin pipeline or middleware stack (without having to repeatedly write the code to parse and stringify it).

Usage

Can be used with any application based on templates, including assemble, verb, and update.

var json = require('view-json');
var templates = require('templates');
 
var app = templates();
app.use(json());
  • When a file with a .json extension is created, this plugin automatically parses the file.contents property and adds the resulting object to file.json.data.
  • file.json has .get and .set methods for getting or setting properties from file.data
  • when .set is called, file.data and file.content are both updated.

Example

// create a collection
app.create('files');
 
// add a "view" to the new collection
var file = app.file('package.json', {content: '{"name": "foo"}'});
console.log(file.json.get('name'));
//=> "foo"
 
file.json.set('name', 'bar');
console.log(file.contents.toString());
//=> '{"name": "bar"}'

fwiw, with minor modifications this could also be used with vinyl files. Let me know if you're interested by creating an issue, and I'll make the modifications.

API

Related projects

  • assemble: Assemble is a powerful, extendable and easy to use static site generator for node.js. Used… more | homepage
  • base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
  • generate: Fast, composable, highly extendable project generator with a user-friendly and expressive API. | homepage
  • templates: System for creating and managing template collections, and rendering templates with any node.js template engine.… more | homepage
  • update: Easily keep anything in your project up-to-date by installing the updaters you want to use… more | homepage
  • verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage
  • vinyl: A virtual file format | homepage

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2016 Jon Schlinkert Released under the MIT license.


This file was generated by verb on January 23, 2016.

Readme

Keywords

none

Package Sidebar

Install

npm i view-json

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • jonschlinkert