map-tag

šŸ· Map template literal expression interpolations with ease

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
map-tag
6601.0.04 years ago4 years agoMinified + gzip package size for map-tag in KB

Readme

map-tag
šŸ· Map template literal expression interpolations with ease.
Install
npm install --save map-tag
mapTag(mapper, mapperContext?)
Returns a function that can be used for tagging template literals. The provided mapper is invoked with Array-method style arguments (expression, i, expressions) for each expression being interpolated into the template literal, where:
  • expression is the current expression
  • i is the position of expression in the list of expressions
  • expressions is every expression

The values returned from mapper will be used instead of the original expressions passed to the template literal.
usage examples
import mapTag from 'map-tag'

const uppercase = mapTag(expression =>
  String.prototype.toUpperCase.call(expression)
)

var name = 'jane'
var role = 'dentist'
uppercase`hello ${ name }, you're a great ${ role }!`
// <- 'hello JANE, you're a great DENTIST!'

import mapTag from 'map-tag'

const encodeParams = mapTag(encodeURIComponent)

var collection = 'Log'
var query = '{}'
var fields = 'level'
var page = 2

encodeParams`/database/${ collection }/${ query }/${ fields }/${ page }`
// <- '/database/Log/%7B%7D/level/2'
license
mit