Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/leodutra/deep-template
- Owner: leodutra
- License: mit
- Created: 2019-10-28T21:08:44.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T23:38:50.000Z (almost 2 years ago)
- Last Synced: 2024-03-25T21:11:41.429Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 240 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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"
```