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

globalize-config-compiler

v0.1.3

Published

Compile globalize messages and formatters using json config.

Downloads

90

Readme

Globalize-config-compiler is a wrapper around globalize-compiler. It allows you to specify the formatters and parsers you wish to use as a plain old javascript object, and will feed that to globalize-compiler.

It is primarily meant to be used with globalize-config-loader and webpack.

Why?

Globalize-compiler attempts to find formatters and parsers inside your javascript code. It's pretty limited, and if you try to use something advanced, such as an angular filter, it won't be able to find them. Globalize-config-compiler allows you to skip the extraction part and manually specify the formatters and parsers.

You can also write your own extractor and feed it to globalize-config-compiler.

Check out the example directory for an example config file and usage. To compile the formatters and parsers, run node index.js inside the example directory, then run test-generated.js to test the generated file.

Usage

var compiler = require('globalize-config-compiler');

var config = {...};

var result = compiler(config, {
  context: context,
  compilerOptions: {
    template: template
  },
  dependentFile: addDependency
});

The second parameter of compiler is an options object with the following properties:

  • loadGlobalData: global cldr data loader function.
  • loadLocaleData: locale cldr data loader function
  • context: directory, message files are relative to this
  • compilerOptions: options to pass to globalize compiler
  • dependentFile: a callback that will be called for each file that the compilation depends on (currently only message files)

All are optional. The default loadGlobalData function will require the following cldr-data modules:

  • cldr-data/supplemental/likelySubtags.json
  • cldr-data/supplemental/numberingSystems.json
  • cldr-data/supplemental/timeData.json
  • cldr-data/supplemental/weekData.json
  • cldr-data/supplemental/plurals.json
  • cldr-data/supplemental/ordinals.json
  • cldr-data/supplemental/currencyData.json

The default loadLocaleData function will require the following cldr-data modules for each locale:

  • cldr-data/main/[locale]/numbers.json
  • cldr-data/main/[locale]/ca-gregorian.json
  • cldr-data/main/[locale]/timeZoneNames.json
  • cldr-data/main/[locale]/currencies.json
  • cldr-data/main/[locale]/dateFields.json
  • cldr-data/main/[locale]/units.json

Config object structure

  • availableLocales: an array of locales to use.
  • messages: path to message file, [locale] will be replaced by the locale. A message formatter will be created for each message using messageFormatter. The path is relative to the context option passed to the compiler.
  • dateFormatters: array of date formatter options. Each element will be passed to the dateFormatter function to create a date formatter. Use null to call the function without the options parameter.
  • dateParsers: array of date parser options. Each element will be passed to the dateParser function to create a date parser. Use null to call the function without the options parameter.
  • numberFormatters: array of number formatter options. Each element will be passed to the numberFormatter function to create a number formatter. Use null to call the function without the options parameter.
  • numberParsers: array of number parser options. Each element will be passed to the numberParser function to create a number parser. Use null to call the function without the options parameter.
  • pluralGenerators: array of plural generator options. Each element will be passed to the pluralGenerator function to create a plural generator. Use null to call the function without the options parameter.
  • currencyFormatters: array of currency formatter parameters. The elemens may either be strings or arrays; in the latter case the first element of the array must be a string. The array may contain a second element, an options object. The string and the options object, if provided, will be passed to the currencyFormatter function to create a currency formatter.
  • relativeTimeFormatters: array of relative time formatter parameters. The elemens may either be strings or arrays; in the latter case the first element of the array must be a string. The array may contain a second element, an options object. The string and the options object, if provided, will be passed to the relativeTimeFormatter function to create a relative time formatter.
  • unitFormatters: array of unit formatter parameters. The elemens may either be strings or arrays; in the latter case the first element of the array must be a string. The array may contain a second element, an options object. The string and the options object, if provided, will be passed to the unitFormatter function to create a unit formatter.

The parser and formatters generated from these options are passed to globalize-compiler to generate a compiled module for each locale. The result is returned as an object with the locales as keys.