A fork of 'olalonde/better-require' - lets you load JSON and YAML files using require syntax. For example: var config = require('./config.json'); Extensions available are: json, yaml, coffee, ts, ls, co
npm install butter-requireA fork of better-require with less supported formats, mainly for usage in uRequire due to some issues and being too heavy.
v0.3 also works well with coffee-script -post & pre 1.7.x- (.coffee, .litcoffee, .coffee.md, ) & also LiveScript (.ls) & coco (.co).
Formats (& dependencies) removed:
- xml: who needs that anymore ? It crashes on Windows anyway...
- six
You can still manually install them of course...
Original docs follow:
_________________________________________________________
Augments require() with support for multiple file formats.
- json
- yaml (.yaml, .yml)
- csv
- xml
- ini
... which return a Javascript module:
- coffeescript (.coffeescript, .coffee)
- six
- clojurescript (.cljs) - not bundled
- dart - not bundled
- typescript (.ts) - not bundled
... work in progress:
- dynamic libraries
- ruby
- python
Behind the scenes, this module adds handlers to require.extensions.
npm install better-require
``javascript`
/**
* @param {String} optional - formats is a white space separated list of formats you would like require() to support.
*/
// support all available extensions
require('better-require')();
// support a subset of extensions
require('better-require')(formats);
Enable support for all file types:
`javascript
require('better-require')();
var config = require('./config.json');
console.log(config);
`
Enable support for only a subset of file types:
`javascript
require('better-require')('json yaml xml');
// we can now require .xml, .yaml and .xml files!
var config = require('./config.yaml');
console.log(config);
``
- require-json
- require-yaml
- require-csv
- require-xml
- require-ini
- see package.json
http://nodejs.org/api/all.html#all_require_extensions