magic strings in javascript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.npmignore
.travis.yml
README.md
index.js
package.json
utils.js

README.md

travis npm downloads

installation

npm install husky-template
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 for more examples.

usage

create an instance of husky by passing it a string with placeholders for your values.

like this:

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.

deep object property support

in other words:

const template = huskyTemplate('lorem ipsum {deep.amet}')
const amet = 'amet'
equal('lorem ipsum amet', template({deep: {amet}}))
map over object properties

see test

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!

npm i
npm t [-- --watch]

see tests