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/make-plural.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
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
|
|
2
|
-
|
|
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(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
|
2
|
+
"use strict";
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
exports.default = void 0;
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
|
9
10
|
|
|
10
|
-
function
|
|
11
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
|
11
12
|
|
|
12
|
-
function
|
|
13
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
|
14
|
+
|
|
15
|
+
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); }
|
|
16
|
+
|
|
17
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
18
|
+
|
|
19
|
+
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
|
20
|
+
|
|
21
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
22
|
|
|
14
23
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
24
|
|
|
25
|
+
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); } }
|
|
26
|
+
|
|
27
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
28
|
+
|
|
16
29
|
/**
|
|
17
30
|
* make-plural -- https://github.com/eemeli/make-plural
|
|
18
31
|
* Copyright (c) 2014-2016 by Eemeli Aro <eemeli@gmail.com>
|
|
@@ -29,23 +42,26 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
29
42
|
* action of contract, negligence or other tortious action, arising out of
|
|
30
43
|
* or in connection with the use or performance of this software.
|
|
31
44
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
var Parser =
|
|
46
|
+
/*#__PURE__*/
|
|
47
|
+
function () {
|
|
34
48
|
function Parser() {
|
|
35
49
|
_classCallCheck(this, Parser);
|
|
36
50
|
}
|
|
37
51
|
|
|
38
52
|
_createClass(Parser, [{
|
|
39
|
-
key:
|
|
53
|
+
key: "parse",
|
|
40
54
|
value: function parse(cond) {
|
|
41
55
|
var _this = this;
|
|
42
56
|
|
|
43
57
|
if (cond === 'i = 0 or n = 1') return 'n >= 0 && n <= 1';
|
|
44
58
|
if (cond === 'i = 0,1') return 'n >= 0 && n < 2';
|
|
59
|
+
|
|
45
60
|
if (cond === 'i = 1 and v = 0') {
|
|
46
61
|
this.v0 = 1;
|
|
47
62
|
return 'n == 1 && v0';
|
|
48
63
|
}
|
|
64
|
+
|
|
49
65
|
return cond.replace(/([tv]) (!?)= 0/g, function (m, sym, noteq) {
|
|
50
66
|
var sn = sym + '0';
|
|
51
67
|
_this[sn] = 1;
|
|
@@ -63,18 +79,22 @@ var Parser = function () {
|
|
|
63
79
|
return '(' + se + x.split(',').join(' || ' + se) + ')';
|
|
64
80
|
}).replace(/(\w+) (!?)= ([0-9]+)\.\.([0-9]+)/g, function (m, sym, noteq, x0, x1) {
|
|
65
81
|
if (Number(x0) + 1 === Number(x1)) {
|
|
66
|
-
if (noteq) return sym
|
|
67
|
-
return
|
|
82
|
+
if (noteq) return "".concat(sym, " != ").concat(x0, " && ").concat(sym, " != ").concat(x1);
|
|
83
|
+
return "(".concat(sym, " == ").concat(x0, " || ").concat(sym, " == ").concat(x1, ")");
|
|
68
84
|
}
|
|
69
|
-
|
|
85
|
+
|
|
86
|
+
if (noteq) return "(".concat(sym, " < ").concat(x0, " || ").concat(sym, " > ").concat(x1, ")");
|
|
87
|
+
|
|
70
88
|
if (sym === 'n') {
|
|
71
|
-
_this.t0 = 1;
|
|
89
|
+
_this.t0 = 1;
|
|
90
|
+
return "(t0 && n >= ".concat(x0, " && n <= ").concat(x1, ")");
|
|
72
91
|
}
|
|
73
|
-
|
|
92
|
+
|
|
93
|
+
return "(".concat(sym, " >= ").concat(x0, " && ").concat(sym, " <= ").concat(x1, ")");
|
|
74
94
|
}).replace(/ and /g, ' && ').replace(/ or /g, ' || ').replace(/ = /g, ' == ');
|
|
75
95
|
}
|
|
76
96
|
}, {
|
|
77
|
-
key:
|
|
97
|
+
key: "vars",
|
|
78
98
|
value: function vars() {
|
|
79
99
|
var vars = [];
|
|
80
100
|
if (this.i) vars.push('i = s[0]');
|
|
@@ -83,12 +103,14 @@ var Parser = function () {
|
|
|
83
103
|
if (this.v) vars.push('v = f.length');
|
|
84
104
|
if (this.v0) vars.push('v0 = !s[1]');
|
|
85
105
|
if (this.t0 || this.n10 || this.n100) vars.push('t0 = Number(s[0]) == n');
|
|
106
|
+
|
|
86
107
|
for (var k in this) {
|
|
87
108
|
if (/^.10+$/.test(k)) {
|
|
88
109
|
var k0 = k[0] === 'n' ? 't0 && s[0]' : k[0];
|
|
89
|
-
vars.push(k
|
|
110
|
+
vars.push("".concat(k, " = ").concat(k0, ".slice(-").concat(k.substr(2).length, ")"));
|
|
90
111
|
}
|
|
91
112
|
}
|
|
113
|
+
|
|
92
114
|
if (!vars.length) return '';
|
|
93
115
|
return 'var ' + ["s = String(n).split('.')"].concat(vars).join(', ');
|
|
94
116
|
}
|
|
@@ -97,7 +119,9 @@ var Parser = function () {
|
|
|
97
119
|
return Parser;
|
|
98
120
|
}();
|
|
99
121
|
|
|
100
|
-
var Tests =
|
|
122
|
+
var Tests =
|
|
123
|
+
/*#__PURE__*/
|
|
124
|
+
function () {
|
|
101
125
|
function Tests(obj) {
|
|
102
126
|
_classCallCheck(this, Tests);
|
|
103
127
|
|
|
@@ -107,53 +131,67 @@ var Tests = function () {
|
|
|
107
131
|
}
|
|
108
132
|
|
|
109
133
|
_createClass(Tests, [{
|
|
110
|
-
key:
|
|
134
|
+
key: "add",
|
|
111
135
|
value: function add(type, cat, src) {
|
|
112
|
-
this[type][cat] = {
|
|
136
|
+
this[type][cat] = {
|
|
137
|
+
src: src,
|
|
138
|
+
values: null
|
|
139
|
+
};
|
|
113
140
|
}
|
|
114
141
|
}, {
|
|
115
|
-
key:
|
|
142
|
+
key: "testCond",
|
|
116
143
|
value: function testCond(n, type, expResult, fn) {
|
|
117
144
|
try {
|
|
118
145
|
var r = (fn || this.obj.fn)(n, type === 'ordinal');
|
|
119
146
|
} catch (e) {
|
|
120
147
|
r = e.toString();
|
|
121
148
|
}
|
|
149
|
+
|
|
122
150
|
if (r !== expResult) {
|
|
123
151
|
throw new Error('Locale ' + JSON.stringify(this.obj.lc) + type + ' rule self-test failed for v = ' + JSON.stringify(n) + ' (was ' + JSON.stringify(r) + ', expected ' + JSON.stringify(expResult) + ')');
|
|
124
152
|
}
|
|
153
|
+
|
|
125
154
|
return true;
|
|
126
155
|
}
|
|
127
156
|
}, {
|
|
128
|
-
key:
|
|
157
|
+
key: "testCat",
|
|
129
158
|
value: function testCat(type, cat, fn) {
|
|
130
159
|
var _this2 = this;
|
|
131
160
|
|
|
132
161
|
var data = this[type][cat];
|
|
162
|
+
|
|
133
163
|
if (!data.values) {
|
|
134
164
|
data.values = data.src.join(' ').replace(/^[ ,]+|[ ,…]+$/g, '').replace(/(0\.[0-9])~(1\.[1-9])/g, '$1 1.0 $2').split(/[ ,~…]+/);
|
|
135
165
|
}
|
|
166
|
+
|
|
136
167
|
data.values.forEach(function (n) {
|
|
137
168
|
_this2.testCond(n, type, cat, fn);
|
|
169
|
+
|
|
138
170
|
if (!/\.0+$/.test(n)) _this2.testCond(Number(n), type, cat, fn);
|
|
139
171
|
});
|
|
140
172
|
return true;
|
|
141
173
|
}
|
|
142
174
|
}, {
|
|
143
|
-
key:
|
|
175
|
+
key: "testAll",
|
|
144
176
|
value: function testAll() {
|
|
145
177
|
for (var cat in this.cardinal) {
|
|
146
178
|
this.testCat('cardinal', cat);
|
|
147
|
-
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
for (var _cat in this.ordinal) {
|
|
148
182
|
this.testCat('ordinal', _cat);
|
|
149
|
-
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return true;
|
|
150
186
|
}
|
|
151
187
|
}]);
|
|
152
188
|
|
|
153
189
|
return Tests;
|
|
154
190
|
}();
|
|
155
191
|
|
|
156
|
-
var MakePlural =
|
|
192
|
+
var MakePlural =
|
|
193
|
+
/*#__PURE__*/
|
|
194
|
+
function () {
|
|
157
195
|
function MakePlural(lc) {
|
|
158
196
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : MakePlural,
|
|
159
197
|
cardinals = _ref.cardinals,
|
|
@@ -163,29 +201,36 @@ var MakePlural = function () {
|
|
|
163
201
|
|
|
164
202
|
if (!cardinals && !ordinals) throw new Error('At least one type of plural is required');
|
|
165
203
|
this.lc = lc;
|
|
166
|
-
this.categories = {
|
|
204
|
+
this.categories = {
|
|
205
|
+
cardinal: [],
|
|
206
|
+
ordinal: []
|
|
207
|
+
};
|
|
167
208
|
this.parser = new Parser();
|
|
168
209
|
this.tests = new Tests(this);
|
|
169
210
|
this.fn = this.buildFunction(cardinals, ordinals);
|
|
170
211
|
this.fn._obj = this;
|
|
171
212
|
this.fn.categories = this.categories;
|
|
213
|
+
|
|
172
214
|
this.fn.test = function () {
|
|
173
215
|
return this.tests.testAll() && this.fn;
|
|
174
216
|
}.bind(this);
|
|
217
|
+
|
|
175
218
|
this.fn.toString = this.fnToString.bind(this);
|
|
176
219
|
return this.fn;
|
|
177
220
|
}
|
|
178
221
|
|
|
179
222
|
_createClass(MakePlural, [{
|
|
180
|
-
key:
|
|
223
|
+
key: "compile",
|
|
181
224
|
value: function compile(type, req) {
|
|
182
225
|
var cases = [];
|
|
183
226
|
var rules = MakePlural.getRules(type, this.lc);
|
|
227
|
+
|
|
184
228
|
if (!rules) {
|
|
185
|
-
if (req) throw new Error(
|
|
229
|
+
if (req) throw new Error("Locale \"".concat(this.lc, "\" ").concat(type, " rules not found"));
|
|
186
230
|
this.categories[type] = ['other'];
|
|
187
231
|
return "'other'";
|
|
188
232
|
}
|
|
233
|
+
|
|
189
234
|
for (var r in rules) {
|
|
190
235
|
var _rules$r$trim$split = rules[r].trim().split(/\s*@\w*/),
|
|
191
236
|
_rules$r$trim$split2 = _toArray(_rules$r$trim$split),
|
|
@@ -196,31 +241,34 @@ var MakePlural = function () {
|
|
|
196
241
|
if (cond) cases.push([this.parser.parse(cond), cat]);
|
|
197
242
|
this.tests.add(type, cat, examples);
|
|
198
243
|
}
|
|
244
|
+
|
|
199
245
|
this.categories[type] = cases.map(function (c) {
|
|
200
246
|
return c[1];
|
|
201
247
|
}).concat('other');
|
|
248
|
+
|
|
202
249
|
if (cases.length === 1) {
|
|
203
|
-
return
|
|
250
|
+
return "(".concat(cases[0][0], ") ? '").concat(cases[0][1], "' : 'other'");
|
|
204
251
|
} else {
|
|
205
|
-
return
|
|
206
|
-
return
|
|
207
|
-
}))
|
|
252
|
+
return _toConsumableArray(cases.map(function (c) {
|
|
253
|
+
return "(".concat(c[0], ") ? '").concat(c[1], "'");
|
|
254
|
+
})).concat(["'other'"]).join('\n : ');
|
|
208
255
|
}
|
|
209
256
|
}
|
|
210
257
|
}, {
|
|
211
|
-
key:
|
|
258
|
+
key: "buildFunction",
|
|
212
259
|
value: function buildFunction(cardinals, ordinals) {
|
|
213
260
|
var _this3 = this;
|
|
214
261
|
|
|
215
262
|
var compile = function compile(c) {
|
|
216
263
|
return c ? (c[1] ? 'return ' : 'if (ord) return ') + _this3.compile.apply(_this3, _toConsumableArray(c)) : '';
|
|
217
264
|
};
|
|
265
|
+
|
|
218
266
|
var fold = {
|
|
219
267
|
vars: function vars(str) {
|
|
220
|
-
return (
|
|
268
|
+
return " ".concat(str, ";").replace(/(.{1,78})(,|$) ?/g, '$1$2\n ');
|
|
221
269
|
},
|
|
222
270
|
cond: function cond(str) {
|
|
223
|
-
return (
|
|
271
|
+
return " ".concat(str, ";").replace(/(.{1,78}) (\|\| |$) ?/gm, '$1\n $2');
|
|
224
272
|
}
|
|
225
273
|
};
|
|
226
274
|
var cond = [ordinals && ['ordinal', !cardinals], cardinals && ['cardinal', true]].map(compile).map(fold.cond);
|
|
@@ -233,14 +281,14 @@ var MakePlural = function () {
|
|
|
233
281
|
return new Function(args, body); // eslint-disable-line no-new-func
|
|
234
282
|
}
|
|
235
283
|
}, {
|
|
236
|
-
key:
|
|
284
|
+
key: "fnToString",
|
|
237
285
|
value: function fnToString(name) {
|
|
238
286
|
return Function.prototype.toString.call(this.fn).replace(/^function( \w+)?/, name ? 'function ' + name : 'function').replace(/\n\/\*(``)?\*\//, '');
|
|
239
287
|
}
|
|
240
288
|
}], [{
|
|
241
|
-
key:
|
|
289
|
+
key: "load",
|
|
242
290
|
value: function load() {
|
|
243
|
-
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
291
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
244
292
|
args[_key] = arguments[_key];
|
|
245
293
|
}
|
|
246
294
|
|
|
@@ -255,16 +303,18 @@ var MakePlural = function () {
|
|
|
255
303
|
return MakePlural;
|
|
256
304
|
}
|
|
257
305
|
}, {
|
|
258
|
-
key:
|
|
306
|
+
key: "getRules",
|
|
259
307
|
value: function getRules(type, locale) {
|
|
260
308
|
if (locale.length) {
|
|
261
309
|
var cat = MakePlural.rules[type];
|
|
262
310
|
if (locale in cat) return cat[locale];
|
|
263
311
|
var lc0 = locale.toLowerCase();
|
|
312
|
+
|
|
264
313
|
for (var lc in cat) {
|
|
265
314
|
if (lc.toLowerCase() === lc0) return cat[lc];
|
|
266
315
|
}
|
|
267
316
|
}
|
|
317
|
+
|
|
268
318
|
return null;
|
|
269
319
|
}
|
|
270
320
|
}]);
|
|
@@ -273,12 +323,13 @@ var MakePlural = function () {
|
|
|
273
323
|
}();
|
|
274
324
|
|
|
275
325
|
exports.default = MakePlural;
|
|
276
|
-
|
|
277
|
-
|
|
278
326
|
MakePlural.cardinals = true;
|
|
279
327
|
MakePlural.ordinals = false;
|
|
280
|
-
MakePlural.rules = {
|
|
281
|
-
|
|
328
|
+
MakePlural.rules = {
|
|
329
|
+
cardinal: {},
|
|
330
|
+
ordinal: {}
|
|
331
|
+
};
|
|
332
|
+
module.exports = exports.default;
|
|
282
333
|
|
|
283
334
|
},{}]},{},[1])(1)
|
|
284
|
-
});
|
|
335
|
+
});
|
package/make-plural.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(
|
|
1
|
+
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).MakePlural=t()}}(function(){return function o(a,c,u){function s(n,t){if(!c[n]){if(!a[n]){var r="function"==typeof require&&require;if(!t&&r)return r(n,!0);if(l)return l(n,!0);var e=new Error("Cannot find module '"+n+"'");throw e.code="MODULE_NOT_FOUND",e}var i=c[n]={exports:{}};a[n][0].call(i.exports,function(t){return s(a[n][1][t]||t)},i,i.exports,o,a,c,u)}return c[n].exports}for(var l="function"==typeof require&&require,t=0;t<u.length;t++)s(u[t]);return s}({1:[function(t,n,r){"use strict";function l(t){return function(t){if(Array.isArray(t)){for(var n=0,r=new Array(t.length);n<t.length;n++)r[n]=t[n];return r}}(t)||e(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function f(t){return function(t){if(Array.isArray(t))return t}(t)||e(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function e(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function i(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function o(t,n){for(var r=0;r<n.length;r++){var e=n[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}function a(t,n,r){return n&&o(t.prototype,n),r&&o(t,r),t}Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var c=function(){function t(){i(this,t)}return a(t,[{key:"parse",value:function(t){var o=this;return"i = 0 or n = 1"===t?"n >= 0 && n <= 1":"i = 0,1"===t?"n >= 0 && n < 2":"i = 1 and v = 0"===t?(this.v0=1,"n == 1 && v0"):t.replace(/([tv]) (!?)= 0/g,function(t,n,r){var e=n+"0";return o[e]=1,r?"!"+e:e}).replace(/\b[fintv]\b/g,function(t){return o[t]=1,t}).replace(/([fin]) % (10+)/g,function(t,n,r){var e=n+r;return o[e]=1,e}).replace(/n10+ = 0/g,"t0 && $&").replace(/(\w+ (!?)= )([0-9.]+,[0-9.,]+)/g,function(t,n,r,e){return"n = 0,1"===t?"(n == 0 || n == 1)":r?n+e.split(",").join(" && "+n):"("+n+e.split(",").join(" || "+n)+")"}).replace(/(\w+) (!?)= ([0-9]+)\.\.([0-9]+)/g,function(t,n,r,e,i){return Number(e)+1===Number(i)?r?"".concat(n," != ").concat(e," && ").concat(n," != ").concat(i):"(".concat(n," == ").concat(e," || ").concat(n," == ").concat(i,")"):r?"(".concat(n," < ").concat(e," || ").concat(n," > ").concat(i,")"):"n"===n?(o.t0=1,"(t0 && n >= ".concat(e," && n <= ").concat(i,")")):"(".concat(n," >= ").concat(e," && ").concat(n," <= ").concat(i,")")}).replace(/ and /g," && ").replace(/ or /g," || ").replace(/ = /g," == ")}},{key:"vars",value:function(){var t=[];for(var n in 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"),this)if(/^.10+$/.test(n)){var r="n"===n[0]?"t0 && s[0]":n[0];t.push("".concat(n," = ").concat(r,".slice(-").concat(n.substr(2).length,")"))}return t.length?"var "+["s = String(n).split('.')"].concat(t).join(", "):""}}]),t}(),u=function(){function n(t){i(this,n),this.obj=t,this.ordinal={},this.cardinal={}}return a(n,[{key:"add",value:function(t,n,r){this[t][n]={src:r,values:null}}},{key:"testCond",value:function(t,n,r,e){try{var i=(e||this.obj.fn)(t,"ordinal"===n)}catch(t){i=t.toString()}if(i!==r)throw new Error("Locale "+JSON.stringify(this.obj.lc)+n+" rule self-test failed for v = "+JSON.stringify(t)+" (was "+JSON.stringify(i)+", expected "+JSON.stringify(r)+")");return!0}},{key:"testCat",value:function(n,r,e){var i=this,t=this[n][r];return t.values||(t.values=t.src.join(" ").replace(/^[ ,]+|[ ,…]+$/g,"").replace(/(0\.[0-9])~(1\.[1-9])/g,"$1 1.0 $2").split(/[ ,~…]+/)),t.values.forEach(function(t){i.testCond(t,n,r,e),/\.0+$/.test(t)||i.testCond(Number(t),n,r,e)}),!0}},{key:"testAll",value:function(){for(var t in this.cardinal)this.testCat("cardinal",t);for(var n in this.ordinal)this.testCat("ordinal",n);return!0}}]),n}(),s=function(){function s(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:s,r=n.cardinals,e=n.ordinals;if(i(this,s),!r&&!e)throw new Error("At least one type of plural is required");return this.lc=t,this.categories={cardinal:[],ordinal:[]},this.parser=new c,this.tests=new u(this),this.fn=this.buildFunction(r,e),(this.fn._obj=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(s,[{key:"compile",value:function(t,n){var r=[],e=s.getRules(t,this.lc);if(!e){if(n)throw new Error('Locale "'.concat(this.lc,'" ').concat(t," rules not found"));return this.categories[t]=["other"],"'other'"}for(var i in e){var o=f(e[i].trim().split(/\s*@\w*/)),a=o[0],c=o.slice(1),u=i.replace("pluralRule-count-","");a&&r.push([this.parser.parse(a),u]),this.tests.add(t,u,c)}return this.categories[t]=r.map(function(t){return t[1]}).concat("other"),1===r.length?"(".concat(r[0][0],") ? '").concat(r[0][1],"' : 'other'"):l(r.map(function(t){return"(".concat(t[0],") ? '").concat(t[1],"'")})).concat(["'other'"]).join("\n : ")}},{key:"buildFunction",value:function(t,n){var r=this,e=function(t){return" ".concat(t,";").replace(/(.{1,78})(,|$) ?/g,"$1$2\n ")},i=function(t){return" ".concat(t,";").replace(/(.{1,78}) (\|\| |$) ?/gm,"$1\n $2")},o=[n&&["ordinal",!t],t&&["cardinal",!0]].map(function(t){return t?(t[1]?"return ":"if (ord) return ")+r.compile.apply(r,l(t)):""}).map(i),a=[e(this.parser.vars())].concat(l(o)).filter(function(t){return!/^[\s;]*$/.test(t)}).map(function(t){return t.replace(/\s+$/gm,"")}).join("\n");return new Function(n&&t?"n, ord":"n",a)}},{key:"fnToString",value:function(t){return Function.prototype.toString.call(this.fn).replace(/^function( \w+)?/,t?"function "+t:"function").replace(/\n\/\*(``)?\*\//,"")}}],[{key:"load",value:function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return n.forEach(function(t){var n=t&&t.supplemental||null;if(!n)throw new Error("Data does not appear to be CLDR data");s.rules={cardinal:n["plurals-type-cardinal"]||s.rules.cardinal,ordinal:n["plurals-type-ordinal"]||s.rules.ordinal}}),s}},{key:"getRules",value:function(t,n){if(n.length){var r=s.rules[t];if(n in r)return r[n];var e=n.toLowerCase();for(var i in r)if(i.toLowerCase()===e)return r[i]}return null}}]),s}();(r.default=s).cardinals=!0,s.ordinals=!1,s.rules={cardinal:{},ordinal:{}},n.exports=r.default},{}]},{},[1])(1)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "make-plural",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Translates Unicode CLDR pluralization rules to executable JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unicode",
|
|
@@ -33,18 +33,18 @@
|
|
|
33
33
|
"version": "git add -f $FILES"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"babel
|
|
37
|
-
"babel
|
|
38
|
-
"babel-
|
|
39
|
-
"babel-
|
|
40
|
-
"babelify": "^
|
|
41
|
-
"browserify": "^
|
|
42
|
-
"cldr-core": "^
|
|
36
|
+
"@babel/cli": "^7.1.2",
|
|
37
|
+
"@babel/core": "^7.1.2",
|
|
38
|
+
"@babel/preset-env": "^7.1.0",
|
|
39
|
+
"babel-plugin-add-module-exports": "^1.0.0",
|
|
40
|
+
"babelify": "^10.0.0",
|
|
41
|
+
"browserify": "^16.2.3",
|
|
42
|
+
"cldr-core": "^34.0.0",
|
|
43
43
|
"expect.js": "*",
|
|
44
|
-
"http-server": "^0.
|
|
45
|
-
"mocha": "^
|
|
46
|
-
"standard": "^
|
|
47
|
-
"uglify-js": "^3.
|
|
44
|
+
"http-server": "^0.11.1",
|
|
45
|
+
"mocha": "^5.2.0",
|
|
46
|
+
"standard": "^12.0.1",
|
|
47
|
+
"uglify-js": "^3.4.9"
|
|
48
48
|
},
|
|
49
49
|
"optionalDependencies": {
|
|
50
50
|
"minimist": "^1.2.0"
|
package/umd/pluralCategories.js
CHANGED
|
@@ -62,7 +62,7 @@ fr: _cc[2],
|
|
|
62
62
|
fur: _cc[1],
|
|
63
63
|
fy: _cc[1],
|
|
64
64
|
ga: {cardinal:["one","two","few","many","other"],ordinal:["one","other"]},
|
|
65
|
-
gd: {cardinal:["one","two","few","other"],ordinal:["other"]},
|
|
65
|
+
gd: {cardinal:["one","two","few","other"],ordinal:["one","two","few","other"]},
|
|
66
66
|
gl: _cc[1],
|
|
67
67
|
gsw: _cc[1],
|
|
68
68
|
gu: {cardinal:["one","other"],ordinal:["one","two","few","many","other"]},
|
|
@@ -76,6 +76,7 @@ hr: {cardinal:["one","few","other"],ordinal:["other"]},
|
|
|
76
76
|
hsb: {cardinal:["one","two","few","other"],ordinal:["other"]},
|
|
77
77
|
hu: _cc[2],
|
|
78
78
|
hy: _cc[2],
|
|
79
|
+
ia: _cc[1],
|
|
79
80
|
id: _cc[0],
|
|
80
81
|
ig: _cc[0],
|
|
81
82
|
ii: _cc[0],
|
|
@@ -161,6 +162,7 @@ ru: {cardinal:["one","few","many","other"],ordinal:["other"]},
|
|
|
161
162
|
rwk: _cc[1],
|
|
162
163
|
sah: _cc[0],
|
|
163
164
|
saq: _cc[1],
|
|
165
|
+
sc: {cardinal:["one","other"],ordinal:["many","other"]},
|
|
164
166
|
scn: {cardinal:["one","other"],ordinal:["many","other"]},
|
|
165
167
|
sd: _cc[1],
|
|
166
168
|
sdh: _cc[1],
|
|
@@ -1 +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"]},ars:{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],io:_cc[1],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:{cardinal:["one","other"],ordinal:["one","two","few","many","other"]},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],scn:{cardinal:["one","other"],ordinal:["many","other"]},sd:_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:{cardinal:["one","other"],ordinal:["few","other"]},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],yue:_cc[0],zh:_cc[0],zu:_cc[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"]},ars:{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:["one","two","few","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],ia:_cc[1],id:_cc[0],ig:_cc[0],ii:_cc[0],in:_cc[0],io:_cc[1],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:{cardinal:["one","other"],ordinal:["one","two","few","many","other"]},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],sc:{cardinal:["one","other"],ordinal:["many","other"]},scn:{cardinal:["one","other"],ordinal:["many","other"]},sd:_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:{cardinal:["one","other"],ordinal:["few","other"]},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],yue:_cc[0],zh:_cc[0],zu:_cc[1]});
|