string-template-format-compose
TypeScript icon, indicating that this package has built-in type declarations

0.1.7 • Public • Published

String Template Format: Compose

Compose string template tags

Usage Examples

Tag that logs

import { compose } from 'string-template-format-compose'
import { inspect } from 'string-template-format-inspect'
 
// Create the tag
const log = compose(console.log, inspect)
 
// Use the tag
const num = 123
const str = 'abc'
const obj = { abc: 123, def: 456 }
const arr = [0, 1, 2]
log`number ${num}; string ${str}; object ${obj}; array ${arr}`

should print:

number 123; string 'abc'; object { abc: 123, def: 456 }; array [ 0, 1, 2 ]

Tag that throws

import { compose, construct } from 'string-template-format-compose'
import { inspect } from 'string-template-format-inspect'
 
// Create the tag
const raise = error => { throw error }
const err = compose(raise, construct(TypeError, inspect))
 
// Use the tag
const obj = { abc: 123, def: 456 }
const key = 'ghi'
err`Object ${obj} does not have property ${key}`

should throw:

TypeError: Object { abc: 123, def: 456 } does not have property 'ghi'

License

MIT © Hoàng Văn Khải

Readme

Keywords

Package Sidebar

Install

npm i string-template-format-compose

Weekly Downloads

0

Version

0.1.7

License

MIT

Unpacked Size

4.28 kB

Total Files

11

Last publish

Collaborators

  • khai96_