# babelon

> JSON templates using ES6+ object notation

Latest version **1.0.5** (published 2018-03-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install babelon
pnpm add babelon
yarn add babelon
bun add babelon
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2018-03-07 |
| First published | 2016-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Foy Savas |
| Maintainers | foysavas |

## Links

- npm: https://www.npmjs.com/package/babelon
- Repository: https://github.com/foysavas/babelon
- Issues: https://github.com/foysavas/babelon/issues
- npm.io page: https://npm.io/package/babelon

## Dependencies (8)

- [babel-core](https://npm.io/package/babel-core.md) ^6.7.2
- [babel-plugin-transform-strict-mode](https://npm.io/package/babel-plugin-transform-strict-mode.md) ^6.6.5
- [babel-plugin-transform-es2015-spread](https://npm.io/package/babel-plugin-transform-es2015-spread.md) ^6.6.5
- [babel-plugin-syntax-object-rest-spread](https://npm.io/package/babel-plugin-syntax-object-rest-spread.md) ^6.5.0
- [babel-plugin-transform-object-rest-spread](https://npm.io/package/babel-plugin-transform-object-rest-spread.md) ^6.6.5
- [babel-plugin-transform-es2015-arrow-functions](https://npm.io/package/babel-plugin-transform-es2015-arrow-functions.md) ^6.5.2
- [babel-plugin-transform-es2015-template-literals](https://npm.io/package/babel-plugin-transform-es2015-template-literals.md) ^6.6.5
- [babel-plugin-transform-es2015-shorthand-properties](https://npm.io/package/babel-plugin-transform-es2015-shorthand-properties.md) ^6.5.0

## Recent versions

- 1.0.5 (latest) — 2018-03-07
- 1.0.3 — 2017-07-09
- 1.0.2 — 2016-06-11
- 1.0.1 — 2016-04-01
- 1.0.0 — 2016-03-11

## README

# babelon

JSON templates using ES6+ object notation.

Like JSON, but really JS.

`babelon` uses `vm`, `Function`, and/or `eval`, so only use it where you trust the input.

## Install

`npm i --save babelon`

## Example

Let's say you want to mockup an JSON response, you can use `babelon` to write a template:

`> example.babelon`

```js
{
  user: {
    id: user_id, /* variables */
    name: `${faker.name.firstName()} ${faker.name.lastName()}` // templates
  },
  posts: posts.map((post) => ({ // iterators
    id: post.id
  })),
  addOne: (v) => { // functions
    let a = 1;
    return v+a;
  },
  ...misc, // object spread properties
  is_active // property shorthand
}
```

`> index.js`
```js
import babelon from 'babelon';
import faker from 'faker';

let tmpl = babelon.compile('example.babelon');

let obj = tmpl({faker, user_id: 1, posts: [{id: 1}], misc: {}, is_active: true});

// obj:
// { user: { id: 1, name: 'First Last' },
//   posts: [ { id: 1 } ],
//   addOne: [Function],
//   is_active: true }
```

## Methods

* `babelon.compileFile(file_path)`: returns callable template
* `babelon.evalFile(file_path, locals = null)`: returns rendered template using locals

* `babelon.compile(code_str)`: returns callable template
* `babelon.eval(code_str, locals = null)`: returns rendered template using locals

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