Skip to content

Commit b037573

Browse files
authored
Merge pull request #62 from yamadapc/develop
Merge develop to master
2 parents 062bb90 + 70f15d9 commit b037573

File tree

10 files changed

+1052
-234
lines changed

10 files changed

+1052
-234
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22
node_js:
33
- 'node'
4+
- '8'
45
- '6'
56
- '5'
67
- '4'

README.md

Lines changed: 60 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Convert numbers to words - their written form.
1414
## Install
1515
With npm:
1616
```bash
17-
npm i --save written-number
17+
npm install --save written-number
1818
```
1919
With bower:
2020
```bash
@@ -26,9 +26,17 @@ bower install written-number
2626
var writtenNumber = require('written-number');
2727
writtenNumber(1234); // => 'one thousand two hundred and thirty-four'
2828

29-
writtenNumber(1234, {lang: 'fr'}); // => 'mille deux cent trente-quatre'
3029
writtenNumber.defaults.lang = 'es';
3130
writtenNumber(4758); // => 'cuatro mil setecientos cincuenta y ocho'
31+
32+
writtenNumber(1234, {lang: 'fr'}); // => 'mille deux cent trente-quatre'
33+
writtenNumber(1234, {lang: 'es'}); // => 'mil doscientos treinta y cuatro'
34+
writtenNumber(1234, {lang: 'pt'}); // => 'mil duzentos e trinta e quatro'
35+
writtenNumber(1234, {lang: 'ar'}); // => 'ألف ومائتان وأربعة وثلاثون'
36+
writtenNumber(1234, {lang: 'eo'}); // => 'mil ducent tridek kvar'
37+
writtenNumber(1234, {lang: 'vi'}); // => 'một ngàn hai trăm và ba mươi bốn'
38+
writtenNumber(1234, {lang: 'uk'}); // => 'одна тисяча двісті тридцять чотири'
39+
writtenNumber(1234, {lang: 'id'}); // => 'seribu dua ratus tiga puluh empat'
3240
```
3341

3442
## Options
@@ -52,93 +60,59 @@ Currently supported languages are:
5260
| Arabic | `ar` |
5361
| Turkish | `tr` |
5462
| English (Indian) | `enIndian` |
63+
| Ukrainian | `uk` |
64+
| Indonesian | `id` |
5565

5666

