data-module

0.0.4 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i data-module

Weekly Downloads

2

Version

0.0.4

License

MIT

Last publish

Collaborators

  • tomekwi