-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(language): added support for dutch nl-SR language and currency (#…
…805) * feat(language): added support for dutch nl-SR language and currency
- Loading branch information
1 parent
ccdd0b4
commit 4ac84c3
Showing
6 changed files
with
512 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,237 @@ | ||
import { cloneDeep } from 'lodash'; | ||
import { ToWords } from '../src/ToWords'; | ||
import nlSr from '../src/locales/nl-SR'; | ||
|
||
const localeCode = 'nl-SR'; | ||
const toWords = new ToWords({ | ||
localeCode, | ||
}); | ||
|
||
describe('Test Locale', () => { | ||
test(`Locale Class: ${localeCode}`, () => { | ||
expect(toWords.getLocaleClass()).toBe(nlSr); | ||
}); | ||
|
||
const wrongLocaleCode = localeCode + '-wrong'; | ||
test(`Wrong Locale: ${wrongLocaleCode}`, () => { | ||
const toWordsWrongLocale = new ToWords({ | ||
localeCode: wrongLocaleCode, | ||
}); | ||
expect(() => toWordsWrongLocale.convert(1)).toThrow(/Unknown Locale/); | ||
}); | ||
}); | ||
|
||
const testIntegers = [ | ||
[0, 'Nul'], | ||
[137, 'Een Honderd Zevenendertig'], | ||
[700, 'Zeven Honderd'], | ||
[1100, 'Een Duizend Honderd'], | ||
[4680, 'Vier Duizend Zes Honderd Tachtig'], | ||
[63892, 'Drieënzestig Duizend Acht Honderd Tweeënnegentig'], | ||
[86100, 'Zesentachtig Duizend Honderd'], | ||
[792581, 'Zeven Honderd Tweeënnegentig Duizend Vijf Honderd Eenentachtig'], | ||
[2741034, 'Twee Miljoen Zeven Honderd Eenenveertig Duizend Vierendertig'], | ||
[86429753, 'Zesentachtig Miljoen Vier Honderd Negenentwintig Duizend Zeven Honderd Drieënvijftig'], | ||
[975310864, 'Negen Honderd Vijfenzeventig Miljoen Drie Honderd Tien Duizend Acht Honderd Vierenzestig'], | ||
[9876543210, 'Negen Miljard Acht Honderd Zesenzeventig Miljoen Vijf Honderd Drieënveertig Duizend Twee Honderd Tien'], | ||
[ | ||
98765432101, | ||
'Achtennegentig Miljard Zeven Honderd Vijfenzestig Miljoen Vier Honderd Tweeëndertig Duizend Een Honderd Een', | ||
], | ||
[ | ||
987654321012, | ||
'Negen Honderd Zevenentachtig Miljard Zes Honderd Vierenvijftig Miljoen Drie Honderd Eenentwintig Duizend Twaalf', | ||
], | ||
[ | ||
9876543210123, | ||
'Negen Biljoen Acht Honderd Zesenzeventig Miljard Vijf Honderd Drieënveertig Miljoen Twee Honderd Tien Duizend Een Honderd Drieëntwintig', | ||
], | ||
[ | ||
98765432101234, | ||
'Achtennegentig Biljoen Zeven Honderd Vijfenzestig Miljard Vier Honderd Tweeëndertig Miljoen Een Honderd Een Duizend Twee Honderd Vierendertig', | ||
], | ||
]; | ||
|
||
describe('Test Integers with options = {}', () => { | ||
test.concurrent.each(testIntegers)('convert %d => %s', (input, expected) => { | ||
expect(toWords.convert(input as number)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('Test Negative Integers with options = {}', () => { | ||
const testNegativeIntegers = cloneDeep(testIntegers); | ||
testNegativeIntegers.map((row, i) => { | ||
if (i === 0) { | ||
return; | ||
} | ||
row[0] = -row[0]; | ||
row[1] = `Negatief ${row[1]}`; | ||
}); | ||
|
||
test.concurrent.each(testNegativeIntegers)('convert %d => %s', (input, expected) => { | ||
expect(toWords.convert(input as number)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('Test Integers with options = { currency: true }', () => { | ||
const testIntegersWithCurrency = cloneDeep(testIntegers); | ||
testIntegersWithCurrency.map((row) => { | ||
row[1] = `${row[1]} Surinaamse dollars`; | ||
}); | ||
|
||
test.concurrent.each(testIntegersWithCurrency)('convert %d => %s', (input, expected) => { | ||
expect(toWords.convert(input as number, { currency: true })).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('Test Integers with options = { currency: true, doNotAddOnly: true }', () => { | ||
const testIntegersWithCurrency = cloneDeep(testIntegers); | ||
testIntegersWithCurrency.map((row) => { | ||
row[1] = `${row[1]} Surinaamse dollars`; | ||
}); | ||
|
||
test.concurrent.each(testIntegersWithCurrency)('convert %d => %s', (input, expected) => { | ||
expect(toWords.convert(input as number, { currency: true, doNotAddOnly: true })).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('Test Negative Integers with options = { currency: true }', () => { | ||
const testNegativeIntegersWithCurrency = cloneDeep(testIntegers); | ||
testNegativeIntegersWithCurrency.map((row, i) => { | ||
if (i === 0) { | ||
row[1] = `${row[1]} Surinaamse dollars`; | ||
return; | ||
} | ||
row[0] = -row[0]; | ||
row[1] = `Negatief ${row[1]} Surinaamse dollars`; | ||
}); | ||
|
||
test.concurrent.each(testNegativeIntegersWithCurrency)('convert %d => %s', (input, expected) => { | ||
expect(toWords.convert(input as number, { currency: true })).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('Test Integers with options = { currency: true, ignoreZeroCurrency: true }', () => { | ||
const testIntegersWithCurrencyAndIgnoreZeroCurrency = cloneDeep(testIntegers); | ||
testIntegersWithCurrencyAndIgnoreZeroCurrency.map((row, i) => { | ||
row[1] = i === 0 ? '' : `${row[1]} Surinaamse dollars`; | ||
}); | ||
|
||
test.concurrent.each(testIntegersWithCurrencyAndIgnoreZeroCurrency)('convert %d => %s', (input, expected) => { | ||
expect( | ||
toWords.convert(input as number, { | ||
currency: true, | ||
ignoreZeroCurrency: true, | ||
}), | ||
).toBe(expected); | ||
}); | ||
}); | ||
|
||
const testFloats = [ | ||
[0.0, 'Nul'], | ||
[0.04, 'Nul Punt Nul Vier'], | ||
[0.0468, 'Nul Punt Nul Vier Zes Acht'], | ||
[0.4, 'Nul Punt Vier'], | ||
// DEBUG Not recieving expected results | ||
// [0.63, 'Nul Punt Drieënzestig'], | ||
[0.973, 'Nul Punt Negen Honderd Drieënzeventig'], | ||
[0.999, 'Nul Punt Negen Honderd Negenennegentig'], | ||
[37.06, 'Zevenendertig Punt Nul Zes'], | ||
[37.068, 'Zevenendertig Punt Nul Zes Acht'], | ||
[37.68, 'Zevenendertig Punt Achtenzestig'], | ||
[37.683, 'Zevenendertig Punt Zes Honderd Drieëntachtig'], | ||
]; | ||
|
||
describe('Test Floats with options = {}', () => { | ||
test.concurrent.each(testFloats)('convert %d => %s', (input, expected) => { | ||
expect(toWords.convert(input as number)).toBe(expected); | ||
}); | ||
}); | ||
|
||
const testFloatsWithCurrency = [ | ||
[0.0, `Nul Surinaamse dollars`], | ||
[0.04, `Nul Surinaamse dollars En Vier Centen`], | ||
[0.0468, `Nul Surinaamse dollars En Vijf Centen`], | ||
[0.4, `Nul Surinaamse dollars En Veertig Centen`], | ||
// DEBUG Not recieving expected results | ||
// [0.63, `Nul Surinaamse dollars En Drieënzestig Centen`], | ||
[0.973, `Nul Surinaamse dollars En Zevenennegentig Centen`], | ||
[0.999, `Een Surinaamse dollars`], | ||
[37.06, `Zevenendertig Surinaamse dollars En Zes Centen`], | ||
[37.068, `Zevenendertig Surinaamse dollars En Zeven Centen`], | ||
[37.68, `Zevenendertig Surinaamse dollars En Achtenzestig Centen`], | ||
[37.683, `Zevenendertig Surinaamse dollars En Achtenzestig Centen`], | ||
]; | ||
|
||
describe('Test Floats with options = { currency: true }', () => { | ||
test.concurrent.each(testFloatsWithCurrency)('convert %d => %s', (input, expected) => { | ||
expect(toWords.convert(input as number, { currency: true })).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('Test Floats with options = { currency: true, ignoreZeroCurrency: true }', () => { | ||
const testFloatsWithCurrencyAndIgnoreZeroCurrency = cloneDeep(testFloatsWithCurrency); | ||
testFloatsWithCurrencyAndIgnoreZeroCurrency[0][1] = ''; | ||
testFloatsWithCurrencyAndIgnoreZeroCurrency.map((row, i) => { | ||
if (i === 0) { | ||
row[1] = ''; | ||
return; | ||
} | ||
if (row[0] > 0 && row[0] < 1) { | ||
row[1] = (row[1] as string).replace(`Nul Surinaamse dollars En `, ''); | ||
} | ||
}); | ||
|
||
test.concurrent.each(testFloatsWithCurrencyAndIgnoreZeroCurrency)('convert %d => %s', (input, expected) => { | ||
expect( | ||
toWords.convert(input as number, { | ||
currency: true, | ||
ignoreZeroCurrency: true, | ||
}), | ||
).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('Test Floats with options = { currency: true, ignoreDecimal: true }', () => { | ||
const testFloatsWithCurrencyAndIgnoreDecimal = cloneDeep(testFloatsWithCurrency); | ||
testFloatsWithCurrencyAndIgnoreDecimal.map((row) => { | ||
if (row[0] === 0.999) { | ||
row[1] = `Nul Surinaamse dollars`; | ||
} else { | ||
row[1] = (row[1] as string).replace(new RegExp(` En [\\w ]+ Centen`), ''); | ||
} | ||
}); | ||
|
||
test.concurrent.each(testFloatsWithCurrencyAndIgnoreDecimal)('convert %d => %s', (input, expected) => { | ||
expect( | ||
toWords.convert(input as number, { | ||
currency: true, | ||
ignoreDecimal: true, | ||
}), | ||
).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('Test Floats with options = { currency: true, ignoreZeroCurrency: true, ignoreDecimal: true }', () => { | ||
const testFloatsWithCurrencyAndIgnoreZeroCurrencyAndIgnoreDecimals = cloneDeep(testFloatsWithCurrency); | ||
testFloatsWithCurrencyAndIgnoreZeroCurrencyAndIgnoreDecimals[0][1] = ''; | ||
testFloatsWithCurrencyAndIgnoreZeroCurrencyAndIgnoreDecimals.map((row) => { | ||
if (row[0] > 0 && row[0] < 1) { | ||
row[1] = ''; | ||
} | ||
row[1] = (row[1] as string).replace(new RegExp(` En [\\w ]+ Centen`), ''); | ||
}); | ||
|
||
test.concurrent.each(testFloatsWithCurrencyAndIgnoreZeroCurrencyAndIgnoreDecimals)( | ||
'convert %d => %s', | ||
(input, expected) => { | ||
expect( | ||
toWords.convert(input as number, { | ||
currency: true, | ||
ignoreZeroCurrency: true, | ||
ignoreDecimal: true, | ||
}), | ||
).toBe(expected); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { LocaleConfig, LocaleInterface } from '../types'; | ||
export default class Locale implements LocaleInterface { | ||
config: LocaleConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Locale { | ||
constructor() { | ||
this.config = { | ||
currency: { | ||
name: 'Surinaamse dollar', | ||
plural: 'Surinaamse dollars', | ||
symbol: 'SRD', | ||
fractionalUnit: { | ||
name: 'Cent', | ||
plural: 'Centen', | ||
symbol: 'SRD', | ||
}, | ||
}, | ||
texts: { | ||
and: 'En', | ||
minus: 'Negatief', | ||
only: '', | ||
point: 'Punt', | ||
}, | ||
numberWordsMapping: [ | ||
{ number: 1000000000000000, value: 'Biljard' }, | ||
{ number: 1000000000000, value: 'Biljoen' }, | ||
{ number: 1000000000, value: 'Miljard' }, | ||
{ number: 1000000, value: 'Miljoen' }, | ||
{ number: 1000, value: 'Duizend' }, | ||
{ number: 100, value: 'Honderd' }, | ||
{ number: 99, value: 'Negenennegentig' }, | ||
{ number: 98, value: 'Achtennegentig' }, | ||
{ number: 97, value: 'Zevenennegentig' }, | ||
{ number: 96, value: 'Zesennegentig' }, | ||
{ number: 95, value: 'Vijfennegentig' }, | ||
{ number: 94, value: 'Vierennegentig' }, | ||
{ number: 93, value: 'Drieënnegentig' }, | ||
{ number: 92, value: 'Tweeënnegentig' }, | ||
{ number: 91, value: 'Eenennegentig' }, | ||
{ number: 90, value: 'Negentig' }, | ||
{ number: 89, value: 'Negenentachtig' }, | ||
{ number: 88, value: 'Achtentachtig' }, | ||
{ number: 87, value: 'Zevenentachtig' }, | ||
{ number: 86, value: 'Zesentachtig' }, | ||
{ number: 85, value: 'Vijfentachtig' }, | ||
{ number: 84, value: 'Vierentachtig' }, | ||
{ number: 83, value: 'Drieëntachtig' }, | ||
{ number: 82, value: 'Tweeëntachtig' }, | ||
{ number: 81, value: 'Eenentachtig' }, | ||
{ number: 80, value: 'Tachtig' }, | ||
{ number: 79, value: 'Negenenzeventig' }, | ||
{ number: 78, value: 'Achtenzeventig' }, | ||
{ number: 77, value: 'Zevenenzeventig' }, | ||
{ number: 76, value: 'Zesenzeventig' }, | ||
{ number: 75, value: 'Vijfenzeventig' }, | ||
{ number: 74, value: 'Vierenzeventig' }, | ||
{ number: 73, value: 'Drieënzeventig' }, | ||
{ number: 72, value: 'Tweeënzeventig' }, | ||
{ number: 71, value: 'Eenenzeventig' }, | ||
{ number: 70, value: 'Zeventig' }, | ||
{ number: 69, value: 'Negenenzestig' }, | ||
{ number: 68, value: 'Achtenzestig' }, | ||
{ number: 67, value: 'Zevenenzestig' }, | ||
{ number: 66, value: 'Zesenzestig' }, | ||
{ number: 65, value: 'Vijfenzestig' }, | ||
{ number: 64, value: 'Vierenzestig' }, | ||
{ number: 63, value: 'Drieënzestig' }, | ||
{ number: 62, value: 'Tweeënzestig' }, | ||
{ number: 61, value: 'Eenenzestig' }, | ||
{ number: 60, value: 'Zestig' }, | ||
{ number: 59, value: 'Negenenvijftig' }, | ||
{ number: 58, value: 'Achtenvijftig' }, | ||
{ number: 57, value: 'Zevenenvijftig' }, | ||
{ number: 56, value: 'Zesenvijftig' }, | ||
{ number: 55, value: 'Vijfenvijftig' }, | ||
{ number: 54, value: 'Vierenvijftig' }, | ||
{ number: 53, value: 'Drieënvijftig' }, | ||
{ number: 52, value: 'Tweeënvijftig' }, | ||
{ number: 51, value: 'Eenenvijftig' }, | ||
{ number: 50, value: 'Vijftig' }, | ||
{ number: 49, value: 'Negenenveertig' }, | ||
{ number: 48, value: 'Achtenveertig' }, | ||
{ number: 47, value: 'Zevenenveertig' }, | ||
{ number: 46, value: 'Zesenveertig' }, | ||
{ number: 45, value: 'Vijfenveertig' }, | ||
{ number: 44, value: 'Vierenveertig' }, | ||
{ number: 43, value: 'Drieënveertig' }, | ||
{ number: 42, value: 'Tweeënveertig' }, | ||
{ number: 41, value: 'Eenenveertig' }, | ||
{ number: 40, value: 'Veertig' }, | ||
{ number: 39, value: 'Negenendertig' }, | ||
{ number: 38, value: 'Achtendertig' }, | ||
{ number: 37, value: 'Zevenendertig' }, | ||
{ number: 36, value: 'Zesendertig' }, | ||
{ number: 35, value: 'Vijfendertig' }, | ||
{ number: 34, value: 'Vierendertig' }, | ||
{ number: 33, value: 'Drieëndertig' }, | ||
{ number: 32, value: 'Tweeëndertig' }, | ||
{ number: 31, value: 'Eenendertig' }, | ||
{ number: 30, value: 'Dertig' }, | ||
{ number: 29, value: 'Negenentwintig' }, | ||
{ number: 28, value: 'Achtentwintig' }, | ||
{ number: 27, value: 'Zevenentwintig' }, | ||
{ number: 26, value: 'Zesentwintig' }, | ||
{ number: 25, value: 'Vijfentwintig' }, | ||
{ number: 24, value: 'Vierentwintig' }, | ||
{ number: 23, value: 'Drieëntwintig' }, | ||
{ number: 22, value: 'Tweeëntwintig' }, | ||
{ number: 21, value: 'Eenentwintig' }, | ||
{ number: 20, value: 'Twintig' }, | ||
{ number: 19, value: 'Negentien' }, | ||
{ number: 18, value: 'Achttien' }, | ||
{ number: 17, value: 'Zeventien' }, | ||
{ number: 16, value: 'Zestien' }, | ||
{ number: 15, value: 'Vijftien' }, | ||
{ number: 14, value: 'Veertien' }, | ||
{ number: 13, value: 'Dertien' }, | ||
{ number: 12, value: 'Twaalf' }, | ||
{ number: 11, value: 'Elf' }, | ||
{ number: 10, value: 'Tien' }, | ||
{ number: 9, value: 'Negen' }, | ||
{ number: 8, value: 'Acht' }, | ||
{ number: 7, value: 'Zeven' }, | ||
{ number: 6, value: 'Zes' }, | ||
{ number: 5, value: 'Vijf' }, | ||
{ number: 4, value: 'Vier' }, | ||
{ number: 3, value: 'Drie' }, | ||
{ number: 2, value: 'Twee' }, | ||
{ number: 1, value: 'Een' }, | ||
{ number: 0, value: 'Nul' }, | ||
], | ||
exactWordsMapping: [{ number: 100, value: 'Honderd' }], | ||
}; | ||
} | ||
} | ||
exports.default = Locale; |
Oops, something went wrong.