Skip to content

Commit

Permalink
fix: lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mastermunj committed Apr 24, 2020
1 parent a1bb8da commit 74bfb9c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
coverage
**/*.d.ts
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ module.exports = {
commonjs: true,
browser: true,
},
rules: {
'prefer-template': 'error',
}
};
4 changes: 2 additions & 2 deletions __tests__/en-IN.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ testNegativeIntegers.map((row, i) => {
return;
}
row[0] = -row[0];
row[1] = 'Minus ' + row[1];
row[1] = `Minus ${row[1]}`;
});

describe('Test Negative Integers with options = {}', () => {
Expand All @@ -45,7 +45,7 @@ describe('Test Negative Integers with options = {}', () => {

const testIntegersWithCurrency = cloneDeep(testIntegers);
testIntegersWithCurrency.map((row) => {
row[1] = row[1] + ` Rupees Only`
row[1] = `${row[1]} Rupees Only`;
});

describe('Test Integers with options = { currency: true }', () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/en-US.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ testNegativeIntegers.map((row, i) => {
return;
}
row[0] = -row[0];
row[1] = 'Minus ' + row[1];
row[1] = `Minus ${row[1]}`;
});

describe('Test Negative Integers with options = {}', () => {
Expand All @@ -45,7 +45,7 @@ describe('Test Negative Integers with options = {}', () => {

const testIntegersWithCurrency = cloneDeep(testIntegers);
testIntegersWithCurrency.map((row) => {
row[1] = row[1] + ` Dollars Only`
row[1] = `${row[1]} Dollars Only`;
});

describe('Test Integers with options = { currency: true }', () => {
Expand Down
15 changes: 7 additions & 8 deletions src/to-words.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export class ToWords {
// Extra check for isFloat to overcome 1.999 rounding off to 2
isFloat = this.isFloat(number);
const isNumberZero = number >= 0 && number < 1;
const split = (number + '').split('.');
let words = this.convertInternal(Number(split[0]), options) + ` ${locale.currency.plural}`;
const split = (number.toString()).split('.');
let words = `${this.convertInternal(Number(split[0]), options)} ${locale.currency.plural}`;

if (isNumberZero && options.ignoreZeroCurrency) {
words = '';
Expand All @@ -85,12 +85,12 @@ export class ToWords {
if (!isNumberZero || !options.ignoreZeroCurrency) {
wordsWithDecimal += ` ${locale.texts.and} `;
}
wordsWithDecimal += this.convertInternal(Number(split[1]) * Math.pow(10, 2 - split[1].length), options) + ` ${locale.currency.fractionalUnit.plural}`;
wordsWithDecimal += `${this.convertInternal(Number(split[1]) * Math.pow(10, 2 - split[1].length), options)} ${locale.currency.fractionalUnit.plural}`;
}
const isEmpty = words.length <= 0 && wordsWithDecimal.length <= 0;
return (!isEmpty && isNegativeNumber ? `${locale.texts.minus} ` : '') + words + wordsWithDecimal + (!isEmpty ? ` ${locale.texts.only}` : '');
} else {
const split = (number + '').split('.');
const split = (number.toString()).split('.');

const words = this.convertInternal(Number(split[0]), options);
let wordsWithDecimal = '';
Expand Down Expand Up @@ -126,16 +126,15 @@ export class ToWords {
words += match.value;
number -= match.number;
if (number > 0) {
words += ' ' + this.convertInternal(number, options);
words += ` ${this.convertInternal(number, options)}`;
}
} else {
const quotient = Math.floor(number / match.number);
const remainder = number % match.number;
if (remainder > 0) {
return this.convertInternal(quotient, options) + ' '
+ match.value + ' ' + this.convertInternal(remainder, options);
return `${this.convertInternal(quotient, options)} ${match.value} ${this.convertInternal(remainder, options)}`
} else {
return this.convertInternal(quotient, options) + ' ' + match.value;
return `${this.convertInternal(quotient, options)} ${match.value}`;
}
}
return words;
Expand Down

0 comments on commit 74bfb9c

Please sign in to comment.