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

0.2.11 • Public • Published

String Template Format

String template tag that accepts any value and returns a string

Usage Examples

Embed objects into string as JSON

import { formatJson } from 'string-template-format'
console.log(formatJson`number ${123}; string: ${'abc'}; object: ${{ abc: 123 }}; array: ${[0, 1, 2]}`)

should print:

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

Format objects with util.inspect

import { formatInspect } from 'string-template-format'
console.log(formatInspect`number ${123}; string: ${'abc'}; object: ${{ abc: 123 }}; array: ${[0, 1, 2]}`)

should print:

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

Custom tags

import { tag } from 'string-template-format'
const myTag = tag(value => `[${typeof value} ${value}]`)
console.log(myTag`${123}${'abc'}${{ abc: 123 }}${[0, 1, 2]}`)

should print:

[number 123]; [string abc]; [object [Object object]]; [array 0,1,2]

License

MIT © Hoàng Văn Khải

/string-template-format/

    Package Sidebar

    Install

    npm i string-template-format

    Weekly Downloads

    3

    Version

    0.2.11

    License

    MIT

    Unpacked Size

    3.71 kB

    Total Files

    5

    Last publish

    Collaborators

    • khai96_