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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mrmartineau/strifx

v0.2.0

Published

A tiny utility for constructing strings conditionally — like clsx for any string.

Readme

strifx

Like clsx for strings — conditionally compose any string, not just classNames.

npm size

The Problem

Building strings with conditional parts is ugly in JavaScript:

// Concatenation hell
const greeting = `Hello${name ? ` ${name}` : ''}${title ? `, ${title}` : ''}! Welcome to ${place}.`;

// Array filter hack
const address = [street, unit ? `Unit ${unit}` : '', `${city}, ${state} ${zip}`, country !== 'US' ? country : '']
  .filter(Boolean)
  .join('\n');

The Solution

import { strifx, when } from '@mrmartineau/strifx';

const greeting = strifx`Hello${when(name, { prefix: ' ' })}${when(title, { prefix: ', ' })}! Welcome to ${place}.`;

const address = strifx.join('\n')(
  street,
  when(unit, { transform: v => `Unit ${v}` }),
  `${city}, ${state} ${zip}`,
  when(country, { test: v => v !== 'US' }),
);

Install

npm install @mrmartineau/strifx
yarn add @mrmartineau/strifx
pnpm add @mrmartineau/strifx
bun add @mrmartineau/strifx

API

strifx — Tagged Template

import { strifx, when } from '@mrmartineau/strifx';

strifx`Hello ${when(name)} world`;
// name = "Zander" → "Hello Zander world"
// name = undefined → "Hello world"

Regular interpolation works as normal:

strifx`Order #${orderId} is ${status}`;
// → "Order #1234 is shipped"

when(value, options?)

Marks a value as conditional. Returns a special marker the tagged template recognises.

when(value)                                    // include if non-nullish (0 and "" kept!)
when(value, { test: v => v > 0 })              // include if predicate passes
when(value, { test: isAdmin })                 // include if boolean gate is truthy
when(value, { prefix: ', ' })                  // prepend when included
when(value, { suffix: '!' })                   // append when included
when(value, { transform: v => v.toUpperCase() }) // transform before including

Evaluation order: nullish check → false check → testtransformprefix/suffix

strifx.join(separator?)

Join parts with an explicit separator. Nullish/false parts are excluded automatically.

strifx.join(', ')('apples', when(bananas), 'cherries');
// bananas = "bananas" → "apples, bananas, cherries"
// bananas = undefined → "apples, cherries"

strifx.join(' AND ')(
  `status = 'active'`,
  when(minAge, { transform: v => `age >= ${v}` }),
  when(region, { transform: v => `region = '${v}'` }),
);
// minAge = 21, region = "EU" → "status = 'active' AND age >= 21 AND region = 'EU'"

Pass an options object to use Intl.ListFormat for locale-aware conjunctions and disjunctions:

strifx.join({ locale: 'en', type: 'conjunction' })('apples', 'bananas', 'cherries');
// → "apples, bananas, and cherries"

strifx.join({ locale: 'en', type: 'disjunction' })('apples', 'bananas', 'cherries');
// → "apples, bananas, or cherries"

strifx.join({ locale: 'en', type: 'conjunction', style: 'narrow' })('apples', 'bananas', 'cherries');
// → "apples, bananas, cherries"

// Nullish/false parts are still filtered out
strifx.join({ locale: 'en', type: 'conjunction' })('apples', when(undefined), 'cherries');
// → "apples and cherries"

Object Syntax

strifx({
  base: 'Dear ',
  name: user.name,
  greeting: [user.isNew, ', welcome!'],  // [condition, text]
  closing: '\nBest regards',
});
// user = { name: 'Zander', isNew: true } → "Dear Zander, welcome!\nBest regards"
// user = { name: 'Zander', isNew: false } → "Dear Zander!\nBest regards"

Template Factory (strifx/template)

Create reusable templates with named placeholders:

import { template, when } from '@mrmartineau/strifx/template';

// Tagged template style
const greeting = template`Dear${when('title', { prefix: ' ' })}${when('name', { prefix: ' ' })}!`;
greeting({ title: 'Dr', name: 'Smith' }); // → "Dear Dr Smith!"
greeting({ name: 'Smith' });               // → "Dear Smith!"

// Function style (better TypeScript inference)
const greeting = template({
  keys: ['name', 'title'] as const,
  render: (v) => strifx`Dear${when(v.title, { prefix: ' ' })}${when(v.name, { prefix: ' ' })}.`,
});

React (strifx/react)

import { useStrifx, when } from '@mrmartineau/strifx/react';

function Greeting({ user }) {
  const title = useStrifx`Dear${when(user.title, { prefix: ' ' })}${when(user.name, { prefix: ' ' })}`;
  return <h1>{title}</h1>;
}

Conditional ReactNode[] with separators:

import { strifxReact, when } from '@mrmartineau/strifx/react';

function StatusBar({ user, notifications }) {
  const parts = strifxReact(' · ')(
    when(user, { transform: u => <strong>{u.name}</strong> }),
    when(notifications, { transform: n => <Badge count={n} /> }),
  );
  return <nav>{parts}</nav>;
}

Nullish vs Falsy

Unlike clsx, strifx uses nullish checking by default. 0 and "" are valid string content and are kept.

| Value | when(value) | Skipped? | | ----------- | ------------- | -------- | | "hello" | ✅ included | | | 0 | ✅ included | | | "" | ✅ included | | | false | ❌ skipped | always | | null | ❌ skipped | always | | undefined | ❌ skipped | always |

License

MIT