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

ilib-localedata

v1.5.6

Published

Load and cache iLib locale data

Readme

ilib-localedata

ilib-localedata loads iLib locale data in a way that avoids race conditions and avoids reloading the same files repeatedly. It merges locale fallback chains, caches aggressively (including sharing in-flight loads so concurrent callers do not duplicate work), and performs I/O through ilib-loader so the same code can run on Node, in browsers, with bundlers, and other environments.

Supported locale data styles

iLib has evolved on several platforms, so this package understands more than one on-disk shape. All of them can be used with synchronous or asynchronous loading, depending on the loader and how the data is packaged.

  • Individual raw JSON files — Typical for Node.js apps: many small files (per locale part and basename, or equivalent layouts), loaded sync or async through the loader.

  • Assembled JSON files, one per locale — A single file per locale contains the locale data your app was configured to need. Which basenames and which locales are included is decided when you run ilib-assemble; at runtime you load one file per locale instead of many fragments. See that package’s documentation in this monorepo for how assembly works.

  • Assembled JS files, one per locale — Same idea as assembled JSON, but each locale is a JavaScript module (modern ES modules). That fits webpack and many websites, where JSON often cannot be import’d the same way as .js.

These styles are historical and practical: they cover the different ways iLib has been deployed while still supporting both sync and async loading paths.

Overview

Application code usually does not call the low-level loadData API. The package exists primarily for other iLib libraries (date formatting, locale info, and so on) to share one loading and caching implementation.

The common exception is startup preloading: apps that depend on those libraries often import LocaleData once and call LocaleData.ensureLocale() so that all later iLib usage can run synchronously without threading async through the whole app (see below).

It is possible to use ilib-localedata for non–iLib locale data if you adopt compatible file layout and conventions, but that is entirely up to the application developer; the design targets iLib data and packages.

Do not rely on loading another package’s raw locale files as a stable API—each package should expose its own documented surface; on-disk basenames and layout are not a contract between packages.

Preloading locale data for app developers

If your app uses iLib libraries, you have two broad options: await each library call that loads data asynchronously (which pushes async through your own APIs), or preload everything once at startup. Preloading uses LocaleData.ensureLocale(). It loads the same assembled locale files as the rest of the stack (the per-locale [locale].js / [locale].json bundles), in the same way as loadData(), but does it once, asynchronously. After that, data lives in the shared cache, so subsequent iLib calls can use synchronous code paths—as if the whole stack were sync.

import { LocaleData } from 'ilib-localedata';
import { getLocale } from 'ilib-env';

// start of app
const locale = getLocale();
await LocaleData.ensureLocale(locale);

// now you can use ilib libraries as if they were sync-loaded:
const df = new DateFormat({ date: 'long', locale });
const formattedDate = df.format(date);

For parameters, failure behavior, and how assembled files are structured, see the ensureLocale documentation in the API reference.

Installation

npm install ilib-localedata

You also need ilib-loader (and its peers such as ilib-env, ilib-locale) so file loading works in your environment (Node, browser, bundler, etc.). Those are declared as dependencies of this package; configure the loader as described in the ilib-loader documentation.

Basic usage

The following pattern is what iLib libraries use internally. If you are maintaining such a package, get a singleton per locale root with the default export getLocaleData (do not new LocaleData() yourself). Pass the filesystem path to your package’s locale directory. Then call loadData with a locale and basename; use sync: true only where the loader supports synchronous reads (for example Node).

import getLocaleData, { LocaleData } from 'ilib-localedata';

// Optional: search additional roots first (e.g. app or OS overrides)
LocaleData.addGlobalRoot('/path/to/custom/locale');

const localeData = getLocaleData({
    path: '/path/to/your-package/locale'
});

// Async (works everywhere)
const data = await localeData.loadData({
    locale: 'de-DE',
    basename: 'info'
});

// Sync, when the loader supports it and data is available
const syncData = localeData.loadData({
    locale: 'de-DE',
    basename: 'info',
    sync: true
});

For merge options, roots, cacheData, and edge cases, see the architecture document and API reference.

Architecture

For how locale data loading, caching, and packaging fit together, see Architecture.

Full JS Docs

To see a full explanation of the LocaleData class, please see the full API documentation.

Logging

Use the name "ilib-localedata" to configure a log4js appender in your app to see logging output from this library.

License

Copyright © 2022, 2025-2026 JEDLSoft

This package is released under the Apache License, Version 2.0. The full license text is available in the LICENSE file in the ilib-mono repository on GitHub.

Release Notes

See CHANGELOG.md.