make-plural 4.2.0 → 4.3.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/bin/common.js +8 -6
- package/bin/make-plural +37 -20
- package/data/ordinals.json +17 -4
- package/data/plurals.json +12 -4
- package/es6/pluralCategories.js +3 -1
- package/es6/plurals.js +838 -206
- package/make-plural.js +94 -43
- package/make-plural.min.js +1 -1
- package/package.json +12 -12
- package/umd/pluralCategories.js +3 -1
- package/umd/pluralCategories.min.js +1 -1
- package/umd/plurals.js +838 -206
- package/umd/plurals.min.js +1 -1
package/bin/common.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
exports.cardinals = exports.combined = void 0;
|
|
7
|
+
var combined = {
|
|
8
|
+
plurals: ["function(n, ord) {\n if (ord) return 'other';\n return 'other';\n}", "function(n, ord) {\n if (ord) return 'other';\n return (n == 1) ? 'one' : 'other';\n}", "function(n, ord) {\n if (ord) return 'other';\n return ((n == 0\n || n == 1)) ? 'one' : 'other';\n}", "function(n, ord) {\n var s = String(n).split('.'), v0 = !s[1];\n if (ord) return 'other';\n return (n == 1 && v0) ? 'one' : 'other';\n}"],
|
|
8
9
|
categories: ['{cardinal:["other"],ordinal:["other"]}', '{cardinal:["one","other"],ordinal:["other"]}', '{cardinal:["one","other"],ordinal:["one","other"]}', '{cardinal:["one","two","other"],ordinal:["other"]}']
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
var cardinals =
|
|
12
|
-
plurals: [
|
|
11
|
+
exports.combined = combined;
|
|
12
|
+
var cardinals = {
|
|
13
|
+
plurals: ["function(n) {\n return 'other';\n}", "function(n) {\n return (n == 1) ? 'one' : 'other';\n}", "function(n) {\n return ((n == 0\n || n == 1)) ? 'one' : 'other';\n}", "function(n) {\n var s = String(n).split('.'), v0 = !s[1];\n return (n == 1 && v0) ? 'one' : 'other';\n}"],
|
|
13
14
|
categories: ['{cardinal:["other"],ordinal:[]}', '{cardinal:["one","other"],ordinal:[]}', '{cardinal:["one","other"],ordinal:[]}', '{cardinal:["one","two","other"],ordinal:[]}']
|
|
14
15
|
};
|
|
16
|
+
exports.cardinals = cardinals;
|
|
15
17
|
|
package/bin/make-plural
CHANGED
|
@@ -1,45 +1,59 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
"use strict";
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var common = _interopRequireWildcard(require("./common"));
|
|
6
6
|
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
7
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
10
8
|
|
|
9
|
+
/** A compiler for make-plural.js
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ./bin/make-plural // checks all locale rules
|
|
13
|
+
* ./bin/make-plural [lc] // prints the locale function for LC
|
|
14
|
+
* ./bin/make-plural [lc] [n] [ord] // prints the (ORD ? ordinal : plural) category for N in locale LC
|
|
15
|
+
*/
|
|
11
16
|
var argv = require('minimist')(process.argv.slice(2), {
|
|
12
|
-
default: {
|
|
13
|
-
|
|
17
|
+
default: {
|
|
18
|
+
locale: null,
|
|
19
|
+
value: null,
|
|
20
|
+
ordinal: null,
|
|
21
|
+
cardinal: null,
|
|
22
|
+
categories: false,
|
|
23
|
+
es6: false
|
|
24
|
+
},
|
|
25
|
+
alias: {
|
|
26
|
+
locale: 'l',
|
|
27
|
+
value: 'v',
|
|
28
|
+
ordinal: 'o',
|
|
29
|
+
cardinal: 'c',
|
|
30
|
+
es6: 'e'
|
|
31
|
+
},
|
|
14
32
|
string: ['locale', 'value'],
|
|
15
33
|
boolean: ['categories', 'es6']
|
|
16
|
-
});
|
|
17
|
-
*
|
|
18
|
-
* Usage:
|
|
19
|
-
* ./bin/make-plural // checks all locale rules
|
|
20
|
-
* ./bin/make-plural [lc] // prints the locale function for LC
|
|
21
|
-
* ./bin/make-plural [lc] [n] [ord] // prints the (ORD ? ordinal : plural) category for N in locale LC
|
|
22
|
-
*/
|
|
34
|
+
});
|
|
23
35
|
|
|
24
36
|
var MakePlural = require('../make-plural').load(require('../data/plurals.json'), require('../data/ordinals.json'));
|
|
25
37
|
|
|
26
38
|
var es6module = function es6module(value) {
|
|
27
|
-
return
|
|
28
|
-
};
|
|
39
|
+
return "\nexport default {\n".concat(value, "\n}");
|
|
40
|
+
}; // UMD pattern adapted from https://github.com/umdjs/umd/blob/master/returnExports.js
|
|
41
|
+
|
|
29
42
|
|
|
30
|
-
// UMD pattern adapted from https://github.com/umdjs/umd/blob/master/returnExports.js
|
|
31
43
|
var umd = function umd(global, value) {
|
|
32
|
-
return
|
|
44
|
+
return "\n(function (root, ".concat(global, ") {\n if (typeof define === 'function' && define.amd) {\n define(").concat(global, ");\n } else if (typeof exports === 'object') {\n module.exports = ").concat(global, ";\n } else {\n root.").concat(global, " = ").concat(global, ";\n }\n}(this, {\n").concat(value, "\n}));");
|
|
33
45
|
};
|
|
34
46
|
|
|
35
47
|
function mapForEachLanguage(cb, opt) {
|
|
36
48
|
var style = opt && !opt.cardinals ? 'ordinal' : 'cardinal';
|
|
37
49
|
var languages = [];
|
|
50
|
+
|
|
38
51
|
for (var lc in MakePlural.rules[style]) {
|
|
39
52
|
var key = /^[A-Z_$][0-9A-Z_$]*$/i.test(lc) && lc !== 'in' ? lc : JSON.stringify(lc);
|
|
40
53
|
var mp = new MakePlural(lc, opt).test();
|
|
41
54
|
languages.push(key + ': ' + cb(mp));
|
|
42
55
|
}
|
|
56
|
+
|
|
43
57
|
return languages;
|
|
44
58
|
}
|
|
45
59
|
|
|
@@ -48,10 +62,11 @@ function printPluralsModule(es6) {
|
|
|
48
62
|
var plurals = mapForEachLanguage(function (mp) {
|
|
49
63
|
var fn = mp.toString();
|
|
50
64
|
cp.forEach(function (p, i) {
|
|
51
|
-
if (fn === p) fn =
|
|
65
|
+
if (fn === p) fn = "_cp[".concat(i, "]");
|
|
52
66
|
});
|
|
53
67
|
return fn;
|
|
54
68
|
});
|
|
69
|
+
|
|
55
70
|
if (es6) {
|
|
56
71
|
console.log('const _cp = [\n' + cp.join(',\n') + '\n];');
|
|
57
72
|
console.log(es6module(plurals.join(',\n\n')));
|
|
@@ -66,10 +81,11 @@ function printCategoriesModule(es6) {
|
|
|
66
81
|
var categories = mapForEachLanguage(function (mp) {
|
|
67
82
|
var cat = JSON.stringify(mp.categories).replace(/"(\w+)":/g, '$1:');
|
|
68
83
|
cc.forEach(function (c, i) {
|
|
69
|
-
if (cat === c) cat =
|
|
84
|
+
if (cat === c) cat = "_cc[".concat(i, "]");
|
|
70
85
|
});
|
|
71
86
|
return cat;
|
|
72
87
|
});
|
|
88
|
+
|
|
73
89
|
if (es6) {
|
|
74
90
|
console.log('const _cc = [\n ' + cc.join(',\n ') + '\n];');
|
|
75
91
|
console.log(es6module(categories.join(',\n')));
|
|
@@ -93,6 +109,7 @@ MakePlural.ordinals = argv.ordinal !== null ? truthy(argv.ordinal) : true;
|
|
|
93
109
|
|
|
94
110
|
if (argv.locale) {
|
|
95
111
|
var mp = new MakePlural(argv.locale).test();
|
|
112
|
+
|
|
96
113
|
if (argv.categories) {
|
|
97
114
|
var cats = mp.categories.cardinal.concat(mp.categories.ordinal).filter(function (v, i, self) {
|
|
98
115
|
return self.indexOf(v) === i;
|
package/data/ordinals.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"supplemental": {
|
|
3
3
|
"version": {
|
|
4
|
-
"_number": "$Revision:
|
|
5
|
-
"_unicodeVersion": "
|
|
6
|
-
"_cldrVersion": "
|
|
4
|
+
"_number": "$Revision: 14397 $",
|
|
5
|
+
"_unicodeVersion": "11.0.0",
|
|
6
|
+
"_cldrVersion": "34"
|
|
7
7
|
},
|
|
8
8
|
"plurals-type-ordinal": {
|
|
9
9
|
"af": {
|
|
@@ -113,6 +113,12 @@
|
|
|
113
113
|
"pluralRule-count-one": "n = 1 @integer 1",
|
|
114
114
|
"pluralRule-count-other": " @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, …"
|
|
115
115
|
},
|
|
116
|
+
"gd": {
|
|
117
|
+
"pluralRule-count-one": "n = 1,11 @integer 1, 11",
|
|
118
|
+
"pluralRule-count-two": "n = 2,12 @integer 2, 12",
|
|
119
|
+
"pluralRule-count-few": "n = 3,13 @integer 3, 13",
|
|
120
|
+
"pluralRule-count-other": " @integer 0, 5~19, 100, 1000, 10000, 100000, 1000000, …"
|
|
121
|
+
},
|
|
116
122
|
"gl": {
|
|
117
123
|
"pluralRule-count-other": " @integer 0~15, 100, 1000, 10000, 100000, 1000000, …"
|
|
118
124
|
},
|
|
@@ -150,6 +156,9 @@
|
|
|
150
156
|
"pluralRule-count-one": "n = 1 @integer 1",
|
|
151
157
|
"pluralRule-count-other": " @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, …"
|
|
152
158
|
},
|
|
159
|
+
"ia": {
|
|
160
|
+
"pluralRule-count-other": " @integer 0~15, 100, 1000, 10000, 100000, 1000000, …"
|
|
161
|
+
},
|
|
153
162
|
"id": {
|
|
154
163
|
"pluralRule-count-other": " @integer 0~15, 100, 1000, 10000, 100000, 1000000, …"
|
|
155
164
|
},
|
|
@@ -271,6 +280,10 @@
|
|
|
271
280
|
"ru": {
|
|
272
281
|
"pluralRule-count-other": " @integer 0~15, 100, 1000, 10000, 100000, 1000000, …"
|
|
273
282
|
},
|
|
283
|
+
"sc": {
|
|
284
|
+
"pluralRule-count-many": "n = 11,8,80,800 @integer 8, 11, 80, 800",
|
|
285
|
+
"pluralRule-count-other": " @integer 0~7, 9, 10, 12~17, 100, 1000, 10000, 100000, 1000000, …"
|
|
286
|
+
},
|
|
274
287
|
"scn": {
|
|
275
288
|
"pluralRule-count-many": "n = 11,8,80,800 @integer 8, 11, 80, 800",
|
|
276
289
|
"pluralRule-count-other": " @integer 0~7, 9, 10, 12~17, 100, 1000, 10000, 100000, 1000000, …"
|
|
@@ -350,4 +363,4 @@
|
|
|
350
363
|
}
|
|
351
364
|
}
|
|
352
365
|
}
|
|
353
|
-
}
|
|
366
|
+
}
|
package/data/plurals.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"supplemental": {
|
|
3
3
|
"version": {
|
|
4
|
-
"_number": "$Revision:
|
|
5
|
-
"_unicodeVersion": "
|
|
6
|
-
"_cldrVersion": "
|
|
4
|
+
"_number": "$Revision: 14397 $",
|
|
5
|
+
"_unicodeVersion": "11.0.0",
|
|
6
|
+
"_cldrVersion": "34"
|
|
7
7
|
},
|
|
8
8
|
"plurals-type-cardinal": {
|
|
9
9
|
"af": {
|
|
@@ -286,6 +286,10 @@
|
|
|
286
286
|
"pluralRule-count-one": "i = 0,1 @integer 0, 1 @decimal 0.0~1.5",
|
|
287
287
|
"pluralRule-count-other": " @integer 2~17, 100, 1000, 10000, 100000, 1000000, … @decimal 2.0~3.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
|
|
288
288
|
},
|
|
289
|
+
"ia": {
|
|
290
|
+
"pluralRule-count-one": "i = 1 and v = 0 @integer 1",
|
|
291
|
+
"pluralRule-count-other": " @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
|
|
292
|
+
},
|
|
289
293
|
"id": {
|
|
290
294
|
"pluralRule-count-other": " @integer 0~15, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
|
|
291
295
|
},
|
|
@@ -626,6 +630,10 @@
|
|
|
626
630
|
"pluralRule-count-one": "n = 1 @integer 1 @decimal 1.0, 1.00, 1.000, 1.0000",
|
|
627
631
|
"pluralRule-count-other": " @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~0.9, 1.1~1.6, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
|
|
628
632
|
},
|
|
633
|
+
"sc": {
|
|
634
|
+
"pluralRule-count-one": "i = 1 and v = 0 @integer 1",
|
|
635
|
+
"pluralRule-count-other": " @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
|
|
636
|
+
},
|
|
629
637
|
"scn": {
|
|
630
638
|
"pluralRule-count-one": "i = 1 and v = 0 @integer 1",
|
|
631
639
|
"pluralRule-count-other": " @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
|
|
@@ -866,4 +874,4 @@
|
|
|
866
874
|
}
|
|
867
875
|
}
|
|
868
876
|
}
|
|
869
|
-
}
|
|
877
|
+
}
|
package/es6/pluralCategories.js
CHANGED
|
@@ -54,7 +54,7 @@ fr: _cc[2],
|
|
|
54
54
|
fur: _cc[1],
|
|
55
55
|
fy: _cc[1],
|
|
56
56
|
ga: {cardinal:["one","two","few","many","other"],ordinal:["one","other"]},
|
|
57
|
-
gd: {cardinal:["one","two","few","other"],ordinal:["other"]},
|
|
57
|
+
gd: {cardinal:["one","two","few","other"],ordinal:["one","two","few","other"]},
|
|
58
58
|
gl: _cc[1],
|
|
59
59
|
gsw: _cc[1],
|
|
60
60
|
gu: {cardinal:["one","other"],ordinal:["one","two","few","many","other"]},
|
|
@@ -68,6 +68,7 @@ hr: {cardinal:["one","few","other"],ordinal:["other"]},
|
|
|
68
68
|
hsb: {cardinal:["one","two","few","other"],ordinal:["other"]},
|
|
69
69
|
hu: _cc[2],
|
|
70
70
|
hy: _cc[2],
|
|
71
|
+
ia: _cc[1],
|
|
71
72
|
id: _cc[0],
|
|
72
73
|
ig: _cc[0],
|
|
73
74
|
ii: _cc[0],
|
|
@@ -153,6 +154,7 @@ ru: {cardinal:["one","few","many","other"],ordinal:["other"]},
|
|
|
153
154
|
rwk: _cc[1],
|
|
154
155
|
sah: _cc[0],
|
|
155
156
|
saq: _cc[1],
|
|
157
|
+
sc: {cardinal:["one","other"],ordinal:["many","other"]},
|
|
156
158
|
scn: {cardinal:["one","other"],ordinal:["many","other"]},
|
|
157
159
|
sd: _cc[1],
|
|
158
160
|
sdh: _cc[1],
|