# better-require

> require('better-require')('json yaml') lets you load JSON and YAML files using require syntax. For example: var config = require('./config.json'); Extensions available are: json, yaml.

Latest version **0.0.3** (published 2013-06-06) · BSD license · 0 weekly downloads

## Install

```sh
npm install better-require
pnpm add better-require
yarn add better-require
bun add better-require
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2013-06-06 |
| First published | 2012-10-22 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 76 |
| Author | Olivier Lalonde |
| Maintainers | olalonde |
| Keywords | require, json, yaml, yml, csv, xml, ini, six, coffee-script, coffeescript, coffee, cljs, clojure, dart, typescript, ts |

## Links

- npm: https://www.npmjs.com/package/better-require
- Repository: git@github.com:olalonde/better-require
- Homepage: https://github.com/olalonde/better-require
- Issues: https://github.com/olalonde/better-require/issues
- npm.io page: https://npm.io/package/better-require

## Dependencies (8)

- [six](https://npm.io/package/six.md)
- [colors](https://npm.io/package/colors.md)
- [require-csv](https://npm.io/package/require-csv.md)
- [require-ini](https://npm.io/package/require-ini.md)
- [require-xml](https://npm.io/package/require-xml.md)
- [require-json](https://npm.io/package/require-json.md)
- [require-yaml](https://npm.io/package/require-yaml.md)
- [coffee-script](https://npm.io/package/coffee-script.md)

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.3 (latest) — 2013-06-06
- 0.0.2 — 2012-11-01
- 0.0.1 — 2012-10-22

## README

Augments require() with support for multiple file formats.

# Supported file formats
 
**... which return a JSON representation:**

- [json](http://en.wikipedia.org/wiki/JSON)
- [yaml](http://en.wikipedia.org/wiki/Yaml) (.yaml, .yml)
- [csv](http://en.wikipedia.org/wiki/Comma-separated_values) 
- [xml](http://en.wikipedia.org/wiki/Xml)
- [ini](http://en.wikipedia.org/wiki/INI_file)

**... which return a Javascript module:**

- [coffeescript](http://coffeescript.org) (.coffeescript, .coffee)
- [six](https://github.com/matthewrobb/six)
- [clojurescript](https://github.com/clojure/clojurescript) (.cljs) - not bundled
- [dart](http://www.dartlang.org/) - not bundled
- [typescript](http://www.typescriptlang.org/) (.ts) - not bundled

**... work in progress:**

- dynamic libraries
- ruby
- python

Behind the scenes, this module adds handlers to [require.extensions](http://nodejs.org/api/all.html#all_require_extensions).

# Install

    npm install better-require

# Usage

```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);
```

# Example 

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);
```

# Dependencies

- [require-json](https://github.com/olalonde/require-json)
- [require-yaml](https://github.com/olalonde/require-yaml)
- [require-csv](https://github.com/olalonde/require-csv)
- [require-xml](https://github.com/olalonde/require-xml)
- [require-ini](https://github.com/olalonde/require-ini)
- see package.json

# Reference

http://nodejs.org/api/all.html#all_require_extensions

---
_Source: https://npm.io/package/better-require · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
