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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@postinumero/formatjs-tools

v0.1.7

Published

An implementation of FormatJS [Application Workflow](https://formatjs.github.io/docs/getting-started/application-workflow/), declaring package messages [with a convention](https://formatjs.github.io/docs/guides/distribute-libraries#declaring-with-a-conven

Readme

@postinumero/formatjs-tools

An implementation of FormatJS Application Workflow, declaring package messages with a convention.

CLI

extract

Extract from app to lang/.extracted.json:

formatjs-tools extract

--path (multiple)

Extract from src to lang/.extracted.json:

formatjs-tools extract --path src

--out-file

Extract from app to lang/en-DEFAULT.json:

formatjs-tools extract --out-file lang/en-DEFAULT.json

aggregate

Aggregate the extracted files from dependencies into a single file for each environment and locale.

Aggregate messages to .lang/aggregated/[environment:]<locale>.json:

formatjs-tools aggregate

collect

Collect the translation files into a single file for each environment and locale.

Collect messages to .lang/collected/[environment:]<locale>.json:

formatjs-tools collect

merge

Merge aggregated messages and collected translations for each environment and locale.

Merge:

  • .lang/aggregated/[environment:]<locale>.json
  • .lang/collected/[environment:]<locale>.json

(saved to: .lang/merged/[environment:]<locale>.json)

formatjs-tools merge

compile

Compile merged files for each environment and locale.

By default, output is written to .lang/compiled/[environment:]<locale>.json:

formatjs-tools compile

To customize the output directory and enable hashed filenames:

formatjs-tools compile --out-dir public/.compiled-lang --hash
  • --out-dir sets a custom output path
  • --hash appends a content hash to filenames (e.g. en-US-abc123.json)
  • A manifest.json is also generated to map [environment:]<locale> to hash values

config

Write internal locale and environment configuration to .lang/config.json.

formatjs-tools config

process-messages

Run all of the commands above in correct order:
config, extract, aggregate, collect, merge, compile

formatjs-tools process-messages

You can give options to individual commands by prefixing the option name with the command name (e.g. --extract.path src).

API

Use programmatically in Node.js:

import {
  aggregate,
  collect,
  compile,
  config,
  extract,
  merge,
  processMessages,
} from "@postinumero/formatjs-tools/commands";

await aggregate();

Config

Configuration is based on:

  • Filenames in the lang directory
  • Optional config.json in the project root
  • Environment variables (locales, environments)

See the example app for reference.

Filename Convention

Files must follow the format:

lang/[environment:]<locale>.json
  • environment is optional and may include multiple segments (e.g. com.example.test).
    By convention, use reverse domain naming. Environments inherit from their parent and subdomains — e.g. com.example.test inherits from com.example, com, example.test and test.
  • locale can include a region (e.g. en-US). Regional locales inherit from the base (e.g. en-US inherits from en).

When messages are extracted, they are saved as .extracted.json.
These files are autogenerated and should not be edited manually — feel free to add them to .gitignore.

To override default messages for all locales, you can create a .default.json file (optionally per environment).

config.json

Use config.json to customize environments and locales. By default, all locales and environments are inferred from filenames in the lang directory.

You can override or extend this behavior:

Replace detected values entirely:

{
  "locales": ["en", "fi"],
  "environments": ["development", "production"]
}

Or extend/modify what's found in the lang directory:

{
  "locales": {
    "include": ["fr"],   // Adds "fr" to any locales found in lang/
    "exclude": ["fi"]    // Removes "fi" if found
  },
  "environments": {
    "include": ["test"]  // Adds "test" environment
  }
}

Library Usage

Example lib uses @formatjs/ts-transformer and ts-patch.

  1. Extend your TSConfig**

    tsconfig.json:

    {
      "extends": "@postinumero/formatjs-tools/configs/tsconfig.lib.json"
    }
  2. Add prebuild script

    package.json:

    {
      "scripts": {
        "prebuild": "formatjs-tools extract --path src",
        "build": "tspc"
      }
    }