Skip to content

Rewrote to es6, fixed some minor issues #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-class-properties"]
}
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
templates/**/*
dist/
test/
22 changes: 22 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": [
"airbnb-base"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
}
},
"env": {
"browser": true
},
"rules": {
"no-restricted-properties": "off",
"import/prefer-default-export": "off",
"no-underscore-dangle": "off"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ build/Release
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

.idea
lcov
.tern-port
.DS_Store
Expand Down
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ node_js:
- 'node'
- '8'
- '6'
- '5'
- '4'
- '0.12'
- '0.11'
- '0.10'
after_script:
- npm i coveralls
- ./node_modules/coveralls/bin/coveralls.js < lcov
38 changes: 0 additions & 38 deletions Gruntfile.js

This file was deleted.

59 changes: 27 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,43 @@ bower install written-number

## Usage
```javascript
var writtenNumber = require('written-number');
writtenNumber(1234); // => 'one thousand two hundred and thirty-four'

writtenNumber.defaults.lang = 'es';
writtenNumber(4758); // => 'cuatro mil setecientos cincuenta y ocho'

writtenNumber(1234, {lang: 'fr'}); // => 'mille deux cent trente-quatre'
writtenNumber(1234, {lang: 'es'}); // => 'mil doscientos treinta y cuatro'
writtenNumber(1234, {lang: 'az'}); // => 'min iki yüz otuz dörd'
writtenNumber(1234, {lang: 'pt'}); // => 'mil duzentos e trinta e quatro'
writtenNumber(1234, {lang: 'ar'}); // => 'ألف ومائتان وأربعة وثلاثون'
writtenNumber(1234, {lang: 'eo'}); // => 'mil ducent tridek kvar'
writtenNumber(1234, {lang: 'vi'}); // => 'một ngàn hai trăm và ba mươi bốn'
writtenNumber(1234, {lang: 'uk'}); // => 'одна тисяча двісті тридцять чотири'
writtenNumber(1234, {lang: 'id'}); // => 'seribu dua ratus tiga puluh empat'
import {WrittenNumber} from 'written-number';
import {
EN,
Es
} from 'written-number/i18n';

const Converter = new WrittenNumber({language: EN});
Converter.convert(1234); // => 'one thousand two hundred and thirty-four'

Converter.setOptions({language: Es});
Converter.convert(4758); // => 'cuatro mil setecientos cincuenta y ocho'
```

## Options
- `noAnd` - Defaults to `false`. Determines whether to use a separator. The
separator is internationalized.
- `lang` - Could be `string` or `object`. Defaults to `'en'`. Determines which
language to use. An i18n configuration object may be passed to support
external language definitions.
- `language` - Could be `object`. No default values provided, you need
to pass one of languages from 'written-number/i18n' or define your own language file.

Currently supported languages are:

| Language | `lang` |
|---------|--------|
| English | `en` |
| Portuguese (Brazil) | `pt` |
| Portuguese (Portugal) | `ptPT` |
| Spanish | `es` |
| French | `fr` |
| Esperanto | `eo` |
| Vietnamese | `vi` |
| Arabic | `ar` |
| Azerbaijan | `az` |
| Turkish | `tr` |
| English (Indian) | `enIndian` |
| Ukrainian | `uk` |
| Indonesian | `id` |
| Russian | `ru` |
| English | `En` |
| Portuguese (Brazil) | `Pt` |
| Portuguese (Portugal) | `PtPT` |
| Spanish | `Es` |
| French | `Fr` |
| Esperanto | `Eo` |
| Vietnamese | `Vi` |
| Arabic | `Ar` |
| Azerbaijan | `Az` |
| Turkish | `Tr` |
| English (Indian) | `EnIndian` |
| Ukrainian | `Uk` |
| Indonesian | `Id` |
| Russian | `Ru` |


## Contributing
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Convert numbers to words - their written form",
"homepage": "https://yamadapc.github.io/js-written-number",
"main": "./dist/written-number.js",
"version": "0.11.0",
"version": "1.0.1-beta",
"keywords": [
"numbers",
"words",
Expand Down
147 changes: 147 additions & 0 deletions dist/i18n/ar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"useLongScale": false,
"baseSeparator": "",
"unitSeparator": "",
"allSeparator": "و",
"base": {
"0": "صفر",
"1": "واحد",
"2": "اثنان",
"3": "ثلاثة",
"4": "أربعة",
"5": "خمسة",
"6": "ستة",
"7": "سبعة",
"8": "ثمانية",
"9": "تسعة",

"10": "عشرة",
"11": "أحد عشر",
"12": "إثنا عشر",
"13": "ثلاثة عشر",
"14": "أربعة عشر",
"15": "خمسة عشر",
"16": "ستة عشر",
"17": "سبعة عشر",
"18": "ثمانية عشر",
"19": "تسعة عشر",

"20": "عشرون",
"21": "واحد وعشرون",
"22": "اثنان وعشرون",
"23": "ثلاثة وعشرون",
"24": "أربعة وعشرون",
"25": "خمسة وعشرون",
"26": "ستة وعشرون",
"27": "سبعة وعشرون",
"28": "ثمانية وعشرون",
"29": "تسعة وعشرون",

"30": "ثلاثون",
"31": "واحد وثلاثون",
"32": "اثنان وثلاثون",
"33": "ثلاثة وثلاثون",
"34": "أربعة وثلاثون",
"35": "خمسة وثلاثون",
"36": "ستة وثلاثون",
"37": "سبعة وثلاثون",
"38": "ثمانية وثلاثون",
"39": "تسعة وثلاثون",

"40": "أربعون",
"41": "واحد وأربعون",
"42": "اثنان وأربعون",
"43": "ثلاثة وأربعون",
"44": "أربعة وأربعون",
"45": "خمسة وأربعون",
"46": "ستة وأربعون",
"47": "سبعة وأربعون",
"48": "ثمانية وأربعون",
"49": "تسعة وأربعون",

"50": "خمسون",
"51": "واحد وخمسون",
"52": "اثنان وخمسون",
"53": "ثلاثة وخمسون",
"54": "أربعة وخمسون",
"55": "خمسة وخمسون",
"56": "ستة وخمسون",
"57": "سبعة وخمسون",
"58": "ثمانية وخمسون",
"59": "تسعة وخمسون",

"60": "ستون",
"61": "واحد وستون",
"62": "اثنان وستون",
"63": "ثلاثة وستون",
"64": "أربعة وستون",
"65": "خمسة وستون",
"66": "ستة وستون",
"67": "سبعة وستون",
"68": "ثمانية وستون",
"69": "تسعة وستون",

"70": "سبعون",
"71": "واحد وسبعون",
"72": "اثنان وسبعون",
"73": "ثلاثة وسبعون",
"74": "أربعة وسبعون",
"75": "خمسة وسبعون",
"76": "ستة وسبعون",
"77": "سبعة وسبعون",
"78": "ثمانية وسبعون",
"79": "تسعة وسبعون",

"80": "ثمانون",
"81": "واحد وثمانون",
"82": "اثنان وثمانون",
"83": "ثلاثة وثمانون",
"84": "أربعة وثمانون",
"85": "خمسة وثمانون",
"86": "ستة وثمانون",
"87": "سبعة وثمانون",
"88": "ثمانية وثمانون",
"89": "تسعة وثمانون",

"90": "تسعون",
"91": "واحد وتسعون",
"92": "اثنان وتسعون",
"93": "ثلاثة وتسعون",
"94": "أربعة وتسعون",
"95": "خمسة وتسعون",
"96": "ستة وتسعون",
"97": "سبعة وتسعون",
"98": "ثمانية وتسعون",
"99": "تسعة وتسعون",

"200": "مائتان",
"300": "ثلاثمائة",
"400": "أربعمائة",
"500": "خمسمائة",
"600": "ستمائة",
"700": "سبعمائة",
"800": "ثمانمائة",
"900": "تسعمائة"
},
"units" : [
{"singular":"مائة", "useBaseInstead": true, "useBaseException": [1]},
{"singular":"ألف", "dual":"ألفان", "plural":"آلاف", "restrictedPlural": true, "avoidPrefixException": [1, 2]},
{"singular":"مليون", "dual":"مليونان", "plural":"ملايين", "restrictedPlural": true, "avoidPrefixException": [1, 2]},
{"singular":"مليار", "dual":"ملياران", "plural":"ملايير", "restrictedPlural": true, "avoidPrefixException": [1, 2]},

{"singular":"تريليون", "avoidPrefixException": [1]},
{"singular":"كوادريليون", "avoidPrefixException": [1]},
{"singular":"كوينتليون", "avoidPrefixException": [1]},
{"singular":"سكستليون", "avoidPrefixException": [1]},
{"singular":"سبتيلليون", "avoidPrefixException": [1]},
{"singular":"أوكتيليون", "avoidPrefixException": [1]},
{"singular":"نونيلليون", "avoidPrefixException": [1]},
{"singular":"دشيليون", "avoidPrefixException": [1]},
{"singular":"أوندشيلليون", "avoidPrefixException": [1]},
{"singular":"دودشيليون", "avoidPrefixException": [1]},
{"singular":"تريدشيليون", "avoidPrefixException": [1]},
{"singular":"كواتوردشيليون", "avoidPrefixException": [1]},
{"singular":"كويندشيليون" , "avoidPrefixException": [1]}
],
"unitExceptions": {}
}
52 changes: 52 additions & 0 deletions dist/i18n/az.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"useLongScale": false,
"baseSeparator": " ",
"unitSeparator": "",
"base": {
"0": "sıfır",
"1": "bir",
"2": "iki",
"3": "üç",
"4": "dörd",
"5": "beş",
"6": "altı",
"7": "yeddi",
"8": "səkkiz",
"9": "doqquz",
"10": "on",
"20": "iyirmi",
"30": "otuz",
"40": "qırx",
"50": "əlli",
"60": "altmış",
"70": "yetmiş",
"80": "səksən",
"90": "doxsan"
},
"units" : [
{
"singular": "yüz",
"avoidPrefixException": [1]
},
{
"singular": "min",
"avoidPrefixException": [1]
},
"milyon",
"milyard",
"trilyon",
"kvadrilyon",
"kentilyon",
"sekstilyon",
"septilyon",
"oktilyon",
"nonilyon",
"desilyon",
"andesilyon",
"dodesilyon",
"tredesilyon",
"katordesilyon",
"kendesilyon"
],
"unitExceptions": []
}
Loading