Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including tibetan-sort-js with all npm packages installed. Try it out:

var tibetanSortJs = require("tibetan-sort-js")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

tibetan-sort-js v2.1.3

Tibetan string sorting according to customary native order

JS Library to sort Tibetan

After exploring different options for tibetan collation in JavaScript, there seems to be no viable option to sort Unicode Tibetan strings. This library hopes to fullfill this purpose in an elegant, modern and efficient manner.

State of the art

The most logical option to sort Tibetan would by using Intl.Collator. The problem is that all browsers seems to use ICU to implement this object, and ICU has a bug on Tibetan collation, which won't be fixed in the short term. It will take even more time for the fix to appear in mainstream browsers, so it's not even a middle term solution. Bugs have been filled for Firefox, ChakraCore, Chrome and Safari.

Pure Javascript implementations of Intl.Collator don't seem to exist, as the only Intl polyfill doesn't support it.

The only library we found that would be of possible use is lasca, but it proved very buggy and extremely inefficient.

This implementation

This implementation aims at being very efficient, at the cost of difficult corner cases in Tibetan. As a consequence:

  • it does not normalize strings (\u0F77 is not treated like \u0FB2\u0F71\u0F80)
  • it does not handle Sanskrit stacks very precisely (the ICU rule &ཀར<ཀརྐ is too difficult to handle)


yarn add tibetan-sort-js --save



Compares two strings in Tibetan Unicode, can be used as argument of The behavior is undefined if the arguments are not strings. Doesn't workswell with non-Tibetan strings.


  • a string first string to be compared.
  • b string second string to be compared.

Returns number 0 if equivalent, 1 if a > b, -1 if a < b


Compares two strings in EWTS, has the same argument and return value as compare. The function only works on customary EWTS and doesn't handle oddly encoded cases such as b.r+g+ya (instead of brgya).


  • add an option to normalize strings?

Release history

See change log.


The code is Copyright 2017-2019 Buddhist Digital Resource Center, and is provided under the MIT License.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free