make-plural
Advanced tools
Comparing version 1.1.4 to 1.2.0
{ | ||
"name": "make-plural", | ||
"version": "1.1.4", | ||
"version": "1.2.0", | ||
"description": "Translates Unicode CLDR pluralization rules to executable JavaScript", | ||
@@ -11,5 +11,5 @@ "keywords": ["unicode", "cldr", "i18n", "internationalization", "pluralization"], | ||
"bugs": { "url": "https://github.com/eemeli/make-plural.js/issues" }, | ||
"files": [ "bin/", "data/", "lib/" ], | ||
"files": [ "bin/", "data/", "make-plural.js" ], | ||
"bin": { "make-plural": "./bin/make-plural" }, | ||
"main": "lib/make-plural" | ||
"main": "make-plural" | ||
} |
@@ -6,3 +6,3 @@ make-plural | ||
[pluralization rules](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html) | ||
to executable JavaScript. | ||
to executable JavaScript functions. | ||
@@ -12,14 +12,17 @@ | ||
``` | ||
```sh | ||
npm install make-plural | ||
``` | ||
or | ||
```sh | ||
git clone https://github.com/eemeli/make-plural.js.git | ||
``` | ||
## Usage: Node | ||
## Usage | ||
```js | ||
> plurals = require('make-plural') | ||
> Plurals = require('make-plural') | ||
{ set_rules: [Function], build: [Function] } | ||
> console.log( plurals.build('fr') ) | ||
> console.log( Plurals.build('fr') ) | ||
function(n) { | ||
@@ -30,3 +33,3 @@ if (n >= 0 && n < 2) return 'one'; | ||
> console.log( plurals.build('sk') ) | ||
> console.log( Plurals.build('sk') ) | ||
function(n) { | ||
@@ -40,3 +43,3 @@ var s = String(n).split('.'), i = s[0], v0 = !s[1]; | ||
> sk = plurals.build('sk', {'return_function':1}) | ||
> sk = Plurals.build('sk', {'return_function':1}) | ||
[Function] | ||
@@ -57,3 +60,32 @@ | ||
## Usage: Web | ||
```html | ||
<script src="path/to/make-plural.js"></script> | ||
<script> | ||
console.log( Plurals.build('sk') ); | ||
var sk = Plurals.build('sk', {'return_function':1}); | ||
console.log( '1: ' + sk(1) + ', 3.0: ' + sk(3.0) + | ||
', "1.0": ' + sk('1.0') + ', "0": ' + sk('0') ); | ||
</script> | ||
``` | ||
With outputs: | ||
``` | ||
function(n) { | ||
var s = String(n).split('.'), i = s[0], v0 = !s[1]; | ||
if (n == 1 && v0) return 'one'; | ||
if ((i >= 2 && i <= 4) && v0) return 'few'; | ||
if (!v0) return 'many'; | ||
return 'other'; | ||
} | ||
1: one, 3.0: few, "1.0": many, "0": other | ||
``` | ||
If `request()` isn't available, the CLDR rules are fetched automatically by the | ||
first call to `Plurals.build()` using a synchronous `XMLHttpRequest` for the | ||
JSON file at the location `data/unicode-cldr-plural-rules.json` relative to the | ||
given `path/to/make-plural.js`. If that doesn't work for you, you should call | ||
`Plurals.set_rules(cldr)` before calling `Plurals.build()`. | ||
## Methods | ||
@@ -68,6 +100,6 @@ | ||
* `no_tests` — if true, the generated function is not verified by testing it | ||
with each of the example values included in the CLDR rules | ||
with each of the example values included in the CLDR rules | ||
* `quiet` — if true, no output is reported to `console.error` on error | ||
* `return_function` — if true, `build` returns an executable function of `n` | ||
rather than a string | ||
rather than a string | ||
@@ -80,3 +112,7 @@ ### set_rules(cldr) | ||
If called within a context where `request()` isn't available and `cldr` is a | ||
string, it's taken as the URL of the JSON file that'll be fetched and parsed | ||
using a synchronous `XMLHttpRequest`. | ||
## Dependencies | ||
@@ -83,0 +119,0 @@ |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
74614
981
116