make-plural 3.0.2 → 3.0.6
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 +1 -1
- package/bin/common.js +15 -0
- package/bin/make-plural +15 -11
- package/data/ordinals.json +3 -3
- package/data/plurals.json +3 -3
- package/make-plural.js +29 -27
- package/make-plural.min.js +1 -1
- package/package.json +19 -15
- package/pluralCategories.js +217 -0
- package/pluralCategories.min.js +1 -0
- package/README.md +0 -293
package/LICENSE
CHANGED
package/bin/common.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var combined = exports.combined = {
|
|
7
|
+
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
|
+
categories: ['{cardinal:["other"],ordinal:["other"]}', '{cardinal:["one","other"],ordinal:["other"]}', '{cardinal:["one","other"],ordinal:["one","other"]}', '{cardinal:["one","two","other"],ordinal:["other"]}']
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
var cardinals = exports.cardinals = {
|
|
12
|
+
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
|
+
categories: ['{cardinal:["other"],ordinal:[]}', '{cardinal:["one","other"],ordinal:[]}', '{cardinal:["one","other"],ordinal:[]}', '{cardinal:["one","two","other"],ordinal:[]}']
|
|
14
|
+
};
|
|
15
|
+
|
package/bin/make-plural
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var _common = require('./common');
|
|
6
|
+
|
|
7
|
+
var common = _interopRequireWildcard(_common);
|
|
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; } }
|
|
10
|
+
|
|
3
11
|
/** A compiler for make-plural.js
|
|
4
12
|
*
|
|
5
13
|
* Usage:
|
|
@@ -8,20 +16,14 @@
|
|
|
8
16
|
* ./bin/make-plural [lc] [n] [ord] // prints the (ORD ? ordinal : plural) category for N in locale LC
|
|
9
17
|
*/
|
|
10
18
|
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
19
|
var argv = require('minimist')(process.argv.slice(2), {
|
|
14
|
-
|
|
20
|
+
default: { locale: null, value: null, ordinal: null, cardinal: null, categories: false },
|
|
15
21
|
alias: { locale: 'l', value: 'v', ordinal: 'o', cardinal: 'c' },
|
|
16
22
|
string: ['locale', 'value'],
|
|
17
23
|
boolean: ['categories']
|
|
18
24
|
}),
|
|
19
25
|
MakePlural = require('../make-plural').load(require('../data/plurals.json'), require('../data/ordinals.json'));
|
|
20
26
|
|
|
21
|
-
var commonPlurals = ['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}'];
|
|
22
|
-
|
|
23
|
-
var commonCategories = ['{cardinal:["other"],ordinal:["other"]}', '{cardinal:["one","other"],ordinal:["other"]}', '{cardinal:["one","other"],ordinal:["one","other"]}', '{cardinal:["one","two","other"],ordinal:["other"]}'];
|
|
24
|
-
|
|
25
27
|
// UMD pattern adapted from https://github.com/umdjs/umd/blob/master/returnExports.js
|
|
26
28
|
function umd(global, value) {
|
|
27
29
|
return '\n(function (root, ' + global + ') {\n if (typeof define === \'function\' && define.amd) {\n define(' + global + ');\n } else if (typeof exports === \'object\') {\n module.exports = ' + global + ';\n } else {\n root.' + global + ' = ' + global + ';\n }\n}(this, {\n' + value + '\n}));';
|
|
@@ -39,26 +41,28 @@ function mapForEachLanguage(cb, opt) {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
function printPluralsModule() {
|
|
44
|
+
var cp = common[MakePlural.ordinals ? 'combined' : 'cardinals'].plurals;
|
|
42
45
|
var plurals = mapForEachLanguage(function (mp) {
|
|
43
46
|
var fn = mp.toString();
|
|
44
|
-
|
|
47
|
+
cp.forEach(function (p, i) {
|
|
45
48
|
if (fn === p) fn = '_cp[' + i + ']';
|
|
46
49
|
});
|
|
47
50
|
return fn;
|
|
48
51
|
});
|
|
49
|
-
console.log('var _cp = [\n' +
|
|
52
|
+
console.log('var _cp = [\n' + cp.join(',\n') + '\n];');
|
|
50
53
|
console.log(umd('plurals', plurals.join(',\n\n')));
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
function printCategoriesModule() {
|
|
57
|
+
var cc = common[MakePlural.ordinals ? 'combined' : 'cardinals'].categories;
|
|
54
58
|
var categories = mapForEachLanguage(function (mp) {
|
|
55
59
|
var cat = JSON.stringify(mp.categories).replace(/"(\w+)":/g, '$1:');
|
|
56
|
-
|
|
60
|
+
cc.forEach(function (c, i) {
|
|
57
61
|
if (cat === c) cat = '_cc[' + i + ']';
|
|
58
62
|
});
|
|
59
63
|
return cat;
|
|
60
64
|
});
|
|
61
|
-
console.log('var _cc = [\n ' +
|
|
65
|
+
console.log('var _cc = [\n ' + cc.join(',\n ') + '\n];');
|
|
62
66
|
console.log(umd('pluralCategories', categories.join(',\n')));
|
|
63
67
|
}
|
|
64
68
|
|
package/data/ordinals.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"supplemental": {
|
|
3
3
|
"version": {
|
|
4
|
-
"
|
|
4
|
+
"_number": "$Revision: 12412 $",
|
|
5
5
|
"_unicodeVersion": "8.0.0",
|
|
6
|
-
"
|
|
6
|
+
"_cldrVersion": "29"
|
|
7
7
|
},
|
|
8
8
|
"plurals-type-ordinal": {
|
|
9
9
|
"af": {
|
|
@@ -323,4 +323,4 @@
|
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
|
-
}
|
|
326
|
+
}
|
package/data/plurals.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"supplemental": {
|
|
3
3
|
"version": {
|
|
4
|
-
"
|
|
4
|
+
"_number": "$Revision: 12002 $",
|
|
5
5
|
"_unicodeVersion": "8.0.0",
|
|
6
|
-
"
|
|
6
|
+
"_cldrVersion": "29"
|
|
7
7
|
},
|
|
8
8
|
"plurals-type-cardinal": {
|
|
9
9
|
"af": {
|
|
@@ -843,4 +843,4 @@
|
|
|
843
843
|
}
|
|
844
844
|
}
|
|
845
845
|
}
|
|
846
|
-
}
|
|
846
|
+
}
|
package/make-plural.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.MakePlural = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
9
|
+
|
|
10
|
+
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
|
11
|
+
|
|
12
|
+
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
|
|
13
|
+
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
+
|
|
2
16
|
/**
|
|
3
17
|
* make-plural.js -- https://github.com/eemeli/make-plural.js/
|
|
4
|
-
* Copyright (c) 2014-
|
|
18
|
+
* Copyright (c) 2014-2016 by Eemeli Aro <eemeli@gmail.com>
|
|
5
19
|
*
|
|
6
20
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
7
21
|
* purpose with or without fee is hereby granted, provided that the above
|
|
@@ -16,21 +30,7 @@
|
|
|
16
30
|
* or in connection with the use or performance of this software.
|
|
17
31
|
*/
|
|
18
32
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Object.defineProperty(exports, '__esModule', {
|
|
22
|
-
value: true
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
26
|
-
|
|
27
|
-
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
|
|
28
|
-
|
|
29
|
-
function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
|
|
30
|
-
|
|
31
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
32
|
-
|
|
33
|
-
var Parser = (function () {
|
|
33
|
+
var Parser = function () {
|
|
34
34
|
function Parser() {
|
|
35
35
|
_classCallCheck(this, Parser);
|
|
36
36
|
}
|
|
@@ -88,15 +88,16 @@ var Parser = (function () {
|
|
|
88
88
|
var k0 = k[0] === 'n' ? 't0 && s[0]' : k[0];
|
|
89
89
|
vars.push(k + ' = ' + k0 + '.slice(-' + k.substr(2).length + ')');
|
|
90
90
|
}
|
|
91
|
-
}
|
|
91
|
+
}
|
|
92
|
+
if (!vars.length) return '';
|
|
92
93
|
return 'var ' + ["s = String(n).split('.')"].concat(vars).join(', ');
|
|
93
94
|
}
|
|
94
95
|
}]);
|
|
95
96
|
|
|
96
97
|
return Parser;
|
|
97
|
-
}
|
|
98
|
+
}();
|
|
98
99
|
|
|
99
|
-
var Tests =
|
|
100
|
+
var Tests = function () {
|
|
100
101
|
function Tests(obj) {
|
|
101
102
|
_classCallCheck(this, Tests);
|
|
102
103
|
|
|
@@ -139,16 +140,16 @@ var Tests = (function () {
|
|
|
139
140
|
value: function testAll() {
|
|
140
141
|
for (var cat in this.cardinal) {
|
|
141
142
|
this.testCat('cardinal', cat);
|
|
142
|
-
}for (var
|
|
143
|
-
this.testCat('ordinal',
|
|
143
|
+
}for (var _cat in this.ordinal) {
|
|
144
|
+
this.testCat('ordinal', _cat);
|
|
144
145
|
}return true;
|
|
145
146
|
}
|
|
146
147
|
}]);
|
|
147
148
|
|
|
148
149
|
return Tests;
|
|
149
|
-
}
|
|
150
|
+
}();
|
|
150
151
|
|
|
151
|
-
var MakePlural =
|
|
152
|
+
var MakePlural = function () {
|
|
152
153
|
function MakePlural(lc) {
|
|
153
154
|
var _ref = arguments.length <= 1 || arguments[1] === undefined ? MakePlural : arguments[1];
|
|
154
155
|
|
|
@@ -165,9 +166,9 @@ var MakePlural = (function () {
|
|
|
165
166
|
this.fn = this.buildFunction(cardinals, ordinals);
|
|
166
167
|
this.fn._obj = this;
|
|
167
168
|
this.fn.categories = this.categories;
|
|
168
|
-
this.fn.test =
|
|
169
|
+
this.fn.test = function () {
|
|
169
170
|
return this.tests.testAll() && this.fn;
|
|
170
|
-
}
|
|
171
|
+
}.bind(this);
|
|
171
172
|
this.fn.toString = this.fnToString.bind(this);
|
|
172
173
|
return this.fn;
|
|
173
174
|
}
|
|
@@ -252,9 +253,10 @@ var MakePlural = (function () {
|
|
|
252
253
|
}]);
|
|
253
254
|
|
|
254
255
|
return MakePlural;
|
|
255
|
-
}
|
|
256
|
+
}();
|
|
257
|
+
|
|
258
|
+
exports.default = MakePlural;
|
|
256
259
|
|
|
257
|
-
exports['default'] = MakePlural;
|
|
258
260
|
|
|
259
261
|
MakePlural.cardinals = true;
|
|
260
262
|
MakePlural.ordinals = false;
|
package/make-plural.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.MakePlural=n()}}(function(){return function n(t,r,e){function i(a,s){if(!r[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var f=r[a]={exports:{}};t[a][0].call(f.exports,function(n){var r=t[a][1][n];return i(r?r:n)},f,f.exports,n,t,r,e)}return r[a].exports}for(var o="function"==typeof require&&require,a=0;a<e.length;a++)i(e[a]);return i}({1:[function(n,t,r){"use strict";function e(n){if(Array.isArray(n)){for(var t=0,r=Array(n.length);t<n.length;t++)r[t]=n[t];return r}return Array.from(n)}function i(n){return Array.isArray(n)?n:Array.from(n)}function o(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var a=function(){function n(n,t){for(var r=0;r<t.length;r++){var e=t[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(n,e.key,e)}}return function(t,r,e){return r&&n(t.prototype,r),e&&n(t,e),t}}(),s=function(){function n(){o(this,n)}return a(n,[{key:"parse",value:function(n){var t=this;return"i = 0 or n = 1"===n?"n >= 0 && n <= 1":"i = 0,1"===n?"n >= 0 && n < 2":"i = 1 and v = 0"===n?(this.v0=1,"n == 1 && v0"):n.replace(/([tv]) (!?)= 0/g,function(n,r,e){var i=r+"0";return t[i]=1,e?"!"+i:i}).replace(/\b[fintv]\b/g,function(n){return t[n]=1,n}).replace(/([fin]) % (10+)/g,function(n,r,e){var i=r+e;return t[i]=1,i}).replace(/n10+ = 0/g,"t0 && $&").replace(/(\w+ (!?)= )([0-9.]+,[0-9.,]+)/g,function(n,t,r,e){return"n = 0,1"===n?"(n == 0 || n == 1)":r?t+e.split(",").join(" && "+t):"("+t+e.split(",").join(" || "+t)+")"}).replace(/(\w+) (!?)= ([0-9]+)\.\.([0-9]+)/g,function(n,r,e,i,o){return Number(i)+1===Number(o)?e?r+" != "+i+" && "+r+" != "+o:"("+r+" == "+i+" || "+r+" == "+o+")":e?"("+r+" < "+i+" || "+r+" > "+o+")":"n"===r?(t.t0=1,"(t0 && n >= "+i+" && n <= "+o+")"):"("+r+" >= "+i+" && "+r+" <= "+o+")"}).replace(/ and /g," && ").replace(/ or /g," || ").replace(/ = /g," == ")}},{key:"vars",value:function t(){var t=[];this.i&&t.push("i = s[0]"),(this.f||this.v)&&t.push("f = s[1] || ''"),this.t&&t.push("t = (s[1] || '').replace(/0+$/, '')"),this.v&&t.push("v = f.length"),this.v0&&t.push("v0 = !s[1]"),(this.t0||this.n10||this.n100)&&t.push("t0 = Number(s[0]) == n");for(var n in this)if(/^.10+$/.test(n)){var r="n"===n[0]?"t0 && s[0]":n[0];t.push(n+" = "+r+".slice(-"+n.substr(2).length+")")}return t.length?"var "+["s = String(n).split('.')"].concat(t).join(", "):""}}]),n}(),u=function(){function n(t){o(this,n),this.obj=t,this.ordinal={},this.cardinal={}}return a(n,[{key:"add",value:function(n,t,r){this[n][t]=r.join(" ").replace(/^[ ,]+|[ ,…]+$/g,"").replace(/(0\.[0-9])~(1\.[1-9])/g,"$1 1.0 $2").split(/[ ,~…]+/)}},{key:"testCond",value:function(n,t,r,e){try{var i=(e||this.obj.fn)(n,"ordinal"===t)}catch(o){i=o.toString()}if(i!==r)throw new Error("Locale "+JSON.stringify(this.obj.lc)+t+" rule self-test failed for v = "+JSON.stringify(n)+" (was "+JSON.stringify(i)+", expected "+JSON.stringify(r)+")");return!0}},{key:"testCat",value:function(n,t,r){var e=this;return this[n][t].forEach(function(i){e.testCond(i,n,t,r),/\.0+$/.test(i)||e.testCond(Number(i),n,t,r)}),!0}},{key:"testAll",value:function(){for(var n in this.cardinal)this.testCat("cardinal",n);for(var
|
|
1
|
+
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.MakePlural=n()}}(function(){return function n(t,r,e){function i(a,s){if(!r[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(o)return o(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var f=r[a]={exports:{}};t[a][0].call(f.exports,function(n){var r=t[a][1][n];return i(r?r:n)},f,f.exports,n,t,r,e)}return r[a].exports}for(var o="function"==typeof require&&require,a=0;a<e.length;a++)i(e[a]);return i}({1:[function(n,t,r){"use strict";function e(n){if(Array.isArray(n)){for(var t=0,r=Array(n.length);t<n.length;t++)r[t]=n[t];return r}return Array.from(n)}function i(n){return Array.isArray(n)?n:Array.from(n)}function o(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var a=function(){function n(n,t){for(var r=0;r<t.length;r++){var e=t[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(n,e.key,e)}}return function(t,r,e){return r&&n(t.prototype,r),e&&n(t,e),t}}(),s=function(){function n(){o(this,n)}return a(n,[{key:"parse",value:function(n){var t=this;return"i = 0 or n = 1"===n?"n >= 0 && n <= 1":"i = 0,1"===n?"n >= 0 && n < 2":"i = 1 and v = 0"===n?(this.v0=1,"n == 1 && v0"):n.replace(/([tv]) (!?)= 0/g,function(n,r,e){var i=r+"0";return t[i]=1,e?"!"+i:i}).replace(/\b[fintv]\b/g,function(n){return t[n]=1,n}).replace(/([fin]) % (10+)/g,function(n,r,e){var i=r+e;return t[i]=1,i}).replace(/n10+ = 0/g,"t0 && $&").replace(/(\w+ (!?)= )([0-9.]+,[0-9.,]+)/g,function(n,t,r,e){return"n = 0,1"===n?"(n == 0 || n == 1)":r?t+e.split(",").join(" && "+t):"("+t+e.split(",").join(" || "+t)+")"}).replace(/(\w+) (!?)= ([0-9]+)\.\.([0-9]+)/g,function(n,r,e,i,o){return Number(i)+1===Number(o)?e?r+" != "+i+" && "+r+" != "+o:"("+r+" == "+i+" || "+r+" == "+o+")":e?"("+r+" < "+i+" || "+r+" > "+o+")":"n"===r?(t.t0=1,"(t0 && n >= "+i+" && n <= "+o+")"):"("+r+" >= "+i+" && "+r+" <= "+o+")"}).replace(/ and /g," && ").replace(/ or /g," || ").replace(/ = /g," == ")}},{key:"vars",value:function t(){var t=[];this.i&&t.push("i = s[0]"),(this.f||this.v)&&t.push("f = s[1] || ''"),this.t&&t.push("t = (s[1] || '').replace(/0+$/, '')"),this.v&&t.push("v = f.length"),this.v0&&t.push("v0 = !s[1]"),(this.t0||this.n10||this.n100)&&t.push("t0 = Number(s[0]) == n");for(var n in this)if(/^.10+$/.test(n)){var r="n"===n[0]?"t0 && s[0]":n[0];t.push(n+" = "+r+".slice(-"+n.substr(2).length+")")}return t.length?"var "+["s = String(n).split('.')"].concat(t).join(", "):""}}]),n}(),u=function(){function n(t){o(this,n),this.obj=t,this.ordinal={},this.cardinal={}}return a(n,[{key:"add",value:function(n,t,r){this[n][t]=r.join(" ").replace(/^[ ,]+|[ ,…]+$/g,"").replace(/(0\.[0-9])~(1\.[1-9])/g,"$1 1.0 $2").split(/[ ,~…]+/)}},{key:"testCond",value:function(n,t,r,e){try{var i=(e||this.obj.fn)(n,"ordinal"===t)}catch(o){i=o.toString()}if(i!==r)throw new Error("Locale "+JSON.stringify(this.obj.lc)+t+" rule self-test failed for v = "+JSON.stringify(n)+" (was "+JSON.stringify(i)+", expected "+JSON.stringify(r)+")");return!0}},{key:"testCat",value:function(n,t,r){var e=this;return this[n][t].forEach(function(i){e.testCond(i,n,t,r),/\.0+$/.test(i)||e.testCond(Number(i),n,t,r)}),!0}},{key:"testAll",value:function(){for(var n in this.cardinal)this.testCat("cardinal",n);for(var t in this.ordinal)this.testCat("ordinal",t);return!0}}]),n}(),l=function(){function n(t){var r=arguments.length<=1||void 0===arguments[1]?n:arguments[1],e=r.cardinals,i=r.ordinals;if(o(this,n),!e&&!i)throw new Error("At least one type of plural is required");return this.lc=t,this.categories={cardinal:[],ordinal:[]},this.parser=new s,this.tests=new u(this),this.fn=this.buildFunction(e,i),this.fn._obj=this,this.fn.categories=this.categories,this.fn.test=function(){return this.tests.testAll()&&this.fn}.bind(this),this.fn.toString=this.fnToString.bind(this),this.fn}return a(n,[{key:"compile",value:function(t,r){var o=[],a=n.rules[t][this.lc];if(!a){if(r)throw new Error('Locale "'+this.lc+'" '+t+" rules not found");return this.categories[t]=["other"],"'other'"}for(var s in a){var u=a[s].trim().split(/\s*@\w*/),l=i(u),f=l[0],c=l.slice(1),h=s.replace("pluralRule-count-","");f&&o.push([this.parser.parse(f),h]),this.tests.add(t,h,c)}return this.categories[t]=o.map(function(n){return n[1]}).concat("other"),1===o.length?"("+o[0][0]+") ? '"+o[0][1]+"' : 'other'":[].concat(e(o.map(function(n){return"("+n[0]+") ? '"+n[1]+"'"})),["'other'"]).join("\n : ")}},{key:"buildFunction",value:function(n,t){var r=this,i=function(n){return n?(n[1]?"return ":"if (ord) return ")+r.compile.apply(r,e(n)):""},o={vars:function(n){return(" "+n+";").replace(/(.{1,78})(,|$) ?/g,"$1$2\n ")},cond:function(n){return(" "+n+";").replace(/(.{1,78}) (\|\| |$) ?/gm,"$1\n $2")}},a=[t&&["ordinal",!n],n&&["cardinal",!0]].map(i).map(o.cond),s=[o.vars(this.parser.vars())].concat(e(a)).filter(function(n){return!/^[\s;]*$/.test(n)}).map(function(n){return n.replace(/\s+$/gm,"")}).join("\n"),u=t&&n?"n, ord":"n";return new Function(u,s)}},{key:"fnToString",value:function(n){return Function.prototype.toString.call(this.fn).replace(/^function( \w+)?/,n?"function "+n:"function").replace("\n/**/","")}}],[{key:"load",value:function(){for(var t=arguments.length,r=Array(t),e=0;t>e;e++)r[e]=arguments[e];return r.forEach(function(t){var r=t&&t.supplemental||null;if(!r)throw new Error("Data does not appear to be CLDR data");n.rules={cardinal:r["plurals-type-cardinal"]||n.rules.cardinal,ordinal:r["plurals-type-ordinal"]||n.rules.ordinal}}),n}}]),n}();r["default"]=l,l.cardinals=!0,l.ordinals=!1,l.rules={cardinal:{},ordinal:{}},t.exports=r["default"]},{}]},{},[1])(1)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "make-plural",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "Translates Unicode CLDR pluralization rules to executable JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unicode",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"bin/",
|
|
24
24
|
"data/",
|
|
25
25
|
"make-plural.*",
|
|
26
|
+
"pluralCategories.*",
|
|
26
27
|
"plurals.*"
|
|
27
28
|
],
|
|
28
29
|
"bin": {
|
|
@@ -31,19 +32,25 @@
|
|
|
31
32
|
"main": "plurals",
|
|
32
33
|
"scripts": {
|
|
33
34
|
"lint": "eslint src/",
|
|
34
|
-
"test": "make test"
|
|
35
|
+
"test": "make test",
|
|
36
|
+
"version": "git add -f $FILES"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
|
-
"babel": "^
|
|
38
|
-
"babel-eslint": "^
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
39
|
+
"babel-cli": "^6.7.7",
|
|
40
|
+
"babel-eslint": "^6.0.3",
|
|
41
|
+
"babel-plugin-add-module-exports": "^0.1.2",
|
|
42
|
+
"babel-preset-es2015": "^6.6.0",
|
|
43
|
+
"babelify": "^7.2.0",
|
|
44
|
+
"browserify": "^13.0.0",
|
|
45
|
+
"cldr-core": "^29.0.0",
|
|
46
|
+
"eslint": "^2.8.0",
|
|
47
|
+
"expect.js": "*",
|
|
48
|
+
"http-server": "^0.9.0",
|
|
49
|
+
"mocha": "*",
|
|
50
|
+
"uglify-js": "*"
|
|
51
|
+
},
|
|
52
|
+
"optionalDependencies": {
|
|
53
|
+
"minimist": "^1.2.0"
|
|
47
54
|
},
|
|
48
55
|
"eslintConfig": {
|
|
49
56
|
"parser": "babel-eslint",
|
|
@@ -70,8 +77,5 @@
|
|
|
70
77
|
],
|
|
71
78
|
"strict": 0
|
|
72
79
|
}
|
|
73
|
-
},
|
|
74
|
-
"optionalDependencies": {
|
|
75
|
-
"minimist": "^1.1.1"
|
|
76
80
|
}
|
|
77
81
|
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
var _cc = [
|
|
2
|
+
{cardinal:["other"],ordinal:["other"]},
|
|
3
|
+
{cardinal:["one","other"],ordinal:["other"]},
|
|
4
|
+
{cardinal:["one","other"],ordinal:["one","other"]},
|
|
5
|
+
{cardinal:["one","two","other"],ordinal:["other"]}
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
(function (root, pluralCategories) {
|
|
9
|
+
if (typeof define === 'function' && define.amd) {
|
|
10
|
+
define(pluralCategories);
|
|
11
|
+
} else if (typeof exports === 'object') {
|
|
12
|
+
module.exports = pluralCategories;
|
|
13
|
+
} else {
|
|
14
|
+
root.pluralCategories = pluralCategories;
|
|
15
|
+
}
|
|
16
|
+
}(this, {
|
|
17
|
+
af: _cc[1],
|
|
18
|
+
ak: _cc[1],
|
|
19
|
+
am: _cc[1],
|
|
20
|
+
ar: {cardinal:["zero","one","two","few","many","other"],ordinal:["other"]},
|
|
21
|
+
as: {cardinal:["one","other"],ordinal:["one","two","few","many","other"]},
|
|
22
|
+
asa: _cc[1],
|
|
23
|
+
ast: _cc[1],
|
|
24
|
+
az: {cardinal:["one","other"],ordinal:["one","few","many","other"]},
|
|
25
|
+
be: {cardinal:["one","few","many","other"],ordinal:["few","other"]},
|
|
26
|
+
bem: _cc[1],
|
|
27
|
+
bez: _cc[1],
|
|
28
|
+
bg: _cc[1],
|
|
29
|
+
bh: _cc[1],
|
|
30
|
+
bm: _cc[0],
|
|
31
|
+
bn: {cardinal:["one","other"],ordinal:["one","two","few","many","other"]},
|
|
32
|
+
bo: _cc[0],
|
|
33
|
+
br: {cardinal:["one","two","few","many","other"],ordinal:["other"]},
|
|
34
|
+
brx: _cc[1],
|
|
35
|
+
bs: {cardinal:["one","few","other"],ordinal:["other"]},
|
|
36
|
+
ca: {cardinal:["one","other"],ordinal:["one","two","few","other"]},
|
|
37
|
+
ce: _cc[1],
|
|
38
|
+
cgg: _cc[1],
|
|
39
|
+
chr: _cc[1],
|
|
40
|
+
ckb: _cc[1],
|
|
41
|
+
cs: {cardinal:["one","few","many","other"],ordinal:["other"]},
|
|
42
|
+
cy: {cardinal:["zero","one","two","few","many","other"],ordinal:["zero","one","two","few","many","other"]},
|
|
43
|
+
da: _cc[1],
|
|
44
|
+
de: _cc[1],
|
|
45
|
+
dsb: {cardinal:["one","two","few","other"],ordinal:["other"]},
|
|
46
|
+
dv: _cc[1],
|
|
47
|
+
dz: _cc[0],
|
|
48
|
+
ee: _cc[1],
|
|
49
|
+
el: _cc[1],
|
|
50
|
+
en: {cardinal:["one","other"],ordinal:["one","two","few","other"]},
|
|
51
|
+
eo: _cc[1],
|
|
52
|
+
es: _cc[1],
|
|
53
|
+
et: _cc[1],
|
|
54
|
+
eu: _cc[1],
|
|
55
|
+
fa: _cc[1],
|
|
56
|
+
ff: _cc[1],
|
|
57
|
+
fi: _cc[1],
|
|
58
|
+
fil: _cc[2],
|
|
59
|
+
fo: _cc[1],
|
|
60
|
+
fr: _cc[2],
|
|
61
|
+
fur: _cc[1],
|
|
62
|
+
fy: _cc[1],
|
|
63
|
+
ga: {cardinal:["one","two","few","many","other"],ordinal:["one","other"]},
|
|
64
|
+
gd: {cardinal:["one","two","few","other"],ordinal:["other"]},
|
|
65
|
+
gl: _cc[1],
|
|
66
|
+
gsw: _cc[1],
|
|
67
|
+
gu: {cardinal:["one","other"],ordinal:["one","two","few","many","other"]},
|
|
68
|
+
guw: _cc[1],
|
|
69
|
+
gv: {cardinal:["one","two","few","many","other"],ordinal:["other"]},
|
|
70
|
+
ha: _cc[1],
|
|
71
|
+
haw: _cc[1],
|
|
72
|
+
he: {cardinal:["one","two","many","other"],ordinal:["other"]},
|
|
73
|
+
hi: {cardinal:["one","other"],ordinal:["one","two","few","many","other"]},
|
|
74
|
+
hr: {cardinal:["one","few","other"],ordinal:["other"]},
|
|
75
|
+
hsb: {cardinal:["one","two","few","other"],ordinal:["other"]},
|
|
76
|
+
hu: _cc[2],
|
|
77
|
+
hy: _cc[2],
|
|
78
|
+
id: _cc[0],
|
|
79
|
+
ig: _cc[0],
|
|
80
|
+
ii: _cc[0],
|
|
81
|
+
"in": _cc[0],
|
|
82
|
+
is: _cc[1],
|
|
83
|
+
it: {cardinal:["one","other"],ordinal:["many","other"]},
|
|
84
|
+
iu: _cc[3],
|
|
85
|
+
iw: {cardinal:["one","two","many","other"],ordinal:["other"]},
|
|
86
|
+
ja: _cc[0],
|
|
87
|
+
jbo: _cc[0],
|
|
88
|
+
jgo: _cc[1],
|
|
89
|
+
ji: _cc[1],
|
|
90
|
+
jmc: _cc[1],
|
|
91
|
+
jv: _cc[0],
|
|
92
|
+
jw: _cc[0],
|
|
93
|
+
ka: {cardinal:["one","other"],ordinal:["one","many","other"]},
|
|
94
|
+
kab: _cc[1],
|
|
95
|
+
kaj: _cc[1],
|
|
96
|
+
kcg: _cc[1],
|
|
97
|
+
kde: _cc[0],
|
|
98
|
+
kea: _cc[0],
|
|
99
|
+
kk: {cardinal:["one","other"],ordinal:["many","other"]},
|
|
100
|
+
kkj: _cc[1],
|
|
101
|
+
kl: _cc[1],
|
|
102
|
+
km: _cc[0],
|
|
103
|
+
kn: _cc[1],
|
|
104
|
+
ko: _cc[0],
|
|
105
|
+
ks: _cc[1],
|
|
106
|
+
ksb: _cc[1],
|
|
107
|
+
ksh: {cardinal:["zero","one","other"],ordinal:["other"]},
|
|
108
|
+
ku: _cc[1],
|
|
109
|
+
kw: _cc[3],
|
|
110
|
+
ky: _cc[1],
|
|
111
|
+
lag: {cardinal:["zero","one","other"],ordinal:["other"]},
|
|
112
|
+
lb: _cc[1],
|
|
113
|
+
lg: _cc[1],
|
|
114
|
+
lkt: _cc[0],
|
|
115
|
+
ln: _cc[1],
|
|
116
|
+
lo: {cardinal:["other"],ordinal:["one","other"]},
|
|
117
|
+
lt: {cardinal:["one","few","many","other"],ordinal:["other"]},
|
|
118
|
+
lv: {cardinal:["zero","one","other"],ordinal:["other"]},
|
|
119
|
+
mas: _cc[1],
|
|
120
|
+
mg: _cc[1],
|
|
121
|
+
mgo: _cc[1],
|
|
122
|
+
mk: {cardinal:["one","other"],ordinal:["one","two","many","other"]},
|
|
123
|
+
ml: _cc[1],
|
|
124
|
+
mn: _cc[1],
|
|
125
|
+
mo: {cardinal:["one","few","other"],ordinal:["one","other"]},
|
|
126
|
+
mr: {cardinal:["one","other"],ordinal:["one","two","few","other"]},
|
|
127
|
+
ms: {cardinal:["other"],ordinal:["one","other"]},
|
|
128
|
+
mt: {cardinal:["one","few","many","other"],ordinal:["other"]},
|
|
129
|
+
my: _cc[0],
|
|
130
|
+
nah: _cc[1],
|
|
131
|
+
naq: _cc[3],
|
|
132
|
+
nb: _cc[1],
|
|
133
|
+
nd: _cc[1],
|
|
134
|
+
ne: _cc[2],
|
|
135
|
+
nl: _cc[1],
|
|
136
|
+
nn: _cc[1],
|
|
137
|
+
nnh: _cc[1],
|
|
138
|
+
no: _cc[1],
|
|
139
|
+
nqo: _cc[0],
|
|
140
|
+
nr: _cc[1],
|
|
141
|
+
nso: _cc[1],
|
|
142
|
+
ny: _cc[1],
|
|
143
|
+
nyn: _cc[1],
|
|
144
|
+
om: _cc[1],
|
|
145
|
+
or: _cc[1],
|
|
146
|
+
os: _cc[1],
|
|
147
|
+
pa: _cc[1],
|
|
148
|
+
pap: _cc[1],
|
|
149
|
+
pl: {cardinal:["one","few","many","other"],ordinal:["other"]},
|
|
150
|
+
prg: {cardinal:["zero","one","other"],ordinal:["other"]},
|
|
151
|
+
ps: _cc[1],
|
|
152
|
+
pt: _cc[1],
|
|
153
|
+
"pt-PT": _cc[1],
|
|
154
|
+
rm: _cc[1],
|
|
155
|
+
ro: {cardinal:["one","few","other"],ordinal:["one","other"]},
|
|
156
|
+
rof: _cc[1],
|
|
157
|
+
root: _cc[0],
|
|
158
|
+
ru: {cardinal:["one","few","many","other"],ordinal:["other"]},
|
|
159
|
+
rwk: _cc[1],
|
|
160
|
+
sah: _cc[0],
|
|
161
|
+
saq: _cc[1],
|
|
162
|
+
sdh: _cc[1],
|
|
163
|
+
se: _cc[3],
|
|
164
|
+
seh: _cc[1],
|
|
165
|
+
ses: _cc[0],
|
|
166
|
+
sg: _cc[0],
|
|
167
|
+
sh: {cardinal:["one","few","other"],ordinal:["other"]},
|
|
168
|
+
shi: {cardinal:["one","few","other"],ordinal:["other"]},
|
|
169
|
+
si: _cc[1],
|
|
170
|
+
sk: {cardinal:["one","few","many","other"],ordinal:["other"]},
|
|
171
|
+
sl: {cardinal:["one","two","few","other"],ordinal:["other"]},
|
|
172
|
+
sma: _cc[3],
|
|
173
|
+
smi: _cc[3],
|
|
174
|
+
smj: _cc[3],
|
|
175
|
+
smn: _cc[3],
|
|
176
|
+
sms: _cc[3],
|
|
177
|
+
sn: _cc[1],
|
|
178
|
+
so: _cc[1],
|
|
179
|
+
sq: {cardinal:["one","other"],ordinal:["one","many","other"]},
|
|
180
|
+
sr: {cardinal:["one","few","other"],ordinal:["other"]},
|
|
181
|
+
ss: _cc[1],
|
|
182
|
+
ssy: _cc[1],
|
|
183
|
+
st: _cc[1],
|
|
184
|
+
sv: _cc[2],
|
|
185
|
+
sw: _cc[1],
|
|
186
|
+
syr: _cc[1],
|
|
187
|
+
ta: _cc[1],
|
|
188
|
+
te: _cc[1],
|
|
189
|
+
teo: _cc[1],
|
|
190
|
+
th: _cc[0],
|
|
191
|
+
ti: _cc[1],
|
|
192
|
+
tig: _cc[1],
|
|
193
|
+
tk: _cc[1],
|
|
194
|
+
tl: _cc[2],
|
|
195
|
+
tn: _cc[1],
|
|
196
|
+
to: _cc[0],
|
|
197
|
+
tr: _cc[1],
|
|
198
|
+
ts: _cc[1],
|
|
199
|
+
tzm: _cc[1],
|
|
200
|
+
ug: _cc[1],
|
|
201
|
+
uk: {cardinal:["one","few","many","other"],ordinal:["few","other"]},
|
|
202
|
+
ur: _cc[1],
|
|
203
|
+
uz: _cc[1],
|
|
204
|
+
ve: _cc[1],
|
|
205
|
+
vi: {cardinal:["other"],ordinal:["one","other"]},
|
|
206
|
+
vo: _cc[1],
|
|
207
|
+
vun: _cc[1],
|
|
208
|
+
wa: _cc[1],
|
|
209
|
+
wae: _cc[1],
|
|
210
|
+
wo: _cc[0],
|
|
211
|
+
xh: _cc[1],
|
|
212
|
+
xog: _cc[1],
|
|
213
|
+
yi: _cc[1],
|
|
214
|
+
yo: _cc[0],
|
|
215
|
+
zh: _cc[0],
|
|
216
|
+
zu: _cc[1]
|
|
217
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var _cc=[{cardinal:["other"],ordinal:["other"]},{cardinal:["one","other"],ordinal:["other"]},{cardinal:["one","other"],ordinal:["one","other"]},{cardinal:["one","two","other"],ordinal:["other"]}];!function(c,o){"function"==typeof define&&define.amd?define(o):"object"==typeof exports?module.exports=o:c.pluralCategories=o}(this,{af:_cc[1],ak:_cc[1],am:_cc[1],ar:{cardinal:["zero","one","two","few","many","other"],ordinal:["other"]},as:{cardinal:["one","other"],ordinal:["one","two","few","many","other"]},asa:_cc[1],ast:_cc[1],az:{cardinal:["one","other"],ordinal:["one","few","many","other"]},be:{cardinal:["one","few","many","other"],ordinal:["few","other"]},bem:_cc[1],bez:_cc[1],bg:_cc[1],bh:_cc[1],bm:_cc[0],bn:{cardinal:["one","other"],ordinal:["one","two","few","many","other"]},bo:_cc[0],br:{cardinal:["one","two","few","many","other"],ordinal:["other"]},brx:_cc[1],bs:{cardinal:["one","few","other"],ordinal:["other"]},ca:{cardinal:["one","other"],ordinal:["one","two","few","other"]},ce:_cc[1],cgg:_cc[1],chr:_cc[1],ckb:_cc[1],cs:{cardinal:["one","few","many","other"],ordinal:["other"]},cy:{cardinal:["zero","one","two","few","many","other"],ordinal:["zero","one","two","few","many","other"]},da:_cc[1],de:_cc[1],dsb:{cardinal:["one","two","few","other"],ordinal:["other"]},dv:_cc[1],dz:_cc[0],ee:_cc[1],el:_cc[1],en:{cardinal:["one","other"],ordinal:["one","two","few","other"]},eo:_cc[1],es:_cc[1],et:_cc[1],eu:_cc[1],fa:_cc[1],ff:_cc[1],fi:_cc[1],fil:_cc[2],fo:_cc[1],fr:_cc[2],fur:_cc[1],fy:_cc[1],ga:{cardinal:["one","two","few","many","other"],ordinal:["one","other"]},gd:{cardinal:["one","two","few","other"],ordinal:["other"]},gl:_cc[1],gsw:_cc[1],gu:{cardinal:["one","other"],ordinal:["one","two","few","many","other"]},guw:_cc[1],gv:{cardinal:["one","two","few","many","other"],ordinal:["other"]},ha:_cc[1],haw:_cc[1],he:{cardinal:["one","two","many","other"],ordinal:["other"]},hi:{cardinal:["one","other"],ordinal:["one","two","few","many","other"]},hr:{cardinal:["one","few","other"],ordinal:["other"]},hsb:{cardinal:["one","two","few","other"],ordinal:["other"]},hu:_cc[2],hy:_cc[2],id:_cc[0],ig:_cc[0],ii:_cc[0],"in":_cc[0],is:_cc[1],it:{cardinal:["one","other"],ordinal:["many","other"]},iu:_cc[3],iw:{cardinal:["one","two","many","other"],ordinal:["other"]},ja:_cc[0],jbo:_cc[0],jgo:_cc[1],ji:_cc[1],jmc:_cc[1],jv:_cc[0],jw:_cc[0],ka:{cardinal:["one","other"],ordinal:["one","many","other"]},kab:_cc[1],kaj:_cc[1],kcg:_cc[1],kde:_cc[0],kea:_cc[0],kk:{cardinal:["one","other"],ordinal:["many","other"]},kkj:_cc[1],kl:_cc[1],km:_cc[0],kn:_cc[1],ko:_cc[0],ks:_cc[1],ksb:_cc[1],ksh:{cardinal:["zero","one","other"],ordinal:["other"]},ku:_cc[1],kw:_cc[3],ky:_cc[1],lag:{cardinal:["zero","one","other"],ordinal:["other"]},lb:_cc[1],lg:_cc[1],lkt:_cc[0],ln:_cc[1],lo:{cardinal:["other"],ordinal:["one","other"]},lt:{cardinal:["one","few","many","other"],ordinal:["other"]},lv:{cardinal:["zero","one","other"],ordinal:["other"]},mas:_cc[1],mg:_cc[1],mgo:_cc[1],mk:{cardinal:["one","other"],ordinal:["one","two","many","other"]},ml:_cc[1],mn:_cc[1],mo:{cardinal:["one","few","other"],ordinal:["one","other"]},mr:{cardinal:["one","other"],ordinal:["one","two","few","other"]},ms:{cardinal:["other"],ordinal:["one","other"]},mt:{cardinal:["one","few","many","other"],ordinal:["other"]},my:_cc[0],nah:_cc[1],naq:_cc[3],nb:_cc[1],nd:_cc[1],ne:_cc[2],nl:_cc[1],nn:_cc[1],nnh:_cc[1],no:_cc[1],nqo:_cc[0],nr:_cc[1],nso:_cc[1],ny:_cc[1],nyn:_cc[1],om:_cc[1],or:_cc[1],os:_cc[1],pa:_cc[1],pap:_cc[1],pl:{cardinal:["one","few","many","other"],ordinal:["other"]},prg:{cardinal:["zero","one","other"],ordinal:["other"]},ps:_cc[1],pt:_cc[1],"pt-PT":_cc[1],rm:_cc[1],ro:{cardinal:["one","few","other"],ordinal:["one","other"]},rof:_cc[1],root:_cc[0],ru:{cardinal:["one","few","many","other"],ordinal:["other"]},rwk:_cc[1],sah:_cc[0],saq:_cc[1],sdh:_cc[1],se:_cc[3],seh:_cc[1],ses:_cc[0],sg:_cc[0],sh:{cardinal:["one","few","other"],ordinal:["other"]},shi:{cardinal:["one","few","other"],ordinal:["other"]},si:_cc[1],sk:{cardinal:["one","few","many","other"],ordinal:["other"]},sl:{cardinal:["one","two","few","other"],ordinal:["other"]},sma:_cc[3],smi:_cc[3],smj:_cc[3],smn:_cc[3],sms:_cc[3],sn:_cc[1],so:_cc[1],sq:{cardinal:["one","other"],ordinal:["one","many","other"]},sr:{cardinal:["one","few","other"],ordinal:["other"]},ss:_cc[1],ssy:_cc[1],st:_cc[1],sv:_cc[2],sw:_cc[1],syr:_cc[1],ta:_cc[1],te:_cc[1],teo:_cc[1],th:_cc[0],ti:_cc[1],tig:_cc[1],tk:_cc[1],tl:_cc[2],tn:_cc[1],to:_cc[0],tr:_cc[1],ts:_cc[1],tzm:_cc[1],ug:_cc[1],uk:{cardinal:["one","few","many","other"],ordinal:["few","other"]},ur:_cc[1],uz:_cc[1],ve:_cc[1],vi:{cardinal:["other"],ordinal:["one","other"]},vo:_cc[1],vun:_cc[1],wa:_cc[1],wae:_cc[1],wo:_cc[0],xh:_cc[1],xog:_cc[1],yi:_cc[1],yo:_cc[0],zh:_cc[0],zu:_cc[1]});
|
package/README.md
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
[](http://en.wikipedia.org/wiki/ISC_license)
|
|
2
|
-
[](https://travis-ci.org/eemeli/make-plural.js)
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
make-plural
|
|
6
|
-
===========
|
|
7
|
-
|
|
8
|
-
Make-plural is a JavaScript module that translates [Unicode CLDR] pluralization
|
|
9
|
-
[rules] to JavaScript functions. It includes both a live parser
|
|
10
|
-
(`make-plural.js`) as well as the generated output for the latest edition of the
|
|
11
|
-
CLDR (`plurals.js`); the latter is just over 2kB in size when minified &
|
|
12
|
-
gzipped and covers 199 languages, so it's probably what you want unless you
|
|
13
|
-
really know what you're doing.
|
|
14
|
-
|
|
15
|
-
Make-plural is written in [ECMAScript 6] and transpiled using [Babel] and
|
|
16
|
-
[Browserify] to CommonJS and AMD and ES6 module formats, as well as being
|
|
17
|
-
suitable for use in browser environments.
|
|
18
|
-
|
|
19
|
-
[Unicode CLDR]: http://cldr.unicode.org/
|
|
20
|
-
[rules]: http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html
|
|
21
|
-
[ECMAScript 6]: https://people.mozilla.org/~jorendorff/es6-draft.html
|
|
22
|
-
[Babel]: https://babeljs.io/
|
|
23
|
-
[Browserify]: http://browserify.org/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## Installation
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
npm install make-plural
|
|
30
|
-
```
|
|
31
|
-
_or_
|
|
32
|
-
```
|
|
33
|
-
bower install make-plural
|
|
34
|
-
```
|
|
35
|
-
_or_
|
|
36
|
-
```
|
|
37
|
-
git clone https://github.com/eemeli/make-plural.js.git
|
|
38
|
-
cd make-plural.js
|
|
39
|
-
npm install
|
|
40
|
-
make all
|
|
41
|
-
```
|
|
42
|
-
_or_ download the latest release from
|
|
43
|
-
[here](https://github.com/eemeli/make-plural.js/releases/latest)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## Precompiled plurals
|
|
47
|
-
|
|
48
|
-
`plurals.js` contains an UMD module that can be included with node's `require`
|
|
49
|
-
or AMD's `define`. In a browser environment, it will populate a global object
|
|
50
|
-
`plurals`. Said module contains 199 functions (one per [language][rules]),
|
|
51
|
-
each taking as a first parameter the value to be classified (either a number or
|
|
52
|
-
a string), and as an optional second parameter, a boolean that if true, applies
|
|
53
|
-
ordinal rather than cardinal rules.
|
|
54
|
-
|
|
55
|
-
`pluralCategories.js` has a similar structure to `plurals.js`, but contains an
|
|
56
|
-
array of the pluralization categories the cardinal and ordinal rules each
|
|
57
|
-
language's pluralization function may output.
|
|
58
|
-
|
|
59
|
-
If your language isn't directly included in either of the above, try removing
|
|
60
|
-
any trailing parts that are separated from the stem by `-` or `_`.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
### Precompiled use: Node
|
|
64
|
-
|
|
65
|
-
```js
|
|
66
|
-
> plurals = require('make-plural/plurals')
|
|
67
|
-
{ af: [Function],
|
|
68
|
-
ak: [Function],
|
|
69
|
-
am: [Function],
|
|
70
|
-
// snip 193 lines...
|
|
71
|
-
yo: [Function],
|
|
72
|
-
zh: [Function],
|
|
73
|
-
zu: [Function] }
|
|
74
|
-
|
|
75
|
-
> plurals.en(1) // 1st param is the value
|
|
76
|
-
'one'
|
|
77
|
-
|
|
78
|
-
> plurals.en(2)
|
|
79
|
-
'other'
|
|
80
|
-
|
|
81
|
-
> plurals.en(2, true) // 2nd param, if true-ish, is for ordinal rules
|
|
82
|
-
'two'
|
|
83
|
-
|
|
84
|
-
> console.log(plurals.en.toString())
|
|
85
|
-
function (n, ord) {
|
|
86
|
-
var s = String(n).split('.'), v0 = !s[1], t0 = Number(s[0]) == n,
|
|
87
|
-
n10 = t0 && s[0].slice(-1), n100 = t0 && s[0].slice(-2);
|
|
88
|
-
if (ord) return (n10 == 1 && n100 != 11) ? 'one'
|
|
89
|
-
: (n10 == 2 && n100 != 12) ? 'two'
|
|
90
|
-
: (n10 == 3 && n100 != 13) ? 'few'
|
|
91
|
-
: 'other';
|
|
92
|
-
return (n == 1 && v0) ? 'one' : 'other';
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
> pluralCategories = require('make-plural/pluralCategories')
|
|
96
|
-
{ af: { cardinal: [ 'one', 'other' ], ordinal: [ 'other' ] },
|
|
97
|
-
ak: { cardinal: [ 'one', 'other' ], ordinal: [ 'other' ] },
|
|
98
|
-
am: { cardinal: [ 'one', 'other' ], ordinal: [ 'other' ] },
|
|
99
|
-
ar:
|
|
100
|
-
{ cardinal: [ 'zero', 'one', 'two', 'few', 'many', 'other' ],
|
|
101
|
-
ordinal: [ 'other' ] },
|
|
102
|
-
// snip 255 lines...
|
|
103
|
-
zh: { cardinal: [ 'other' ], ordinal: [ 'other' ] },
|
|
104
|
-
zu: { cardinal: [ 'one', 'other' ], ordinal: [ 'other' ] } }
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Precompiled use: Web
|
|
108
|
-
|
|
109
|
-
```html
|
|
110
|
-
<script src="path/to/make-plural/plurals.js"></script>
|
|
111
|
-
<script>
|
|
112
|
-
var ru = plurals.ru
|
|
113
|
-
console.log('1: ' + plurals.ru(1) + ', 3.0: ' + plurals.ru(3.0) +
|
|
114
|
-
', "1.0": ' + plurals.ru('1.0') + ', "0": ' + plurals.ru('0'));
|
|
115
|
-
console.log(plurals.ru.toString());
|
|
116
|
-
</script>
|
|
117
|
-
```
|
|
118
|
-
With outputs:
|
|
119
|
-
```
|
|
120
|
-
1: one, 3.0: few, "1.0": other, "0": many
|
|
121
|
-
|
|
122
|
-
function(n, ord) {
|
|
123
|
-
var s = String(n).split('.'), i = s[0], v0 = !s[1], i10 = i.slice(-1),
|
|
124
|
-
i100 = i.slice(-2);
|
|
125
|
-
if (ord) return 'other';
|
|
126
|
-
return (v0 && i10 == 1 && i100 != 11) ? 'one'
|
|
127
|
-
: (v0 && (i10 >= 2 && i10 <= 4) && (i100 < 12
|
|
128
|
-
|| i100 > 14)) ? 'few'
|
|
129
|
-
: (v0 && i10 == 0 || v0 && (i10 >= 5 && i10 <= 9)
|
|
130
|
-
|| v0 && (i100 >= 11 && i100 <= 14)) ? 'many'
|
|
131
|
-
: 'other';
|
|
132
|
-
}
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
Note that with `plurals.min.js`, the stringified function would be rendered as:
|
|
136
|
-
```js
|
|
137
|
-
function (e,t){var r=String(e).split("."),n=r[0],o=!r[1],c=n.slice(-1),
|
|
138
|
-
i=n.slice(-2);return t?"other":o&&1==c&&11!=i?"one":o&&c>=2&&4>=c&&(12>i||i>14)?
|
|
139
|
-
"few":o&&0==c||o&&c>=5&&9>=c||o&&i>=11&&14>=i?"many":"other"}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
## Live compiler: `make-plural.js`
|
|
144
|
-
|
|
145
|
-
### MakePlural.load(cldr, ...)
|
|
146
|
-
Loads CLDR rules from one or more `cldr` variables, each of which must be an
|
|
147
|
-
object formatted like [this][json].
|
|
148
|
-
|
|
149
|
-
No plural data is included by default, so you'll need to call this at least
|
|
150
|
-
once, or otherwise fill the `MakePlural.rules` object.
|
|
151
|
-
|
|
152
|
-
The default CLDR rules are included in make-plural, and may be loaded as seen
|
|
153
|
-
in the examples below.
|
|
154
|
-
|
|
155
|
-
[json]: https://github.com/unicode-cldr/cldr-core/blob/master/supplemental/plurals.json
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
### new MakePlural(lc, { cardinals, ordinals })
|
|
159
|
-
Returns a function that takes an argument `n` and returns its plural category
|
|
160
|
-
for the given locale `lc`.
|
|
161
|
-
|
|
162
|
-
The returned function has an overloaded `toString(name)` method that may be
|
|
163
|
-
used to generate a clean string representation of the function, with an
|
|
164
|
-
optional name `name`.
|
|
165
|
-
|
|
166
|
-
The optional second parameter may contain the following boolean members:
|
|
167
|
-
* `cardinals` — if true, rules for cardinal values (1 day, 2 days, etc.) are
|
|
168
|
-
included
|
|
169
|
-
* `ordinals` — if true, rules for ordinal values (1st, 2nd, etc.) are included
|
|
170
|
-
|
|
171
|
-
If both `cardinals` and `ordinals` are true, the returned function takes a
|
|
172
|
-
second parameter `ord`. Then, if `ord` is true, the function will return the
|
|
173
|
-
ordinal rather than cardinal category applicable to `n` in locale `lc`.
|
|
174
|
-
|
|
175
|
-
If the second parameter is undefined, the values are taken from
|
|
176
|
-
`MakePlural.cardinals` (default `true`) and `MakePlural.ordinals` (default
|
|
177
|
-
`false`).
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
### Live use: Node
|
|
181
|
-
|
|
182
|
-
```js
|
|
183
|
-
> MakePlural = require('make-plural/make-plural').load(
|
|
184
|
-
... require('make-plural/data/plurals.json'),
|
|
185
|
-
... require('make-plural/data/ordinals.json'))
|
|
186
|
-
{ [Function: MakePlural]
|
|
187
|
-
cardinals: true,
|
|
188
|
-
ordinals: false,
|
|
189
|
-
rules:
|
|
190
|
-
{ cardinal:
|
|
191
|
-
{ af: [Object],
|
|
192
|
-
ak: [Object],
|
|
193
|
-
am: [Object],
|
|
194
|
-
// snip 193 lines...
|
|
195
|
-
yo: [Object],
|
|
196
|
-
zh: [Object],
|
|
197
|
-
zu: [Object] },
|
|
198
|
-
ordinal:
|
|
199
|
-
{ af: [Object],
|
|
200
|
-
am: [Object],
|
|
201
|
-
ar: [Object],
|
|
202
|
-
// snip 78 lines...
|
|
203
|
-
vi: [Object],
|
|
204
|
-
zh: [Object],
|
|
205
|
-
zu: [Object] } } }
|
|
206
|
-
|
|
207
|
-
> sk = new MakePlural('sk') // Note: not including ordinals by default
|
|
208
|
-
{ [Function]
|
|
209
|
-
_obj:
|
|
210
|
-
{ lc: 'sk',
|
|
211
|
-
cardinals: true,
|
|
212
|
-
ordinals: false,
|
|
213
|
-
categories: { cardinal: [Object], ordinal: [] },
|
|
214
|
-
parser: { v0: 1, i: 1 },
|
|
215
|
-
tests: { obj: [Circular], ordinal: {}, cardinal: [Object] },
|
|
216
|
-
fn: [Circular] },
|
|
217
|
-
categories: { cardinal: [ 'one', 'few', 'many', 'other' ], ordinal: [] },
|
|
218
|
-
test: [Function],
|
|
219
|
-
toString: [Function] }
|
|
220
|
-
|
|
221
|
-
> sk(1)
|
|
222
|
-
'one'
|
|
223
|
-
|
|
224
|
-
> sk(3.0)
|
|
225
|
-
'few'
|
|
226
|
-
|
|
227
|
-
> sk('1.0')
|
|
228
|
-
'many'
|
|
229
|
-
|
|
230
|
-
> sk('0')
|
|
231
|
-
'other'
|
|
232
|
-
|
|
233
|
-
> console.log(sk.toString())
|
|
234
|
-
function(n) {
|
|
235
|
-
var s = String(n).split('.'), i = s[0], v0 = !s[1];
|
|
236
|
-
return (i == 1 && v0 ) ? 'one'
|
|
237
|
-
: ((i >= 2 && i <= 4) && v0 ) ? 'few'
|
|
238
|
-
: (!v0 ) ? 'many'
|
|
239
|
-
: 'other';
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
`make-plural.js` may also be used in browser environments; see `test/index.html`
|
|
244
|
-
for an example of its use.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
## CLI Usage
|
|
248
|
-
|
|
249
|
-
```sh
|
|
250
|
-
$ ./bin/make-plural > plurals.js
|
|
251
|
-
|
|
252
|
-
$ ./bin/make-plural fr
|
|
253
|
-
function fr(n, ord) {
|
|
254
|
-
if (ord) return (n == 1) ? 'one' : 'other';
|
|
255
|
-
return (n >= 0 && n < 2) ? 'one' : 'other';
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
$ ./bin/make-plural --locale fr --value 1.5
|
|
259
|
-
one
|
|
260
|
-
|
|
261
|
-
$ ./bin/make-plural 1.5 -l fr --ordinal
|
|
262
|
-
other
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
Please see the source of `src/index.js` for more details.
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
## Dependencies
|
|
270
|
-
|
|
271
|
-
Make-plural has no required runtime dependencies. CLDR plural rule data is
|
|
272
|
-
included in JSON format; make-plural supports the [LDML Language Plural Rules]
|
|
273
|
-
as used in CLDR release 24 and later.
|
|
274
|
-
|
|
275
|
-
The CLI binary `bin/make-plural` does use [minimist] as an argument parser, but
|
|
276
|
-
that is not required for any other use.
|
|
277
|
-
|
|
278
|
-
Using `MakePlural.load()`, you may make use of external sources of CLDR data.
|
|
279
|
-
For example, the following works when using together with [cldr-data]:
|
|
280
|
-
```js
|
|
281
|
-
> cldr = require('cldr-data');
|
|
282
|
-
> MakePlural = require('make-plural/make-plural').load(
|
|
283
|
-
cldr('supplemental/plurals'),
|
|
284
|
-
cldr('supplemental/ordinals')
|
|
285
|
-
);
|
|
286
|
-
> en = new MakePlural('en');
|
|
287
|
-
> en(3, true)
|
|
288
|
-
'few'
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
[LDML Language Plural Rules]: http://unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules
|
|
292
|
-
[minimist]: https://www.npmjs.com/package/minimist
|
|
293
|
-
[cldr-data]: https://www.npmjs.org/package/cldr-data
|