Socket
Socket
Sign inDemoInstall

cldr-plurals-runtime-js

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cldr-plurals-runtime-js

Javascript runtime for CLDR plural rules generated by camertron/cldr-plurals.


Version published
Maintainers
1
Install size
14.9 kB
Created

Changelog

Source

1.2.0

  • Support CLDR v38 syntax.
  • Convert to a Javascript package.
    • What was I thinking publishing this as a Ruby gem before? Smh.

Readme

Source

cldr-plurals-runtime-js

Build Status

Javascript runtime methods for CLDR plural rules (see camertron/cldr-plurals).

Installation

gem install cldr-plurals-runtime-js

Usage

const runtime = require('cldr-plurals-runtime');

Functionality

The CLDR data set contains plural information for numerous languages in an expression-based format defined by Unicode's TR35. The document describes how to determine the various parts of a number and how to use those parts to determine the plural rule. The parts as they appear in TR35 are:

SymbolValue
nabsolute value of the source number (integer and decimals).
iinteger digits of n.
vnumber of visible fraction digits in n, with trailing zeros.
wnumber of visible fraction digits in n, without trailing zeros.
fvisible fractional digits in n, with trailing zeros.
tvisible fractional digits in n, without trailing zeros.

cldr-plurals-runtime-js is an implementation of these calculations in Javascript. Rules can be compiled into Javascript using the cldr-plurals rubygem:

require 'cldr-plurals'

rules = CldrPlurals::Compiler::RuleList.new(:ru).tap do |rule_list|
  rule_list.add_rule(:one, 'v = 0 and i % 10 = 1 and i % 100 != 11')
  rule_list.add_rule(:few, 'v = 0 and i % 10 = 2..4 and i % 100 != 12..14')
  rule_list.add_rule(:many, 'v = 0 and i % 10 = 0 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 11..14')
end

js_code = rules.to_code(:javascript)

Once you've produced the Javascript code for the rule list, you can execute them like so:

const runtime = require('cldr-plurals-runtime');
const rule = function() { ... }  // code generated above by cldr-plurals
console.log(rule('3', runtime))  // => "few"

Requirements

No external requirements.

Running Tests

jasmine-node spec/ should do the trick.

Authors

Keywords

FAQs

Last updated on 24 Nov 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc