Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

to-words

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

to-words - npm Package Compare versions

Comparing version 1.0.3 to 2.0.0

__tests__/en-IN.spec.ts

55

package.json
{
"name": "to-words",
"version": "1.0.3",
"description": "Converts Numbers (including decimal points) into words for Indian style.",
"main": "index.js",
"version": "2.0.0",
"description": "Converts numbers (including decimal points) into words & currency.",
"main": "dist/to-words.js",
"scripts": {
"transpile": "babel src -d lib",
"lint": "eslint .",
"lint-fix": "eslint . --fix"
"clean": "rimraf dist/*",
"build": "npm run clean && tsc",
"lint": "eslint --ext .js,.ts .",
"lint-fix": "eslint --ext .js,.ts . --fix",
"test": "jest --detectOpenHandles --coverage"
},

@@ -14,5 +16,14 @@ "keywords": [

"number to words",
"Indian style number to words",
"Indian style number to words currency"
"number to words currency",
"international number to words",
"international number to words currency",
"i18n",
"converter",
"number",
"word",
"currency"
],
"engines": {
"node": ">=10.0.0"
},
"author": "Munjal Dhamecha",

@@ -22,7 +33,20 @@ "license": "MIT",

"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.6.0",
"eslint": "^4.7.1",
"eslint-config-google": "^0.9.1",
"eslint-config-standard": "^10.2.1"
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@types/jest": "^25.2.1",
"@types/lodash": "^4.14.150",
"@types/node": "^13.13.2",
"@types/source-map-support": "^0.5.1",
"@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0",
"eslint": "^6.8.0",
"eslint-plugin-import": "^2.20.2",
"husky": "^4.2.5",
"jest": "^25.4.0",
"lodash": "^4.17.15",
"rimraf": "^3.0.2",
"source-map-support": "^0.5.18",
"standard-version": "^7.1.0",
"ts-jest": "^25.4.0",
"typescript": "^3.8.3"
},

@@ -32,3 +56,8 @@ "repository": {

"url": "https://github.com/mastermunj/to-words.git"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}

@@ -13,29 +13,74 @@ # Number to Words

## Usage
Importing
```js
const { ToWords } = require('to-words');
```
OR
```js
Import { ToWords } from 'to-words';
```
Config Options
```js
yarn add to-words
const toWords = new ToWords({
localeCode: 'en-IN',
converterOptions: {
currency: true,
ignoreDecimal: false,
ignoreZeroCurrency: false,
}
});
```
Options can be set at instance level, or along with individual call to `convert` method.
```js
const toWords = new ToWords();
let words = toWords.convert(123); // words = One Hundred Twenty Three
## Usage
words = toWords.convert(123.45); // words = One Hundred Twenty Three Point Fourty Five
words = toWords.convert(123.045); // words = One Hundred Twenty Three Point Zero Four Five
```
*Note: When fractional part starts with zero, the digits after decimal points are converted into respective numbers individually*
To convert to currency
```js
let toWords = require('to-words');
let words = toWords(123); // words = One Hundred Twenty Three
const toWords = new ToWords();
let words = toWords.convert(452, { currency: true }); // words = Four Hundred Fifty Two Rupees Only
words = toWords(123.45); // words = One Hundred Twenty Three Point Fourty Five
words = toWords.convert(452.36, { currency: true }); // words = Four Hundred Fifty Two Rupees And Thirty Six Paise Only
```
To convert to currency
To discard fractional unit
```js
let toWords = require('to-words');
let words = toWords(452, {currency: true}); // words = Four Hundred Fifty Two Rupee Only
const toWords = new ToWords();
words = toWords(452.36, {currency: true}); // words = Four Hundred Fifty Two Rupee And Thirty Six Paise Only
let words = toWords.convert(452.36, { currency: true, ignoreDecimal: true }); // words = Four Hundred Fifty Two Rupees Only
```
To ignore major currency number when it's zero
## Inspiration
```js
const toWords = new ToWords();
let words = toWords.convert(0.572, { currency: true, ignoreZeroCurrency: true }); // words = Five Hundred Seventy Two Paise Only
```
## Options
| Option | Type | Default | Description |
| ------------- | ------------- | ------------- | ------------- |
| localeCode | string | 'en-IN' | Locale code for selecting i18n. Currently only `en-IN` & `en-US` are supported. Please open issue / PR if more needed. |
| currency | boolean | false | Whether the number to be converted into words written as currency. *Note: When currency:true, number will be rounded off to two decimals before converting to words* |
| ignoreDecimal | boolean | false | Whether to ignore fractional unit of number while converting into words. |
| ignoreZeroCurrency | boolean | false | Whether to ignore zero currency value while converting into words. |
## Inspiration for core logic
[https://stackoverflow.com/a/46221860](https://stackoverflow.com/a/46221860)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc