Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

message-format

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

message-format - npm Package Compare versions

Comparing version 0.0.7 to 0.1.0

.eslintrc

6

dist/data.js

@@ -34,5 +34,7 @@ "use strict";

Object.keys(locales).forEach(function (locale) {
var plural = locales[locale];
var _locales$locale = locales[locale];
var plural = _locales$locale.plural;
var ordinal = _locales$locale.ordinal;
data.locales[locale] = {
locale: locale, plural: plural
locale: locale, plural: plural, ordinal: ordinal
};

@@ -39,0 +41,0 @@ });

"use strict";
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
/**

@@ -24,2 +26,4 @@ * Interpretr

var cache = _ref.cache;
_classCallCheck(this, Interpreter);
this.originalLocale = locale;

@@ -64,8 +68,12 @@ this.localeData = data;

type = element[1],
style = element[2];
style = element[2],
offset = 0,
options = undefined;
if ("#" === id) {
var _id = parent[0],
_offset = parent[2];
return this.interpretNumber(_id, _offset, null);
id = parent[0];
type = "selectordinal" === parent[1] ? "ordinal" : "number";
offset = parent[2];
style = null;
}

@@ -75,3 +83,9 @@

case "number":
return this.interpretNumber(id, 0, style);
case "ordinal":
// TODO: rbnf
case "spellout":
// TODO: rbnf
case "duration":
// TODO: duration
return this.interpretNumber(id, offset, style);
case "date":

@@ -81,5 +95,6 @@ case "time":

case "plural":
var offset = element[2],
options = element[3];
return this.interpretPlural(id, offset, options);
case "selectordinal":
offset = element[2];
options = element[3];
return this.interpretPlural(id, type, offset, options);
case "select":

@@ -133,6 +148,6 @@ return this.interpretSelect(id, style);

Interpreter.prototype.interpretPlural = function interpretPlural(id, offset, children) {
Interpreter.prototype.interpretPlural = function interpretPlural(id, type, offset, children) {
var _this = this;
var plural = this.localeData.plural,
parent = [id, "plural", offset /*, children*/],
var plural = "selectordinal" === type ? this.localeData.ordinal : this.localeData.plural,
parent = [id, type, offset /*, children*/],
options = {};

