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

strict-tag

v0.2.0

Published

An es2015 template tag function that validates substitutions.

Downloads

4

Readme

Strict tag

An es2015 template tag function that validates template substitutions to guard against null and undefined values. Because sometimes, you really don't want "undefined" or "null" in your strings.

For example, urls are usually somewhere where you want to be strict:

const fooId;
fetch(`/foos/${fooId}`).then(...)

In this case, you're going to be trying to figure out why you're getting a 404 on /foo/undefined. Stop the request from even happening with a more specific error using strict:

const strict = require('strict-tag');
const fooId;
fetch(strict`/foos/${fooId}`).then(...)

This would throw an error during the template evaluation:

/Users/johnvh/dev/strict-tag/index.js:17
      throw new StrictTemplateError(`Template substitution at index ${i} is invalid`);
      ^

StrictTemplateError: Template substitution at index 0 is invalid
    at StrictTemplateError (/Users/johnvh/dev/strict-tag/index.js:3:5)
    at /Users/johnvh/dev/strict-tag/index.js:17:13

Usage

Install: npm install strict-tag

Use:

const strict = require('strict-tag');
console.log(strict`pid: ${process.pid}`);

strict

Default export. A template tag function that throws a StrictTemplateError if any substitutions are null or undefined.

strict.with(isInvalidFn)

A factory to create a template tag function that validates arguments using the isInvalidFn predicate function. isInvalidFn is invoked with each subtitution:

const _ = require('lodash');
const strict = require('strict');
const strictEmpty = strict.with(_.isEmpty);
const a = '';
console.log(strictEmpty`hello ${a}`); // throws

strict.StrictTemplateError

An error for invalid template substitutions.