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

icu-transliterator

v0.3.7

Published

node.js bindings for ICU rule-based transliterators and rule-based number formats

Downloads

34

Readme

node-icu-transliterator

This module provides node.js bindings for ICU’s Rule-Based Transliterators and Rule-Based Number Formats.

The module is published on NPM as icu-transliterator. To install it, you need to have ICU installed and accessible to pkg-config. On macOS, you can install ICU with Homebrew by running brew install icu4c. You can add it to the pkg-config path with export PKG_CONFIG_PATH=/usr/local/opt/icu4c/lib/pkgconfig.

Rule-Based Transliterators

Example:

let RBT = require('icu-transliterator').RBT;

let myRBT = RBT('Latin-Cyrillic', RBT.FORWARD);
myRBT.transliterate('mir'); // -> 'мир'

let myRBT = RBT.fromRules('a > b; b > a;', RBT.FORWARD);
myRBT.transliterate('abcd'); // -> 'bacd'

RBT.register('foo', 'a > c; b > d;');
let myRBT = RBT('foo', RBT.FORWARD);
myRBT.transliterate('abcd'); // -> 'cdcd'

RBT(id, dir) creates a transliterator from an ICU transliterator ID. The first argument is the ID. The optional second argument is the direction, either RBT.FORWARD (default) or RBT.REVERSE.

RBT.fromRules(rules, dir) creates a transliterator from a rules string. The first argument is rules string and the second argument is the direction, either RBT.FORWARD or RBT.REVERSE. If the second argument is omitted, it defaults to RBT.FORWARD.

The returned transliterator object has a single method transliterate. It takes one argument, a string to transliterate, and returns the transliterated string.

RBT.register(id, rules, dir) registers a new transliterator with ICU. The first argument is the new ID, the second argument is the rules string, and the optional third argument is the direction, either RBT.FORWARD (default) or RBT.REVERSE. Once registered, you can access the transliterator with RBT(id, dir).

Rule-Based Number Formats

Example:

let RBNF = require('icu-transliterator').RBNF;

let myRBNF = RBNF('eng');
myRBNF.format(14); //  -> 'fourteen'

let myRBNF = RBNF('eng', RBNF.ORDINAL);
myRBNF.format(14); //  -> '14th'

let myRBNF = RBNF.fromRules('-x: minus >>; x.x: << point >>; zero; one; two; three; four; five; six; seven; eight; nine; 10: << >>; 100: << >>>; 1000: <<, >>>; 1,000,000: <<, >>>; 1,000,000,000: <<, >>>; 1,000,000,000,000: <<, >>>; 1,000,000,000,000,000: =#,##0=; ');
myRBNF.format(1.1); // -> 'one point one'

RBNF(language, tag) creates a number formatter for a built-in ICU locale. The first argument is the language code (ISO 639 alpha-2 or alpha-3). The optional second argument is one of RBNF.SPELLOUT (default), RBNF.ORDINAL, RBNF.DURATION, or RBNF.NUMBERING_SYSTEM.

RBNF.fromRules(rules) creates a number formatter from the passed-in rules string.

The returned formatter object has a single method format. It takes one argument, a number to format, and returns the formatted string.