Comparing version 2.0.3 to 2.1.0
module.exports = { | ||
root: true, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
}, | ||
plugins: [ | ||
'@typescript-eslint', | ||
'jest', | ||
], | ||
@@ -11,11 +16,14 @@ extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:jest/recommended', | ||
'plugin:jest/style', | ||
'prettier', | ||
'prettier/@typescript-eslint', | ||
'plugin:prettier/recommended', | ||
], | ||
env: { | ||
es6: true, | ||
node: true, | ||
commonjs: true, | ||
browser: true, | ||
}, | ||
rules: { | ||
'prefer-template': 'error', | ||
browser: false, | ||
} | ||
}; |
@@ -5,2 +5,9 @@ # Changelog | ||
## [2.1.0](https://github.com/mastermunj/to-words/compare/v2.0.3...v2.1.0) (2020-05-01) | ||
### Features | ||
* improve .gitignore ([2e406d9](https://github.com/mastermunj/to-words/commit/2e406d90ced857b9c73cbff98c810172c26e9dd4)) | ||
### [2.0.3](https://github.com/mastermunj/to-words/compare/v2.0.2...v2.0.3) (2020-04-25) | ||
@@ -7,0 +14,0 @@ |
@@ -1,1 +0,1 @@ | ||
export * from './src/to-words'; | ||
export * from './src/to-words'; |
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
collectCoverage: true, | ||
coverageDirectory: 'coverage', | ||
coverageProvider: 'v8', | ||
verbose: true, | ||
roots: [ | ||
'<rootDir>', | ||
], | ||
roots: ['<rootDir>'], | ||
testMatch: [ | ||
@@ -9,0 +10,0 @@ '**/__tests__/**/*.+(ts|tsx|js)', |
{ | ||
"name": "to-words", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"description": "Converts numbers (including decimal points) into words & currency.", | ||
"main": "dist/to-words.js", | ||
"scripts": { | ||
"clean": "rimraf dist/*", | ||
"build": "npm run clean && tsc", | ||
"lint": "eslint --ext .js,.ts .", | ||
"lint-fix": "eslint --ext .js,.ts . --fix", | ||
"test": "jest --detectOpenHandles --coverage" | ||
}, | ||
"keywords": [ | ||
@@ -26,7 +18,31 @@ "to words", | ||
], | ||
"engines": { | ||
"node": ">=10.0.0" | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mastermunj/to-words.git" | ||
}, | ||
"license": "MIT", | ||
"author": "Munjal Dhamecha", | ||
"license": "MIT", | ||
"main": "dist/to-words.js", | ||
"scripts": { | ||
"build": "npm run clean && tsc --noEmitOnError", | ||
"build:watch": "npm run build -- --watch", | ||
"clean": "rimraf dist coverage", | ||
"lint": "eslint --ext .js,.ts .", | ||
"lint:fix": "npm run lint -- --fix", | ||
"release": "standard-version", | ||
"release:mock": "npm run release -- --dry-run", | ||
"test": "jest --detectOpenHandles --coverage", | ||
"test:watch": "npm run test -- --watch" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged", | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS" | ||
} | ||
}, | ||
"lint-staged": { | ||
"package.json": [ | ||
"sort-package-json" | ||
] | ||
}, | ||
"dependencies": {}, | ||
@@ -38,13 +54,18 @@ "devDependencies": { | ||
"@types/lodash": "^4.14.150", | ||
"@types/node": "^13.13.2", | ||
"@types/node": "^13.13.4", | ||
"@types/source-map-support": "^0.5.1", | ||
"@typescript-eslint/eslint-plugin": "^2.29.0", | ||
"@typescript-eslint/parser": "^2.29.0", | ||
"@typescript-eslint/eslint-plugin": "^2.30.0", | ||
"@typescript-eslint/parser": "^2.30.0", | ||
"eslint": "^6.8.0", | ||
"eslint-plugin-import": "^2.20.2", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-jest": "^23.8.2", | ||
"eslint-plugin-prettier": "^3.1.3", | ||
"husky": "^4.2.5", | ||
"jest": "^25.4.0", | ||
"jest": "^25.5.3", | ||
"lint-staged": "^10.2.2", | ||
"lodash": "^4.17.15", | ||
"prettier": "^2.0.5", | ||
"rimraf": "^3.0.2", | ||
"source-map-support": "^0.5.18", | ||
"sort-package-json": "^1.42.1", | ||
"source-map-support": "^0.5.19", | ||
"standard-version": "^7.1.0", | ||
@@ -54,11 +75,5 @@ "ts-jest": "^25.4.0", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mastermunj/to-words.git" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS" | ||
} | ||
"engines": { | ||
"node": ">=10.0.0" | ||
} | ||
} |
@@ -56,2 +56,2 @@ import { LocaleInterface } from './locale.interface'; | ||
]; | ||
} | ||
} |
@@ -58,2 +58,2 @@ import { LocaleInterface } from './locale.interface'; | ||
]; | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
export interface LocaleInterface { | ||
@@ -3,0 +2,0 @@ currency: { |
@@ -18,6 +18,6 @@ import { LocaleInterface } from './locales/locale.interface'; | ||
converterOptions?: ConverterOptions; | ||
} | ||
}; | ||
interface ConstructorOf<T> { | ||
new(): T; | ||
new (): T; | ||
} | ||
@@ -30,10 +30,13 @@ | ||
constructor(options: ToWordsOptions = {}) { | ||
this.options = Object.assign({ | ||
localeCode: 'en-IN', | ||
converterOptions: DefaultConverterOptions, | ||
}, options); | ||
this.options = Object.assign( | ||
{ | ||
localeCode: 'en-IN', | ||
converterOptions: DefaultConverterOptions, | ||
}, | ||
options, | ||
); | ||
} | ||
private getLocaleClass(): ConstructorOf<LocaleInterface> { | ||
return (require(`./locales/${this.options.localeCode}`)).Locale; | ||
return require(`./locales/${this.options.localeCode}`).Locale; | ||
} | ||
@@ -45,3 +48,3 @@ | ||
const LocaleClass = this.getLocaleClass(); | ||
this.locale = new LocaleClass; | ||
this.locale = new LocaleClass(); | ||
} catch (e) { | ||
@@ -69,3 +72,3 @@ throw new Error(`Unknown Locale "${this.options.localeCode}"`); | ||
const isNegativeNumber = (number < 0); | ||
const isNegativeNumber = number < 0; | ||
if (isNegativeNumber) { | ||
@@ -80,4 +83,6 @@ number = Math.abs(number); | ||
const isNumberZero = number >= 0 && number < 1; | ||
const split = (number.toString()).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 | ||
}`; | ||
@@ -93,8 +98,16 @@ if (isNumberZero && options.ignoreZeroCurrency) { | ||
} | ||
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}` : ''); | ||
return ( | ||
(!isEmpty && isNegativeNumber ? `${locale.texts.minus} ` : '') + | ||
words + | ||
wordsWithDecimal + | ||
(!isEmpty ? ` ${locale.texts.only}` : '') | ||
); | ||
} else { | ||
const split = (number.toString()).split('.'); | ||
const split = number.toString().split('.'); | ||
@@ -117,3 +130,7 @@ const words = this.convertInternal(Number(split[0]), options); | ||
const isEmpty = words.length <= 0 && wordsWithDecimal.length <= 0; | ||
return (!isEmpty && isNegativeNumber ? `${locale.texts.minus} ` : '') + words + wordsWithDecimal; | ||
return ( | ||
(!isEmpty && isNegativeNumber ? `${locale.texts.minus} ` : '') + | ||
words + | ||
wordsWithDecimal | ||
); | ||
} | ||
@@ -127,2 +144,3 @@ } | ||
}); | ||
if (!match) { | ||
@@ -143,3 +161,5 @@ throw new Error(`Invalid Number "${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 { | ||
@@ -146,0 +166,0 @@ return `${this.convertInternal(quotient, options)} ${match.value}`; |
@@ -25,6 +25,8 @@ { | ||
"forceConsistentCasingInFileNames": true | ||
"forceConsistentCasingInFileNames": true, | ||
"resolveJsonModule": true | ||
}, | ||
"exclude": [ | ||
"node_modules", "**/*.spec.ts", "**/*.test.ts" | ||
"node_modules", | ||
"__tests__" | ||
], | ||
@@ -31,0 +33,0 @@ "include": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43852
27
1120
23