Skip to content

Commit

Permalink
fix: convert یکصد to number in WordsToNumber function
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-master committed Jun 22, 2018
1 parent 132a7ed commit 3540b48
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 135 deletions.
1 change: 0 additions & 1 deletion dist/index.esm.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions dist/index.min.js

This file was deleted.

6 changes: 3 additions & 3 deletions dist/modules/NumberToWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
numberToWord[900] = "نه صد";

/**
* [toWords, Convert Numbers to Persian Text]
* @param {[type]} number
* @return {[type]}
* toWords, Convert Numbers to Persian Text
* @param {String} number
* @return {Number|String}
*/
var toWords = function toWords(number) {
var unit = 100;
Expand Down
1 change: 1 addition & 0 deletions dist/modules/WordsToNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@

this.adjective = {
صد: 100,
یکصد: 100,
دویست: 200,
سیصد: 300,
چهارصد: 400,
Expand Down
2 changes: 1 addition & 1 deletion dist/modules/WordsToNumber.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions dist/index.esm.js → dist/persian-tools.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/persian-tools.esm.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions dist/index.js → dist/persian-tools.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/persian-tools.umd.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/persian-tools.umd.min.js

Large diffs are not rendered by default.

176 changes: 88 additions & 88 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
{
"name": "persian-tools",
"version": "0.0.2",
"description": "An anthology of a variety of tools for Persian language in javascript",
"main": "dist/index.min.js",
"scripts": {
"test": "jest",
"lint": "eslint src test scripts",
"lint:fix": "npm run lint -- --fix",
"build": "node scripts/build.js",
"build:esm": "rollup -c scripts/rollup.config.esm.js",
"build:umd": "rollup -c scripts/rollup.config.umd.js",
"build:modules": "rollup -c scripts/rollup.config.modules.js",
"watch": "rollup -c scripts/rollup.config.umd.js --watch",
"release": "npm run build && npm run test && standard-version"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ali-master/persian-tools.git"
},
"files": [
"src",
"dist"
],
"keywords": [
"persian tools",
"number to persian words",
"persian words to number",
"Arabic numbers to Persian",
"Arabic numbers to English",
"English numbers to Persian",
"Persian numbers to English",
"verify iranian national id",
"verify iranian card-number"
],
"author": "Ali Torki <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/ali-master/persian-tools/issues"
},
"homepage": "https://github.com/ali-master/persian-tools#readme",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.3",
"babel-jest": "^23.0.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.7.0",
"chalk": "^2.4.1",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-standard": "^3.1.0",
"globby": "^8.0.1",
"jest-cli": "^23.1.0",
"prettier": "^1.13.5",
"prettier-eslint": "^8.8.1",
"rollup": "^0.60.7",
"rollup-plugin-babel": "^3.0.4",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-json": "^3.0.0",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-progress": "^0.4.0",
"rollup-plugin-uglify": "^4.0.0",
"shelljs": "^0.8.2",
"standard-version": "^4.4.0",
"uglify-es": "^3.3.9"
},
"jest": {
"transform": {
"^.+\\.js$": "babel-jest"
},
"testEnvironment": "node",
"modulePathIgnorePatterns": [
"dist/.*",
"src/.*"
],
"testPathIgnorePatterns": [
"/node_modules/",
"/dist/",
"/src/"
]
},
"dependencies": {}
"name": "persian-tools",
"version": "0.0.2",
"description": "An anthology of a variety of tools for Persian language in javascript",
"main": "dist/persian-tools.umd.min.js",
"scripts": {
"test": "jest",
"lint": "eslint src test scripts",
"lint:fix": "npm run lint -- --fix",
"build": "node scripts/build.js",
"build:esm": "rollup -c scripts/rollup.config.esm.js",
"build:umd": "rollup -c scripts/rollup.config.umd.js",
"build:modules": "rollup -c scripts/rollup.config.modules.js",
"watch": "rollup -c scripts/rollup.config.umd.js --watch",
"release": "npm run build && npm run test && standard-version"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ali-master/persian-tools.git"
},
"files": [
"src",
"dist"
],
"keywords": [
"persian tools",
"number to persian words",
"persian words to number",
"Arabic numbers to Persian",
"Arabic numbers to English",
"English numbers to Persian",
"Persian numbers to English",
"verify iranian national id",
"verify iranian card-number"
],
"author": "Ali Torki <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/ali-master/persian-tools/issues"
},
"homepage": "https://github.com/ali-master/persian-tools#readme",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.3",
"babel-jest": "^23.0.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.7.0",
"chalk": "^2.4.1",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-friendly-formatter": "^4.0.1",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-standard": "^3.1.0",
"globby": "^8.0.1",
"jest-cli": "^23.1.0",
"prettier": "^1.13.5",
"prettier-eslint": "^8.8.1",
"rollup": "^0.60.7",
"rollup-plugin-babel": "^3.0.4",
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-json": "^3.0.0",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-progress": "^0.4.0",
"rollup-plugin-uglify": "^4.0.0",
"shelljs": "^0.8.2",
"standard-version": "^4.4.0",
"uglify-es": "^3.3.9"
},
"jest": {
"transform": {
"^.+\\.js$": "babel-jest"
},
"testEnvironment": "node",
"modulePathIgnorePatterns": [
"dist/.*",
"src/.*"
],
"testPathIgnorePatterns": [
"/node_modules/",
"/dist/",
"/src/"
]
},
"dependencies": {}
}
4 changes: 2 additions & 2 deletions scripts/rollup.config.esm.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from "path";
import config, { dist } from "./rollup.config";
import config, { dist, name } from "./rollup.config";

