Skip to content

Latest commit

 

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Wrap a plain JS object into an ES6 module.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages