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

make-plural

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

make-plural - npm Package Compare versions

Comparing version 3.0.0-rc4 to 3.0.0

356

make-plural.js
(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){
"use strict";
'use strict';

@@ -8,6 +8,9 @@ var _toArray = function (arr) { return Array.isArray(arr) ? arr : Array.from(arr); };

var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
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; }; })();
Object.defineProperty(exports, '__esModule', {
value: true
});
/**

@@ -35,64 +38,72 @@ * make-plural.js -- https://github.com/eemeli/make-plural.js/

_createClass(Parser, {
parse: {
value: function parse(cond) {
var _this = this;
_createClass(Parser, [{
key: 'parse',
value: function parse(cond) {
var _this = this;
if (cond === "i = 0 or n = 1") {
return "n >= 0 && n <= 1";
}if (cond === "i = 0,1") {
return "n >= 0 && n < 2";
}if (cond === "i = 1 and v = 0") {
this.v0 = 1;
return "n == 1 && v0";
if (cond === 'i = 0 or n = 1') {
return 'n >= 0 && n <= 1';
}if (cond === 'i = 0,1') {
return 'n >= 0 && n < 2';
}if (cond === 'i = 1 and v = 0') {
this.v0 = 1;
return 'n == 1 && v0';
}
return cond.replace(/([tv]) (!?)= 0/g, function (m, sym, noteq) {
var sn = sym + '0';
_this[sn] = 1;
return noteq ? '!' + sn : sn;
}).replace(/\b[fintv]\b/g, function (m) {
_this[m] = 1;
return m;
}).replace(/([fin]) % (10+)/g, function (m, sym, num) {
var sn = sym + num;
_this[sn] = 1;
return sn;
}).replace(/n10+ = 0/g, 't0 && $&').replace(/(\w+ (!?)= )([0-9.]+,[0-9.,]+)/g, function (m, se, noteq, x) {
if (m === 'n = 0,1') return '(n == 0 || n == 1)';
if (noteq) return se + x.split(',').join(' && ' + se);
return '(' + se + x.split(',').join(' || ' + se) + ')';
}).replace(/(\w+) (!?)= ([0-9]+)\.\.([0-9]+)/g, function (m, sym, noteq, x0, x1) {
if (Number(x0) + 1 === Number(x1)) {
if (noteq) return '' + sym + ' != ' + x0 + ' && ' + sym + ' != ' + x1;
return '(' + sym + ' == ' + x0 + ' || ' + sym + ' == ' + x1 + ')';
}
return cond.replace(/([tv]) (!?)= 0/g, function (m, sym, noteq) {
var sn = sym + "0";
_this[sn] = 1;
return noteq ? "!" + sn : sn;
}).replace(/\b[fintv]\b/g, function (m) {
_this[m] = 1;
return m;
}).replace(/([fin]) % (10+)/g, function (m, sym, num) {
var sn = sym + num;
_this[sn] = 1;
return sn;
}).replace(/n10+ = 0/g, "t0 && $&").replace(/(\w+ (!?)= )([0-9.]+,[0-9.,]+)/g, function (m, se, noteq, x) {
if (m === "n = 0,1") return "(n == 0 || n == 1)";
if (noteq) return se + x.split(",").join(" && " + se);
return "(" + se + x.split(",").join(" || " + se) + ")";
}).replace(/(\w+) (!?)= ([0-9]+)\.\.([0-9]+)/g, function (m, sym, noteq, x0, x1) {
if (Number(x0) + 1 === Number(x1)) {
if (noteq) return "" + sym + " != " + x0 + " && " + sym + " != " + x1;
return "(" + sym + " == " + x0 + " || " + sym + " == " + x1 + ")";
}
if (noteq) return "(" + sym + " < " + x0 + " || " + sym + " > " + x1 + ")";
if (sym === "n") {
_this.t0 = 1;return "(t0 && n >= " + x0 + " && n <= " + x1 + ")";
}
return "(" + sym + " >= " + x0 + " && " + sym + " <= " + x1 + ")";
}).replace(/ and /g, " && ").replace(/ or /g, " || ").replace(/ = /g, " == ");
if (noteq) return '(' + sym + ' < ' + x0 + ' || ' + sym + ' > ' + x1 + ')';
if (sym === 'n') {
_this.t0 = 1;return '(t0 && n >= ' + x0 + ' && n <= ' + x1 + ')';
}
return '(' + sym + ' >= ' + x0 + ' && ' + sym + ' <= ' + x1 + ')';
}).replace(/ and /g, ' && ').replace(/ or /g, ' || ').replace(/ = /g, ' == ');
}
}, {
key: 'vars',
value: (function (_vars) {
function vars() {
return _vars.apply(this, arguments);
}
},
vars: {
value: function vars() {
var vars = [];
if (this.i) vars.push("i = s[0]");
if (this.f || this.v) vars.push("f = s[1] || ''");
if (this.t) vars.push("t = (s[1] || '').replace(/0+$/, '')");
if (this.v) vars.push("v = f.length");
if (this.v0) vars.push("v0 = !s[1]");
if (this.t0 || this.n10 || this.n100) vars.push("t0 = Number(s[0]) == n");
for (var k in this) {
if (/^.10+$/.test(k)) {
var k0 = k[0] === "n" ? "t0 && s[0]" : k[0];
vars.push("" + k + " = " + k0 + ".slice(-" + k.substr(2).length + ")");
}
}if (!vars.length) {
return "";
}return "var " + ["s = String(n).split('.')"].concat(vars).join(", ");
}
}
});
vars.toString = function () {
return _vars.toString();
};
return vars;
})(function () {
var vars = [];
if (this.i) vars.push('i = s[0]');
if (this.f || this.v) vars.push('f = s[1] || \'\'');
if (this.t) vars.push('t = (s[1] || \'\').replace(/0+$/, \'\')');
if (this.v) vars.push('v = f.length');
if (this.v0) vars.push('v0 = !s[1]');
if (this.t0 || this.n10 || this.n100) vars.push('t0 = Number(s[0]) == n');
for (var k in this) {
if (/^.10+$/.test(k)) {
var k0 = k[0] === 'n' ? 't0 && s[0]' : k[0];
vars.push('' + k + ' = ' + k0 + '.slice(-' + k.substr(2).length + ')');
}
}if (!vars.length) return '';
return 'var ' + ['s = String(n).split(\'.\')'].concat(vars).join(', ');
})
}]);
return Parser;

@@ -110,42 +121,41 @@ })();

_createClass(Tests, {
add: {
value: function add(type, cat, examples) {
this[type][cat] = examples.join(" ").replace(/^[ ,]+|[ ,…]+$/g, "").replace(/(0\.[0-9])~(1\.[1-9])/g, "$1 1.0 $2").split(/[ ,~…]+/);
_createClass(Tests, [{
key: 'add',
value: function add(type, cat, examples) {
this[type][cat] = examples.join(' ').replace(/^[ ,]+|[ ,…]+$/g, '').replace(/(0\.[0-9])~(1\.[1-9])/g, '$1 1.0 $2').split(/[ ,~…]+/);
}
}, {
key: 'testCond',
value: function testCond(n, type, expResult, fn) {
try {
var r = (fn || this.obj.fn)(n, type === 'ordinal');
} catch (e) {
r = e.toString();
}
},
testCond: {
value: function testCond(n, type, expResult, fn) {
try {
var r = (fn || this.obj.fn)(n, type === "ordinal");
} catch (e) {
r = e.toString();
}
if (r !== expResult) {
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) + ")");
}
return true;
if (r !== expResult) {
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) + ')');
}
},
testCat: {
value: function testCat(type, cat, fn) {
var _this = this;
return true;
}
}, {
key: 'testCat',
value: function testCat(type, cat, fn) {
var _this2 = this;
this[type][cat].forEach(function (n) {
_this.testCond(n, type, cat, fn);
if (!/\.0+$/.test(n)) _this.testCond(Number(n), type, cat, fn);
});
return true;
}
},
testAll: {
value: function testAll() {
for (var cat in this.cardinal) {
this.testCat("cardinal", cat);
}for (var cat in this.ordinal) {
this.testCat("ordinal", cat);
}return true;
}
this[type][cat].forEach(function (n) {
_this2.testCond(n, type, cat, fn);
if (!/\.0+$/.test(n)) _this2.testCond(Number(n), type, cat, fn);
});
return true;
}
});
}, {
key: 'testAll',
value: function testAll() {
for (var cat in this.cardinal) {
this.testCat('cardinal', cat);
}for (var cat in this.ordinal) {
this.testCat('ordinal', cat);
}return true;
}
}]);

@@ -157,18 +167,15 @@ return Tests;

function MakePlural(lc) {
var opt = arguments[1] === undefined ? {} : arguments[1];
var _ref = arguments[1] === undefined ? MakePlural : arguments[1];
var cardinals = _ref.cardinals;
var ordinals = _ref.ordinals;
_classCallCheck(this, MakePlural);
if (typeof lc == "object") {
opt = lc;
lc = opt.lc;
}
this.lc = lc || MakePlural.lc;
this.cardinals = opt.cardinals || MakePlural.cardinals;
this.ordinals = opt.ordinals || MakePlural.ordinals;
if (!this.ordinals && !this.cardinals) throw new Error("At least one type of plural is required");
if (!cardinals && !ordinals) throw new Error('At least one type of plural is required');
this.lc = lc;
this.categories = { cardinal: [], ordinal: [] };
this.parser = new Parser();
this.tests = new Tests(this);
this.fn = this.buildFunction();
this.fn = this.buildFunction(cardinals, ordinals);
this.fn._obj = this;

@@ -183,78 +190,76 @@ this.fn.categories = this.categories;

_createClass(MakePlural, {
compile: {
value: function compile(type, req) {
var cases = [];
var rules = MakePlural.rules[type][this.lc];
if (!rules) {
if (req) throw new Error("Locale \"" + this.lc + "\" " + type + " rules not found");
this.categories[type] = ["other"];
return "'other'";
}
for (var r in rules) {
var _rules$r$trim$split = rules[r].trim().split(/\s*@\w*/);
_createClass(MakePlural, [{
key: 'compile',
value: function compile(type, req) {
var cases = [];
var rules = MakePlural.rules[type][this.lc];
if (!rules) {
if (req) throw new Error('Locale "' + this.lc + '" ' + type + ' rules not found');
this.categories[type] = ['other'];
return '\'other\'';
}
for (var r in rules) {
var _rules$r$trim$split = rules[r].trim().split(/\s*@\w*/);
var _rules$r$trim$split2 = _toArray(_rules$r$trim$split);
var _rules$r$trim$split2 = _toArray(_rules$r$trim$split);
var cond = _rules$r$trim$split2[0];
var examples = _rules$r$trim$split2.slice(1);
var cat = r.replace("pluralRule-count-", "");
if (cond) cases.push([this.parser.parse(cond), cat]);
this.tests.add(type, cat, examples);
}
this.categories[type] = cases.map(function (c) {
return c[1];
}).concat("other");
if (cases.length === 1) {
return "(" + cases[0][0] + ") ? '" + cases[0][1] + "' : 'other'";
} else {
return [].concat(_toConsumableArray(cases.map(function (c) {
return "(" + c[0] + ") ? '" + c[1] + "'";
})), ["'other'"]).join("\n : ");
}
var cond = _rules$r$trim$split2[0];
var examples = _rules$r$trim$split2.slice(1);
var cat = r.replace('pluralRule-count-', '');
if (cond) cases.push([this.parser.parse(cond), cat]);
this.tests.add(type, cat, examples);
}
},
buildFunction: {
value: function buildFunction() {
var _this = this;
this.categories[type] = cases.map(function (c) {
return c[1];
}).concat('other');
if (cases.length === 1) {
return '(' + cases[0][0] + ') ? \'' + cases[0][1] + '\' : \'other\'';
} else {
return [].concat(_toConsumableArray(cases.map(function (c) {
return '(' + c[0] + ') ? \'' + c[1] + '\'';
})), ['\'other\'']).join('\n : ');
}
}
}, {
key: 'buildFunction',
value: function buildFunction(cardinals, ordinals) {
var _this3 = this;
var compile = function (c) {
return c ? (c[1] ? "return " : "if (ord) return ") + _this.compile.apply(_this, _toConsumableArray(c)) : "";
var compile = function compile(c) {
return c ? (c[1] ? 'return ' : 'if (ord) return ') + _this3.compile.apply(_this3, _toConsumableArray(c)) : '';
},
fold = { vars: function vars(str) {
return (' ' + str + ';').replace(/(.{1,78})(,|$) ?/g, '$1$2\n ');
},
fold = { vars: function (str) {
return (" " + str + ";").replace(/(.{1,78})(,|$) ?/g, "$1$2\n ");
},
cond: function (str) {
return (" " + str + ";").replace(/(.{1,78}) (\|\| |$) ?/gm, "$1\n $2");
} },
cond = [this.ordinals && ["ordinal", !this.cardinals], this.cardinals && ["cardinal", true]].map(compile).map(fold.cond),
body = [fold.vars(this.parser.vars())].concat(_toConsumableArray(cond)).join("\n").replace(/\s+$/gm, "").replace(/^[\s;]*[\r\n]+/gm, ""),
args = this.ordinals && this.cardinals ? "n, ord" : "n";
return new Function(args, body);
}
},
fnToString: {
value: function fnToString(name) {
return Function.prototype.toString.call(this.fn).replace(/^function( \w+)?/, name ? "function " + name : "function").replace("\n/**/", "");
}
cond: function cond(str) {
return (' ' + str + ';').replace(/(.{1,78}) (\|\| |$) ?/gm, '$1\n $2');
} },
cond = [ordinals && ['ordinal', !cardinals], cardinals && ['cardinal', true]].map(compile).map(fold.cond),
body = [fold.vars(this.parser.vars())].concat(_toConsumableArray(cond)).join('\n').replace(/\s+$/gm, '').replace(/^[\s;]*[\r\n]+/gm, ''),
args = ordinals && cardinals ? 'n, ord' : 'n';
return new Function(args, body);
}
}, {
load: {
value: function load() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
key: 'fnToString',
value: function fnToString(name) {
return Function.prototype.toString.call(this.fn).replace(/^function( \w+)?/, name ? 'function ' + name : 'function').replace('\n/**/', '');
}
}], [{
key: 'load',
value: function load() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
args.forEach(function (cldr) {
var data = cldr && cldr.supplemental || null;
if (!data) throw new Error("Data does not appear to be CLDR data");
MakePlural.rules = {
cardinal: data["plurals-type-cardinal"] || MakePlural.rules.cardinal,
ordinal: data["plurals-type-ordinal"] || MakePlural.rules.ordinal
};
});
return MakePlural;
}
args.forEach(function (cldr) {
var data = cldr && cldr.supplemental || null;
if (!data) throw new Error('Data does not appear to be CLDR data');
MakePlural.rules = {
cardinal: data['plurals-type-cardinal'] || MakePlural.rules.cardinal,
ordinal: data['plurals-type-ordinal'] || MakePlural.rules.ordinal
};
});
return MakePlural;
}
});
}]);

