Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

formatjs-extract-cldr-data

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formatjs-extract-cldr-data

Utility library that extracts the CLDR data that's needed by the FormatJS libraries.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
decreased by-47.13%
Maintainers
1
Weekly downloads
 
Created
Source

FormatJS Extract CLDR Data

Utility library that extracts the CLDR data that's needed by the FormatJS libraries.

npm Version Build Status Dependency Status

Usage

This package offers a function to extract the CLDR data needed by the FormatJS libraries via its default export. The data is returned as an object keyed by locale language tags; e.g., "en-US". This package leverages the fact that language tags are hierarchical and will only return the unique, de-duplicated data that's needed.

The following example shows how the locale hierarchy is used to return the unique data:

var extractData = require('formatjs-extract-cldr-data');

var data = extractData({
    locales    : ['en-US', 'en-GB'],
    pluralRules: true
});

console.log(data);
// => { en: { locale: 'en', pluralRuleFunction: [Function] } }

Since the pluralRuleFunction for the root locale "en" is the same as used in the locales: "en-US" and "en-GB", it is returned.

Data Shape

The data object returned from this package will have the following shape, here's the data for English:

{ en:
   { locale: 'en',
     pluralRuleFunction: [Function],
     fields:
      { year: [Object],
        month: [Object],
        day: [Object],
        hour: [Object],
        minute: [Object],
        second: [Object] } } }

Each field has the following shape, here's the data for English year:

{ displayName: 'Year',
  relative: { '0': 'this year', '1': 'next year', '-1': 'last year' },
  relativeTime:
   { future: { one: 'in {0} year', other: 'in {0} years' },
     past: { one: '{0} year ago', other: '{0} years ago' } } }

Options

In order for any data to be returned, the value true must be assigned to either the pluralRules and/or relativeFields options. By default, data will be returned for all locales in the CLDR; to limit which locales, assign an array of them to the locales option.

locales

An optional array of locales to extract data for, specified as string language tags. By default, data will be returned for all locales in the CLDR.

pluralRules

Boolean for whether or not pluralRuleFunctions should be extracted for the specified locales. These functions will support both cardinal and ordinal pluralization. These functions are generated using the make-plural project.

relativeFields

Boolean for whether or not fields should be extracted for the specified locales. The field data that's extracted is limited to the data required to support FormatJS' relative time formatting features, and it's organized in the shape described above.

Updating the CLDR Data

The CLDR version and data used by this package can be easily updated by running the Grunt task:

$ grunt update-cldr-data

Running this task will download the latest version of the CLDR's official JSON files and copy the files required by this package into the data/ directory.

License

This software is free to use under the Yahoo Inc. BSD license. See the LICENSE file for license text and copyright information.

The CLDR data contained in this packaged is licensed under the Apache, ICU, and Unicode licenses. See the CLDR license files for their license text and copyright information.

Keywords

FAQs

Package last updated on 02 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc