Skip to content

Commit 9203212

Browse files
authored
Merge branch 'develop' into master
2 parents fa047ea + 062bb90 commit 9203212

File tree

6 files changed

+409
-263
lines changed

6 files changed

+409
-263
lines changed

README.md

Lines changed: 47 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
- - -
1212
Convert numbers to words - their written form.
1313

14-
## Install with npm
15-
14+
## Install
15+
With npm:
1616
```bash
1717
npm i --save written-number
1818
```
19-
20-
## Install with bower
21-
19+
With bower:
2220
```bash
2321
bower install written-number
2422
```
@@ -27,6 +25,10 @@ bower install written-number
2725
```javascript
2826
var writtenNumber = require('written-number');
2927
writtenNumber(1234); // => 'one thousand two hundred and thirty-four'
28+
29+
writtenNumber(1234, {lang: 'fr'}); // => 'mille deux cent trente-quatre'
30+
writtenNumber.defaults.lang = 'es';
31+
writtenNumber(4758); // => 'cuatro mil setecientos cincuenta y ocho'
3032
```
3133

3234
## Options
@@ -36,77 +38,43 @@ writtenNumber(1234); // => 'one thousand two hundred and thirty-four'
3638
language to use. An i18n configuration object may be passed to support
3739
external language definitions.
3840

39-
## Internationalization
4041
Currently supported languages are:
41-
- English `lang = "en"`
42-
- Portuguese (Brazil) `lang = "pt"`
43-
- Portuguese (Portugal) `lang = "ptPT"`
44-
- Spanish `lang = "es"`
45-
- French `lang = "fr"`
46-
- Esperanto `lang = "eo"`
47-
- Vietnamese `lang = "vi"`
48-
- Turkish `lang = "tr"`
49-
- English (Indian) `lang = "enIndian"`
50-
- Ukrainian `lang = "uk"`
51-
52-
### Spanish Example
53-
```javascript
54-
var writtenNumber = require('written-number');
55-
writtenNumber(1234, { lang: 'es' }); // => 'mil doscientos treinta y cuatro'
56-
```
5742

58-
```javascript
59-
var writtenNumber = require('written-number');
60-
writtenNumber.defaults.lang = 'es';
61-
writtenNumber(4758); // => 'cuatro mil setecientos cincuenta y ocho'
62-
```
43+
| Language | `lang` |
44+
|---------|--------|
45+
| English | `en` |
46+
| Portuguese (Brazil) | `pt` |
47+
| Portuguese (Portugal) | `ptPT` |
48+
| Spanish | `es` |
49+
| French | `fr` |
50+
| Esperanto | `eo` |
51+
| Vietnamese | `vi` |
52+
| Arabic | `ar` |
53+
| Turkish | `tr` |
54+
| English (Indian) | `enIndian` |
55+
| Ukrainian | `uk` |
6356

64-
### Portuguese (Brazil) Example
65-
```javascript
66-
var writtenNumber = require('written-number');
67-
writtenNumber(1234, { lang: 'pt' }); // => 'mil duzentos e trinta e quatro'
68-
```
69-
70-
### French Example
71-
```javascript
72-
var writtenNumber = require('written-number');
73-
writtenNumber(1234, { lang: 'fr' }); // => 'mille deux cent trente-quatre'
74-
```
75-
76-
### Esperanto Example
77-
```javascript
78-
var writtenNumber = require('written-number');
79-
writtenNumber(1234, { lang: 'eo' }); // => 'mil ducent tridek kvar'
80-
```
81-
82-
### Vietnamese Example
83-
```javascript
84-
var writtenNumber = require('written-number');
85-
writtenNumber(1234, { lang: 'vi' }); // => 'một ngàn hai trăm và ba mươi bốn'
86-
```
8757

88-
### Ukrainian Example
8958
```javascript
9059
var writtenNumber = require('written-number');
60+
writtenNumber(1234, {lang: 'es'}); // => 'mil doscientos treinta y cuatro'
61+
writtenNumber(1234, {lang: 'pt'}); // => 'mil duzentos e trinta e quatro'
62+
writtenNumber(1234, {lang: 'fr'}); // => 'mille deux cent trente-quatre'
63+
writtenNumber(1234, {lang: 'ar'}); // => 'ألف ومائتان وأربعة وثلاثون'
64+
writtenNumber(1234, {lang: 'eo'}); // => 'mil ducent tridek kvar'
65+
writtenNumber(1234, {lang: 'vi'}); // => 'một ngàn hai trăm và ba mươi bốn'
9166
writtenNumber(1234, { lang: 'uk' }); // => 'одна тисяча двісті тридцять чотири'
9267
```
9368

94-
## Options
95-
Property | Value
96-
-------------- | -------------
97-
noAnd | false
98-
lang | 'en'
99-
100-
### Configure your own language
101-
Each language has it's own unique grammar exceptions. You can create your own
102-
language.json file in the folder "i18n" and give writtenNumber support for it. I
103-
don't think the current scheme and logic cover all the cases, but may be cover
69+
70+
## Configure your own language
71+
Each language has it's own unique grammar exceptions. You can create your own
72+
language.json file in the folder "i18n" and give writtenNumber support for it. I
73+
don't think the current scheme and logic cover all the cases, but may be cover
10474
some.
10575