export default config({
output: {
format: "es",
sourcemap: true,
file: path.resolve(dist, "index.esm.js")
file: path.resolve(dist, name + ".esm.js")
}
});
6 changes: 3 additions & 3 deletions scripts/rollup.config.umd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import config, { dist, minify } from "./rollup.config";
import config, { dist, name, minify } from "./rollup.config";

export default [
config({
Expand All @@ -8,15 +8,15 @@ export default [
extend: true,
sourcemap: true,
name: "persian-tools",
file: path.resolve(dist, "index.js")
file: path.resolve(dist, name + ".umd.js")
}
}),
config({
plugins: [minify()],
output: {
format: "umd",
name: "persian-tools-min",
file: path.resolve(dist, "index.min.js")
file: path.resolve(dist, name + ".umd.min.js")
}
})
];
7 changes: 1 addition & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
// Digits Converter
import {
digitsEnToFa,
digitsFaToEn,
digitsArToFa,
digitsArToEn
} from "./modules/digits";
import { digitsEnToFa, digitsFaToEn, digitsArToFa, digitsArToEn } from "./modules/digits";
// check and convert persian string
import isPersian from "./modules/isPersian";
import toPersianChars from "./modules/toPersianChars";
Expand Down
9 changes: 4 additions & 5 deletions src/modules/NumberToWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ numberToWord[800] = "هشت صد";
numberToWord[900] = "نه صد";

/**
* [toWords, Convert Numbers to Persian Text]
* @param {[type]} number
* @return {[type]}
* toWords, Convert Numbers to Persian Text
* @param {String} number
* @return {Number|String}
*/
const toWords = number => {
let unit = 100;
Expand All @@ -62,8 +62,7 @@ const toWords = number => {
result += numberToWord[number];
break;
} else {
result +=
numberToWord[Math.floor(number / unit) * unit] + " و ";
result += numberToWord[Math.floor(number / unit) * unit] + " و ";
number %= unit;
}
}
Expand Down
19 changes: 4 additions & 15 deletions src/modules/WordsToNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class WordsToNumber {

this.adjective = {
صد: 100,
یکصد: 100,
دویست: 200,
سیصد: 300,
چهارصد: 400,
Expand Down Expand Up @@ -79,11 +80,8 @@ class WordsToNumber {

let numbersConverted = this.compute(this.tokenize(words));

numbersConverted = addCommas
? addCommasFn(numbersConverted)
: numbersConverted;
numbersConverted =
digits === "fa" ? digitsEnToFa(numbersConverted) : numbersConverted;
numbersConverted = addCommas ? addCommasFn(numbersConverted) : numbersConverted;
numbersConverted = digits === "fa" ? digitsEnToFa(numbersConverted) : numbersConverted;

return numbersConverted;
}
Expand All @@ -93,16 +91,7 @@ class WordsToNumber {

let result = [];

words
.split(" ")
.forEach(
word =>
word === "و"
? ""
: !isNaN(+word)
? result.push(+word)
: result.push(word)
);
words.split(" ").forEach(word => (word === "و" ? "" : !isNaN(+word) ? result.push(+word) : result.push(word)));

return result;
}
Expand Down

0 comments on commit 3540b48

Please sign in to comment.