Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/leodutra/deep-template

Create "curried" templates from deep JS structures using ES6 template syntax
https://github.com/leodutra/deep-template

Last synced: 1 day ago
JSON representation

Create "curried" templates from deep JS structures using ES6 template syntax

Awesome Lists containing this project

README

        

# deep-template
Create "curried" templates from deep JS structures using ES6 template syntax

## Install
In a browser:
```html

```

Using npm:
```shell
$ npm i -g npm
$ npm i --save deep-template
```

## Usage

### deepTemplate(String, Object) -> String
```js
var deepTemplate = require('deep-template');
var buildPath = deepTemplate('/api/users/${id}/');
buildPath({id: '549873456448'}); // -> "/api/users/549873456448/"
```

### deepTemplate(Object, Object) -> Object
```js
var configTemplate = {
a: ['/api/users/${id}/${action}'],
b: {
deep: {
foo: [
{
stuff: 'DEFAULT_ENV=${env}'
}
]
}
},
c: function() { console.log('avoided') },
d: /keepRegExp/gim,
e: 'keep simple texts',
f: 10
};
var defaults = {action: 'defaultAction', env: '/usr/bin/bash'};
var configBuilder = deepTemplate(configTemplate, defaults);
configBuilder({id: '549873456448'});
/* -> {
a: ["/api/users/549873456448/defaultAction"],
b: {
deep: {
foo: [{
stuff: "DEFAULT_ENV=/usr/bin/bash"
}]
}
},
c: function() { console.log('avoided') },
d: /keepRegExp/gim,
e: "keep simple texts",
f: 10
}
*/
```

### deepTemplate(String, Array) -> String
```js
var arrayBuildPath = deepTemplate('/api/users/${0}/${1}/${2}', [null, null, 'ascending']);
arrayBuildPath(['549873456448', 'getUser']); // -> "/api/users/549873456448/getUser/ascending"
```