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

@messageformat/cli

v4.0.1

Published

MessageFormat CLI

Downloads

44,461

Readme

Command-line MessageFormat Compiler

Parses and compiles JSON, JSON5, YAML and .properties files of MessageFormat strings into an ES module of corresponding hierarchical functions.

This package was previously named messageformat-cli.

Installation

npm install --save-dev @messageformat/core @messageformat/cli

If you're intending to publish a library with external dependencies, you should also include the runtime as a dependency:

npm install @messageformat/runtime

Usage

npx messageformat [options] [input]

input should consist of one or more files or directories, unless defined in a configuration file. Directories are recursively scanned for .json, .json5, .yaml, .yml and .properties files. With multiple input files, shared parts of the start of their paths are dropped out of the generated module's structure.

Options

In addition to defining options on the command line, options may also be set in the "messageformat" object in your package.json file, or in a messageformat.rc.{js,json,yaml} configuration file, using the long-form option names as keys. Input files and directories may also be given as an "include" array in a configuration file. Command-line options override configuration files.

| Option | Short | Description | | ------------ | ----- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | delimiters | -d | Set of characters by which the file path is split into output object. Default value is ._/\. | | extensions | -e | Array or comma-separated list of file extensions to parse as source files. Default: ['.json', '.json5', '.yaml', '.yml', '.properties'] | | locale=lc | -l | The locale(s) lc to include; if multiple, first is default and others are selected by matching message key. If not set or empty, path keys matching any locale code will set the active locale, starting with a default en locale. | | options | | Options to pass to the MessageFormat constructor via its second argument. On the command line, use dot-notation to set values, e.g. --options.currency=EUR. For custom formatters, string values will be require()'d based on the current working directory. | | outfile=of | -o | Write output to the file of. If unspecified or -, prints to stdout. | | simplify | -s | Simplify the output object structure, by dropping intermediate keys when those keys are shared across all objects at that level, in addition to the default filtering-out of shared keys at the root of the object. |

Examples

With messages/strings.json, compile it into an ES module using the default English locale:

npx messageformat messages/strings.json --outfile=messages/en.js

With messages/en.json and messages/fr.json, combine both into an ES module, with the default export's top-level keys en and fr containing functions that each use the correct language's pluralization rules:

npx messageformat messages/ --locale=en,fr --outfile=messages.js

Note: The locale option could be left out here if is known that the data does not include any 2-3 letter keys matching other locales.


Same, but with this configuration in package.json:

{
  ...,
  "messageformat": {
    "locale": ["en", "fr"],
    "include": [
      "messages/"
    ],
    "outfile": "messages.js"
  },
  "scripts": {
    ...,
    "build:messages": "messageformat"
  }
}
npm run build:messages

Messageformat is an OpenJS Foundation project, and we follow its Code of Conduct.