From 95694d53f09c8012fce18bc86defc4283cf19bde Mon Sep 17 00:00:00 2001 From: sliterok Date: Wed, 15 Nov 2017 19:30:20 +0500 Subject: [PATCH 1/3] General sign support --- src/numbers2words.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/numbers2words.js b/src/numbers2words.js index ed45cb7..1dbae08 100644 --- a/src/numbers2words.js +++ b/src/numbers2words.js @@ -86,7 +86,7 @@ T2W.prototype.toWords = function( number ){ }; } - return this.translate( this.tokenize(number, this._tokenLength)); + return this.translate( this.tokenize(number, this._tokenLength), Math.sign(number) > 0); }; /** From 24a6108372f77c49c5bad8cf158d3a874119c234 Mon Sep 17 00:00:00 2001 From: sliterok Date: Wed, 15 Nov 2017 19:32:08 +0500 Subject: [PATCH 2/3] en_US locale minus support --- src/locales/en_US.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/locales/en_US.js b/src/locales/en_US.js index 692cc8d..6c81420 100644 --- a/src/locales/en_US.js +++ b/src/locales/en_US.js @@ -16,7 +16,8 @@ T2W.EN_US.DICTIONARY = { tens :[ "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" ], hundred :"hundred", radix :["", "thousand", "million"], - delimiters :["-", "and"] + delimiters :["-", "and"], + signs :["minus"] }; /** @@ -40,7 +41,7 @@ T2W.EN_US.MAX_NUMBERS = 9; * @param {number} index * @return {string} */ -T2W.EN_US.prototype.translate = function( numbers ) { +T2W.EN_US.prototype.translate = function( numbers, sign ) { // Check max value if(numbers.length * T2W.EN_US.TOKEN_LENGTH > T2W.EN_US.MAX_NUMBERS){ @@ -60,6 +61,8 @@ T2W.EN_US.prototype.translate = function( numbers ) { words.unshift( this._getTrio( this.tokenize( numbers[idx], 1 ), idx, max)); } + if(sign === false) words.unshift( T2W.EN_US.DICTIONARY.signs[0] + " " ); + return words.join(""); }; From 8cbec6bd4901c08f1b414fb3479f29b5a291c966 Mon Sep 17 00:00:00 2001 From: sliterok Date: Wed, 15 Nov 2017 19:33:42 +0500 Subject: [PATCH 3/3] en_US locale number range change --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ac6988..315ab21 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ translator.toWords(1234) ##Now available locales - id_ID (0...999999999) - de_DE (0...999999999) - - en_US (0...999999999) + - en_US (-999999999...999999999) - cs_CZ (0...999999999) **You can implement your locale vocabulary**. For additional locale send pull request with locale file + tests.