10676
##### useLongScale:
107-
'Boolean' that indicates if it use [long or short
108-
scale](http://en.wikipedia.org/wiki/Long_and_short_scales). This differs the
109-
meaning of the words `billion`, `trillion` and so on.
77+
'Boolean' that indicates if it use [long or short scale](http://en.wikipedia.org/wiki/Long_and_short_scales). This differs the meaning of the words `billion`, `trillion` and so on.
11078

11179
##### baseSeparator:
11280
'String' that separates the base cardinal numbers.
@@ -116,9 +84,12 @@ Example: 29 -> twenty`-`eight. Spanish uses the conector " y ".
11684
'String' that separates the units from the last base cardinal numbers.
11785
Example: 1234 -> one thousand two hundred **and** thirty-four
11886

87+
##### allSeparator:
88+
'String' that separates all cardinals, not only the last one.
89+
Example: 1125 -> ألف **و**مائة **و**خمسة **و**عشرون
90+
11991
##### base:
120-
Base cardinals numbers. Numbers that have unique names and are used to build
121-
others.
92+
Base cardinals numbers. Numbers that have unique names and are used to build others.
12293

12394
##### alternativeBase:
12495
Alternative versions of base cardinals numbers for usage with specific units (ex. thousands in Ukrainian use feminine form of base cardinal numbers). These bases will be treated as an extension for the default `base`.
@@ -136,10 +107,7 @@ Alternative versions of base cardinals numbers for usage with specific units (ex
136107
Number units.
137108
It can be:
138109
- String
139-
140-
- Object normal flow. Give support to singular and plural units. English does
141-
not need this, but spanish does.
142-
110+
- Object normal flow. Give support to singular, dual, and plural units. English does not need this, but spanish does.
143111
```json
144112
{
145113
"singular": "millón",
@@ -174,13 +142,13 @@ Selects an `alternativeBase` name which this unit should prefer over the default
174142
}
175143
```
176144

145+
177146
- Object with `useBaseInstead` exception.
178147

179-
In some languages like spanish, specific units like "ciento", use the base
180-
cardinal number instead.
148+
In some languages like spanish and arabic, specific units like "ciento", use the base cardinal number instead.
181149

182-
With `useBaseException` you can also specify with which unit (1 to 9) you don't
183-
want use the base cardinal instead and use the regular behaviour.
150+
- Object with `useBaseException`: You can also specify with which unit (1 to 9) you don't
151+
want use the base cardinal instead and use the regular behaviour:
184152

185153
```json
186154
{
@@ -189,32 +157,27 @@ want use the base cardinal instead and use the regular behaviour.
189157
"useBaseException": [1]
190158
}
191159
```
192-
193-
- Object with `avoidPrefixException` exception.
194-
160+
- Object with `avoidPrefixException` exception:
195161
In some languages like spanish, specific units like "mil" does not use the base
196162
cardinal number prefix for unit 1.
197-
198163
```json
199164
{
200165
"singular": "mil",
201166
"avoidPrefixException": [1]
202167
}
203168
```
204-
205-
206169
- Object with `avoidInNumberPlural` exception.
207-
208170
In some languages like french, specific units like "cent" does not use the plural form inside of
209171
numbers wioth trailing numbers other than 0, for example "deux cents" and "deux cent trois".
210-
211172
```json
212173
{
213174
"singular": "cent",
214175
"plural": "cents",
215176
"avoidInNumberPlural": true
216177
}
217178
```
179+
- Object with `restrictedPlural` boolean:
180+
If plural is used only for numbers from 3 to 10 , but the singular form is used if the number is older than 11.
218181

219182
- Object with `useSingularEnding` exception and `useFewEnding` exception.
220183

@@ -234,85 +197,14 @@ In some languages like Ukrainian, singular form of the unit is also used for any
234197
##### unitExceptions:
235198
Sometimes grammar exceptions affect the base cardinal joined to the unit. You
236199
can set specific exceptions to any base cardinal number.
237-
238200
Spanish example:
239-
240201
```
241202
Without Exception (Wrong): 1232000 -> **uno** millón doscientos treinta y dos mil
242-
```
243-
244-
```
245203
With Exception: 1232000 -> **un** millón doscientos treinta y dos mil
246204
```
247205

248-
### English configuration example
249-
```json
250-
{
251-
"useLongScale": false,
252-
"baseSeparator": "-",
253-
"unitSeparator": "and ",
254-
"base": {
255-
"0": "zero",
256-
"1": "one",
257-
"2": "two",
258-
"3": "three",
259-
...
260-
"90": "ninety"
261-
},
262-
"units" : [
263-
"hundred",
264-
"thousand",
265-
"million",
266-
"billion",
267-
"trillion",
268-
...
269-
"quindecillion"
270-
],
271-
"unitExceptions": []
272-
}
273-
```
274-
275-
### Spanish configuration example
276-
```json
277-
{
278-
"useLongScale": true,
279-
"baseSeparator": " y ",
280-
"unitSeparator": "",
281-
"base": {
282-
"0": "cero",
283-
"1": "uno",
284-
"2": "dos",
285-
"3": "tres",
286-
...
287-
"1000": "mil"
288-
},
289-
"unitExceptions": {
290-
"1": "un"
291-
},
292-
"units" : [
293-
{
294-
"singular": "ciento",
295-
"useBaseInstead": true,
296-
"useBaseException": [1]
297-
},
298-
{
299-
"singular": "mil",
300-
"avoidPrefixException": [1]
301-
},
302-
{
303-
"singular": "millón",
304-
"plural": "millones"
305-
},
306-
...
307-
]
308-
}
309-
```
310-
311206
## Contributing
312-
Do your changes and submit a PR. If you've write access and want to bump the
313-
version, run `mversion [major|minor|patch] -m`. That'll bump both `bower.json`
314-
and `package.json`.
207+
Do your changes and submit a PR. If you've write access and want to bump the version, run `mversion [major|minor|patch] -m`. That'll bump both `bower.json` and `package.json`.
315208

316209
## License
317-
This code is licensed under the MIT license for Pedro Tacla Yamada. For more
318-
information, please refer to the [LICENSE](/LICENSE) file.
210+
This code is licensed under the MIT license for Pedro Tacla Yamada. For more information, please refer to the [LICENSE](/LICENSE) file.

0 commit comments

Comments
 (0)