@@ -145,3 +160,3 @@ Object.keys(children).forEach(function (key) {

exactSelector = "=" + arg,
keywordSelector = plural(arg - offset),
keywordSelector = plural ? plural(arg - offset) : "other",
func = options[exactSelector] || options[keywordSelector] || options.other;

@@ -148,0 +163,0 @@ return func(args);

"use strict";
function _i(s) {
return Math.floor(Math.abs(+s));
}
function _v(s) {
return (s + ".").split(".")[1].length;
}
function _f(s) {
return +(s + ".").split(".")[1];
}
function _t(s) {
return +("" + s).replace(/^[^.]*.?|0+$/g, "");
}
var p = [function (s) {

@@ -26,3 +14,3 @@ var n = +s;

}, function (s) {
var i = _i(s),
var i = Math.floor(Math.abs(+s)),
n = +s;

@@ -46,5 +34,4 @@ // i = 0 or n = 1

}, function (s) {
var i = _i(s),
v = _v(s),
n = +s;
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length;
// i = 1 and v = 0

@@ -62,3 +49,3 @@ if (i === 1 && v === 0) return "one";

return "other";
}, function (s) {
}, function () {
return "other";

@@ -77,6 +64,5 @@ }, function (s) {

}, function (s) {
var i = _i(s),
v = _v(s),
f = _f(s),
n = +s;
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length,
f = +(s + ".").split(".")[1];
// v = 0 and i % 10 = 1 and i % 100 != 11 or f % 10 = 1 and f % 100 != 11

@@ -88,5 +74,4 @@ if (v === 0 && i % 10 === 1 && i % 100 !== 11 || f % 10 === 1 && f % 100 !== 11) return "one";

}, function (s) {
var i = _i(s),
v = _v(s),
n = +s;
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length;
// i = 1 and v = 0

@@ -113,4 +98,4 @@ if (i === 1 && v === 0) return "one";

}, function (s) {
var i = _i(s),
t = _t(s),
var i = Math.floor(Math.abs(+s)),
t = +("" + s).replace(/^[^.]*.?|0+$/g, ""),
n = +s;

@@ -121,6 +106,5 @@ // n = 1 or t != 0 and i = 0,1

}, function (s) {
var i = _i(s),
v = _v(s),
f = _f(s),
n = +s;
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length,
f = +(s + ".").split(".")[1];
// v = 0 and i % 100 = 1 or f % 100 = 1

@@ -134,4 +118,3 @@ if (v === 0 && i % 100 === 1 || f % 100 === 1) return "one";

}, function (s) {
var i = _i(s),
n = +s;
var i = Math.floor(Math.abs(+s));
// i = 0,1

@@ -141,6 +124,5 @@ if (i === 0 || i === 1) return "one";

}, function (s) {
var i = _i(s),
v = _v(s),
f = _f(s),
n = +s;
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length,
f = +(s + ".").split(".")[1];
// v = 0 and i = 1,2,3 or v = 0 and i % 10 != 4,6,9 or v != 0 and f % 10 != 4,6,9

@@ -170,5 +152,4 @@ if (v === 0 && (i === 1 || i === 2 || i === 3) || v === 0 && (i % 10 !== 4 && i % 10 !== 6 && i % 10 !== 9) || v !== 0 && (f % 10 !== 4 && f % 10 !== 6 && f % 10 !== 9)) return "one";

}, function (s) {
var i = _i(s),
v = _v(s),
n = +s;
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length;
// v = 0 and i % 10 = 1

@@ -184,4 +165,4 @@ if (v === 0 && i % 10 === 1) return "one";

}, function (s) {
var i = _i(s),
v = _v(s),
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length,
n = +s;

@@ -196,5 +177,4 @@ // i = 1 and v = 0

}, function (s) {
var i = _i(s),
t = _t(s),
n = +s;
var i = Math.floor(Math.abs(+s)),
t = +("" + s).replace(/^[^.]*.?|0+$/g, "");
// t = 0 and i % 10 = 1 and i % 100 != 11 or t != 0

@@ -218,3 +198,3 @@ if (t === 0 && i % 10 === 1 && i % 100 !== 11 || t !== 0) return "one";

}, function (s) {
var i = _i(s),
var i = Math.floor(Math.abs(+s)),
n = +s;

@@ -227,3 +207,3 @@ // n = 0

}, function (s) {
var f = _f(s),
var f = +(s + ".").split(".")[1],
n = +s;

@@ -238,4 +218,4 @@ // n % 10 = 1 and n % 100 != 11..19

}, function (s) {
var v = _v(s),
f = _f(s),
var v = (s + ".").split(".")[1].length,
f = +(s + ".").split(".")[1],
n = +s;

@@ -248,6 +228,5 @@ // n % 10 = 0 or n % 100 = 11..19 or v = 2 and f % 100 = 11..19

}, function (s) {
var i = _i(s),
v = _v(s),
f = _f(s),
n = +s;
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length,
f = +(s + ".").split(".")[1];
// v = 0 and i % 10 = 1 or f % 10 = 1

@@ -257,4 +236,4 @@ if (v === 0 && i % 10 === 1 || f % 10 === 1) return "one";

}, function (s) {
var i = _i(s),
v = _v(s),
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length,
n = +s;

@@ -276,5 +255,4 @@ // i = 1 and v = 0

}, function (s) {
var i = _i(s),
v = _v(s),
n = +s;
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length;
// i = 1 and v = 0

@@ -293,3 +271,3 @@ if (i === 1 && v === 0) return "one";

}, function (s) {
var v = _v(s),
var v = (s + ".").split(".")[1].length,
n = +s;

@@ -300,5 +278,4 @@ // n = 1 and v = 0

}, function (s) {
var i = _i(s),
v = _v(s),
n = +s;
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length;
// v = 0 and i % 10 = 1 and i % 100 != 11

@@ -312,3 +289,3 @@ if (v === 0 && i % 10 === 1 && i % 100 !== 11) return "one";

}, function (s) {
var i = _i(s),
var i = Math.floor(Math.abs(+s)),
n = +s;

@@ -321,4 +298,4 @@ // i = 0 or n = 1

}, function (s) {
var i = _i(s),
f = _f(s),
var i = Math.floor(Math.abs(+s)),
f = +(s + ".").split(".")[1],
n = +s;

@@ -329,5 +306,4 @@ // n = 0,1 or i = 0 and f = 1

}, function (s) {
var i = _i(s),
v = _v(s),
n = +s;
var i = Math.floor(Math.abs(+s)),
v = (s + ".").split(".")[1].length;
// v = 0 and i % 100 = 1

@@ -345,202 +321,326 @@ if (v === 0 && i % 100 === 1) return "one";

return "other";
}, function (s) {
var i = Math.floor(Math.abs(+s));
// i % 10 = 1,2,5,7,8 or i % 100 = 20,50,70,80
if (i % 10 === 1 || i % 10 === 2 || i % 10 === 5 || i % 10 === 7 || i % 10 === 8 || (i % 100 === 20 || i % 100 === 50 || i % 100 === 70 || i % 100 === 80)) return "one";
// i % 10 = 3,4 or i % 1000 = 100,200,300,400,500,600,700,800,900
if (i % 10 === 3 || i % 10 === 4 || (i % 1000 === 100 || i % 1000 === 200 || i % 1000 === 300 || i % 1000 === 400 || i % 1000 === 500 || i % 1000 === 600 || i % 1000 === 700 || i % 1000 === 800 || i % 1000 === 900)) return "few";
// i = 0 or i % 10 = 6 or i % 100 = 40,60,90
if (i === 0 || i % 10 === 6 || (i % 100 === 40 || i % 100 === 60 || i % 100 === 90)) return "many";
return "other";
}, function (s) {
var n = +s;
// n = 1,5,7,8,9,10
if (n === 1 || n === 5 || n === 7 || n === 8 || n === 9 || n === 10) return "one";
// n = 2,3
if (n === 2 || n === 3) return "two";
// n = 4
if (n === 4) return "few";
// n = 6
if (n === 6) return "many";
return "other";
}, function (s) {
var n = +s;
// n = 1,3
if (n === 1 || n === 3) return "one";
// n = 2
if (n === 2) return "two";
// n = 4
if (n === 4) return "few";
return "other";
}, function (s) {
var n = +s;
// n = 0,7,8,9
if (n === 0 || n === 7 || n === 8 || n === 9) return "zero";
// n = 1
if (n === 1) return "one";
// n = 2
if (n === 2) return "two";
// n = 3,4
if (n === 3 || n === 4) return "few";
// n = 5,6
if (n === 5 || n === 6) return "many";
return "other";
}, function (s) {
var n = +s;
// n % 10 = 1 and n % 100 != 11
if (n % 10 === 1 && n % 100 !== 11) return "one";
// n % 10 = 2 and n % 100 != 12
if (n % 10 === 2 && n % 100 !== 12) return "two";
// n % 10 = 3 and n % 100 != 13
if (n % 10 === 3 && n % 100 !== 13) return "few";
return "other";
}, function (s) {
var n = +s;
// n = 1
if (n === 1) return "one";
// n = 2,3
if (n === 2 || n === 3) return "two";
// n = 4
if (n === 4) return "few";
// n = 6
if (n === 6) return "many";
return "other";
}, function (s) {
var n = +s;
// n = 1,5
if (n === 1 || n === 5) return "one";
return "other";
}, function (s) {
var n = +s;
// n = 11,8,80,800
if (n === 11 || n === 8 || n === 80 || n === 800) return "many";
return "other";
}, function (s) {
var i = Math.floor(Math.abs(+s));
// i = 1
if (i === 1) return "one";
// i = 0 or i % 100 = 2..20,40,60,80
if (i === 0 || (2 <= i % 100 && i % 100 <= 20 || i % 100 === 40 || i % 100 === 60 || i % 100 === 80)) return "many";
return "other";
}, function (s) {
var n = +s;
// n % 10 = 6 or n % 10 = 9 or n % 10 = 0 and n != 0
if (n % 10 === 6 || n % 10 === 9 || n % 10 === 0 && n !== 0) return "many";
return "other";
}, function (s) {
var i = Math.floor(Math.abs(+s));
// i % 10 = 1 and i % 100 != 11
if (i % 10 === 1 && i % 100 !== 11) return "one";
// i % 10 = 2 and i % 100 != 12
if (i % 10 === 2 && i % 100 !== 12) return "two";
// i % 10 = 7,8 and i % 100 != 17,18
if ((i % 10 === 7 || i % 10 === 8) && (i % 100 !== 17 && i % 100 !== 18)) return "many";
return "other";
}, function (s) {
var n = +s;
// n = 1
if (n === 1) return "one";
// n = 2,3
if (n === 2 || n === 3) return "two";
// n = 4
if (n === 4) return "few";
return "other";
}, function (s) {
var n = +s;
// n = 1..4
if (1 <= n && n <= 4) return "one";
return "other";
}, function (s) {
var n = +s;
// n = 1
if (n === 1) return "one";
// n % 10 = 4 and n % 100 != 14
if (n % 10 === 4 && n % 100 !== 14) return "many";
return "other";
}, function (s) {
var n = +s;
// n % 10 = 1,2 and n % 100 != 11,12
if ((n % 10 === 1 || n % 10 === 2) && (n % 100 !== 11 && n % 100 !== 12)) return "one";
return "other";
}, function (s) {
var n = +s;
// n % 10 = 3 and n % 100 != 13
if (n % 10 === 3 && n % 100 !== 13) return "few";
return "other";
}];
module.exports = {
af: p[0],
ak: p[1],
am: p[2],
ar: p[3],
asa: p[0],
ast: p[4],
az: p[0],
be: p[5],
bem: p[0],
bez: p[0],
bg: p[0],
bh: p[1],
bm: p[6],
bn: p[2],
bo: p[6],
br: p[7],
brx: p[0],
bs: p[8],
ca: p[4],
cgg: p[0],
chr: p[0],
ckb: p[0],
cs: p[9],
cy: p[10],
da: p[11],
de: p[4],
dsb: p[12],
dv: p[0],
dz: p[6],
ee: p[0],
el: p[0],
en: p[4],
eo: p[0],
es: p[0],
et: p[4],
eu: p[0],
fa: p[2],
ff: p[13],
fi: p[4],
fil: p[14],
fo: p[0],
fr: p[13],
fur: p[0],
fy: p[4],
ga: p[15],
gd: p[16],
gl: p[4],
gsw: p[0],
gu: p[2],
guw: p[1],
gv: p[17],
ha: p[0],
haw: p[0],
he: p[18],
hi: p[2],
hr: p[8],
hsb: p[12],
hu: p[0],
hy: p[13],
id: p[6],
ig: p[6],
ii: p[6],
"in": p[6],
is: p[19],
it: p[4],
iu: p[20],
iw: p[18],
ja: p[6],
jbo: p[6],
jgo: p[0],
ji: p[4],
jmc: p[0],
jv: p[6],
jw: p[6],
ka: p[0],
kab: p[13],
kaj: p[0],
kcg: p[0],
kde: p[6],
kea: p[6],
kk: p[0],
kkj: p[0],
kl: p[0],
km: p[6],
kn: p[2],
ko: p[6],
ks: p[0],
ksb: p[0],
ksh: p[21],
ku: p[0],
kw: p[20],
ky: p[0],
lag: p[22],
lb: p[0],
lg: p[0],
lkt: p[6],
ln: p[1],
lo: p[6],
lt: p[23],
lv: p[24],
mas: p[0],
mg: p[1],
mgo: p[0],
mk: p[25],
ml: p[0],
mn: p[0],
mo: p[26],
mr: p[2],
ms: p[6],
mt: p[27],
my: p[6],
nah: p[0],
naq: p[20],
nb: p[0],
nd: p[0],
ne: p[0],
nl: p[4],
nn: p[0],
nnh: p[0],
no: p[0],
nqo: p[6],
nr: p[0],
nso: p[1],
ny: p[0],
nyn: p[0],
om: p[0],
or: p[0],
os: p[0],
pa: p[1],
pap: p[0],
pl: p[28],
prg: p[24],
ps: p[0],
pt: p[29],
"pt-PT": p[30],
rm: p[0],
ro: p[26],
rof: p[0],
root: p[6],
ru: p[31],
rwk: p[0],
sah: p[6],
saq: p[0],
se: p[20],
seh: p[0],
ses: p[6],
sg: p[6],
sh: p[8],
shi: p[32],
si: p[33],
sk: p[9],
sl: p[34],
sma: p[20],
smi: p[20],
smj: p[20],
smn: p[20],
sms: p[20],
sn: p[0],
so: p[0],
sq: p[0],
sr: p[8],
ss: p[0],
ssy: p[0],
st: p[0],
sv: p[4],
sw: p[4],
syr: p[0],
ta: p[0],
te: p[0],
teo: p[0],
th: p[6],
ti: p[1],
tig: p[0],
tk: p[0],
tl: p[14],
tn: p[0],
to: p[6],
tr: p[0],
ts: p[0],
tzm: p[35],
ug: p[0],
uk: p[31],
ur: p[4],
uz: p[0],
ve: p[0],
vi: p[6],
vo: p[0],
vun: p[0],
wa: p[1],
wae: p[0],
wo: p[6],
xh: p[0],
xog: p[0],
yi: p[4],
yo: p[6],
zh: p[6],
zu: p[2]
af: { plural: p[0], ordinal: p[6] },
ak: { plural: p[1] },
am: { plural: p[2], ordinal: p[6] },
ar: { plural: p[3], ordinal: p[6] },
asa: { plural: p[0] },
ast: { plural: p[4] },
az: { plural: p[0], ordinal: p[36] },
be: { plural: p[5] },
bem: { plural: p[0] },
bez: { plural: p[0] },
bg: { plural: p[0], ordinal: p[6] },
bh: { plural: p[1] },
bm: { plural: p[6] },
bn: { plural: p[2], ordinal: p[37] },
bo: { plural: p[6] },
br: { plural: p[7] },
brx: { plural: p[0] },
bs: { plural: p[8], ordinal: p[6] },
ca: { plural: p[4], ordinal: p[38] },
cgg: { plural: p[0] },
chr: { plural: p[0] },
ckb: { plural: p[0] },
cs: { plural: p[9], ordinal: p[6] },
cy: { plural: p[10], ordinal: p[39] },
da: { plural: p[11], ordinal: p[6] },
de: { plural: p[4], ordinal: p[6] },
dsb: { plural: p[12], ordinal: p[6] },
dv: { plural: p[0] },
dz: { plural: p[6] },
ee: { plural: p[0] },
el: { plural: p[0], ordinal: p[6] },
en: { plural: p[4], ordinal: p[40] },
eo: { plural: p[0] },
es: { plural: p[0], ordinal: p[6] },
et: { plural: p[4], ordinal: p[6] },
eu: { plural: p[0], ordinal: p[6] },
fa: { plural: p[2], ordinal: p[6] },
ff: { plural: p[13] },
fi: { plural: p[4], ordinal: p[6] },
fil: { plural: p[14], ordinal: p[0] },
fo: { plural: p[0] },
fr: { plural: p[13], ordinal: p[0] },
fur: { plural: p[0] },
fy: { plural: p[4], ordinal: p[6] },
ga: { plural: p[15] },
gd: { plural: p[16] },
gl: { plural: p[4], ordinal: p[6] },
gsw: { plural: p[0] },
gu: { plural: p[2], ordinal: p[41] },
guw: { plural: p[1] },
gv: { plural: p[17] },
ha: { plural: p[0] },
haw: { plural: p[0] },
he: { plural: p[18], ordinal: p[6] },
hi: { plural: p[2], ordinal: p[41] },
hr: { plural: p[8], ordinal: p[6] },
hsb: { plural: p[12], ordinal: p[6] },
hu: { plural: p[0], ordinal: p[42] },
hy: { plural: p[13], ordinal: p[0] },
id: { plural: p[6], ordinal: p[6] },
ig: { plural: p[6] },
ii: { plural: p[6] },
"in": { plural: p[6], ordinal: p[6] },
is: { plural: p[19], ordinal: p[6] },
it: { plural: p[4], ordinal: p[43] },
iu: { plural: p[20] },
iw: { plural: p[18], ordinal: p[6] },
ja: { plural: p[6], ordinal: p[6] },
jbo: { plural: p[6] },
jgo: { plural: p[0] },
ji: { plural: p[4] },
jmc: { plural: p[0] },
jv: { plural: p[6] },
jw: { plural: p[6] },
ka: { plural: p[0], ordinal: p[44] },
kab: { plural: p[13] },
kaj: { plural: p[0] },
kcg: { plural: p[0] },
kde: { plural: p[6] },
kea: { plural: p[6] },
kk: { plural: p[0], ordinal: p[45] },
kkj: { plural: p[0] },
kl: { plural: p[0] },
km: { plural: p[6], ordinal: p[6] },
kn: { plural: p[2], ordinal: p[6] },
ko: { plural: p[6], ordinal: p[6] },
ks: { plural: p[0] },
ksb: { plural: p[0] },
ksh: { plural: p[21] },
ku: { plural: p[0] },
kw: { plural: p[20] },
ky: { plural: p[0], ordinal: p[6] },
lag: { plural: p[22] },
lb: { plural: p[0] },
lg: { plural: p[0] },
lkt: { plural: p[6] },
ln: { plural: p[1] },
lo: { plural: p[6], ordinal: p[0] },
lt: { plural: p[23], ordinal: p[6] },
lv: { plural: p[24], ordinal: p[6] },
mas: { plural: p[0] },
mg: { plural: p[1] },
mgo: { plural: p[0] },
mk: { plural: p[25], ordinal: p[46] },
ml: { plural: p[0], ordinal: p[6] },
mn: { plural: p[0], ordinal: p[6] },
mo: { plural: p[26], ordinal: p[0] },
mr: { plural: p[2], ordinal: p[47] },
ms: { plural: p[6], ordinal: p[0] },
mt: { plural: p[27] },
my: { plural: p[6], ordinal: p[6] },
nah: { plural: p[0] },
naq: { plural: p[20] },
nb: { plural: p[0], ordinal: p[6] },
nd: { plural: p[0] },
ne: { plural: p[0], ordinal: p[48] },
nl: { plural: p[4], ordinal: p[6] },
nn: { plural: p[0] },
nnh: { plural: p[0] },
no: { plural: p[0] },
nqo: { plural: p[6] },
nr: { plural: p[0] },
nso: { plural: p[1] },
ny: { plural: p[0] },
nyn: { plural: p[0] },
om: { plural: p[0] },
or: { plural: p[0] },
os: { plural: p[0] },
pa: { plural: p[1], ordinal: p[6] },
pap: { plural: p[0] },
pl: { plural: p[28], ordinal: p[6] },
prg: { plural: p[24], ordinal: p[6] },
ps: { plural: p[0] },
pt: { plural: p[29], ordinal: p[6] },
"pt-PT": { plural: p[30] },
rm: { plural: p[0] },
ro: { plural: p[26], ordinal: p[0] },
rof: { plural: p[0] },
root: { plural: p[6], ordinal: p[6] },
ru: { plural: p[31], ordinal: p[6] },
rwk: { plural: p[0] },
sah: { plural: p[6] },
saq: { plural: p[0] },
se: { plural: p[20] },
seh: { plural: p[0] },
ses: { plural: p[6] },
sg: { plural: p[6] },
sh: { plural: p[8], ordinal: p[6] },
shi: { plural: p[32] },
si: { plural: p[33], ordinal: p[6] },
sk: { plural: p[9], ordinal: p[6] },
sl: { plural: p[34], ordinal: p[6] },
sma: { plural: p[20] },
smi: { plural: p[20] },
smj: { plural: p[20] },
smn: { plural: p[20] },
sms: { plural: p[20] },
sn: { plural: p[0] },
so: { plural: p[0] },
sq: { plural: p[0], ordinal: p[49] },
sr: { plural: p[8], ordinal: p[6] },
ss: { plural: p[0] },
ssy: { plural: p[0] },
st: { plural: p[0] },
sv: { plural: p[4], ordinal: p[50] },
sw: { plural: p[4], ordinal: p[6] },
syr: { plural: p[0] },
ta: { plural: p[0], ordinal: p[6] },
te: { plural: p[0], ordinal: p[6] },
teo: { plural: p[0] },
th: { plural: p[6], ordinal: p[6] },
ti: { plural: p[1] },
tig: { plural: p[0] },
tk: { plural: p[0] },
tl: { plural: p[14], ordinal: p[0] },
tn: { plural: p[0] },
to: { plural: p[6] },
tr: { plural: p[0], ordinal: p[6] },
ts: { plural: p[0] },
tzm: { plural: p[35] },
ug: { plural: p[0] },
uk: { plural: p[31], ordinal: p[51] },
ur: { plural: p[4], ordinal: p[6] },
uz: { plural: p[0], ordinal: p[6] },
ve: { plural: p[0] },
vi: { plural: p[6], ordinal: p[0] },
vo: { plural: p[0] },
vun: { plural: p[0] },
wa: { plural: p[1] },
wae: { plural: p[0] },
wo: { plural: p[6] },
xh: { plural: p[0] },
xog: { plural: p[0] },
yi: { plural: p[4] },
yo: { plural: p[6] },
zh: { plural: p[6], ordinal: p[6] },
zu: { plural: p[2], ordinal: p[6] }
};

@@ -5,2 +5,4 @@ "use strict";

var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
/*!

@@ -26,2 +28,4 @@ * Intl.MessageFormat polyfill

var options = arguments[2] === undefined ? {} : arguments[2];
_classCallCheck(this, MessageFormat);
if ("object" !== typeof this || !(this instanceof MessageFormat)) {

@@ -28,0 +32,0 @@ return new MessageFormat(pattern, locale, options);

"use strict";
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
/**

@@ -24,2 +26,4 @@ * Parser

var escape = _ref.escape;
_classCallCheck(this, Parser);
this.escape = escape || "'";

@@ -76,3 +80,3 @@ this.pattern = null;

length = pattern.length,
isPlural = "plural" === parentType,
isHashSpecial = "plural" === parentType || "selectordinal" === parentType,
isArgStyle = "style" === parentType,

@@ -82,3 +86,3 @@ escape = this.escape;

char = pattern.charAt(this.index);
if ("{" === char || "}" === char || isPlural && "#" === char || isArgStyle && this.isWhitespace(char)) {
if ("{" === char || "}" === char || isHashSpecial && "#" === char || isArgStyle && this.isWhitespace(char)) {
break;

@@ -92,3 +96,3 @@ } else if ("'" === escape && "'" === char) {

} else if ( // only when necessary
"{" === char || "}" === char || isPlural && "#" === char || isArgStyle && this.isWhitespace(char)) {
"{" === char || "}" === char || isHashSpecial && "#" === char || isArgStyle && this.isWhitespace(char)) {
text += char;

@@ -152,3 +156,3 @@ while (++this.index < length) {

// end argument
if ("plural" === type || "select" === type) {
if ("plural" === type || "selectordinal" === type || "select" === type) {
throw new Error(this.expectedToken(type + " message options"));

@@ -166,7 +170,7 @@ }

offset = undefined;
if ("plural" === type) {
if ("plural" === type || "selectordinal" === type) {
offset = this.parsePluralOffset();
}
if ("plural" === type || "select" === type) {
format = this.parseSubMessages(type);
} else if ("select" === type) {
format = this.parseSubMessages(type);
} else {

@@ -182,3 +186,3 @@ format = this.parseSimpleFormat();

return "plural" === type ? [id, type, offset, format] : [id, type, format];
return "plural" === type || "selectordinal" === type ? [id, type, offset, format] : [id, type, format];
};

@@ -213,3 +217,3 @@

argType = undefined,
types = ["number", "date", "time", "ordinal", "duration", "spellout", "plural", "select"];
types = ["number", "date", "time", "ordinal", "duration", "spellout", "plural", "selectordinal", "select"];
for (var t = 0, tt = types.length; t < tt; ++t) {

@@ -216,0 +220,0 @@ var type = types[t];

{
"name": "message-format",
"version": "0.0.7",
"version": "0.1.0",
"description": "Intl.MessageFormat polyfill supporting ICU message format",

@@ -8,6 +8,7 @@ "main": "dist/message-format.js",

"devDependencies": {
"6to5": "3.1.1",
"6to5-core": "3.1.1",
"6to5-loader": "3.0.0",
"babel": "4.0.1",
"babel-core": "4.0.1",
"babel-loader": "4.0.0",
"benchmark": "1.0.0",
"eslint": "0.14.1",
"intl": "0.1.4",

@@ -17,5 +18,5 @@ "intl-messageformat": "1.0.4",

"istanbul-instrumenter-loader": "0.1.2",
"jasmine-core": "2.1.3",
"jasmine-core": "2.2.0",
"jasmine-node": "1.14.5",
"jshint": "2.6.0",
"jscs": "1.11.3",
"karma": "0.12.31",

@@ -29,3 +30,3 @@ "karma-chrome-launcher": "0.1.7",

"karma-safari-launcher": "0.1.1",
"karma-sourcemap-loader": "0.3.2",
"karma-sourcemap-loader": "0.3.3",
"karma-webpack": "1.5.0",

@@ -35,9 +36,9 @@ "webpack": "1.5.3"

"scripts": {
"benchmark": "6to5-node --loose=all scripts/benchmark.js",
"benchmark": "babel-node --loose=all scripts/benchmark.js",
"cldr": "scripts/cldr.sh",
"jshint": "jshint src/*.js",
"prepublish": "6to5 --loose=all src --out-dir dist",
"test": "npm run jshint && npm run test-node && npm run test-browsers",
"lint": "jscs src/*.js && eslint src/*.js || true",
"prepublish": "mkdir -p dist && babel --loose=all src --out-dir dist && webpack -p",
"test": "npm run lint && npm run test-node && npm run test-browsers",
"test-browsers": "karma start --browsers Firefox,PhantomJS --single-run",
"test-node": "6to5-node --loose=all -t -- node_modules/.bin/jasmine-node --test-dir test"
"test-node": "babel-node --loose=all -t -- node_modules/.bin/jasmine-node --test-dir test"
},

@@ -44,0 +45,0 @@ "repository": {

@@ -50,6 +50,15 @@ # message-format

### Supported ICU Formats
* `number` - `percent`, `currency`
* `date` - `short`, `medium`, `long`, `full`
* `time` - `short`, `medium`, `long`, `full`
* `plural`
* `selectordinal`
* `select`
### Unsupported ICU Formats
`ordinal`, `duration`, and `spellout` arguments are supported by the parser,
but will just `toString()`. These are not supported by `Intl.NumberFormat`.
but just act like `number`. These are not supported by `Intl.NumberFormat`.
They require a lot of language-specific code, and would make the library

@@ -155,2 +164,14 @@ undesireably large. For now, if you need these kinds of formats, you can pass

### selectordinal
```js
var message = new MessageFormat('{ n, selectordinal,\
one {#st}\
two {#nd}\
few {#rd}\
other {#th}\
} place', 'en')
message.format({ n:102 }) // "102nd place"
```
### Complex string with select and plural in ES6

@@ -157,0 +178,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc