0.0.4 • Published 9 years ago

data-module v0.0.4

Weekly downloads
7
License
MIT
Repository
github
Last release
9 years ago

data-module

Wrap a plain JS object into an ES6 module.

Installation

npm install data-module

Usage

var dataModule = require('data-module');

dataModule(
    { object: 'with'
    , some: ['important', 'data']
    }).toString();

// Outputs String: >
//     export default {"object":"with","some":["important","data"]};
//

API

dataModule(data, options)

data

Type: any

The data to be wrapped in a module.

options.formatting(data)

Default: JSON.stringify
Type: Function
Should accept arguments: data (type: any)
Should return type: String

The formatting function. When passed the original data, it should return its representation in valid JavaScript code.

We ship the function dataModule.formatting.diffy([options])(data), which you can use here. The default value for options is {indentString: ' '}. We use format-json's diffy formatter to generate the output.

License

MIT © Tomek Wiszniewski.