Socket
Socket
Sign inDemoInstall

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 1.1.4 to 1.2.0

make-plural.js

6

package.json
{
"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

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