make-plural 3.0.5 → 3.0.6

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.
Files changed (2) hide show
  1. package/package.json +1 -9
  2. package/README.md +0 -298
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "make-plural",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
4
4
  "description": "Translates Unicode CLDR pluralization rules to executable JavaScript",
5
5
  "keywords": [
6
6
  "unicode",
@@ -52,14 +52,6 @@
52
52
  "optionalDependencies": {
53
53
  "minimist": "^1.2.0"
54
54
  },
55
- "babel": {
56
- "presets": [
57
- "es2015"
58
- ],
59
- "plugins": [
60
- "add-module-exports"
61
- ]
62
- },
63
55
  "eslintConfig": {
64
56
  "parser": "babel-eslint",
65
57
  "env": {
package/README.md DELETED
@@ -1,298 +0,0 @@
1
- [![ISC License](https://img.shields.io/npm/l/make-plural.svg)](http://en.wikipedia.org/wiki/ISC_license)
2
- [![Build Status](https://travis-ci.org/eemeli/make-plural.js.svg?branch=master)](https://travis-ci.org/eemeli/make-plural.js)
3
-
4
-
5
- make-plural
6
- ===========
7
-
8
- Make-plural is a JavaScript module that translates [Unicode CLDR] pluralization
9
- [rules] to JavaScript functions. It includes both a live parser
10
- (`make-plural.js`) as well as the generated output for the latest edition of the
11
- CLDR (`plurals.js`); the latter is just over 2kB in size when minified &
12
- gzipped and covers 199 languages, so it's probably what you want unless you
13
- really know what you're doing.
14
-
15
- Make-plural is written in [ECMAScript 6] and transpiled using [Babel] and
16
- [Browserify] to CommonJS and AMD and ES6 module formats, as well as being
17
- suitable for use in browser environments.
18
-
19
- [Unicode CLDR]: http://cldr.unicode.org/
20
- [rules]: http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html
21
- [ECMAScript 6]: https://people.mozilla.org/~jorendorff/es6-draft.html
22
- [Babel]: https://babeljs.io/
23
- [Browserify]: http://browserify.org/
24
-
25
-
26
- ## Installation
27
-
28
- ```
29
- npm install make-plural
30
- ```
31
- _or_
32
- ```
33
- bower install make-plural
34
- ```
35
- _or_
36
- ```
37
- git clone https://github.com/eemeli/make-plural.js.git
38
- cd make-plural.js
39
- npm install
40
- make all
41
- ```
42
- _or_ download the latest release from
43
- [here](https://github.com/eemeli/make-plural.js/releases/latest)
44
-
45
-
46
- ## Precompiled plurals
47
-
48
- `plurals.js` contains an UMD module that can be included with node's `require`
49
- or AMD's `define`. In a browser environment, it will populate a global object
50
- `plurals`. Said module contains 199 functions (one per [language][rules]),
51
- each taking as a first parameter the value to be classified (either a number or
52
- a string), and as an optional second parameter, a boolean that if true, applies
53
- ordinal rather than cardinal rules.
54
-
55
- `pluralCategories.js` has a similar structure to `plurals.js`, but contains an
56
- array of the pluralization categories the cardinal and ordinal rules each
57
- language's pluralization function may output.
58
-
59
- If your language isn't directly included in either of the above, try removing
60
- any trailing parts that are separated from the stem by `-` or `_`. Note also
61
- that the [capitalization of locale codes] is lowercase for the language, but
62
- uppercase for the country, so for example the code for Portugese as spoken in
63
- Portugal is `pt-PT`.
64
-
65
- [capitalization of locale codes]: https://tools.ietf.org/html/bcp47#section-2.1.1
66
-
67
-
68
- ### Precompiled use: Node
69
-
70
- ```js
71
- > plurals = require('make-plural/plurals')
72
- { af: [Function],
73
- ak: [Function],
74
- am: [Function],
75
- // snip 193 lines...
76
- yo: [Function],
77
- zh: [Function],
78
- zu: [Function] }
79
-
80
- > plurals.en(1) // 1st param is the value
81
- 'one'
82
-
83
- > plurals.en(2)
84
- 'other'
85
-
86
- > plurals.en(2, true) // 2nd param, if true-ish, is for ordinal rules
87
- 'two'
88
-
89
- > console.log(plurals.en.toString())
90
- function (n, ord) {
91
- var s = String(n).split('.'), v0 = !s[1], t0 = Number(s[0]) == n,
92
- n10 = t0 && s[0].slice(-1), n100 = t0 && s[0].slice(-2);
93
- if (ord) return (n10 == 1 && n100 != 11) ? 'one'
94
- : (n10 == 2 && n100 != 12) ? 'two'
95
- : (n10 == 3 && n100 != 13) ? 'few'
96
- : 'other';
97
- return (n == 1 && v0) ? 'one' : 'other';
98
- }
99
-
100
- > pluralCategories = require('make-plural/pluralCategories')
101
- { af: { cardinal: [ 'one', 'other' ], ordinal: [ 'other' ] },
102
- ak: { cardinal: [ 'one', 'other' ], ordinal: [ 'other' ] },
103
- am: { cardinal: [ 'one', 'other' ], ordinal: [ 'other' ] },
104
- ar:
105
- { cardinal: [ 'zero', 'one', 'two', 'few', 'many', 'other' ],
106
- ordinal: [ 'other' ] },
107
- // snip 255 lines...
108
- zh: { cardinal: [ 'other' ], ordinal: [ 'other' ] },
109
- zu: { cardinal: [ 'one', 'other' ], ordinal: [ 'other' ] } }
110
- ```
111
-
112
- ### Precompiled use: Web
113
-
114
- ```html
115
- <script src="path/to/make-plural/plurals.js"></script>
116
- <script>
117
- var ru = plurals.ru
118
- console.log('1: ' + plurals.ru(1) + ', 3.0: ' + plurals.ru(3.0) +
119
- ', "1.0": ' + plurals.ru('1.0') + ', "0": ' + plurals.ru('0'));
120
- console.log(plurals.ru.toString());
121
- </script>
122
- ```
123
- With outputs:
124
- ```
125
- 1: one, 3.0: few, "1.0": other, "0": many
126
-
127
- function(n, ord) {
128
- var s = String(n).split('.'), i = s[0], v0 = !s[1], i10 = i.slice(-1),
129
- i100 = i.slice(-2);
130
- if (ord) return 'other';
131
- return (v0 && i10 == 1 && i100 != 11) ? 'one'
132
- : (v0 && (i10 >= 2 && i10 <= 4) && (i100 < 12
133
- || i100 > 14)) ? 'few'
134
- : (v0 && i10 == 0 || v0 && (i10 >= 5 && i10 <= 9)
135
- || v0 && (i100 >= 11 && i100 <= 14)) ? 'many'
136
- : 'other';
137
- }
138
- ```
139
-
140
- Note that with `plurals.min.js`, the stringified function would be rendered as:
141
- ```js
142
- function (e,t){var r=String(e).split("."),n=r[0],o=!r[1],c=n.slice(-1),
143
- i=n.slice(-2);return t?"other":o&&1==c&&11!=i?"one":o&&c>=2&&4>=c&&(12>i||i>14)?
144
- "few":o&&0==c||o&&c>=5&&9>=c||o&&i>=11&&14>=i?"many":"other"}
145
- ```
146
-
147
-
148
- ## Live compiler: `make-plural.js`
149
-
150
- ### MakePlural.load(cldr, ...)
151
- Loads CLDR rules from one or more `cldr` variables, each of which must be an
152
- object formatted like [this][json].
153
-
154
- No plural data is included by default, so you'll need to call this at least
155
- once, or otherwise fill the `MakePlural.rules` object.
156
-
157
- The default CLDR rules are included in make-plural, and may be loaded as seen
158
- in the examples below.
159
-
160
- [json]: https://github.com/unicode-cldr/cldr-core/blob/master/supplemental/plurals.json
161
-
162
-
163
- ### new MakePlural(lc, { cardinals, ordinals })
164
- Returns a function that takes an argument `n` and returns its plural category
165
- for the given locale `lc`.
166
-
167
- The returned function has an overloaded `toString(name)` method that may be
168
- used to generate a clean string representation of the function, with an
169
- optional name `name`.
170
-
171
- The optional second parameter may contain the following boolean members:
172
- * `cardinals` — if true, rules for cardinal values (1 day, 2 days, etc.) are
173
- included
174
- * `ordinals` — if true, rules for ordinal values (1st, 2nd, etc.) are included
175
-
176
- If both `cardinals` and `ordinals` are true, the returned function takes a
177
- second parameter `ord`. Then, if `ord` is true, the function will return the
178
- ordinal rather than cardinal category applicable to `n` in locale `lc`.
179
-
180
- If the second parameter is undefined, the values are taken from
181
- `MakePlural.cardinals` (default `true`) and `MakePlural.ordinals` (default
182
- `false`).
183
-
184
-
185
- ### Live use: Node
186
-
187
- ```js
188
- > MakePlural = require('make-plural/make-plural').load(
189
- ... require('make-plural/data/plurals.json'),
190
- ... require('make-plural/data/ordinals.json'))
191
- { [Function: MakePlural]
192
- cardinals: true,
193
- ordinals: false,
194
- rules:
195
- { cardinal:
196
- { af: [Object],
197
- ak: [Object],
198
- am: [Object],
199
- // snip 193 lines...
200
- yo: [Object],
201
- zh: [Object],
202
- zu: [Object] },
203
- ordinal:
204
- { af: [Object],
205
- am: [Object],
206
- ar: [Object],
207
- // snip 78 lines...
208
- vi: [Object],
209
- zh: [Object],
210
- zu: [Object] } } }
211
-
212
- > sk = new MakePlural('sk') // Note: not including ordinals by default
213
- { [Function]
214
- _obj:
215
- { lc: 'sk',
216
- cardinals: true,
217
- ordinals: false,
218
- categories: { cardinal: [Object], ordinal: [] },
219
- parser: { v0: 1, i: 1 },
220
- tests: { obj: [Circular], ordinal: {}, cardinal: [Object] },
221
- fn: [Circular] },
222
- categories: { cardinal: [ 'one', 'few', 'many', 'other' ], ordinal: [] },
223
- test: [Function],
224
- toString: [Function] }
225
-
226
- > sk(1)
227
- 'one'
228
-
229
- > sk(3.0)
230
- 'few'
231
-
232
- > sk('1.0')
233
- 'many'
234
-
235
- > sk('0')
236
- 'other'
237
-
238
- > console.log(sk.toString())
239
- function(n) {
240
- var s = String(n).split('.'), i = s[0], v0 = !s[1];
241
- return (i == 1 && v0 ) ? 'one'
242
- : ((i >= 2 && i <= 4) && v0 ) ? 'few'
243
- : (!v0 ) ? 'many'
244
- : 'other';
245
- }
246
- ```
247
-
248
- `make-plural.js` may also be used in browser environments; see `test/index.html`
249
- for an example of its use.
250
-
251
-
252
- ## CLI Usage
253
-
254
- ```sh
255
- $ ./bin/make-plural > plurals.js
256
-
257
- $ ./bin/make-plural fr
258
- function fr(n, ord) {
259
- if (ord) return (n == 1) ? 'one' : 'other';
260
- return (n >= 0 && n < 2) ? 'one' : 'other';
261
- }
262
-
263
- $ ./bin/make-plural --locale fr --value 1.5
264
- one
265
-
266
- $ ./bin/make-plural 1.5 -l fr --ordinal
267
- other
268
- ```
269
-
270
- Please see the source of `src/index.js` for more details.
271
-
272
-
273
-
274
- ## Dependencies
275
-
276
- Make-plural has no required runtime dependencies. CLDR plural rule data is
277
- included in JSON format; make-plural supports the [LDML Language Plural Rules]
278
- as used in CLDR release 24 and later.
279
-
280
- The CLI binary `bin/make-plural` does use [minimist] as an argument parser, but
281
- that is not required for any other use.
282
-
283
- Using `MakePlural.load()`, you may make use of external sources of CLDR data.
284
- For example, the following works when using together with [cldr-data]:
285
- ```js
286
- > cldr = require('cldr-data');
287
- > MakePlural = require('make-plural/make-plural').load(
288
- cldr('supplemental/plurals'),
289
- cldr('supplemental/ordinals')
290
- );
291
- > en = new MakePlural('en');
292
- > en(3, true)
293
- 'few'
294
- ```
295
-
296
- [LDML Language Plural Rules]: http://unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules
297
- [minimist]: https://www.npmjs.com/package/minimist
298
- [cldr-data]: https://www.npmjs.org/package/cldr-data