You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
writtenNumber(1234, { lang:'vi' }); // => 'một ngàn hai trăm và ba mươi bốn'
86
-
```
87
-
88
-
### Indonesian Example
89
-
```javascript
90
-
var writtenNumber =require('written-number');
91
-
writtenNumber(1234, { lang:'id' }); // => 'seribu dua ratus tiga puluh empat'
92
-
```
93
-
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
51
+
| Language |`lang`|
52
+
|---------|--------|
53
+
| English |`en`|
54
+
| Portuguese (Brazil) |`pt`|
55
+
| Portuguese (Portugal) |`ptPT`|
56
+
| Spanish |`es`|
57
+
| French |`fr`|
58
+
| Esperanto |`eo`|
59
+
| Vietnamese |`vi`|
60
+
| Arabic |`ar`|
61
+
| Turkish |`tr`|
62
+
| English (Indian) |`enIndian`|
63
+
| Ukrainian |`uk`|
64
+
| Indonesian |`id`|
65
+
66
+
67
+
## Configure your own language
68
+
Each language has it's own unique grammar exceptions. You can create your own
69
+
language.json file in the folder "i18n" and give writtenNumber support for it. I
70
+
don't think the current scheme and logic cover all the cases, but may be cover
104
71
some.
105
72
106
73
##### 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.
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.
110
75
111
76
##### baseSeparator:
112
77
'String' that separates the base cardinal numbers.
@@ -116,31 +81,69 @@ Example: 29 -> twenty`-`eight. Spanish uses the conector " y ".
116
81
'String' that separates the units from the last base cardinal numbers.
117
82
Example: 1234 -> one thousand two hundred **and** thirty-four
118
83
84
+
##### allSeparator:
85
+
'String' that separates all cardinals, not only the last one.
86
+
Example: 1125 -> ألف **و**مائة **و**خمسة **و**عشرون
87
+
119
88
##### base:
120
-
Base cardinals numbers. Numbers that have unique names and are used to build
121
-
others.
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
+
```
122
102
123
103
##### units:
124
104
Number units.
125
105
It can be:
126
106
- String
127
-
128
-
- Object normal flow. Give support to singular and plural units. English does
129
-
not need this, but spanish does.
130
-
107
+
- Object normal flow. Give support to singular, dual, and plural units. English does not need this, but spanish does.
131
108
```json
132
109
{
133
110
"singular": "millón",
134
111
"plural": "millones"
135
112
}
136
113
```
137
114
115
+
- Object with `few` word form.
116
+
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`.
118
+
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
+
```
139
+
140
+
138
141
- Object with `useBaseInstead` exception.
139
-
In some languages like spanish, specific units like "ciento", use the base
140
-
cardinal number instead.
141
142
142
-
With `useBaseException` you can also specify with which unit (1 to 9) you don't
143
-
want use the base cardinal instead and use the regular behaviour.
143
+
In some languages like spanish and arabic, specific units like "ciento", use the base cardinal number instead.
144
+
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:
144
147
145
148
```json
146
149
{
@@ -149,115 +152,54 @@ want use the base cardinal instead and use the regular behaviour.
149
152
"useBaseException": [1]
150
153
}
151
154
```
152
-
153
-
- Object with `avoidPrefixException` exception.
154
-
155
+
- Object with `avoidPrefixException` exception:
155
156
In some languages like spanish, specific units like "mil" does not use the base
156
157
cardinal number prefix for unit 1.
157
-
158
158
```json
159
159
{
160
160
"singular": "mil",
161
161
"avoidPrefixException": [1]
162
162
}
163
163
```
164
-
165
-
166
164
- Object with `avoidInNumberPlural` exception.
167
-
168
165
In some languages like french, specific units like "cent" does not use the plural form inside of
169
166
numbers wioth trailing numbers other than 0, for example "deux cents" and "deux cent trois".
170
-
171
167
```json
172
168
{
173
169
"singular": "cent",
174
170
"plural": "cents",
175
171
"avoidInNumberPlural": true
176
172
}
177
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.
178
176
179
-
##### unitExceptions:
180
-
Sometimes grammar exceptions affect the base cardinal joined to the unit. You
181
-
can set specific exceptions to any base cardinal number.
177
+
- Object with `useSingularEnding` exception and `useFewEnding` exception.
182
178
183
-
Spanish example:
184
-
185
-
```
186
-
Without Exception (Wrong): 1232000 -> **uno** millón doscientos treinta y dos mil
187
-
```
188
-
189
-
```
190
-
With Exception: 1232000 -> **un** millón doscientos treinta y dos mil
191
-
```
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.
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
254
199
```
255
200
256
201
## Contributing
257
-
Do your changes and submit a PR. If you've write access and want to bump the
258
-
version, run `mversion [major|minor|patch] -m`. That'll bump both `bower.json`
259
-
and `package.json`.
202
+
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`.
260
203
261
204
## License
262
-
This code is licensed under the MIT license for Pedro Tacla Yamada. For more
263
-
information, please refer to the [LICENSE](/LICENSE) file.
205
+
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