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

@adameisfeld/mustachr

v0.0.6

Published

Extract hardcoded values from files and replace them with mustache-style template variables. Ideal for sanitizing secrets in HAR files and other structured text.

Readme

Mustachr 🥸

Mustachr is a lightweight, open-source CLI and TypeScript library for extracting and injecting values in structured files using Mustache-style templates.

It lets you sanitize sensitive data by replacing it with template tokens, or inject dynamic values into templated files. mustachr is especially useful for test fixture sanitization, API mocking, and configuration management.


Installation

npm install --save-dev mustachr

Or globally for CLI use:

npm install -g mustachr

Concepts

Mustachr supports two primary operations:

  • Extraction: Replaces matching values in a file with {{ TOKEN }} placeholders
  • Injection: Replaces {{ TOKEN }} placeholders with actual values

Example

Input file (example.txt)

{
  "apiKey": "SuperSecret123",
  "user": "admin"
}

Extractions file (mustachr.extractions.ts)

import { defineExtractions } from '@adameisfeld/mustachr';

export default defineExtractions([
  {
    type: 'string',
    property: 'API_KEY',
    search: 'SuperSecret123',
    replace: '{{ property }}',
  },
]);

After Extraction

{
  "apiKey": "{{ API_KEY }}",
  "user": "admin"
}

Injections file (mustachr.injections.ts)

import { defineInjections } from '@adameisfeld/mustachr';

export default defineInjections({
  API_KEY: 'Mocked1234'
});

After Injection

{
  "apiKey": "Mocked1234",
  "user": "admin"
}

Configuration 🛠️

Mustachr uses two configuration files:

  • Extractions File: Defines how values should be matched and replaced (for sanitization)
  • Injections File: Defines values to replace {{ tokens }} (for hydration)

These can be written as .ts, .js, or .json files and exported using defineExtractions() or defineInjections():

// mustachr.extractions.ts
import { defineExtractions } from '@adameisfeld/mustachr';

export default defineExtractions([ /* extractions here */ ]);
// mustachr.injections.ts
import { defineInjections } from '@adameisfeld/mustachr';

export default defineInjections({ /* injections here */ });

The CLI will automatically pick up these files if named:

  • mustachr.extractions.ts|js|json
  • mustachr.injections.ts|js|json

Or you can specify them manually via --extractions and --injections.


Extraction Types

mustachr supports three types of extractions: string, regex, and env.

string 🔤 Extraction

Matches exact string values and replaces them with tokens.

{
  type: 'string',
  property: 'API_KEY',
  search: 'SuperSecret123',
  replace: '{{ property }}'
}

Replaces "SuperSecret123" with {{ API_KEY }}


regex 🧪 Extraction

Matches patterns using regular expressions.

{
  type: 'regex',
  property: 'TOKEN',
  search: 'token=[a-zA-Z0-9]+',
  replace: 'token={{ property }}'
}

Replaces "token=abcd1234" with "token={{ TOKEN }}"


env 📦 Extraction

Reads values from a .env file and replaces matching values in the target file.

{
  type: 'env',
  path: './.env'
}

If .env contains:

API_KEY=SuperSecret123
DB_PASSWORD=Hunter2

Then any matching strings in the input file are replaced with {{ API_KEY }} and {{ DB_PASSWORD }} respectively.


CLI Usage

You can use mustachr from the command line to extract or inject values in any file:

mustachr extract <file> [options]
mustachr inject <file> [options]

Extract Example

mustachr extract ./example.txt --extractions ./mustachr.extractions.ts --out ./output.txt

Inject Example

mustachr inject ./output.txt --injections ./mustachr.injections.ts --out ./hydrated.txt

If --extractions or --injections are omitted, mustachr will look for default files like mustachr.extractions.ts in the current directory.


Programmatic API

You can use mustachr directly in code:

import { extract, inject, defineExtractions, defineInjections } from '@adameisfeld/mustachr';

const sanitized = await extract({
  input: 'key=SuperSecret123',
  extractions: defineExtractions([
    {
      type: 'string',
      property: 'API_KEY',
      search: 'SuperSecret123',
      replace: '{{ property }}',
    },
  ]),
});

const hydrated = inject({
  input: sanitized,
  injections: defineInjections({ API_KEY: 'Mocked1234' }),
});

Testing

Mustachr is fully covered with unit tests using Vitest:

npm run test

Use Cases

  • Redacting secrets in HAR files or other structured test artifacts
  • Injecting dynamic data into mock API responses
  • Generating reproducible test fixtures
  • Cleaning up sensitive config before sharing

License

MIT © 2025