Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/christian-fei/husky-template
magic strings in javascript
https://github.com/christian-fei/husky-template
magic string template utility
Last synced: 22 days ago
JSON representation
magic strings in javascript
- Host: GitHub
- URL: https://github.com/christian-fei/husky-template
- Owner: christian-fei
- Created: 2017-02-13T23:36:31.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-17T22:24:12.000Z (almost 7 years ago)
- Last Synced: 2024-04-13T22:19:46.768Z (9 months ago)
- Topics: magic, string, template, utility
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![travis][travis-image]][travis-url]
[![npm][npm-image]][npm-url]
[![downloads][downloads-image]][downloads-url][travis-image]: https://img.shields.io/travis/christian-fei/husky-template.svg?style=flat
[travis-url]: https://travis-ci.org/christian-fei/husky-template
[npm-image]: https://img.shields.io/npm/v/husky-template.svg?style=flat
[npm-url]: https://npmjs.org/package/husky-template
[downloads-image]: https://img.shields.io/npm/dm/husky-template.svg?style=flat
[downloads-url]: https://npmjs.org/package/husky-template# installation
```
npm install husky-template
``````javascript
const huskyTemplate = require('husky-template')
let template = huskyTemplate('lorem {ipsum} {dolor.sit.amet}')const ipsum = 'ipsum'
template = template({ipsum}) // lorem ipsum {dolor.sit.amet}
const amet = 'dolor sit amet'
template = template({dolor:{sit:{amet}}}) // lorem ipsum dolor sit amet
```[See usage-section](#usage) for more examples.
# usage
create an instance of husky by passing it a string with placeholders for your values.
like this:
```javascript
const text = 'lorem {ipsum} {amet}'
const template = huskyTemplate(text)const curriedTemplate = template({ipsum})
equal('lorem ipsum {amet}', curriedTemplate)
equal('lorem ipsum amet', curriedTemplate({amet}))
```### Features
##### curried templates
use the power of partial application on your templates! [See usage-section](#usage).
##### deep object property support
in other words:
```javascript
const template = huskyTemplate('lorem ipsum {deep.amet}')
const amet = 'amet'
equal('lorem ipsum amet', template({deep: {amet}}))
```##### map over object properties
[see test](./test/index.js#L34)
```javascript
test('maps over object property', () => {
const ipsum = 'ipsum'.split('')
let template = huskyTemplate(`lorem {this.ipsum.map(i => i + '_').join('')}`)
template = template({ipsum})
equal(template.toString(), 'lorem i_p_s_u_m_')
})
```## tests
please feel free to submit pull-requests, backed by tests!
```bash
npm i
npm t [-- --watch]
```[see tests](./test)