Skip to content

Commit 70f15d9

Browse files
committed
Improve documentation
1 parent c03364a commit 70f15d9

File tree

1 file changed

+37
-123
lines changed

1 file changed

+37
-123
lines changed

README.md

Lines changed: 37 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ 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'
3231

32+
writtenNumber(1234, {lang: 'fr'}); // => 'mille deux cent trente-quatre'
3333
writtenNumber(1234, {lang: 'es'}); // => 'mil doscientos treinta y cuatro'
3434
writtenNumber(1234, {lang: 'pt'}); // => 'mil duzentos e trinta e quatro'
3535
writtenNumber(1234, {lang: 'ar'}); // => 'ألف ومائتان وأربعة وثلاثون'
@@ -64,141 +64,55 @@ Currently supported languages are:
6464
| Indonesian | `id` |
6565

6666

67-
## Configure your own language
68-
Each language has it's own unique grammar exceptions. You can create your own
67+
## Contributing
68+
69+
### Configure your own language
70+
Each language has its own unique grammar exceptions. You can create your own
6971
language.json file in the folder "i18n" and give writtenNumber support for it. I
7072
don't think the current scheme and logic cover all the cases, but may be cover
7173
some.
7274

73-
##### useLongScale:
74-
'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.
75-
76-
##### baseSeparator:
77-
'String' that separates the base cardinal numbers.
78-
Example: 29 -> twenty`-`eight. Spanish uses the conector " y ".
79-
80-
##### unitSeparator:
81-
'String' that separates the units from the last base cardinal numbers.
82-
Example: 1234 -> one thousand two hundred **and** thirty-four
83-
84-
##### allSeparator:
85-
'String' that separates all cardinals, not only the last one.
86-
Example: 1125 -> ألف **و**مائة **و**خمسة **و**عشرون
87-
88-
##### base:
89-
Base cardinals numbers. Numbers that have unique names and are used to build others.
90-
91-
##### alternativeBase:
92-
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`.
93-
94-
```json
95-
"alternativeBase": {
96-
"feminine": {
97-
"1": "одна",
98-
"2": "дві"
99-
}
100-
}
101-
```
102-
103-
##### units:
104-
Number units.
105-
It can be:
106-
- String
107-
- Object normal flow. Give support to singular, dual, and plural units. English does not need this, but spanish does.
108-
```json
109-
{
110-
"singular": "millón",
111-
"plural": "millones"
112-
}
113-
```
114-
115-
- Object with `few` word form.
75+
The following parameters have been used for the currently available languages:
11676

117-
In some languages like Ukrainian, there are specific unit forms for values from 2 (including) to 4 (including). This forms can be specified with `few`.
11877

119-
```json
120-
{
121-
"singular": "мільйон",
122-
"few": "мільйони",
123-
"plural": "мільйонів",
124-
}
125-
```
126-
127-
- Object with `useAlternativeBase`.
128-
129-
Selects an `alternativeBase` name which this unit should prefer over the default `base` if possible.
130-
131-
```json
132-
{
133-
"singular": "тисяча",
134-
"few": "тисячі",
135-
"plural": "тисяч",
136-
"useAlternativeBase": "feminine"
137-
}
138-
```
78+
### Language parameters
13979

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 |
14090

141-
- Object with `useBaseInstead` exception.
91+
### Units parameters
14292

143-
In some languages like spanish and arabic, specific units like "ciento", use the base cardinal number instead.
93+
A `unit` can be:
94+
- A simple string. e.g. `"hundred"`
95+
- An Object with multiple parameters:
14496

145-
- Object with `useBaseException`: You can also specify with which unit (1 to 9) you don't
146-
want use the base cardinal instead and use the regular behaviour:
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` |
147112

148-
```json
149-
{
150-
"singular": "ciento",
151-
"useBaseInstead": true,
152-
"useBaseException": [1]
153-
}
154-
```
155-
- Object with `avoidPrefixException` exception:
156-
In some languages like spanish, specific units like "mil" does not use the base
157-
cardinal number prefix for unit 1.
158-
```json
159-
{
160-
"singular": "mil",
161-
"avoidPrefixException": [1]
162-
}
163-
```
164-
- Object with `avoidInNumberPlural` exception.
165-
In some languages like french, specific units like "cent" does not use the plural form inside of
166-
numbers wioth trailing numbers other than 0, for example "deux cents" and "deux cent trois".
167-
```json
168-
{
169-
"singular": "cent",
170-
"plural": "cents",
171-
"avoidInNumberPlural": true
172-
}
173-
```
174-
- Object with `restrictedPlural` boolean:
175-
If plural is used only for numbers from 3 to 10 , but the singular form is used if the number is older than 11.
176-
177-
- Object with `useSingularEnding` exception and `useFewEnding` exception.
178-
179-
In some languages like Ukrainian, singular form of the unit is also used for any values that end with 1 (21, 31, 14, ..., 101, ...) and "few" form of the unit is also used for any values that end with 2, 3 and 4 (22, 33, 44, ..., 104, ...). The `avoidEndingRules` exception provides values (1 to 999) where these rules must be ignored and the plural form must be used instead.
180-
181-
```json
182-
{
183-
"singular": "мільйон",
184-
"few": "мільйони",
185-
"plural": "мільйонів",
186-
"useSingularEnding": true,
187-
"useFewEnding": true,
188-
"avoidEndingRules": [11, 12, 13, 14, 111, 112, 113, 114, 211, 212, 213, 214, 311, 312, 313, 314, 411, 412, 413, 414, 511, 512, 513, 514, 611, 612, 613, 614, 711, 712, 713, 714, 811, 812, 813, 814, 911, 912, 913, 914]
189-
}
190-
```
191113

192-
##### unitExceptions:
193-
Sometimes grammar exceptions affect the base cardinal joined to the unit. You
194-
can set specific exceptions to any base cardinal number.
195-
Spanish example:
196-
```
197-
Without Exception (Wrong): 1232000 -> **uno** millón doscientos treinta y dos mil
198-
With Exception: 1232000 -> **un** millón doscientos treinta y dos mil
199-
```
200114

201-
## Contributing
115+
### Versioning
202116
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`.
203117

204118
## License

0 commit comments

Comments
 (0)