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

f-strings

v0.0.0

Published

Tagged template function to write readable multi-line strings with embedded if-else conditions and automatic dedentation

Readme

f-strings

f-strings provides a tagged template f that allows you to write readable multi-line strings with embedded if-else conditions and automatic dedentation.

Installation

npm install f-strings

Usage

Use If, Else, and EndIf expressions to include conditional content.

import { f, If, Else, EndIf } from 'f-strings';

const history = [
  { role: 'user', content: 'Hello' },
  { role: 'assistant', content: 'Hi there!' },
];

const question = 'What is the capital of France?';

const prompt = f`
  You are a helpful assistant.

  ${If(history.length)}
  Conversation history:
  ${history.map((msg) => `- ${msg.role}: ${msg.content}`)}
  ${Else}
  No conversation history.
  ${EndIf}

  User question:
  ${question}
`;

console.log(message);
You are a helpful assistant.

Conversation history:
- user: Hello
- assistant: Hi there!

User question:
What is the capital of France?

Dedentation

Strips indentation from multi-line strings.

import { f, If, EndIf } from 'f-strings';

const prompt = f`
      Hello
        World!
          How are you?
      I'm good, thank you!
`;

console.log(dedented);
Hello
  World!
    How are you?
I'm good, thank you!

Lazyness

Expressions can be lazily evaluated, so you can use functions to generate content only when needed.

import { f, If, EndIf } from 'f-strings';

const messages = await getMessages(); 

const prompt = f`
  ${If(messages.length)}
    You have ${messages.length} messages:
    ${() => messages.map((msg) => `- ${msg}`)}
  ${Else}
    No messages.
  ${EndIf}
`;

console.log(prompt);
You have 1000 messages:
- Message 1
- Message 2
...
- Message 1000

API

f - Tagged Template Function

f`template ${value} string`

If(condition) - Conditional Block

Starts a conditional block. Includes the following content if the condition is truthy.

const text = f`
  ${If(condition)}
    content when true
  ${EndIf}
`;

Else() - Alternative Block

Starts an alternative block. Includes the following content if the condition is falsy.

![NOTE] Else can be used without calling it as a function: ${Else} or ${Else()}.

const text = f`
  ${If(condition)}
    content when true
  ${Else}
    content when false
  ${EndIf}
`;

EndIf - End Conditional

Marks the end of a conditional block. Required for every If.

![NOTE] EndIf can be used without calling it as a function: ${EndIf} or ${EndIf()}.

License

MIT