make-plural
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -98,4 +98,5 @@ (function () { | ||
exports.build = function(lc, op_function) { | ||
var fn_body = [], symbols = {}, tests = {}; | ||
exports.build = function(lc, opt) { | ||
var fn, fn_str, lines = [], symbols = {}, tests = {}; | ||
if (!opt) opt = {}; | ||
if (!rules) exports.set_rules(); | ||
@@ -107,12 +108,15 @@ if (!rules[lc]) { console.error('ERROR: locale "' + lc + '" not found'); return null; } | ||
cond = parts.shift().trim(); | ||
if (cond) fn_body.push('if (' + parse(cond, symbols) + ') return \'' + key + '\';'); | ||
if (cond) lines.push('if (' + parse(cond, symbols) + ') return \'' + key + '\';'); | ||
tests[key] = test_values(parts.join(' ')); | ||
} | ||
fn_body.unshift(vars(symbols)); | ||
fn_body.push('return \'other\';'); | ||
var fn = new Function('n', fn_body.join('\n').trim()); | ||
lines.unshift(vars(symbols)); | ||
lines.push('return \'other\';'); | ||
fn = new Function('n', lines.join('\n').trim()); | ||
if (!test(fn, tests)) return null; | ||
return op_function ? fn : 'function(n) {\n ' + fn_body.join('\n ').trim() + '\n}'; | ||
if (opt['return_function']) return fn; | ||
fn_str = 'function(n) {\n ' + lines.join('\n ') + '\n}'; | ||
if (opt['minify']) fn_str = fn_str.replace(/\s+/g, '').replace(/{var/, '{var '); | ||
return fn_str; | ||
}; | ||
})(); |
{ | ||
"name": "make-plural", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Translates Unicode CLDR pluralization rules to executable JavaScript", | ||
@@ -5,0 +5,0 @@ "keywords": ["unicode", "CLDR", "i18n", "internationalization", "pluralization"], |
@@ -40,3 +40,3 @@ make-plural.js | ||
> sk = plurals.build('sk', true) | ||
> sk = plurals.build('sk', {'return_function':1}) | ||
[Function] | ||
@@ -60,6 +60,9 @@ | ||
### build(lc, op_function) | ||
### build(lc, opt) | ||
By default, returns a string representation of a function that takes a single | ||
argument `n` and returns its plural category for the given locale `lc`. If | ||
`op_function` is `true`, it returns an executable function instead. | ||
argument `n` and returns its plural category for the given locale `lc`. The | ||
optional `opt` object may contain the following members: | ||
* `return_function` -- if true, `build` returns an executable function of `n` | ||
rather than a string | ||
* `minify` -- if true, the string output of `build` is minified | ||
@@ -66,0 +69,0 @@ ### set_rules(cldr) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
71076
948
77