{"id":29376529,"url":"https://github.com/twitter/twitter-cldr-js","last_synced_at":"2025-07-09T22:43:26.563Z","repository":{"id":4076553,"uuid":"5181699","full_name":"twitter/twitter-cldr-js","owner":"twitter","description":"JavaScript implementation of the ICU (International Components for Unicode) that uses the Common Locale Data Repository to format dates, plurals, and more.  Based on twitter-cldr-rb.","archived":false,"fork":false,"pushed_at":"2023-04-10T11:27:13.000Z","size":26979,"stargazers_count":347,"open_issues_count":13,"forks_count":55,"subscribers_count":122,"default_branch":"master","last_synced_at":"2024-05-09T19:34:58.880Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twitter.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-07-25T16:38:15.000Z","updated_at":"2024-04-28T16:51:31.000Z","dependencies_parsed_at":"2023-07-06T17:46:22.093Z","dependency_job_id":null,"html_url":"https://github.com/twitter/twitter-cldr-js","commit_stats":{"total_commits":270,"total_committers":19,"mean_commits":"14.210526315789474","dds":0.6777777777777778,"last_synced_commit":"a6c80807e5468e84f3c2fb0915d1d00beb14b810"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/twitter/twitter-cldr-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twitter%2Ftwitter-cldr-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twitter%2Ftwitter-cldr-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twitter%2Ftwitter-cldr-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twitter%2Ftwitter-cldr-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twitter","download_url":"https://codeload.github.com/twitter/twitter-cldr-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twitter%2Ftwitter-cldr-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264504617,"owners_count":23618831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-09T22:43:25.707Z","updated_at":"2025-07-09T22:43:26.551Z","avatar_url":"https://github.com/twitter.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## twitter-cldr-js  [![Build Status](https://secure.travis-ci.org/twitter/twitter-cldr-js.png?branch=master)](http://travis-ci.org/twitter/twitter-cldr-js)\n\nTwitterCldr uses Unicode's Common Locale Data Repository (CLDR) to format certain types of text into their\nlocalized equivalents via the Rails asset pipeline.  It is a port of [twitter-cldr-rb](http://github.com/twitter/twitter-cldr-rb), a Ruby gem that uses the same CLDR data.  Originally, this project was not a gem, but a collection of JavaScript files.  It has been turned into a gem to move the JavaScript compiling routines from twitter-cldr-rb and provide support for the asset pipeline.\n\nCurrently, twitter-cldr-js supports the following:\n\n1. Date and time formatting\n2. Relative date and time formatting (eg. 1 month ago)\n3. Number formatting (decimal, currency, and percentage)\n4. Long/short decimals\n5. Plural rules\n6. Bidirectional reordering\n7. Text Segmentation\n\n## Installation\n\nAdd twitter-cldr-js to your Gemfile:\n\n```ruby\ngem 'twitter_cldr_js', :require =\u003e 'twitter_cldr/js'\n```\n\nIf you're not using bundler, run `gem install twitter_cldr_js` and then require `twitter_cldr/js` somewhere in your project.  Note that twitter-cldr-js isn't really designed to run outside of Rails.  If you need the JavaScript functionality it provides but aren't using Rails, consider copying the compiled JavaScript files (lib/assets/javascripts/twitter_cldr/*.js) into your project by hand instead of using this gem directly.\n\nYou can also get twitter-cldr-js in a form of an NPM package:\n\n```bash\nnpm install twitter_cldr\n```\n\nCheck out [twitter/twitter-cldr-npm](https://github.com/twitter/twitter-cldr-npm) repository for details.\n\n## Usage with Rails\n\nTo use twitter-cldr-js, you need to make use of two files: the core file with the libraries, `core.js` and one of the various locale data files, `es.js`, `en.js` etc. You can include them in your JavaScript manifest (`app/assets/javascripts/application.js`) like this:\n\n```ruby\n//= require twitter_cldr/es\n//= require twitter_cldr/core\n```\n\nThis will make the core library twitter-cldr-js available to the JavaScript in your app along with the data bundle for the Spanish locale. If your app supports multiple languages however, this single-locale approach won't be much use.  Instead, require the right file with `javascript_include_tag` for example in a view or a layout:\n\n```ruby\n\u003c%= javascript_include_tag \"twitter_cldr/#{I18n.locale}.js\" %\u003e\n```\n\n## Initialization\n\nYou need to load the core library along with a language bundle for optimal use. If you load the data bundle before the core library, the core library sets the data bundle as its data source.\n\n```ruby\n//= require twitter_cldr/es\n//= require twitter_cldr/core\n```\n\nYou can verify that by trying this:\n\n```javascript\nTwitterCldr.Settings.locale(); // \"es\"\n```\n\nIf you only load the core library, without the data set, the same command will result in an error.\n\n```javascript\n// (only loaded `twitter_cldr/core`)\nTwitterCldr.Settings.locale(); // Error: \"Data not set\"\n```\n\nYou can change the data bundle the library is using as its source by invoking the `set_data` method on the TwitterCldr object.\n\n```javascript\n\nes_data = ...; // The es locale data bundle\nar_data = ...; // The ar locale data bundle\n\nTwitterCldr.set_data(es_data);\nTwitterCldr.Settings.locale(); // \"es\"\n\nTwitterCldr.set_data(ar_data);\nTwitterCldr.Settings.locale(); // \"ar\"\n```\n\n### Dates and Times\n\n```javascript\n// include the es data bundle for the Spanish DateTimeFormatter\nvar fmt = new TwitterCldr.DateTimeFormatter();\n\nfmt.format(new Date(), {\"type\": \"full\"});                     // \"lunes, 12 de diciembre de 2011 21:44:57 UTC -0800\"\nfmt.format(new Date(), {\"type\": \"long\"});                     // \"12 de diciembre de 201121:45:42 -08:00\"\nfmt.format(new Date(), {\"type\": \"medium\"});                   // \"12/12/2011 21:46:09\"\nfmt.format(new Date(), {\"type\": \"short\"});                    // \"12/12/11 21:47\"\n\nfmt.format(new Date(), {\"format\": \"date\", \"type\": \"full\"});   // \"lunes, 12 de diciembre de 2011\"\nfmt.format(new Date(), {\"format\": \"date\", \"type\": \"long\"});   // \"12 de diciembre de 2011\"\nfmt.format(new Date(), {\"format\": \"date\", \"type\": \"medium\"}); // \"12/12/2011\"\nfmt.format(new Date(), {\"format\": \"date\", \"type\": \"short\"});  // \"12/12/11\"\n\nfmt.format(new Date(), {\"format\": \"time\", \"type\": \"full\"});   // \"21:44:57 UTC -0800\"\nfmt.format(new Date(), {\"format\": \"time\", \"type\": \"long\"});   // \"21:45:42 -08:00\"\nfmt.format(new Date(), {\"format\": \"time\", \"type\": \"medium\"}); // \"21:46:09\"\nfmt.format(new Date(), {\"format\": \"time\", \"type\": \"short\"});  // \"21:47\"\n```\n\nThe default CLDR data set only includes 4 date formats, full, long, medium, and short.  See below for a list of additional formats.\n\n#### Additional Date Formats\n\nBesides the default date formats, CLDR supports a number of additional ones.  The list of available formats varys for each locale.  To get a full list, use the `additional_formats` method:\n\n```javascript\n// [\"EEEEd\", \"Ed\", \"GGGGyMd\", \"H\", \"Hm\", \"Hms\", \"M\", \"MEd\", \"MMM\", \"MMMEEEEd\", \"MMMEd\", ... ]\nTwitterCldr.DateTimeFormatter.additional_formats();\n```\n\nYou can use any of the returned formats as the `format` option when formatting dates:\n\n```javascript\n// 30/11/2012 15:38:33\nfmt.format(new Date(), {});\n// 30 de noviembre\nfmt.format(new Date(), {\"format\": \"additional\", \"type\": \"EEEEd\"});\n```\n\nIt's important to know that, even though a format may not be available across locales, TwitterCLDR will do it's best to approximate if no exact match can be found.\n\n##### List of additional date format examples for English:\n\n| Format | Output           |\n|:-------|------------------|\n| EHm    | Wed 17:05        |\n| EHms   | Wed 17:05:33     |\n| Ed     | 28 Wed           |\n| Ehm    | Wed 5:05 p.m.    |\n| Ehms   | Wed 5:05:33 p.m. |\n| Gy     | 2012 AD          |\n| H      | 17               |\n| Hm     | 17:05            |\n| Hms    | 17:05:33         |\n| M      | 11               |\n| MEd    | Wed 11/28        |\n| MMM    | Nov              |\n| MMMEd  | Wed Nov 28       |\n| MMMd   | Nov 28           |\n| Md     | 11/28            |\n| d      | 28               |\n| h      | 5 p.m.           |\n| hm     | 5:05 p.m.        |\n| hms    | 5:05:33 p.m.     |\n| ms     | 05:33            |\n| y      | 2012             |\n| yM     | 11/2012          |\n| yMEd   | Wed 11/28/2012   |\n| yMMM   | Nov 2012         |\n| yMMMEd | Wed Nov 28 2012  |\n| yMMMd  | Nov 28 2012      |\n| yMd    | 11/28/2012       |\n| yQQQ   | Q4 2012          |\n| yQQQQ  | 4th quarter 2012 |\n\n### Relative Dates and Times\n\nIn addition to formatting full dates and times, TwitterCLDR supports relative time spans.  It tries to guess the best time unit (eg. days, hours, minutes, etc) based on the length of time given.  Indicate past or future by using negative or positive numbers respectively:\n\n```javascript\n// include the en data bundle for the English TimespanFormatter\nvar fmt = new TwitterCldr.TimespanFormatter();\nvar then = Math.round(new Date(2012, 1, 1, 12, 0, 0).getTime() / 1000);\nvar now = Math.round(Date.now() / 1000);\n\nfmt.format(then - now);                    // \"6 months ago\"\nfmt.format(then - now, {unit: \"week\"});    // \"24 weeks ago\"\nfmt.format(then - now, {unit: \"year\"});    // \"0 years ago\"\nfmt.format(then + now, {unit: \"week\"});    // \"In 24 weeks\"\nfmt.format(then + now, {unit: \"year\"});    // \"In 0 years\"\n```\n\nThe `TimespanFormatter` can also handle time spans without a direction via the `direction: \"none\"` option.  Directionless timespans can be combined with the `type` option:\n\n```javascript\nfmt.format(180, {direction: \"none\", type: \"short\"});                 // \"3 mins\"\nfmt.format(180, {direction: \"none\", type: \"abbreviated\"});           // \"3m\"\nfmt.format(180, {direction: \"none\", type: \"short\", unit: \"second\"}); // \"180 secs\"\n```\n\nBy default, timespans are exact representations of a given unit of elapsed time.  TwitterCLDR also supports approximate timespans which round up to the nearest larger unit.  For example, \"44 seconds\" remains \"44 seconds\" while \"45 seconds\" becomes \"1 minute\".  To approximate, pass the `approximate: true` option:\n\n```javascript\nfmt.format(44, {approximate: true});  // Dentro de 44 segundos\nfmt.format(45, {approximate: true});  // Dentro de 1 minuto\nfmt.format(52, {approximate: true});  // Dentro de 1 minuto\n```\n\n### Numbers\n\ntwitter-cldr-js number formatting supports decimals, currencies, and percentages.\n\n#### Decimals\n\n```javascript\n// include the es data bundle for the Spanish NumberFormatter\nvar fmt = new TwitterCldr.DecimalFormatter();\nfmt.format(1337);                      // \"1.337\"\nfmt.format(-1337);                     // \"-1.337\"\nfmt.format(1337, {precision: 2});      // \"1.337,00\"\n```\n\n#### Short / Long Decimals\n\nIn addition to formatting regular decimals, TwitterCLDR supports short and long decimals.  Short decimals abbreviate the notation for the appropriate power of ten, for example \"1M\" for 1,000,000 or \"2K\" for 2,000.  Long decimals include the full notation, for example \"1 million\" or \"2 thousand\":\n\n```javascript\nvar fmt = new TwitterCldr.ShortDecimalFormatter();\nfmt.format(2337);     // 2K\nfmt.format(1337123);  // 1M\n\nfmt = new TwitterCldr.LongDecimalFormatter();\nfmt.format(2337);     // 2 thousand\nfmt.format(1337123);  // 1 million\n```\n\n#### Currencies\n\n```javascript\nvar fmt = new TwitterCldr.CurrencyFormatter();\nfmt.format(1337, {currency: \"EUR\"});                 // 1.337,00 €\n```\n\n#### Percentages\n\n```javascript\nvar fmt = new TwitterCldr.PercentFormatter();\nfmt.format(1337);                      // 1.337%\nfmt.format(1337, {precision: 2});      // 1.337,00%\n```\n\n#### More on Currencies\n\nIf you're looking for a list of supported currencies, use the `Currencies` function:\n\n```javascript\n# all supported currency codes\nTwitterCldr.Currencies.currency_codes()             # [\"ADP\", \"AED\", \"AFA\", \"AFN\", ... ]\n\n# data for a specific currency code\nTwitterCldr.Currencies.for_code(\"CAD\")            # {currency: \"CAD\", name: \"Canadian dollar\", cldr_symbol: \"CA$\", symbol: \"$\", code_points: [36]}\n```\n\n### Plural Rules\n\nSome languages, like English, have \"countable\" nouns.  You probably know this concept better as \"plural\" and \"singular\", i.e. the difference between \"strawberry\" and \"strawberries\".  Other languages, like Russian, have three plural forms: one (numbers ending in 1), few (numbers ending in 2, 3, or 4), and many (everything else).  Still other languages like Japanese don't use countable nouns at all.\n\nTwitterCLDR makes it easy to find the plural rules for any numeric value:\n\n```javascript\n// include the ru data bundle for access to Russian Plural rules\nTwitterCldr.PluralRules.rule_for(1);      // \"one\"\nTwitterCldr.PluralRules.rule_for(2);      // \"few\"\nTwitterCldr.PluralRules.rule_for(8);      // \"many\"\n```\n\nGet all the rules for your language:\n\n```javascript\nTwitterCldr.PluralRules.all();            // [\"one\", \"few\", \"many\", \"other\"]\n```\n\n### Rule Based Number Formatting\n\nThe available rule-based number formats defined by the CLDR data set vary by language. Some languages support ordinal and cardinal numbers, occasionally with an additional masculine/feminine option, while others do not. You'll need to consult the list of available formats for your language.\n\nRule-based number formats are categorized by groups, and within groups by rulesets. You'll need to specify both to make use of all the available formats for your language.\n\nTo get a list of supported groups for the current locale, use the `group_names` method:\n\n```javascript\n// include the en data bundle for the English RBNF Formatter\nvar formatter = new TwitterCldr.RBNF()\nformatter.group_names()\n```\n\nTo get a list of supported rulesets for a group name, use the `rule_set_names_for_group` method:\n\n```javascript\nformatter.rule_set_names_for_group('SpelloutRules')\n// [ '2d-year', 'spellout-numbering-year', 'spellout-numbering', ..., 'spellout-ordinal-verbose' ]\n\nformatter.rule_set_names_for_group('OrdinalRules')\n// [ 'digits-ordinal' ]\n```\n\nOnce you've chosen a group and ruleset, you can pass them to the `format` method:\n```javascript\nformatter.format(123, 'OrdinalRules', 'digits-ordinal')\n// '123rd'\n```\n\nIn comparison, here is what the Spanish formatting looks like\n```javascript\n// include the es data bundle for the Spanish RBNF Formatter\nvar formatter = new TwitterCldr.RBNF()\nformat.format(123, 'OrdinalRules', 'digits-ordinal-masculine') // '123º'\nformat.format(123, 'OrdinalRules', 'digits-ordinal-feminine')  // '123ª'\n```\n\nFor languages that have support for SpelloutRules, like English (and other languages), you can also specify an ordinal spellout:\n```javascript\nformatter.format(1024, \"SpelloutRules\", \"spellout-ordinal\")\n// 'one thousand twenty-fourth'\n```\n\n### Handling Bidirectional Text\n\nWhen it comes to displaying text written in both right-to-left (RTL) and left-to-right (LTR) languages, most display systems run into problems.  The trouble is that Arabic or Hebrew text and English text (for example) often get scrambled visually and are therefore difficult to read.  It's not usually the basic ASCII characters like A-Z that get scrambled - it's most often punctuation marks and the like that are confusingly mixed up (they are considered \"weak\" types by Unicode).\n\nTo mitigate this problem, Unicode supports special invisible characters that force visual reordering so that mixed RTL and LTR (called \"bidirectional\") text renders naturally on the screen.  The Unicode Consortium has developed an algorithm (The Unicode Bidirectional Algorithm, or UBA) that intelligently inserts these control characters where appropriate.  You can make use of the UBA implementation in TwitterCLDR by creating a new instance of `TwitterCldr.Bidi` via the `from_string` method, and manipulating it like so:\n\n```javascript\nvar bidi_str = TwitterCldr.Bidi.from_string(\"hello نزوة world\", {\"direction\": \"RTL\"});\nbidi_str.reorder_visually();\nbidi_str.toString();\n```\n**Disclaimer**: Google Translate tells me the Arabic in the example above means \"fancy\", but my confidence is not very high, especially since all the letters are unattached. Apologies to any native speakers :)\n\n### Postal Codes\n\nThe CLDR contains postal code validation regexes for a number of countries.\n\n```javascript\n// United States\nTwitterCldr.PostalCodes.is_valid(\"us\", \"94103\");     // true\nTwitterCldr.PostalCodes.is_valid(\"us\", \"9410\");      // false\n\n// England (Great Britain)\nTwitterCldr.PostalCodes.is_valid(\"gb\", \"BS98 1TL\");  // true\n\n// Sweden\nTwitterCldr.PostalCodes.is_valid(\"se\", \"280 12\");    // true\n\n// Canada\nTwitterCldr.PostalCodes.is_valid(\"ca\", \"V3H 1Z7\");   // true\n```\n\nGet a list of supported territories by using the `territories` method:\n\n```javascript\nTwitterCldr.PostalCodes.territories();  // [\"ad\", \"am\", \"ar\", \"as\", \"at\", ... ]\n```\n\nJust want the regex?  No problem:\n\n```javascript\nTwitterCldr.PostalCodes.regex_for_territory(\"us\");  // /\\d{5}([ \\-]\\d{4})?/\n```\n\n### Phone Codes\n\nLook up phone codes by territory:\n\n```javascript\n// United States\nTwitterCldr.PhoneCodes.code_for_territory(\"us\");  // \"1\"\n\n// Perú\nTwitterCldr.PhoneCodes.code_for_territory(\"pe\");  // \"51\"\n\n// Egypt\nTwitterCldr.PhoneCodes.code_for_territory(\"eg\");  // \"20\"\n\n// Denmark\nTwitterCldr.PhoneCodes.code_for_territory(\"dk\"); // \"45\"\n```\n\nGet a list of supported territories by using the `territories` method:\n\n```javascript\nTwitterCldr.PhoneCodes.territories();  // [\"zw\", \"an\", \"tr\", \"by\", \"mh\", ...]\n```\n\n### Territories Containment\n\nDetermine if a territory/region contains another region or a country (as describe [here](http://www.unicode.org/cldr/charts/25/supplemental/territory_containment_un_m_49.html)):\n\n```javascript\nTwitterCldr.TerritoriesContainment.children('151') // [\"BG\", \"BY\", \"CZ\", \"HU\", \"MD\", \"PL\", ...]\nTwitterCldr.TerritoriesContainment.children('RU')  // []\n\nTwitterCldr.TerritoriesContainment.parents('013') // [\"419\", \"003\", \"019\"]\nTwitterCldr.TerritoriesContainment.parents('001') // []\n\nTwitterCldr.TerritoriesContainment.contains('151', 'RU') // true\nTwitterCldr.TerritoriesContainment.contains('419', 'BZ') // true\nTwitterCldr.TerritoriesContainment.contains('419', 'FR') // false\n```\n\n### Unicode Regular Expressions\n\nUnicode regular expressions are an implementaion of regular expressions that support all Unicode characters in the [BMP](http://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane). They provide support for multi-character strings, Unicode character escapes, set operations (unions, intersections, and differences), and character sets.\n\n#### Changes to Character Classes\n\nHere's a complete list of the operations you can do inside a Unicode regex's character class.\n\n| Regex              | Description                                                                                                         |\n|:-------------------|:--------------------------------------------------------------------------------------------------------------------|\n|`[a]`               | The set containing 'a'.                                                                                             |\n|`[a-z]`             | The set containing 'a' through 'z' and all letters in between, in Unicode order.                                    |\n|`[^a-z]`            | The set containing all characters except 'a' through 'z', that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF. |\n|`[[pat1][pat2]]`    | The union of sets specified by pat1 and pat2.                                                                       |\n|`[[pat1]\u0026[pat2]]`   | The intersection of sets specified by pat1 and pat2.                                                                |\n|`[[pat1]-[pat2]]`   | The [symmetric difference](http://en.wikipedia.org/wiki/Symmetric_difference) of sets specified by pat1 and pat2.   |\n|`[:Lu:] or \\p{Lu}`  | The set of characters having the specified Unicode property; in this case, Unicode uppercase letters.               |\n|`[:^Lu:] or \\P{Lu}` | The set of characters not having the given Unicode property.                                                        |\n\nFor a description of available Unicode properties, see [Wikipedia](http://en.wikipedia.org/wiki/Unicode_character_property#General_Category) (click on \"[show]\").\n\n#### Using Unicode Regexes\n\nCreate Unicode regular expressions via the `compile` method:\n\n```javascript\n\nregex = TwitterCldr.UnicodeRegex.compile(\"[:Lu:]+\");\nregex2 = TwitterCldr.UnicodeRegex.compile(\"\\\\p{Lu}+\", \"g\");\n\t\t\t\t\t\t\t//escaping the '\\'\nregex3 = TwitterCldr.UnicodeRegex.compile(\"[[a-z]-[d-g]]+\", \"g\");\n\t\t\t\t\t\t\t//supports the JavaScript RegExp modifiers\n```\n\nOnce compiled, instances of `UnicodeRegex` can be directly used to match against a string:\n\n```javascript\n\nregex.match(\"ABC\");  // [\"ABC\"]\nregex2.match(\"ABCDfooABC\");  // [\"ABCD\", \"ABC\"]\nregex3.match(\"dog\"); // [\"o\"]\n```\n\nAlternatively, you can convert a `UnicodeRegex` into a native JavaScript regex by calling its `to_regexp` method:\n\n```javascript\n\nregex3.to_regexp(); // /(?:[\\u0061-\\u0063]|[\\u0068-\\u007a])+/g\nregex3.to_regexp().test(\"a\"); // true\nregex3.to_regexp().test(\"d\"); // false\n```\n\nProtip: Try to avoid negation in character classes (eg. [^abc] and \\P{Lu}) as it tends to negatively affect both performance when constructing regexes as well as matching.\n\n### Text Segmentation\n\nTwitterCLDR currently supports text segmentation by sentence as described in the [Unicode Technical Report #29](http://www.unicode.org/reports/tr29/). The segmentation algorithm makes use of Unicode regular expressions (described above). Segmentation by word, line, and grapheme boundaries could also be supported if someone wants them.\n\nText segmentation is performed by the `BreakIterator` class (name borrowed from ICU). You can use the `each_sentence` method segment by sentence.\n\n```javascript\n\niterator = new TwitterCldr.BreakIterator(\"en\");\niterator.each_sentence(\"The. Quick. Brown. Fox.\");\n\t\t\t\t\t\t// \"The.\", \" Quick.\", \" Brown.\", \" Fox.\"\n```\n\nTo improve segmentation accuracy, a list of special segmentation exceptions have been created by the ULI (Unicode Interoperability Technical Committee). They help with special cases like the abbreviations \"Mr.\" and \"Ms.\" where breaks should not occur. ULI rules are enabled by default, but you can disable them via the `use_uli_exceptions` option:\n\n```javascript\n\niterator = new TwitterCldr.BreakIterator (\"en\",\n\t\t\t\t\t\t{\"use_uli_exceptions\" : false}\n\t\t\t\t\t);\niterator.each_sentence(\"I like Ms. Murphy, she's nice.\");\n\t\t\t\t\t\t// [\"I like Ms.\", \" Murphy, she's nice.\"]\n```\n\n### Generating the JavaScript\n\nThe JavaScript files that make up twitter-cldr-js can be automatically generated for each language via a set of Rake tasks.\n\n* Build js files in the current directory: `bundle exec rake twitter_cldr:js:compile`\n* Build js files into a given directory: `bundle exec rake twitter_cldr:js:compile OUTPUT_DIR=/path/to/output/dir`\n* Build only the specified locales: `bundle exec rake twitter_cldr:js:compile OUTPUT_DIR=/path/to/output/dir LOCALES=ar,he,ko,ja`\n\n* Rebuild the js files internally in the gem: `bundle exec rake twitter_cldr:js:update`\n\n## Requirements\n\ntwitter-cldr-js requires Rails 3.1 or later.  To run the JavaScript test suite, you'll need Node and the jasmine-node NPM package.\n\n## Running Tests\n\n1. Install node (eg. `brew install node`, `sudo apt-get install node`, etc)\n2. Install jasmine-node: `npm install jasmine-node -g`\n2. Run `bundle install`\n3. Run `bundle exec rake`\n\n## Authors\n\n* Cameron C. Dutro: https://github.com/camertron\n* Portions taken from the ruby-cldr gem by Sven Fuchs: https://github.com/svenfuchs/ruby-cldr\n\n## Links\n* twitter-cldr-rb [https://github.com/twitter/twitter-cldr-rb](https://github.com/twitter/twitter-cldr-rb)\n* ruby-cldr gem: [https://github.com/svenfuchs/ruby-cldr](https://github.com/svenfuchs/ruby-cldr)\n* CLDR homepage: [http://cldr.unicode.org/](http://cldr.unicode.org/)\n\n## License\n\nCopyright 2015 Twitter, Inc.\n\nLicensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwitter%2Ftwitter-cldr-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwitter%2Ftwitter-cldr-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwitter%2Ftwitter-cldr-js/lists"}