@@ -264,3 +269,3 @@ return MakePlural;

module.exports = MakePlural;
exports['default'] = MakePlural;

@@ -270,4 +275,5 @@ MakePlural.cardinals = true;

MakePlural.rules = { cardinal: {}, ordinal: {} };
module.exports = exports['default'];
},{}]},{},[1])(1)
});

@@ -1,1 +0,1 @@

!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var r;r="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,r.MakePlural=n()}}(function(){return function n(r,t,i){function e(o,s){if(!t[o]){if(!r[o]){var u="function"==typeof require&&require;if(!s&&u)return u(o,!0);if(a)return a(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var c=t[o]={exports:{}};r[o][0].call(c.exports,function(n){var t=r[o][1][n];return e(t?t:n)},c,c.exports,n,r,t,i)}return t[o].exports}for(var a="function"==typeof require&&require,o=0;o<i.length;o++)e(i[o]);return e}({1:[function(n,r,t){"use strict";var i=function(n){return Array.isArray(n)?n:Array.from(n)},e=function(n){if(Array.isArray(n)){for(var r=0,t=Array(n.length);r<n.length;r++)t[r]=n[r];return t}return Array.from(n)},a=function(){function n(n,r){for(var t in r){var i=r[t];i.configurable=!0,i.value&&(i.writable=!0)}Object.defineProperties(n,r)}return function(r,t,i){return t&&n(r.prototype,t),i&&n(r,i),r}}(),o=function(n,r){if(!(n instanceof r))throw new TypeError("Cannot call a class as a function")},s=function(){function n(){o(this,n)}return a(n,{parse:{value:function(n){var r=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,t,i){var e=t+"0";return r[e]=1,i?"!"+e:e}).replace(/\b[fintv]\b/g,function(n){return r[n]=1,n}).replace(/([fin]) % (10+)/g,function(n,t,i){var e=t+i;return r[e]=1,e}).replace(/n10+ = 0/g,"t0 && $&").replace(/(\w+ (!?)= )([0-9.]+,[0-9.,]+)/g,function(n,r,t,i){return"n = 0,1"===n?"(n == 0 || n == 1)":t?r+i.split(",").join(" && "+r):"("+r+i.split(",").join(" || "+r)+")"}).replace(/(\w+) (!?)= ([0-9]+)\.\.([0-9]+)/g,function(n,t,i,e,a){return Number(e)+1===Number(a)?i?""+t+" != "+e+" && "+t+" != "+a:"("+t+" == "+e+" || "+t+" == "+a+")":i?"("+t+" < "+e+" || "+t+" > "+a+")":"n"===t?(r.t0=1,"(t0 && n >= "+e+" && n <= "+a+")"):"("+t+" >= "+e+" && "+t+" <= "+a+")"}).replace(/ and /g," && ").replace(/ or /g," || ").replace(/ = /g," == ")}},vars:{value:function r(){var r=[];this.i&&r.push("i = s[0]"),(this.f||this.v)&&r.push("f = s[1] || ''"),this.t&&r.push("t = (s[1] || '').replace(/0+$/, '')"),this.v&&r.push("v = f.length"),this.v0&&r.push("v0 = !s[1]"),(this.t0||this.n10||this.n100)&&r.push("t0 = Number(s[0]) == n");for(var n in this)if(/^.10+$/.test(n)){var t="n"===n[0]?"t0 && s[0]":n[0];r.push(""+n+" = "+t+".slice(-"+n.substr(2).length+")")}return r.length?"var "+["s = String(n).split('.')"].concat(r).join(", "):""}}}),n}(),u=function(){function n(r){o(this,n),this.obj=r,this.ordinal={},this.cardinal={}}return a(n,{add:{value:function(n,r,t){this[n][r]=t.join(" ").replace(/^[ ,]+|[ ,…]+$/g,"").replace(/(0\.[0-9])~(1\.[1-9])/g,"$1 1.0 $2").split(/[ ,~…]+/)}},testCond:{value:function(n,r,t,i){try{var e=(i||this.obj.fn)(n,"ordinal"===r)}catch(a){e=a.toString()}if(e!==t)throw new Error("Locale "+JSON.stringify(this.obj.lc)+r+" rule self-test failed for v = "+JSON.stringify(n)+" (was "+JSON.stringify(e)+", expected "+JSON.stringify(t)+")");return!0}},testCat:{value:function(n,r,t){var i=this;return this[n][r].forEach(function(e){i.testCond(e,n,r,t),/\.0+$/.test(e)||i.testCond(Number(e),n,r,t)}),!0}},testAll:{value:function(){for(var n in this.cardinal)this.testCat("cardinal",n);for(var n in this.ordinal)this.testCat("ordinal",n);return!0}}}),n}(),l=function(){function n(r){var t=void 0===arguments[1]?{}:arguments[1];if(o(this,n),"object"==typeof r&&(t=r,r=t.lc),this.lc=r||n.lc,this.cardinals=t.cardinals||n.cardinals,this.ordinals=t.ordinals||n.ordinals,!this.ordinals&&!this.cardinals)throw new Error("At least one type of plural is required");return this.categories={cardinal:[],ordinal:[]},this.parser=new s,this.tests=new u(this),this.fn=this.buildFunction(),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,{compile:{value:function(r,t){var a=[],o=n.rules[r][this.lc];if(!o){if(t)throw new Error('Locale "'+this.lc+'" '+r+" rules not found");return this.categories[r]=["other"],"'other'"}for(var s in o){var u=o[s].trim().split(/\s*@\w*/),l=i(u),c=l[0],f=l.slice(1),h=s.replace("pluralRule-count-","");c&&a.push([this.parser.parse(c),h]),this.tests.add(r,h,f)}return this.categories[r]=a.map(function(n){return n[1]}).concat("other"),1===a.length?"("+a[0][0]+") ? '"+a[0][1]+"' : 'other'":[].concat(e(a.map(function(n){return"("+n[0]+") ? '"+n[1]+"'"})),["'other'"]).join("\n : ")}},buildFunction:{value:function(){var n=this,r=function(r){return r?(r[1]?"return ":"if (ord) return ")+n.compile.apply(n,e(r)):""},t={vars:function(n){return(" "+n+";").replace(/(.{1,78})(,|$) ?/g,"$1$2\n ")},cond:function(n){return(" "+n+";").replace(/(.{1,78}) (\|\| |$) ?/gm,"$1\n $2")}},i=[this.ordinals&&["ordinal",!this.cardinals],this.cardinals&&["cardinal",!0]].map(r).map(t.cond),a=[t.vars(this.parser.vars())].concat(e(i)).join("\n").replace(/\s+$/gm,"").replace(/^[\s;]*[\r\n]+/gm,""),o=this.ordinals&&this.cardinals?"n, ord":"n";return new Function(o,a)}},fnToString:{value:function(n){return Function.prototype.toString.call(this.fn).replace(/^function( \w+)?/,n?"function "+n:"function").replace("\n/**/","")}}},{load:{value:function(){for(var r=arguments.length,t=Array(r),i=0;r>i;i++)t[i]=arguments[i];return t.forEach(function(r){var t=r&&r.supplemental||null;if(!t)throw new Error("Data does not appear to be CLDR data");n.rules={cardinal:t["plurals-type-cardinal"]||n.rules.cardinal,ordinal:t["plurals-type-ordinal"]||n.rules.ordinal}}),n}}}),n}();r.exports=l,l.cardinals=!0,l.ordinals=!1,l.rules={cardinal:{},ordinal:{}}},{}]},{},[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,u){if(!r[a]){if(!t[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(o)return o(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var c=r[a]={exports:{}};t[a][0].call(c.exports,function(n){var r=t[a][1][n];return i(r?r:n)},c,c.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";var e=function(n){return Array.isArray(n)?n:Array.from(n)},i=function(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)},o=function(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")},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}}();Object.defineProperty(r,"__esModule",{value:!0});var u=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(n){function t(){return n.apply(this,arguments)}return t.toString=function(){return n.toString()},t}(function(){var n=[];this.i&&n.push("i = s[0]"),(this.f||this.v)&&n.push("f = s[1] || ''"),this.t&&n.push("t = (s[1] || '').replace(/0+$/, '')"),this.v&&n.push("v = f.length"),this.v0&&n.push("v0 = !s[1]"),(this.t0||this.n10||this.n100)&&n.push("t0 = Number(s[0]) == n");for(var t in this)if(/^.10+$/.test(t)){var r="n"===t[0]?"t0 && s[0]":t[0];n.push(""+t+" = "+r+".slice(-"+t.substr(2).length+")")}return n.length?"var "+["s = String(n).split('.')"].concat(n).join(", "):""})}]),n}(),s=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 n in this.ordinal)this.testCat("ordinal",n);return!0}}]),n}(),l=function(){function n(t){var r=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 u,this.tests=new s(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 u in a){var s=a[u].trim().split(/\s*@\w*/),l=e(s),c=l[0],f=l.slice(1),h=u.replace("pluralRule-count-","");c&&o.push([this.parser.parse(c),h]),this.tests.add(t,h,f)}return this.categories[t]=o.map(function(n){return n[1]}).concat("other"),1===o.length?"("+o[0][0]+") ? '"+o[0][1]+"' : 'other'":[].concat(i(o.map(function(n){return"("+n[0]+") ? '"+n[1]+"'"})),["'other'"]).join("\n : ")}},{key:"buildFunction",value:function(n,t){var r=this,e=function(n){return n?(n[1]?"return ":"if (ord) return ")+r.compile.apply(r,i(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(e).map(o.cond),u=[o.vars(this.parser.vars())].concat(i(a)).join("\n").replace(/\s+$/gm,"").replace(/^[\s;]*[\r\n]+/gm,""),s=t&&n?"n, ord":"n";return new Function(s,u)}},{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)});
{
"name": "make-plural",
"version": "3.0.0-rc4",
"version": "3.0.0",
"description": "Translates Unicode CLDR pluralization rules to executable JavaScript",

@@ -37,11 +37,11 @@ "keywords": [

"devDependencies": {
"babel": "^4.7.9",
"babel-eslint": "*",
"babelify": "^5.0.4",
"browserify": "^9.0.3",
"babel": "^5.1.11",
"babel-eslint": "^3.0.1",
"babelify": "^6.0.2",
"browserify": "^9.0.8",
"cldr-core": "^27.0.1",
"eslint": "*",
"eslint": "^0.19.0",
"expect.js": "^0.3.1",
"http-server": "^0.7.5",
"mocha": "^2.2.1",
"http-server": "^0.8.0",
"mocha": "^2.2.4",
"uglify-js": "^2.4.19"

@@ -48,0 +48,0 @@ },

@@ -155,3 +155,3 @@ [![ISC License](https://img.shields.io/npm/l/make-plural.svg)](http://en.wikipedia.org/wiki/ISC_license)

### new MakePlural(lc, opt)
### new MakePlural(lc, { cardinals, ordinals })
Returns a function that takes an argument `n` and returns its plural category

@@ -164,3 +164,3 @@ for the given locale `lc`.

The optional `opt` parameter may contain the following boolean members:
The optional second parameter may contain the following boolean members:
* `cardinals` — if true, rules for cardinal values (1 day, 2 days, etc.) are

@@ -170,12 +170,11 @@ included

If both `opt.ordinals` and `opt.cardinals` are true, the returned function takes
a second parameter `ord`. Then, if `ord` is true, the function will return the
If both `cardinals` and `ordinals` are true, the returned function takes a
second parameter `ord`. Then, if `ord` is true, the function will return the
ordinal rather than cardinal category applicable to `n` in locale `lc`.
If `lc` or the `opt` values are not set, the values are taken from
`MakePlural.lc` (no default value), `MakePlural.cardinals` (default `true`) and
`MakePlural.ordinals` (default `false`).
If the second parameter is undefined, the values are taken from
`MakePlural.cardinals` (default `true`) and `MakePlural.ordinals` (default
`false`).
### Live use: Node

@@ -182,0 +181,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc