npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chalk-stencil

v1.0.0

Published

Tagged template literal for stylish outputs

Downloads

22

Readme

Chalk Stencil

Build Status Coverage Status Code Style

The tagged template literal for colorful command line outputs that you didn't know you needed!

asciicast

Note: The asciinema video still references the module by its original name chalk-template, sorry about that. Please don't let it confuses you, the module is called chalk-stencil 🙏

Install

$ npm install --save chalk-stencil

# or

$ yarn add chalk-stencil

Usage

You can create a colorful template using all the Chalk's available styles:

const chalk = require('chalk-stencil')
const msg = chalk`This ${'text::red'} is going to be red,
  and this ${'one::yellow'} yellow`

console.log(msg({ text: 'text', one: 'other text' }))

Features

Multiple props

As seen above, you can create a template that accepts multiple properties, each one with its own style.

chalk`This ${'text::red'} is going to be red,
  and this ${'one::yellow'} yellow`

This will return a template function which will accept an object which properties will be used to fill the placeholders.

Style chaining

You can also chain multiple styles for each property:

chalk`Red, white background and bold ${'prop1::red.bgWhite.bold'},
  cyan underlined ${'prop2::cyan.underline'}`

Default style

You may want to give a default style to a whole template, well, you can by adding the ::<style> at the very end of the string:

const errorMsg = chalk`Error: The ${'errorOrigin::underline.cyan'}
  exploded with the power of a thousand rainbows!::red`

console.error(errorMsg({ errorOrigin: 'Spaceship' }))

Unstyled template

You can even use this as a simple templating system, without styles; just drop the ::<style> part:

const msg = chalk`Just a ${'prop1'} with ${'prop2'}`
console.log(msg({ prop1: 'simple template', prop2: 'no style' }))
// = Just a simple template with no style

Plain values

You can also use the special _ key, to pass in simple values, instead of objects:

const tpl = chalk`I just want this ${'_::magenta'} to be magenta`

tpl('thing')
// = I just want this thing to be magenta
//                    ^^^^^ magenta
tpl(42)
// I just want this 42 to be magenta
//                  ^^ magenta

Raw strings

You can use raw strings as well, it Just Works:

chalk`The following ${'text will be colored::magenta'}.`

Simple usage

The chalk-stencil tagged literal will always return a function, so that you can pass properties to it, but you can also use it as if it was a plain tag:

console.log(chalk`I'm going to ${'rock::green'} tonight.::bold`)
// = I'm going to rock tonight.
//                ^^^^ this one is green - everything else is just bold
// note how you don't have to "call" the function at the end
// i.e. no chalk`something`() to produce the actual string

Related

Chalk: chalk

License

MIT © Federico Giovagnoli