🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

view-json

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

view-json

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`.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

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

  • 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.

FAQs

Package last updated on 23 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts