@formatjs/intl-unified-numberformat
Advanced tools
Comparing version 0.4.6 to 0.4.8
@@ -6,2 +6,24 @@ # Change Log | ||
## [0.4.8](https://github.com/formatjs/formatjs/compare/@formatjs/intl-unified-numberformat@0.4.7...@formatjs/intl-unified-numberformat@0.4.8) (2019-09-03) | ||
**Note:** Version bump only for package @formatjs/intl-unified-numberformat | ||
## [0.4.7](https://github.com/formatjs/formatjs/compare/@formatjs/intl-unified-numberformat@0.4.6...@formatjs/intl-unified-numberformat@0.4.7) (2019-09-03) | ||
### Bug Fixes | ||
* **@formatjs/intl-relativetimeformat:** pass in raw locales to lookup ([9c2af2a](https://github.com/formatjs/formatjs/commit/9c2af2a)) | ||
* **@formatjs/intl-unified-numberformat:** memoize Intl.PluralRules ([429a7db](https://github.com/formatjs/formatjs/commit/429a7db)) | ||
* **@formatjs/intl-unified-numberformat:** pass in raw locales to lookup ([719c6f2](https://github.com/formatjs/formatjs/commit/719c6f2)) | ||
* **@formatjs/intl-unified-numberformat:** rely on Intl.PluralRules supported locales instead of both PL & NumberFormat ([8c8578d](https://github.com/formatjs/formatjs/commit/8c8578d)) | ||
## [0.4.6](https://github.com/formatjs/formatjs/compare/@formatjs/intl-unified-numberformat@0.4.5...@formatjs/intl-unified-numberformat@0.4.6) (2019-08-29) | ||
@@ -8,0 +30,0 @@ |
@@ -36,2 +36,3 @@ import { Unit } from './units-constants'; | ||
private nf; | ||
private pl; | ||
private locale; | ||
@@ -38,0 +39,0 @@ private patternData?; |
@@ -24,2 +24,9 @@ "use strict"; | ||
}; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -61,5 +68,2 @@ var intl_utils_1 = require("@formatjs/intl-utils"); | ||
} | ||
function intersection(arr1, arr2) { | ||
return arr1.filter(function (s) { return ~arr2.indexOf(s); }); | ||
} | ||
var DEFAULT_LOCALE = new NativeNumberFormat().resolvedOptions().locale; | ||
@@ -78,8 +82,7 @@ var UnifiedNumberFormat = /** @class */ (function () { | ||
this.unitDisplay = unitDisplay || 'short'; | ||
var resolvedLocale = intl_utils_1.resolveSupportedLocales(intersection(NativeNumberFormat.supportedLocalesOf(locales), Intl.PluralRules.supportedLocalesOf(locales)).concat([ | ||
DEFAULT_LOCALE, | ||
]), UnifiedNumberFormat.__unitLocaleData__)[0]; | ||
var resolvedLocale = intl_utils_1.resolveSupportedLocales(__spreadArrays((Array.isArray(locales) ? locales : [locales]), [DEFAULT_LOCALE]), UnifiedNumberFormat.__unitLocaleData__)[0]; | ||
this.patternData = findUnitData(resolvedLocale, this.unit); | ||
} | ||
this.nf = new NativeNumberFormat(locales, __assign({}, options, { style: style === 'unit' ? 'decimal' : style })); | ||
this.nf = new NativeNumberFormat(locales, __assign(__assign({}, options), { style: style === 'unit' ? 'decimal' : style })); | ||
this.pl = new Intl.PluralRules(locales); | ||
this.locale = this.nf.resolvedOptions().locale; | ||
@@ -90,3 +93,3 @@ } | ||
if (this.patternData) { | ||
var pl = new Intl.PluralRules(this.locale).select(num); | ||
var pl = this.pl.select(num); | ||
var pattern = this.patternData[this.unitDisplay][pl === 'one' ? 'one' : 'other']; | ||
@@ -93,0 +96,0 @@ return pattern.replace('{0}', formattedNum); |
@@ -19,4 +19,7 @@ (function (global, factory) { | ||
function resolveSupportedLocales(locales, localeData, aliases) { | ||
if (aliases === void 0) { aliases = {}; } | ||
/* @generated */ | ||
// prettier-ignore | ||
var aliases = { "aa-SAAHO": "ssy", "aam": "aas", "aar": "aa", "abk": "ab", "adp": "dz", "afr": "af", "aju": "jrb", "aka": "ak", "alb": "sq", "als": "sq", "amh": "am", "ara": "ar", "arb": "ar", "arg": "an", "arm": "hy", "art-lojban": "jbo", "asm": "as", "aue": "ktz", "ava": "av", "ave": "ae", "aym": "ay", "ayr": "ay", "ayx": "nun", "az-AZ": "az-Latn-AZ", "aze": "az", "azj": "az", "bak": "ba", "bam": "bm", "baq": "eu", "bcc": "bal", "bcl": "bik", "bel": "be", "ben": "bn", "bgm": "bcg", "bh": "bho", "bih": "bho", "bis": "bi", "bjd": "drl", "bod": "bo", "bos": "bs", "bre": "br", "bs-BA": "bs-Latn-BA", "bul": "bg", "bur": "my", "bxk": "luy", "bxr": "bua", "cat": "ca", "ccq": "rki", "cel-gaulish": "xtg-x-cel-gaulish", "ces": "cs", "cha": "ch", "che": "ce", "chi": "zh", "chu": "cu", "chv": "cv", "cjr": "mom", "cka": "cmr", "cld": "syr", "cmk": "xch", "cmn": "zh", "cnr": "sr-ME", "cor": "kw", "cos": "co", "coy": "pij", "cqu": "quh", "cre": "cr", "cwd": "cr", "cym": "cy", "cze": "cs", "dan": "da", "deu": "de", "dgo": "doi", "dhd": "mwr", "dik": "din", "diq": "zza", "div": "dv", "drh": "mn", "drw": "fa-af", "dut": "nl", "dzo": "dz", "ekk": "et", "ell": "el", "emk": "man", "eng": "en", "epo": "eo", "esk": "ik", "est": "et", "eus": "eu", "ewe": "ee", "fao": "fo", "fas": "fa", "fat": "ak", "fij": "fj", "fin": "fi", "fra": "fr", "fre": "fr", "fry": "fy", "fuc": "ff", "ful": "ff", "gav": "dev", "gaz": "om", "gbo": "grb", "geo": "ka", "ger": "de", "gfx": "vaj", "ggn": "gvr", "gla": "gd", "gle": "ga", "glg": "gl", "glv": "gv", "gno": "gon", "gre": "el", "grn": "gn", "gti": "nyc", "gug": "gn", "guj": "gu", "guv": "duz", "gya": "gba", "ha-Latn-GH": "ha-GH", "ha-Latn-NE": "ha-NE", "ha-Latn-NG": "ha-NG", "hat": "ht", "hau": "ha", "hbs": "sr-Latn", "hdn": "hai", "hea": "hmn", "heb": "he", "her": "hz", "him": "srx", "hin": "hi", "hmo": "ho", "hrr": "jal", "hrv": "hr", "hun": "hu", "hye": "hy", "i-ami": "ami", "i-bnn": "bnn", "i-hak": "hak", "i-klingon": "tlh", "i-lux": "lb", "i-navajo": "nv", "i-pwn": "pwn", "i-tao": "tao", "i-tay": "tay", "i-tsu": "tsu", "i-default": "en-x-i-default", "i-enochian": "und-x-i-enochian", "i-mingo": "see-x-i-mingo", "ibi": "opa", "ibo": "ig", "ice": "is", "ido": "io", "iii": "ii", "ike": "iu", "iku": "iu", "ile": "ie", "ilw": "gal", "in": "id", "ina": "ia", "ind": "id", "ipk": "ik", "isl": "is", "ita": "it", "iw": "he", "jav": "jv", "jeg": "oyb", "ji": "yi", "jpn": "ja", "jw": "jv", "kal": "kl", "kan": "kn", "kas": "ks", "kat": "ka", "kau": "kr", "kaz": "kk", "kgc": "tdf", "kgh": "kml", "khk": "mn", "khm": "km", "kik": "ki", "kin": "rw", "kir": "ky", "kk-Cyrl-KZ": "kk-KZ", "kmr": "ku", "knc": "kr", "kng": "kg", "knn": "kok", "koj": "kwv", "kom": "kv", "kon": "kg", "kor": "ko", "kpv": "kv", "krm": "bmf", "ks-Arab-IN": "ks-IN", "ktr": "dtp", "kua": "kj", "kur": "ku", "kvs": "gdj", "kwq": "yam", "kxe": "tvd", "ky-Cyrl-KG": "ky-KG", "kzj": "dtp", "kzt": "dtp", "lao": "lo", "lat": "la", "lav": "lv", "lbk": "bnc", "lii": "raq", "lim": "li", "lin": "ln", "lit": "lt", "lmm": "rmx", "ltz": "lb", "lub": "lu", "lug": "lg", "lvs": "lv", "mac": "mk", "mah": "mh", "mal": "ml", "mao": "mi", "mar": "mr", "may": "ms", "meg": "cir", "mhr": "chm", "mkd": "mk", "mlg": "mg", "mlt": "mt", "mn-Cyrl-MN": "mn-MN", "mnk": "man", "mo": "ro", "mol": "ro", "mon": "mn", "mri": "mi", "ms-Latn-BN": "ms-BN", "ms-Latn-MY": "ms-MY", "ms-Latn-SG": "ms-SG", "msa": "ms", "mst": "mry", "mup": "raj", "mwj": "vaj", "mya": "my", "myt": "mry", "nad": "xny", "nau": "na", "nav": "nv", "nbl": "nr", "ncp": "kdz", "nde": "nd", "ndo": "ng", "nep": "ne", "nld": "nl", "nno": "nn", "nnx": "ngv", "no": "nb", "no-bok": "nb", "no-BOKMAL": "nb", "no-nyn": "nn", "no-NYNORSK": "nn", "nob": "nb", "nor": "nb", "npi": "ne", "nts": "pij", "nya": "ny", "oci": "oc", "ojg": "oj", "oji": "oj", "ori": "or", "orm": "om", "ory": "or", "oss": "os", "oun": "vaj", "pa-IN": "pa-Guru-IN", "pa-PK": "pa-Arab-PK", "pan": "pa", "pbu": "ps", "pcr": "adx", "per": "fa", "pes": "fa", "pli": "pi", "plt": "mg", "pmc": "huw", "pmu": "phr", "pnb": "lah", "pol": "pl", "por": "pt", "ppa": "bfy", "ppr": "lcq", "prs": "fa-AF", "pry": "prt", "pus": "ps", "puz": "pub", "que": "qu", "quz": "qu", "rmy": "rom", "roh": "rm", "ron": "ro", "rum": "ro", "run": "rn", "rus": "ru", "sag": "sg", "san": "sa", "sca": "hle", "scc": "sr", "scr": "hr", "sgn-BE-FR": "sfb", "sgn-BE-NL": "vgt", "sgn-CH-DE": "sgg", "sh": "sr-Latn", "shi-MA": "shi-Tfng-MA", "sin": "si", "skk": "oyb", "slk": "sk", "slo": "sk", "slv": "sl", "sme": "se", "smo": "sm", "sna": "sn", "snd": "sd", "som": "so", "sot": "st", "spa": "es", "spy": "kln", "sqi": "sq", "sr-BA": "sr-Cyrl-BA", "sr-ME": "sr-Latn-ME", "sr-RS": "sr-Cyrl-RS", "sr-XK": "sr-Cyrl-XK", "src": "sc", "srd": "sc", "srp": "sr", "ssw": "ss", "sun": "su", "swa": "sw", "swc": "sw-CD", "swe": "sv", "swh": "sw", "tah": "ty", "tam": "ta", "tat": "tt", "tdu": "dtp", "tel": "te", "tgk": "tg", "tgl": "fil", "tha": "th", "thc": "tpo", "thx": "oyb", "tib": "bo", "tie": "ras", "tir": "ti", "tkk": "twm", "tl": "fil", "tlw": "weo", "tmp": "tyj", "tne": "kak", "tnf": "fa-af", "ton": "to", "tsf": "taj", "tsn": "tn", "tso": "ts", "ttq": "tmh", "tuk": "tk", "tur": "tr", "tw": "ak", "twi": "ak", "tzm-Latn-MA": "tzm-MA", "ug-Arab-CN": "ug-CN", "uig": "ug", "ukr": "uk", "umu": "del", "uok": "ema", "urd": "ur", "uz-AF": "uz-Arab-AF", "uz-UZ": "uz-Latn-UZ", "uzb": "uz", "uzn": "uz", "vai-LR": "vai-Vaii-LR", "ven": "ve", "vie": "vi", "vol": "vo", "wel": "cy", "wln": "wa", "wol": "wo", "xba": "cax", "xho": "xh", "xia": "acn", "xkh": "waw", "xpe": "kpe", "xsj": "suj", "xsl": "den", "ybd": "rki", "ydd": "yi", "yid": "yi", "yma": "lrr", "ymt": "mtm", "yor": "yo", "yos": "zom", "yue-CN": "yue-Hans-CN", "yue-HK": "yue-Hant-HK", "yuu": "yug", "zai": "zap", "zh-CN": "zh-Hans-CN", "zh-guoyu": "zh", "zh-hakka": "hak", "zh-HK": "zh-Hant-HK", "zh-min-nan": "nan", "zh-MO": "zh-Hant-MO", "zh-SG": "zh-Hans-SG", "zh-TW": "zh-Hant-TW", "zh-xiang": "hsn", "zh-min": "nan-x-zh-min", "zha": "za", "zho": "zh", "zsm": "ms", "zul": "zu", "zyb": "za" }; | ||
function resolveSupportedLocales(locales, localeData) { | ||
var resolvedLocales = (Array.isArray(locales) ? locales : [locales]) | ||
@@ -72,2 +75,9 @@ .filter(function (s) { return typeof s === 'string'; }) | ||
}; | ||
var __spreadArrays = (undefined && undefined.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
function isUnitSupported(unit) { | ||
@@ -106,5 +116,2 @@ try { | ||
} | ||
function intersection(arr1, arr2) { | ||
return arr1.filter(function (s) { return ~arr2.indexOf(s); }); | ||
} | ||
var DEFAULT_LOCALE = new NativeNumberFormat().resolvedOptions().locale; | ||
@@ -123,8 +130,7 @@ var UnifiedNumberFormat = /** @class */ (function () { | ||
this.unitDisplay = unitDisplay || 'short'; | ||
var resolvedLocale = resolveSupportedLocales(intersection(NativeNumberFormat.supportedLocalesOf(locales), Intl.PluralRules.supportedLocalesOf(locales)).concat([ | ||
DEFAULT_LOCALE, | ||
]), UnifiedNumberFormat.__unitLocaleData__)[0]; | ||
var resolvedLocale = resolveSupportedLocales(__spreadArrays((Array.isArray(locales) ? locales : [locales]), [DEFAULT_LOCALE]), UnifiedNumberFormat.__unitLocaleData__)[0]; | ||
this.patternData = findUnitData(resolvedLocale, this.unit); | ||
} | ||
this.nf = new NativeNumberFormat(locales, __assign$1({}, options, { style: style === 'unit' ? 'decimal' : style })); | ||
this.nf = new NativeNumberFormat(locales, __assign$1(__assign$1({}, options), { style: style === 'unit' ? 'decimal' : style })); | ||
this.pl = new Intl.PluralRules(locales); | ||
this.locale = this.nf.resolvedOptions().locale; | ||
@@ -135,3 +141,3 @@ } | ||
if (this.patternData) { | ||
var pl = new Intl.PluralRules(this.locale).select(num); | ||
var pl = this.pl.select(num); | ||
var pattern = this.patternData[this.unitDisplay][pl === 'one' ? 'one' : 'other']; | ||
@@ -138,0 +144,0 @@ return pattern.replace('{0}', formattedNum); |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).IntlUnifiedNumberFormat={})}(this,function(t){"use strict";function l(t,e,n){void 0===n&&(n={});var r,i,o,a,l=(Array.isArray(t)?t:[t]).filter(function(t){return"string"==typeof t}).map(function(t){return n[t]||t}),u=[];for(r=0,i=l.length;r<i;r+=1)for(o=l[r].toLowerCase().split("-");o.length;)if(e){if(a=e[o.join("-")]){u.push(a.locale);break}o.pop()}return u}var u=function(){return(u=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},s=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n};var f=Intl.NumberFormat;var p=(new f).resolvedOptions().locale,c=(y.prototype.format=function(t){var e=this.nf.format(t);if(this.patternData){var n=new Intl.PluralRules(this.locale).select(t);return this.patternData[this.unitDisplay]["one"===n?"one":"other"].replace("{0}",e)}return e},y.prototype.formatToParts=function(t){return this.nf.formatToParts(t)},y.prototype.resolvedOptions=function(){var t=this.nf.resolvedOptions();return this.unit&&(t.style="unit",t.unit=this.unit,t.unitDisplay=this.unitDisplay),t},y.supportedLocalesOf=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return l(t[0],y.__unitLocaleData__)},y.__addUnitLocaleData=function(n){Object.keys(n).forEach(function(t){var e=n[t];if(!e||!e.locale)throw new Error("Locale data provided to UnifiedNumberFormat is missing a `locale` property value");y.__unitLocaleData__[e.locale.toLowerCase()]=e})},y.polyfilled=!0,y.__unitLocaleData__={},y);function y(t,e){void 0===e&&(e={});var n=e.style,r=e.unit,i=e.unitDisplay,o=s(e,["style","unit","unitDisplay"]);if(this.unit=void 0,this.unitDisplay=void 0,"unit"===n){if(!r)throw new TypeError("Unit is required for `style: unit`");this.unit=r,this.unitDisplay=i||"short";var a=l(function(t,e){return t.filter(function(t){return~e.indexOf(t)})}(f.supportedLocalesOf(t),Intl.PluralRules.supportedLocalesOf(t)).concat([p]),y.__unitLocaleData__)[0];this.patternData=function t(e,n){var r=c.__unitLocaleData__,i="";if(r[e=e.toLowerCase()]){if(r[e].units[n])return r[e].units[n];if(!r[e].parentLocale)throw new RangeError("Cannot find data for "+e);i=r[e].parentLocale}else i=e.split("-")[0];return t(i,n)}(a,this.unit)}this.nf=new f(t,u({},o,{style:"unit"===n?"decimal":n})),this.locale=this.nf.resolvedOptions().locale}t.UnifiedNumberFormat=c,t.isUnitSupported=function(t){try{new Intl.NumberFormat(void 0,{style:"unit",unit:t})}catch(t){return!1}return!0},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(a,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((a=a||self).IntlUnifiedNumberFormat={})}(this,function(a){"use strict";var l={"aa-SAAHO":"ssy",aam:"aas",aar:"aa",abk:"ab",adp:"dz",afr:"af",aju:"jrb",aka:"ak",alb:"sq",als:"sq",amh:"am",ara:"ar",arb:"ar",arg:"an",arm:"hy","art-lojban":"jbo",asm:"as",aue:"ktz",ava:"av",ave:"ae",aym:"ay",ayr:"ay",ayx:"nun","az-AZ":"az-Latn-AZ",aze:"az",azj:"az",bak:"ba",bam:"bm",baq:"eu",bcc:"bal",bcl:"bik",bel:"be",ben:"bn",bgm:"bcg",bh:"bho",bih:"bho",bis:"bi",bjd:"drl",bod:"bo",bos:"bs",bre:"br","bs-BA":"bs-Latn-BA",bul:"bg",bur:"my",bxk:"luy",bxr:"bua",cat:"ca",ccq:"rki","cel-gaulish":"xtg-x-cel-gaulish",ces:"cs",cha:"ch",che:"ce",chi:"zh",chu:"cu",chv:"cv",cjr:"mom",cka:"cmr",cld:"syr",cmk:"xch",cmn:"zh",cnr:"sr-ME",cor:"kw",cos:"co",coy:"pij",cqu:"quh",cre:"cr",cwd:"cr",cym:"cy",cze:"cs",dan:"da",deu:"de",dgo:"doi",dhd:"mwr",dik:"din",diq:"zza",div:"dv",drh:"mn",drw:"fa-af",dut:"nl",dzo:"dz",ekk:"et",ell:"el",emk:"man",eng:"en",epo:"eo",esk:"ik",est:"et",eus:"eu",ewe:"ee",fao:"fo",fas:"fa",fat:"ak",fij:"fj",fin:"fi",fra:"fr",fre:"fr",fry:"fy",fuc:"ff",ful:"ff",gav:"dev",gaz:"om",gbo:"grb",geo:"ka",ger:"de",gfx:"vaj",ggn:"gvr",gla:"gd",gle:"ga",glg:"gl",glv:"gv",gno:"gon",gre:"el",grn:"gn",gti:"nyc",gug:"gn",guj:"gu",guv:"duz",gya:"gba","ha-Latn-GH":"ha-GH","ha-Latn-NE":"ha-NE","ha-Latn-NG":"ha-NG",hat:"ht",hau:"ha",hbs:"sr-Latn",hdn:"hai",hea:"hmn",heb:"he",her:"hz",him:"srx",hin:"hi",hmo:"ho",hrr:"jal",hrv:"hr",hun:"hu",hye:"hy","i-ami":"ami","i-bnn":"bnn","i-hak":"hak","i-klingon":"tlh","i-lux":"lb","i-navajo":"nv","i-pwn":"pwn","i-tao":"tao","i-tay":"tay","i-tsu":"tsu","i-default":"en-x-i-default","i-enochian":"und-x-i-enochian","i-mingo":"see-x-i-mingo",ibi:"opa",ibo:"ig",ice:"is",ido:"io",iii:"ii",ike:"iu",iku:"iu",ile:"ie",ilw:"gal",in:"id",ina:"ia",ind:"id",ipk:"ik",isl:"is",ita:"it",iw:"he",jav:"jv",jeg:"oyb",ji:"yi",jpn:"ja",jw:"jv",kal:"kl",kan:"kn",kas:"ks",kat:"ka",kau:"kr",kaz:"kk",kgc:"tdf",kgh:"kml",khk:"mn",khm:"km",kik:"ki",kin:"rw",kir:"ky","kk-Cyrl-KZ":"kk-KZ",kmr:"ku",knc:"kr",kng:"kg",knn:"kok",koj:"kwv",kom:"kv",kon:"kg",kor:"ko",kpv:"kv",krm:"bmf","ks-Arab-IN":"ks-IN",ktr:"dtp",kua:"kj",kur:"ku",kvs:"gdj",kwq:"yam",kxe:"tvd","ky-Cyrl-KG":"ky-KG",kzj:"dtp",kzt:"dtp",lao:"lo",lat:"la",lav:"lv",lbk:"bnc",lii:"raq",lim:"li",lin:"ln",lit:"lt",lmm:"rmx",ltz:"lb",lub:"lu",lug:"lg",lvs:"lv",mac:"mk",mah:"mh",mal:"ml",mao:"mi",mar:"mr",may:"ms",meg:"cir",mhr:"chm",mkd:"mk",mlg:"mg",mlt:"mt","mn-Cyrl-MN":"mn-MN",mnk:"man",mo:"ro",mol:"ro",mon:"mn",mri:"mi","ms-Latn-BN":"ms-BN","ms-Latn-MY":"ms-MY","ms-Latn-SG":"ms-SG",msa:"ms",mst:"mry",mup:"raj",mwj:"vaj",mya:"my",myt:"mry",nad:"xny",nau:"na",nav:"nv",nbl:"nr",ncp:"kdz",nde:"nd",ndo:"ng",nep:"ne",nld:"nl",nno:"nn",nnx:"ngv",no:"nb","no-bok":"nb","no-BOKMAL":"nb","no-nyn":"nn","no-NYNORSK":"nn",nob:"nb",nor:"nb",npi:"ne",nts:"pij",nya:"ny",oci:"oc",ojg:"oj",oji:"oj",ori:"or",orm:"om",ory:"or",oss:"os",oun:"vaj","pa-IN":"pa-Guru-IN","pa-PK":"pa-Arab-PK",pan:"pa",pbu:"ps",pcr:"adx",per:"fa",pes:"fa",pli:"pi",plt:"mg",pmc:"huw",pmu:"phr",pnb:"lah",pol:"pl",por:"pt",ppa:"bfy",ppr:"lcq",prs:"fa-AF",pry:"prt",pus:"ps",puz:"pub",que:"qu",quz:"qu",rmy:"rom",roh:"rm",ron:"ro",rum:"ro",run:"rn",rus:"ru",sag:"sg",san:"sa",sca:"hle",scc:"sr",scr:"hr","sgn-BE-FR":"sfb","sgn-BE-NL":"vgt","sgn-CH-DE":"sgg",sh:"sr-Latn","shi-MA":"shi-Tfng-MA",sin:"si",skk:"oyb",slk:"sk",slo:"sk",slv:"sl",sme:"se",smo:"sm",sna:"sn",snd:"sd",som:"so",sot:"st",spa:"es",spy:"kln",sqi:"sq","sr-BA":"sr-Cyrl-BA","sr-ME":"sr-Latn-ME","sr-RS":"sr-Cyrl-RS","sr-XK":"sr-Cyrl-XK",src:"sc",srd:"sc",srp:"sr",ssw:"ss",sun:"su",swa:"sw",swc:"sw-CD",swe:"sv",swh:"sw",tah:"ty",tam:"ta",tat:"tt",tdu:"dtp",tel:"te",tgk:"tg",tgl:"fil",tha:"th",thc:"tpo",thx:"oyb",tib:"bo",tie:"ras",tir:"ti",tkk:"twm",tl:"fil",tlw:"weo",tmp:"tyj",tne:"kak",tnf:"fa-af",ton:"to",tsf:"taj",tsn:"tn",tso:"ts",ttq:"tmh",tuk:"tk",tur:"tr",tw:"ak",twi:"ak","tzm-Latn-MA":"tzm-MA","ug-Arab-CN":"ug-CN",uig:"ug",ukr:"uk",umu:"del",uok:"ema",urd:"ur","uz-AF":"uz-Arab-AF","uz-UZ":"uz-Latn-UZ",uzb:"uz",uzn:"uz","vai-LR":"vai-Vaii-LR",ven:"ve",vie:"vi",vol:"vo",wel:"cy",wln:"wa",wol:"wo",xba:"cax",xho:"xh",xia:"acn",xkh:"waw",xpe:"kpe",xsj:"suj",xsl:"den",ybd:"rki",ydd:"yi",yid:"yi",yma:"lrr",ymt:"mtm",yor:"yo",yos:"zom","yue-CN":"yue-Hans-CN","yue-HK":"yue-Hant-HK",yuu:"yug",zai:"zap","zh-CN":"zh-Hans-CN","zh-guoyu":"zh","zh-hakka":"hak","zh-HK":"zh-Hant-HK","zh-min-nan":"nan","zh-MO":"zh-Hant-MO","zh-SG":"zh-Hans-SG","zh-TW":"zh-Hant-TW","zh-xiang":"hsn","zh-min":"nan-x-zh-min",zha:"za",zho:"zh",zsm:"ms",zul:"zu",zyb:"za"};function s(a,n){var t,r,i,e,o=(Array.isArray(a)?a:[a]).filter(function(a){return"string"==typeof a}).map(function(a){return l[a]||a}),s=[];for(t=0,r=o.length;t<r;t+=1)for(i=o[t].toLowerCase().split("-");i.length;)if(n){if(e=n[i.join("-")]){s.push(e.locale);break}i.pop()}return s}var u=function(){return(u=Object.assign||function(a){for(var n,t=1,r=arguments.length;t<r;t++)for(var i in n=arguments[t])Object.prototype.hasOwnProperty.call(n,i)&&(a[i]=n[i]);return a}).apply(this,arguments)},h=function(a,n){var t={};for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&n.indexOf(r)<0&&(t[r]=a[r]);if(null!=a&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(a);i<r.length;i++)n.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(a,r[i])&&(t[r[i]]=a[r[i]])}return t},m=function(){for(var a=0,n=0,t=arguments.length;n<t;n++)a+=arguments[n].length;var r=Array(a),i=0;for(n=0;n<t;n++)for(var e=arguments[n],o=0,s=e.length;o<s;o++,i++)r[i]=e[o];return r};var c=Intl.NumberFormat;var k=(new c).resolvedOptions().locale,p=(f.prototype.format=function(a){var n=this.nf.format(a);if(this.patternData){var t=this.pl.select(a);return this.patternData[this.unitDisplay]["one"===t?"one":"other"].replace("{0}",n)}return n},f.prototype.formatToParts=function(a){return this.nf.formatToParts(a)},f.prototype.resolvedOptions=function(){var a=this.nf.resolvedOptions();return this.unit&&(a.style="unit",a.unit=this.unit,a.unitDisplay=this.unitDisplay),a},f.supportedLocalesOf=function(){for(var a=[],n=0;n<arguments.length;n++)a[n]=arguments[n];return s(a[0],f.__unitLocaleData__)},f.__addUnitLocaleData=function(t){Object.keys(t).forEach(function(a){var n=t[a];if(!n||!n.locale)throw new Error("Locale data provided to UnifiedNumberFormat is missing a `locale` property value");f.__unitLocaleData__[n.locale.toLowerCase()]=n})},f.polyfilled=!0,f.__unitLocaleData__={},f);function f(a,n){void 0===n&&(n={});var t=n.style,r=n.unit,i=n.unitDisplay,e=h(n,["style","unit","unitDisplay"]);if(this.unit=void 0,this.unitDisplay=void 0,"unit"===t){if(!r)throw new TypeError("Unit is required for `style: unit`");this.unit=r,this.unitDisplay=i||"short";var o=s(m(Array.isArray(a)?a:[a],[k]),f.__unitLocaleData__)[0];this.patternData=function a(n,t){var r=p.__unitLocaleData__,i="";if(r[n=n.toLowerCase()]){if(r[n].units[t])return r[n].units[t];if(!r[n].parentLocale)throw new RangeError("Cannot find data for "+n);i=r[n].parentLocale}else i=n.split("-")[0];return a(i,t)}(o,this.unit)}this.nf=new c(a,u(u({},e),{style:"unit"===t?"decimal":t})),this.pl=new Intl.PluralRules(a),this.locale=this.nf.resolvedOptions().locale}a.UnifiedNumberFormat=p,a.isUnitSupported=function(a){try{new Intl.NumberFormat(void 0,{style:"unit",unit:a})}catch(a){return!1}return!0},Object.defineProperty(a,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=intl-unified-numberformat.min.js.map |
@@ -36,2 +36,3 @@ import { Unit } from './units-constants'; | ||
private nf; | ||
private pl; | ||
private locale; | ||
@@ -38,0 +39,0 @@ private patternData?; |
@@ -23,2 +23,9 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
import { resolveSupportedLocales } from '@formatjs/intl-utils'; | ||
@@ -58,5 +65,2 @@ export function isUnitSupported(unit) { | ||
} | ||
function intersection(arr1, arr2) { | ||
return arr1.filter(function (s) { return ~arr2.indexOf(s); }); | ||
} | ||
var DEFAULT_LOCALE = new NativeNumberFormat().resolvedOptions().locale; | ||
@@ -75,8 +79,7 @@ var UnifiedNumberFormat = /** @class */ (function () { | ||
this.unitDisplay = unitDisplay || 'short'; | ||
var resolvedLocale = resolveSupportedLocales(intersection(NativeNumberFormat.supportedLocalesOf(locales), Intl.PluralRules.supportedLocalesOf(locales)).concat([ | ||
DEFAULT_LOCALE, | ||
]), UnifiedNumberFormat.__unitLocaleData__)[0]; | ||
var resolvedLocale = resolveSupportedLocales(__spreadArrays((Array.isArray(locales) ? locales : [locales]), [DEFAULT_LOCALE]), UnifiedNumberFormat.__unitLocaleData__)[0]; | ||
this.patternData = findUnitData(resolvedLocale, this.unit); | ||
} | ||
this.nf = new NativeNumberFormat(locales, __assign({}, options, { style: style === 'unit' ? 'decimal' : style })); | ||
this.nf = new NativeNumberFormat(locales, __assign(__assign({}, options), { style: style === 'unit' ? 'decimal' : style })); | ||
this.pl = new Intl.PluralRules(locales); | ||
this.locale = this.nf.resolvedOptions().locale; | ||
@@ -87,3 +90,3 @@ } | ||
if (this.patternData) { | ||
var pl = new Intl.PluralRules(this.locale).select(num); | ||
var pl = this.pl.select(num); | ||
var pattern = this.patternData[this.unitDisplay][pl === 'one' ? 'one' : 'other']; | ||
@@ -90,0 +93,0 @@ return pattern.replace('{0}', formattedNum); |
{ | ||
"name": "@formatjs/intl-unified-numberformat", | ||
"version": "0.4.6", | ||
"version": "0.4.8", | ||
"description": "Ponyfill for intl unified numberformat proposal", | ||
@@ -22,6 +22,7 @@ "keywords": [ | ||
"devDependencies": { | ||
"formatjs-extract-cldr-data": "^9.6.0" | ||
"@formatjs/intl-pluralrules": "^1.1.1", | ||
"formatjs-extract-cldr-data": "^9.6.2" | ||
}, | ||
"dependencies": { | ||
"@formatjs/intl-utils": "^0.7.0" | ||
"@formatjs/intl-utils": "^1.0.1" | ||
}, | ||
@@ -39,3 +40,3 @@ "scripts": { | ||
}, | ||
"gitHead": "b05a1d489aa6eb6ff8ace60dbc29aaddff206336" | ||
"gitHead": "a00fcd57d1ade294efa943daee587c638223e572" | ||
} |
@@ -67,9 +67,2 @@ import {Unit} from './units-constants'; | ||
function intersection( | ||
arr1: Array<string | undefined>, | ||
arr2: Array<string | undefined> | ||
): Array<string | undefined> { | ||
return arr1.filter(s => ~arr2.indexOf(s as string)); | ||
} | ||
const DEFAULT_LOCALE = new NativeNumberFormat().resolvedOptions().locale; | ||
@@ -81,2 +74,3 @@ | ||
private nf: Intl.NumberFormat; | ||
private pl: Intl.PluralRules; | ||
private locale: string; | ||
@@ -96,9 +90,3 @@ private patternData?: UnitData; | ||
const resolvedLocale = resolveSupportedLocales( | ||
[ | ||
...intersection( | ||
NativeNumberFormat.supportedLocalesOf(locales), | ||
Intl.PluralRules.supportedLocalesOf(locales) | ||
), | ||
DEFAULT_LOCALE, | ||
], | ||
[...(Array.isArray(locales) ? locales : [locales]), DEFAULT_LOCALE], | ||
UnifiedNumberFormat.__unitLocaleData__ | ||
@@ -112,2 +100,3 @@ )[0]; | ||
}); | ||
this.pl = new Intl.PluralRules(locales); | ||
this.locale = this.nf.resolvedOptions().locale; | ||
@@ -119,3 +108,3 @@ } | ||
if (this.patternData) { | ||
const pl = new Intl.PluralRules(this.locale).select(num); | ||
const pl = this.pl.select(num); | ||
const pattern = this.patternData[this.unitDisplay as 'long'][ | ||
@@ -122,0 +111,0 @@ pl === 'one' ? 'one' : 'other' |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
18682560
42778
2
+ Added@formatjs/intl-utils@1.6.0(transitive)
- Removed@formatjs/intl-utils@0.7.0(transitive)
Updated@formatjs/intl-utils@^1.0.1