cldr-text-direction 0.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +50 -0
- package/index.d.mts +19 -0
- package/index.mjs +2 -0
- package/package.json +41 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025-Present Aviv Keller
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# cldr-text-direction
|
|
2
|
+
|
|
3
|
+
Finds whether a locale is written left-to-right or right-to-left, using the
|
|
4
|
+
[Unicode CLDR](https://cldr.unicode.org/) and the Unicode Character
|
|
5
|
+
Database. Works in every JavaScript engine, unlike
|
|
6
|
+
`Intl.Locale.prototype.getTextInfo()`.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install cldr-text-direction
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import { getTextDirection, isRightToLeft } from "cldr-text-direction";
|
|
18
|
+
|
|
19
|
+
getTextDirection("ar"); // "rtl"
|
|
20
|
+
getTextDirection("en-US"); // "ltr"
|
|
21
|
+
getTextDirection("ar-Latn"); // "ltr" (Arabic in Latin script)
|
|
22
|
+
getTextDirection("az-Arab"); // "rtl"
|
|
23
|
+
|
|
24
|
+
document.documentElement.dir = getTextDirection(navigator.language);
|
|
25
|
+
|
|
26
|
+
isRightToLeft("he"); // true
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The default export is `getTextDirection`, with every export as a property:
|
|
30
|
+
`import getTextDirection from "cldr-text-direction"`.
|
|
31
|
+
|
|
32
|
+
## API
|
|
33
|
+
|
|
34
|
+
### `getTextDirection(locale)`
|
|
35
|
+
|
|
36
|
+
Returns `"rtl"` or `"ltr"`. A script subtag decides when there is one;
|
|
37
|
+
otherwise the locale's CLDR layout, or for languages without CLDR data, the
|
|
38
|
+
direction of the language's likely script.
|
|
39
|
+
|
|
40
|
+
### `isRightToLeft(locale)`
|
|
41
|
+
|
|
42
|
+
Returns whether `getTextDirection(locale)` is `"rtl"`.
|
|
43
|
+
|
|
44
|
+
### `VERSION`
|
|
45
|
+
|
|
46
|
+
The CLDR version of the data, such as `"49.0.0"`.
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT. Includes data from the Unicode CLDR and the Unicode Character Database, © Unicode, Inc., under the [Unicode License v3](https://www.unicode.org/license.txt).
|
package/index.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const VERSION: string;
|
|
2
|
+
/**
|
|
3
|
+
* Returns the direction a locale's text is written in
|
|
4
|
+
* @param {string | Intl.Locale} locale
|
|
5
|
+
* @returns {"ltr" | "rtl"}
|
|
6
|
+
*/
|
|
7
|
+
export declare function getTextDirection(locale: string | Intl.Locale): "ltr" | "rtl";
|
|
8
|
+
/**
|
|
9
|
+
* Checks whether a locale's text is written right-to-left
|
|
10
|
+
* @param {string | Intl.Locale} locale
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
export declare function isRightToLeft(locale: string | Intl.Locale): boolean;
|
|
14
|
+
declare const _default: typeof getTextDirection & {
|
|
15
|
+
getTextDirection: typeof getTextDirection;
|
|
16
|
+
isRightToLeft: typeof isRightToLeft;
|
|
17
|
+
VERSION: string;
|
|
18
|
+
};
|
|
19
|
+
export { _default as default };
|
package/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! cldr-text-direction | MIT License | Includes data © Unicode, Inc., Unicode License v3 (https://www.unicode.org/license.txt) */
|
|
2
|
+
const e=/* @__PURE__ */ new Map;function t(t){if(typeof t!=`string`)return new Intl.Locale(t).baseName;let n=e.get(t);return n===void 0&&(e.size>=1e3&&e.clear(),n=new Intl.Locale(t).baseName,e.set(t,n)),n}function n(e,n){let r=t(n);for(;!e.locales.has(r);){let t=r.lastIndexOf(`-`);r=e.aliases.get(r)??(t===-1?`und`:r.slice(0,t))}return r}function r(e,t){return e.values[e.locales.get(n(e,t))]}const i={values:[`ltr`,`rtl`],locales:/* @__PURE__ */ new Map([[`und`,0],[`aao`,1],[`abh`,1],[`abv`,1],[`acm`,1],[`acq`,1],[`acw`,1],[`acx`,1],[`adf`,1],[`ae`,1],[`aeb`,1],[`aec`,1],[`aee`,1],[`aeq`,1],[`afb`,1],[`aib`,1],[`aii`,1],[`aij`,1],[`aiq`,1],[`amw`,1],[`apc`,1],[`apd`,1],[`ar`,1],[`arc`,1],[`arq`,1],[`ars`,1],[`ary`,1],[`arz`,1],[`ask`,1],[`atn`,1],[`auj`,1],[`auz`,1],[`avd`,1],[`avl`,1],[`ayh`,1],[`ayl`,1],[`ayn`,1],[`ayp`,1],[`azb`,1],[`bal`,1],[`bdz`,1],[`bej`,1],[`bft`,1],[`bgn`,1],[`bgp`,1],[`bhe`,1],[`bhm`,1],[`bhn`,1],[`bjf`,1],[`bjm`,1],[`bqi`,1],[`brh`,1],[`brk`,1],[`bsh`,1],[`bsk`,1],[`chg`,1],[`cja`,1],[`ckb`,1],[`clh`,1],[`czk`,1],[`dcc`,1],[`def`,1],[`deh`,1],[`dgl`,1],[`dmk`,1],[`dml`,1],[`dv`,1],[`ecy`,1],[`esh`,1],[`fa`,1],[`fay`,1],[`faz`,1],[`fia`,1],[`fub`,1],[`gbz`,1],[`ggg`,1],[`gha`,1],[`ghr`,1],[`gig`,1],[`gjk`,1],[`gju`,1],[`glh`,1],[`glk`,1],[`grr`,1],[`gwc`,1],[`gwf`,1],[`gwt`,1],[`gzi`,1],[`hac`,1],[`haz`,1],[`hbo`,1],[`he`,1],[`hkh`,1],[`hnd`,1],[`hno`,1],[`hoh`,1],[`hrt`,1],[`hrz`,1],[`hss`,1],[`huy`,1],[`isk`,1],[`itk`,1],[`jad`,1],[`jat`,1],[`jbe`,1],[`jbn`,1],[`jdg`,1],[`ji`,1],[`jnd`,1],[`jog`,1],[`jpa`,1],[`jpr`,1],[`jrb`,1],[`jye`,1],[`kbu`,1],[`kby`,1],[`kcy`,1],[`kfm`,1],[`khw`,1],[`klj`,1],[`kmz`,1],[`kqd`,1],[`ks`,1],[`ktl`,1],[`kvx`,1],[`kxp`,1],[`lad`,1],[`lah`,1],[`lhs`,1],[`lki`,1],[`lrc`,1],[`lrk`,1],[`lrl`,1],[`lsa`,1],[`lsd`,1],[`lss`,1],[`luv`,1],[`luz`,1],[`mby`,1],[`mde`,1],[`mey`,1],[`mfa`,1],[`mfi`,1],[`mhj`,1],[`mid`,1],[`mki`,1],[`mnj`,1],[`mve`,1],[`mvy`,1],[`myz`,1],[`mzb`,1],[`mzn`,1],[`nli`,1],[`nlm`,1],[`nqo`,1],[`ntz`,1],[`nyq`,1],[`oar`,1],[`obm`,1],[`odk`,1],[`omy`,1],[`oru`,1],[`ota`,1],[`otk`,1],[`oui`,1],[`pal`,1],[`pbt`,1],[`pgd`,1],[`phl`,1],[`phn`,1],[`phr`,1],[`phv`,1],[`plk`,1],[`prc`,1],[`prd`,1],[`prx`,1],[`ps`,1],[`psh`,1],[`psi`,1],[`pst`,1],[`qxq`,1],[`rdb`,1],[`rhg`,1],[`rmt`,1],[`sam`,1],[`sbn`,1],[`scl`,1],[`sd`,1],[`sdb`,1],[`sdf`,1],[`sdg`,1],[`sdh`,1],[`sds`,1],[`sgr`,1],[`sgy`,1],[`shd`,1],[`shm`,1],[`shu`,1],[`shv`,1],[`siy`,1],[`siz`,1],[`skr`,1],[`smp`,1],[`smy`,1],[`sog`,1],[`sqo`,1],[`sqt`,1],[`srh`,1],[`srz`,1],[`ssh`,1],[`sts`,1],[`swb`,1],[`syc`,1],[`syn`,1],[`syr`,1],[`tjo`,1],[`tks`,1],[`tmr`,1],[`tov`,1],[`tra`,1],[`trg`,1],[`trm`,1],[`trw`,1],[`ug`,1],[`ur`,1],[`ush`,1],[`uzs`,1],[`vaf`,1],[`vgr`,1],[`vmh`,1],[`wbk`,1],[`wne`,1],[`wni`,1],[`wsv`,1],[`xco`,1],[`xhe`,1],[`xka`,1],[`xkc`,1],[`xkj`,1],[`xkp`,1],[`xld`,1],[`xly`,1],[`xmn`,1],[`xmr`,1],[`xna`,1],[`xpr`,1],[`xsa`,1],[`xsd`,1],[`xvi`,1],[`ydg`,1],[`yhd`,1],[`yi`,1],[`yih`,1],[`yud`,1],[`zba`,1],[`zdj`,1],[`zrp`,1],[`zum`,1],[`bal-Latn`,0],[`ff-Adlm`,1],[`kk-Arab`,1],[`ks-Deva`,0],[`pa-Arab`,1],[`sd-Deva`,0],[`uz-Arab`,1]]),aliases:/* @__PURE__ */ new Map([[`kk-AF`,`kk-Arab-AF`],[`kk-CN`,`kk-Arab-CN`],[`kk-IR`,`kk-Arab-IR`],[`kk-MN`,`kk-Arab-MN`],[`pa-PK`,`pa-Arab-PK`],[`sd-IN`,`sd-Deva-IN`],[`uz-AF`,`uz-Arab-AF`]])},a=/* @__PURE__ */ new Set(/* @__PURE__ */ `Hebr Arab Syrc Thaa Cprt Khar Phnx Nkoo Lydi Avst Samr Armi Sarb Prti Phli Orkh Mand Merc Mero Mani Mend Narb Nbat Palm Phlp Hatr Hung Adlm Rohg Sogd Sogo Elym Chrs Yezi Ougr Gara Sidt`.split(` `)),o=`49.0.0`,s=/^[A-Z][a-z]{3}$/;function c(e){let n=t(e).split(`-`)[1];return n!==void 0&&s.test(n)?a.has(n)?`rtl`:`ltr`:r(i,e)}function l(e){return c(e)===`rtl`}var u=/* @__PURE__ */ Object.assign(c,{getTextDirection:c,isRightToLeft:l,VERSION:o});export{o as VERSION,u as default,c as getTextDirection,l as isRightToLeft};
|
package/package.json
CHANGED
|
@@ -1 +1,41 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "cldr-text-direction",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Find whether a locale is written right-to-left or left-to-right, based on the Unicode CLDR",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"unicode",
|
|
7
|
+
"cldr",
|
|
8
|
+
"rtl",
|
|
9
|
+
"ltr",
|
|
10
|
+
"bidi",
|
|
11
|
+
"direction",
|
|
12
|
+
"dir",
|
|
13
|
+
"i18n",
|
|
14
|
+
"locale"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "Aviv Keller <me@aviv.sh>",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "./index.mjs",
|
|
20
|
+
"types": "./index.d.mts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./index.d.mts",
|
|
24
|
+
"default": "./index.mjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"index.mjs",
|
|
29
|
+
"index.d.mts"
|
|
30
|
+
],
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/avivkeller/unicode-packages.git",
|
|
35
|
+
"directory": "packages/cldr/text-direction"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/avivkeller/unicode-packages/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/avivkeller/unicode-packages/tree/main/packages/cldr/text-direction#readme"
|
|
41
|
+
}
|