57-
```javascript
58-
var writtenNumber = require('written-number');
59-
writtenNumber(1234, {lang: 'es'}); // => 'mil doscientos treinta y cuatro'
60-
writtenNumber(1234, {lang: 'pt'}); // => 'mil duzentos e trinta e quatro'
61-
writtenNumber(1234, {lang: 'fr'}); // => 'mille deux cent trente-quatre'
62-
writtenNumber(1234, {lang: 'ar'}); // => 'ألف ومائتان وأربعة وثلاثون'
63-
writtenNumber(1234, {lang: 'eo'}); // => 'mil ducent tridek kvar'
64-
writtenNumber(1234, {lang: 'vi'}); // => 'một ngàn hai trăm và ba mươi bốn'
65-
```
66-
67-
## Configure your own language
68-
Each language has it's own unique grammar exceptions. You can create your own language.json file in the folder "i18n" and give writtenNumber support for it. I don't think the current scheme and logic cover all the cases, but may be cover some.
69-
70-
##### useLongScale:
71-
'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.
72-
73-
##### baseSeparator:
74-
'String' that separates the base cardinal numbers.
75-
Example: 29 -> twenty`-`eight. Spanish uses the conector " y ".
76-
77-
##### unitSeparator:
78-
'String' that separates the units from the last base cardinal numbers.
79-
Example: 1234 -> one thousand two hundred **and** thirty-four
80-
81-
##### allSeparator:
82-
'String' that separates all cardinals, not only the last one.
83-
Example: 1125 -> ألف **و**مائة **و**خمسة **و**عشرون
84-
85-
##### base:
86-
Base cardinals numbers. Numbers that have unique names and are used to build others.
87-
88-
##### units:
89-
Number units.
90-
It can be:
91-
- String
92-
- Object normal flow. Give support to singular, dual, and plural units. English does not need this, but spanish does.
93-
```json
94-
{
95-
"singular": "millón",
96-
"plural": "millones"
97-
}
98-
```
99-
- Object with `useBaseInstead` exception.
100-
In some languages like spanish and arabic, specific units like "ciento", use the base cardinal number instead.
101-
- Object with `useBaseException`: You can also specify with which unit (1 to 9) you don't
102-
want use the base cardinal instead and use the regular behaviour:
103-
```json
104-
{
105-
"singular": "ciento",
106-
"useBaseInstead": true,
107-
"useBaseException": [1]
108-
}
109-
```
110-
- Object with `avoidPrefixException` exception:
111-
In some languages like spanish, specific units like "mil" does not use the base
112-
cardinal number prefix for unit 1.
113-
```json
114-
{
115-
"singular": "mil",
116-
"avoidPrefixException": [1]
117-
}
118-
```
119-
- Object with `avoidInNumberPlural` exception.
120-
In some languages like french, specific units like "cent" does not use the plural form inside of
121-
numbers wioth trailing numbers other than 0, for example "deux cents" and "deux cent trois".
122-
```json
123-
{
124-
"singular": "cent",
125-
"plural": "cents",
126-
"avoidInNumberPlural": true
127-
}
128-
```
129-
- Object with `restrictedPlural` boolean:
130-
If plural is used only for numbers from 3 to 10 , but the singular form is used if the number is older than 11.
131-
132-
##### unitExceptions:
133-
Sometimes grammar exceptions affect the base cardinal joined to the unit. You
134-
can set specific exceptions to any base cardinal number.
135-
Spanish example:
136-
```
137-
Without Exception (Wrong): 1232000 -> **uno** millón doscientos treinta y dos mil
138-
With Exception: 1232000 -> **un** millón doscientos treinta y dos mil
139-
```
140-
14167
## Contributing
68+
69+
### Configure your own language
70+
Each language has its own unique grammar exceptions. You can create your own
71+
language.json file in the folder "i18n" and give writtenNumber support for it. I
72+
don't think the current scheme and logic cover all the cases, but may be cover
73+
some.
74+
75+
The following parameters have been used for the currently available languages:
76+
77+
78+
### Language parameters
79+
80+
| Parameter | Type | Description | Examples |
81+
|-----------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
82+
| `useLongScale` | boolean | Indicates if it uses [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. |
83+
| `baseSeparator` | string | Separates the base cardinal numbers. | 29 -> twenty`-`eight. Spanish uses the connector " y " |
84+
| `unitSeparator` | string | Separates the units from the last base cardinal numbers. | 1234 -> one thousand two hundred **and** thirty-four |
85+
| `allSeparator` | string | Separates all cardinals, not only the last one. | 1125 -> ألف **و**مائة **و**خمسة **و**عشرون |
86+
| `base` | Object | Base cardinals numbers. Numbers that have unique names and are used to build others. | |
87+
| `alternativeBase` | Object | Alternative versions of base cardinals numbers for usage with specific units. These bases will be treated as an extension for the default `base`. | ``` "alternativeBase": { "feminine": {"1":"одна","2":"дві"} } ``` |
88+
| `units` | Array | A list of number units (string or Object). Gives support to singular, dual an plural units. Check the Object parameters below. | |
89+
| `unitExceptions` | Object | Sometimes grammar exceptions affect the base cardinal joined to the unit. You can set specific exceptions to any base cardinal number. | Converting 1232000 in Spanish: Without Exception (Wrong): -> **uno** millón doscientos treinta y dos mil With Exception: -> **un** millón doscientos treinta y dos mil |
90+
91+
### Units parameters
92+
93+
A `unit` can be:
94+
- A simple string. e.g. `"hundred"`
95+
- An Object with multiple parameters:
96+
97+
| Unit parameter | Description | e.g. of languages |
98+
|------------------------|--------------------------------------------------------------------------------------------------------|-------------------|
99+
| `singular` | One element. | All |
100+
| `dual` | Two elements. | `ar` |
101+
| `plural` | Two or more elements. (or 3 or more) | All |
102+
| `few` | Between 2 and 4 including. | `uk` |
103+
| `useAlternativeBase` | Overwrites default `base`. | `uk` |
104+
| `useBaseInstead` | Use the base cardinal number instead. | `es`,`hu`,`pt` |
105+
| `useBaseException` | Specify with which unit (1 to 9) you don't want to use the base, and instead use the regular behavior. | `es`,`hu`,`pt` |
106+
| `avoidPrefixException` | Units not using the base cardinal number prefix for unit 1. | `id`,`tr`,`it` |
107+
| `avoidInNumberPlural` | Units not using the plural form with trailing numbers other than 0. | `fr` |
108+
| `restrictedPlural` | Plural only for 3 to 10. Singular if >= 11. | `ar` |
109+
| `useSingularEnding` | Use singular form for numbers ending with 1. | `uk` |
110+
| `useFewEnding` | Use _few_ form for numbers ending with 2, 3 or 4. | `uk` |
111+
| `avoidEndingRules` | Plural form used instead of `useSingularEnding` and `useFewEnding` | `uk` |
112+
113+
114+
115+
### Versioning
142116
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`.
143117

144118
## License

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Convert numbers to words - their written form",
44
"homepage": "https://yamadapc.github.io/js-written-number",
55
"main": "./dist/written-number.js",
6-
"version": "0.8.1",
6+
"version": "0.9.0",
77
"keywords": [
88
"numbers",
99
"words",

0 commit comments

Comments
 (0)