├── .eslintrc.json ├── .gitignore ├── .npmignore ├── .nycrc ├── .travis.yml ├── .vscode └── settings.json ├── README.md ├── bower.json ├── content └── thai-baht-text-cover-1.jpg ├── dist ├── thai-baht-text.js ├── thai-baht-text.js.map └── thai-baht-text.min.js ├── example ├── example_es5.js ├── example_es6.mjs └── example_umd │ ├── example_umd.js │ ├── index.html │ └── index_git.html ├── index.d.ts ├── package.json ├── src └── thai-baht-text.ts ├── stryker.config.json ├── tests └── unit │ └── thai-baht-text.spec.ts └── tsconfig.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "es6": true, 6 | "node": true 7 | }, 8 | "extends": "airbnb-base", 9 | "parserOptions": { 10 | "sourceType": "module" 11 | }, 12 | "rules": { 13 | "indent": [ 14 | "error", 15 | "tab" 16 | ], 17 | "no-tabs": 0, 18 | "linebreak-style": [ 19 | "error", 20 | "unix" 21 | ], 22 | "quotes": [ 23 | "error", 24 | "single" 25 | ], 26 | "semi": [ 27 | "error", 28 | "never" 29 | ], 30 | "no-console": 0, 31 | "max-len": [ 32 | "error", 33 | 200 34 | ] 35 | }, 36 | "globals": { 37 | "describe": true, 38 | "it": true 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | coverage 3 | .nyc_output 4 | 5 | # Log 6 | logs 7 | *.log 8 | 9 | # Package manager cahce 10 | yarn.lock 11 | package-lock.json 12 | 13 | old 14 | # Stryker 15 | .stryker-tmp 16 | reports 17 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | tests 3 | example 4 | content 5 | coverage 6 | node_modules 7 | old 8 | 9 | .vscode 10 | .eslintrc 11 | .nycrc 12 | .travis.yml 13 | .bower.json 14 | .nyc_output -------------------------------------------------------------------------------- /.nycrc: -------------------------------------------------------------------------------- 1 | { 2 | "include": [ 3 | "src/**/*.ts" 4 | ], 5 | "exclude": [ 6 | "tests/**/*.spec.js" 7 | ], 8 | "all": true, 9 | "sourceMap": true, 10 | "cache": false, 11 | "check-coverage": true, 12 | "extension": [".ts"] 13 | } 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "node" 4 | - "13" 5 | - "12" 6 | - "10" 7 | script: "npm test" 8 | before_script: 9 | - npm install -g codecov 10 | after_success: 11 | - codecov 12 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "workbench.colorCustomizations": { 3 | "activityBar.background": "#0F1F82", 4 | "titleBar.activeBackground": "#142BB5", 5 | "titleBar.activeForeground": "#F9F9FE" 6 | } 7 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Thai Baht Text JS 2 | 3 | [![NPM Download](https://img.shields.io/npm/dt/thai-baht-text.svg?style=flat-square)](https://www.npmjs.com/package/thai-baht-text) 4 | [![codecov-svg](https://img.shields.io/codecov/c/github/antronic/thai-baht-text-js.svg?style=flat-square)](https://codecov.io/gh/antronic/thai-baht-text-js) 5 | [![NPM Version](https://img.shields.io/npm/v/thai-baht-text.svg?style=flat-square)](https://www.npmjs.com/package/thai-baht-text) 6 | [![license-svg](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://opensource.org/licenses/MIT) 7 | ![ts](https://flat.badgen.net/badge/Built%20With/TypeScript/blue) 8 | 9 | ![Thai Baht Text JS](/content/thai-baht-text-cover-1.jpg) 10 | 11 | [Installation](#%EF%B8%8F-installation--%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B8%95%E0%B8%B4%E0%B8%94%E0%B8%95%E0%B8%B1%E0%B9%89%E0%B8%87) | [Usage](#%EF%B8%8F-usage--%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99) 12 | 13 | 14 | >### Now, Thai Baht text supports TypeScript 🎉!! 15 | 16 | Thai Baht Text JS converts numbers into Thai text. It provides flexibility as a cross-platform library for both browser and Node.js, written in TypeScript. 17 | 18 | ```Javascript 19 | > 10050 20 | // หนึ่งหมื่นห้าสิบบาทถ้วน 21 | ``` 22 | 23 | ## ⚒️ Installation | วิธีติดตั้ง 24 | ```bash 25 | npm install thai-baht-text --save 26 | ``` 27 | or 28 | ```bash 29 | yarn add thai-baht-text 30 | ``` 31 | 37 | 38 | 39 | ## ⚙️ Usage | วิธีการใช้งาน 40 | 41 | **[Live Demo](#)** (Coming soon) 42 | 43 | ### Node.js 44 | ```javascript 45 | // ----CommonJS---- 46 | const ThaiBahtText = require('thai-baht-text') // for CommonJS 47 | // ----ES Module---- 48 | import ThaiBahtText from 'thai-baht-text' 49 | 50 | let money = 10050 51 | let moneyText = ThaiBahtText(money) 52 | 53 | console.log(moneyText) 54 | // OUTPUT: หนึ่งหมื่นห้าสิบบาทถ้วน 55 | 56 | money = 12345678988888.50 57 | 58 | console.log(ThaiBahtText(money)) 59 | // OUTPUT: สิบสองล้านล้านสามแสนสี่หมื่นห้าพันหกร้อยเจ็ดสิบแปดล้านเก้าแสนแปดหมื่นแปดพันแปดร้อยแปดสิบแปดบาทห้าสิบสตางค์ 60 | ``` 61 | 62 | ### In the browser 63 | 64 | Since Thai Baht Text JS is built as a UMD module, you can simply add `thai-baht-text.min.js` as the `src` in a script tag in the browser without needing to install any additional libraries or polyfills. 65 | 66 | ```html 67 | ... 68 | 69 | 73 | 74 | ``` 75 | 76 | ### More infomation 77 | - **[CommonJS Example](/example/example_es5.js)** 78 | - **[ES Module Example](/example/example_es6.js)** 79 | - **[Browser version (UMD)](/example/example_umd)** 80 | 81 | ## 🧑‍💻 Development 82 | * `npm run test` to run all tests in this project 83 | * `npm run test:watch` to run all tests in watch mode. This allows us to develop/refactor code and get fast feedback to ensure we don't break anything. 84 | * `npm run buid` to compile and minify the project, then output it to the `dist` directory. 85 | 86 | 88 | 89 | ## 🗺️ Features plan 90 | - [ ] Return just only number text without unit 91 | - [ ] Convert to Thai number 92 | 93 | 94 | ## License 95 | The Thai-Baht-Text JS is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). 96 | 97 | ## ✉️ Dear you, 98 | If you find any bugs or have a feature request, please open a pull request or create an issue. 99 | 100 | 101 |


102 | ___ 103 | แปลง เลข เป็น บาทไทย, 104 | 105 | thai baht text javascript, 106 | 107 | thai baht text js 108 | that-baht-text.js 109 | that-baht-text.js typescript 110 | 111 | Convert number to Thai Baht as Text 112 | 113 | แปลงเลขให้เป็นหน่วยบาทไทย -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "thai-baht-text", 3 | "description": "Convert number to Thai Bath as Text", 4 | "main": "dist/thai-baht-text.min.js", 5 | "version": "2.0.0", 6 | "authors": [ 7 | "Jirachai Chansivanon " 8 | ], 9 | "license": "MIT", 10 | "keywords": [ 11 | "Thai", 12 | "baht", 13 | "text", 14 | "ThaiBaht", 15 | "ThaiBahtText", 16 | "Thai", 17 | "baht", 18 | "Thai", 19 | "baht", 20 | "text", 21 | "convert", 22 | "javascript", 23 | "convert", 24 | "thai", 25 | "baht", 26 | "typescript", 27 | "Thai baht text js", 28 | "แปลงเลขไทย", 29 | "แปลงเลขเงินไทย", 30 | "convert thai baht" 31 | ], 32 | "homepage": "https://github.com/antronic/thai-baht-text-js", 33 | "ignore": [ 34 | "**/.*", 35 | "node_modules", 36 | "bower_components", 37 | "test", 38 | "tests", 39 | "old" 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /content/thai-baht-text-cover-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antronic/thai-baht-text-js/29a653bf815cd7260010b7818d86cfa600f47d23/content/thai-baht-text-cover-1.jpg -------------------------------------------------------------------------------- /dist/thai-baht-text.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var MAX_POSITION = 6; 3 | var UNIT_POSITION = 0; 4 | var TEN_POSITION = 1; 5 | var PRIMARY_UNIT = 'บาท'; 6 | var SECONDARY_UNIT = 'สตางค์'; 7 | var WHOLE_NUMBER_TEXT = 'ถ้วน'; 8 | var NUMBER_TEXTS = ['ศูนย์', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า', 'สิบ']; 9 | var UNIT_TEXTS = ['สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน', 'ล้าน']; 10 | var getIntegerDigits = function (numberStringInput) { return parseInt(numberStringInput.split('.')[0], 10); }; 11 | var getFractionalDigits = function (numberStringInput) { return parseInt(numberStringInput.split('.')[1], 10); }; 12 | var hasFractionalDigits = function (numberInput) { return numberInput !== undefined && numberInput !== 0; }; 13 | function isZeroValue(input) { 14 | return parseInt("".concat(input), 10) === 0; 15 | } 16 | var isUnitPosition = function (position) { return position == UNIT_POSITION; }; 17 | var isTenPosition = function (position) { return position % MAX_POSITION == TEN_POSITION; }; 18 | var isMillionsPosition = function (position) { return (position >= MAX_POSITION && position % MAX_POSITION == 0); }; 19 | var isLastPosition = function (position, lengthOfDigits) { return position + 1 < lengthOfDigits; }; 20 | var reverseNumber = function (number) { 21 | var numberStr = number.toString(); 22 | return numberStr.split('').reverse().join(''); 23 | }; 24 | var getBathUnit = function (position, number) { 25 | var unitText = ''; 26 | if (!isUnitPosition(position)) { 27 | unitText = UNIT_TEXTS[Math.abs(position - 1) % MAX_POSITION]; 28 | } 29 | if (isZeroValue(number) && !isMillionsPosition(position)) { 30 | unitText = ''; 31 | } 32 | return unitText; 33 | }; 34 | var getBathText = function (position, number, lengthOfDigits) { 35 | var _number = parseInt(number, 10); 36 | var numberText = NUMBER_TEXTS[_number]; 37 | if (isZeroValue(_number)) { 38 | return ''; 39 | } 40 | if (isTenPosition(position) && _number == 1) { 41 | numberText = ''; 42 | } 43 | if (isTenPosition(position) && _number == 2) { 44 | numberText = 'ยี่'; 45 | } 46 | if (isMillionsPosition(position) && isLastPosition(position, lengthOfDigits) && _number == 1) { 47 | numberText = 'เอ็ด'; 48 | } 49 | if (lengthOfDigits == 2 && isLastPosition(position, lengthOfDigits) && _number == 1) { 50 | numberText = 'เอ็ด'; 51 | } 52 | if (lengthOfDigits > 1 && isUnitPosition(position) && _number == 1) { 53 | numberText = 'เอ็ด'; 54 | } 55 | return numberText; 56 | }; 57 | var convert = function (numberInput) { 58 | var numberReverse = reverseNumber(numberInput); 59 | var textOutput = ''; 60 | numberReverse.split('') 61 | .forEach(function (number, i) { 62 | textOutput = "".concat(getBathText(i, number, numberReverse.length)).concat(getBathUnit(i, number)).concat(textOutput); 63 | }); 64 | return textOutput; 65 | }; 66 | var parseFloatWithPrecision = function (number, precision) { 67 | if (precision === void 0) { precision = 2; } 68 | var numberFloatStr = parseFloat(number).toString().split('.'); 69 | var integerUnitStr = numberFloatStr[0]; 70 | var fractionalUnitStr = (numberFloatStr.length == 2) ? numberFloatStr[1].substring(0, precision) : '00'; 71 | return parseFloat("".concat(integerUnitStr, ".").concat(fractionalUnitStr)).toFixed(precision); 72 | }; 73 | var convertFullMoney = function (numberInput) { 74 | var numberStr = parseFloatWithPrecision(numberInput); 75 | var integerDigits = getIntegerDigits(numberStr); 76 | var fractionalDigits = getFractionalDigits(numberStr); 77 | var intTextOutput = convert(integerDigits); 78 | var textOutput = []; 79 | if (intTextOutput) { 80 | textOutput.push("".concat([intTextOutput, PRIMARY_UNIT].join(''))); 81 | } 82 | if (intTextOutput && !hasFractionalDigits(fractionalDigits)) { 83 | textOutput.push(WHOLE_NUMBER_TEXT); 84 | } 85 | if (hasFractionalDigits(fractionalDigits) && convert(fractionalDigits)) { 86 | textOutput.push("".concat([convert(fractionalDigits), SECONDARY_UNIT].join(''))); 87 | } 88 | return textOutput.join(''); 89 | }; 90 | function ThaiBahtText(input) { 91 | if (isNaN(Number("".concat(input)))) { 92 | throw new TypeError('Invalid input. Expected a number or a string representing a number.'); 93 | } 94 | return convertFullMoney("".concat(input)); 95 | } 96 | if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { 97 | module.exports = ThaiBahtText; 98 | exports.ThaiBahtText = ThaiBahtText; 99 | exports.THBText = ThaiBahtText; 100 | exports.default = ThaiBahtText; 101 | } 102 | else { 103 | window.ThaiBahtText = ThaiBahtText; 104 | window.THBText = window.ThaiBahtText; 105 | } 106 | //# sourceMappingURL=thai-baht-text.js.map -------------------------------------------------------------------------------- /dist/thai-baht-text.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"thai-baht-text.js","sourceRoot":"","sources":["../src/thai-baht-text.ts"],"names":[],"mappings":";AAOA,IAAM,YAAY,GAAG,CAAC,CAAA;AACtB,IAAM,aAAa,GAAG,CAAC,CAAA;AACvB,IAAM,YAAY,GAAG,CAAC,CAAA;AAEtB,IAAM,YAAY,GAAG,KAAK,CAAA;AAC1B,IAAM,cAAc,GAAG,QAAQ,CAAA;AAC/B,IAAM,iBAAiB,GAAG,MAAM,CAAA;AAEhC,IAAM,YAAY,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;AACvG,IAAM,UAAU,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;AAEjE,IAAM,gBAAgB,GAAG,UAAC,iBAAyB,IAAa,OAAA,QAAQ,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAA7C,CAA6C,CAAA;AAC7G,IAAM,mBAAmB,GAAG,UAAC,iBAAyB,IAAa,OAAA,QAAQ,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAA7C,CAA6C,CAAA;AAEhH,IAAM,mBA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AE,CAAC,CAAE,CAAC,CAAA;IAC7D,CAAC;IACD,IAAI,aAAa,IAAI,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC7D,UAAU,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IACnC,CAAC;IACD,IAAI,mBAAmB,CAAC,gBAAgB,CAAC,IAAI,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACxE,UAAU,CAAC,IAAI,CAAC,UAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAE,CAAC,CAAA;IAC3E,CAAC;IAED,OAAO,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAC3B,CAAC,CAAA;AAKD,SAAS,YAAY,CAAC,KAAsB;IAC3C,IAAI,KAAK,CAAC,MAAM,CAAC,UAAG,KAAK,CAAE,CAAC,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CAAC,qEAAqE,CAAC,CAAA;IAC3F,CAAC;IACD,OAAO,gBAAgB,CAAC,UAAG,KAAK,CAAE,CAAC,CAAA;AACpC,CAAC;AAOD,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,WAAW,EAAE,CAAC;IAC5E,MAAM,CAAC,OAAO,GAAG,YAAY,CAAA;IAC7B,OAAO,CAAC,YAAY,GAAG,YAAY,CAAA;IACnC,OAAO,CAAC,OAAO,GAAG,YAAY,CAAA;IAC9B,OAAO,CAAC,OAAO,GAAG,YAAY,CAAA;AAC/B,CAAC;KAAM,CAAC;IACP,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAElC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,YAAY,CAAA;AACrC,CAAC"} -------------------------------------------------------------------------------- /dist/thai-baht-text.min.js: -------------------------------------------------------------------------------- 1 | "use strict";var MAX_POSITION=6;var UNIT_POSITION=0;var TEN_POSITION=1;var PRIMARY_UNIT="บาท";var SECONDARY_UNIT="สตางค์";var WHOLE_NUMBER_TEXT="ถ้วน";var NUMBER_TEXTS=["ศูนย์","หนึ่ง","สอง","สาม","สี่","ห้า","หก","เจ็ด","แปด","เก้า","สิบ"];var UNIT_TEXTS=["สิบ","ร้อย","พัน","หมื่น","แสน","ล้าน"];var getIntegerDigits=function(t){return parseInt(t.split(".")[0],10)};var getFractionalDigits=function(t){return parseInt(t.split(".")[1],10)};var hasFractionalDigits=function(t){return t!==undefined&&t!==0};function isZeroValue(t){return parseInt("".concat(t),10)===0}var isUnitPosition=function(t){return t==UNIT_POSITION};var isTenPosition=function(t){return t%MAX_POSITION==TEN_POSITION};var isMillionsPosition=function(t){return t>=MAX_POSITION&&t%MAX_POSITION==0};var isLastPosition=function(t,i){return t+11&&isUnitPosition(t)&&r==1){e="เอ็ด"}return e};var convert=function(t){var n=reverseNumber(t);var r="";n.split("").forEach(function(t,i){r="".concat(getBathText(i,t,n.length)).concat(getBathUnit(i,t)).concat(r)});return r};var parseFloatWithPrecision=function(t,i){if(i===void 0){i=2}var n=parseFloat(t).toString().split(".");var r=n[0];var e=n.length==2?n[1].substring(0,i):"00";return parseFloat("".concat(r,".").concat(e)).toFixed(i)};var convertFullMoney=function(t){var i=parseFloatWithPrecision(t);var n=getIntegerDigits(i);var r=getFractionalDigits(i);var e=convert(n);var a=[];if(e){a.push("".concat([e,PRIMARY_UNIT].join("")))}if(e&&!hasFractionalDigits(r)){a.push(WHOLE_NUMBER_TEXT)}if(hasFractionalDigits(r)&&convert(r)){a.push("".concat([convert(r),SECONDARY_UNIT].join("")))}return a.join("")};function ThaiBahtText(t){if(isNaN(Number("".concat(t)))){throw new TypeError("Invalid input. Expected a number or a string representing a number.")}return convertFullMoney("".concat(t))}if(typeof module!=="undefined"&&typeof module.exports!=="undefined"){module.exports=ThaiBahtText;exports.ThaiBahtText=ThaiBahtText;exports.THBText=ThaiBahtText;exports.default=ThaiBahtText}else{window.ThaiBahtText=ThaiBahtText;window.THBText=window.ThaiBahtText} -------------------------------------------------------------------------------- /example/example_es5.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable import/no-extraneous-dependencies */ 2 | 3 | const ThaiBahtText = require('../dist/thai-baht-text.min') // for ES5 4 | 5 | // This module is very simple to use 6 | // You just put the number that you want to convert into the first parameter 7 | // LIKE THIS --> THBText(Number) 8 | 9 | let money = 10050 10 | const moneyText = ThaiBahtText(money) 11 | 12 | console.log(moneyText) 13 | // OUTPUT: หนึ่งหมื่นห้าสิบบาทถ้วน 14 | 15 | money = 12345678988888.50 16 | 17 | console.log(ThaiBahtText(money)) 18 | // OUTPUT: สิบสองล้านล้านสามแสนสี่หมื่นห้าพันหกร้อยเจ็ดสิบแปดล้านเก้าแสนแปดหมื่นแปดพันแปดร้อยแปดสิบแปดบาทห้าสิบสตางค์ 19 | 20 | // You can see that this module can handle big number, but 21 | // it must not over than 9007199254740991 that is MAX_SAFE_INTEGER of javascript. 22 | -------------------------------------------------------------------------------- /example/example_es6.mjs: -------------------------------------------------------------------------------- 1 | import ThaiBahtText from '../dist/thai-baht-text.min.js' // for ES6 2 | 3 | // This module is very simple to use 4 | // You just put the number that you want to convert into the first parameter 5 | // LIKE THIS --> ThaiBahtText(Number) 6 | 7 | let money = 10050 8 | const moneyText = ThaiBahtText(money) 9 | 10 | console.log(moneyText) 11 | // OUTPUT: หนึ่งหมื่นห้าสิบบาทถ้วน 12 | 13 | money = 12345678988888.50 14 | 15 | console.log(ThaiBahtText(money)) 16 | // OUTPUT: สิบสองล้านล้านสามแสนสี่หมื่นห้าพันหกร้อยเจ็ดสิบแปดล้านเก้าแสนแปดหมื่นแปดพันแปดร้อยแปดสิบแปดบาทห้าสิบสตางค์ 17 | 18 | // You can see that this module can handle big number, but 19 | // it must not over than 9007199254740991 that is MAX_SAFE_INTEGER of javascript. 20 | -------------------------------------------------------------------------------- /example/example_umd/example_umd.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable import/no-extraneous-dependencies */ 2 | 3 | // This module is very simple to use 4 | // You just put the number that you want to convert into the first parameter 5 | // LIKE THIS --> ThaiBahtText(Number) 6 | 7 | const money1 = 10050 8 | const moneyText1 = ThaiBahtText(money1) 9 | 10 | console.log(moneyText1) 11 | // OUTPUT: หนึ่งหมื่นห้าสิบบาทถ้วน 12 | 13 | const money2 = 12345678988888.50 14 | const moneyText2 = ThaiBahtText(money2) 15 | 16 | console.log(moneyText2) 17 | // OUTPUT: สิบสองล้านล้านสามแสนสี่หมื่นห้าพันหกร้อยเจ็ดสิบแปดล้านเก้าแสนแปดหมื่นแปดพันแปดร้อยแปดสิบแปดบาทห้าสิบสตางค์ 18 | 19 | // Display on browser 20 | const box1 = document.createElement('div') 21 | box1.appendChild( 22 | document.createTextNode(`${money1} = ${moneyText1}`) 23 | ) 24 | 25 | const box2 = document.createElement('div') 26 | box2.appendChild( 27 | document.createTextNode(`${money2} = ${moneyText2}`) 28 | ) 29 | 30 | document.body.appendChild(box1) 31 | document.body.appendChild(box2) 32 | 33 | // You can see that this module can handle big number, but 34 | // it must not over than 9007199254740991 that is MAX_SAFE_INTEGER of javascript. 35 | -------------------------------------------------------------------------------- /example/example_umd/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/example_umd/index_git.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | 11 | 15 | 16 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare function ThaiBahtText(stringNumberInput: string): string; 2 | declare function ThaiBahtText(numberInput: number): string; 3 | 4 | declare function ThaiBahtText(input: string | number): string; 5 | 6 | interface Window { 7 | ThaiBahtText: typeof ThaiBahtText; 8 | THBText: typeof ThaiBahtText; 9 | } 10 | 11 | export as namespace ThaiBahtText; 12 | 13 | export { ThaiBahtText, ThaiBahtText as THBText }; 14 | 15 | declare module 'thai-baht-text' { 16 | export default ThaiBahtText; 17 | } 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "thai-baht-text", 3 | "version": "2.0.6", 4 | "description": "Convert number to Thai Bath as Text", 5 | "main": "dist/thai-baht-text.min.js", 6 | "types": "index.d.ts", 7 | "scripts": { 8 | "test-mocha": "ts-mocha tests/unit/*.spec.ts", 9 | "test-mocha-watch": "ts-mocha --watch src/*.spec.js", 10 | "test": "cross-env NODE_ENV=test nyc --all npm run test-mocha", 11 | "test:watch": "cross-env NODE_ENV=test nyc --all npm run test-mocha-watch", 12 | "test:mutation": "npx stryker run", 13 | "build": "tsc && uglifyjs --mangle webkit,v8 ./dist/thai-baht-text.js -o ./dist/thai-baht-text.min.js" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/antronic/thai-baht-text-js.git" 18 | }, 19 | "keywords": [ 20 | "Thai", 21 | "baht", 22 | "text", 23 | "ThaiBaht", 24 | "ThaiBahtText", 25 | "Thai baht", 26 | "Thai baht text", 27 | "convert", 28 | "javascript", 29 | "typescript", 30 | "Thai baht text js", 31 | "แปลงเลขไทย", 32 | "แปลงเลขเงินไทย", 33 | "convert thai baht" 34 | ], 35 | "author": "Jirachai Chansivanon ", 36 | "license": "MIT", 37 | "bugs": { 38 | "url": "https://github.com/antronic/thai-baht-text-js/issues" 39 | }, 40 | "homepage": "https://github.com/antronic/thai-baht-text-js#readme", 41 | "devDependencies": { 42 | "@istanbuljs/nyc-config-typescript": "^1.0.2", 43 | "@types/chai": "^4.3.17", 44 | "@types/jsdom": "^21.1.7", 45 | "@types/mocha": "^10.0.7", 46 | "@types/node": "^22.2.0", 47 | "chai": "^4.5.0", 48 | "cross-env": "^7.0.2", 49 | "eslint": "^6.8.0", 50 | "eslint-config-airbnb-base": "^14.1.0", 51 | "eslint-plugin-import": "^2.20.2", 52 | "mocha": "^10.7.3", 53 | "nyc": "^17.0.0", 54 | "@stryker-mutator/core": "^7.3.0", 55 | "@stryker-mutator/mocha-runner": "^7.3.0", 56 | "ts-mocha": "^10.0.0", 57 | "typescript": "^5.5.4", 58 | "uglify-js": "^3.19.2" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/thai-baht-text.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Jirachai Chansivanon 3 | * @see {@link https://github.com/antronic/that-baht-text-js|GitHub} 4 | */ 5 | 6 | // Constants 7 | const MAX_POSITION = 6 8 | const UNIT_POSITION = 0 9 | const TEN_POSITION = 1 10 | 11 | const PRIMARY_UNIT = 'บาท' 12 | const SECONDARY_UNIT = 'สตางค์' 13 | const WHOLE_NUMBER_TEXT = 'ถ้วน' 14 | 15 | const NUMBER_TEXTS = ['ศูนย์', 'หนึ่ง', 'สอง', 'สาม', 'สี่', 'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า', 'สิบ'] 16 | const UNIT_TEXTS = ['สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน', 'ล้าน'] 17 | 18 | const getIntegerDigits = (numberStringInput: string): number => parseInt(numberStringInput.split('.')[0], 10) 19 | const getFractionalDigits = (numberStringInput: string): number => parseInt(numberStringInput.split('.')[1], 10) 20 | 21 | const hasFractionalDigits = (numberInput: number | undefined) => numberInput !== undefined && numberInput !== 0 22 | 23 | function isZeroValue(numberStringInput: string): boolean 24 | function isZeroValue(numberInput: number): boolean 25 | function isZeroValue(input: string | number): boolean { 26 | return parseInt(`${input}`, 10) === 0 27 | } 28 | 29 | const isUnitPosition = (position: number) => position == UNIT_POSITION 30 | const isTenPosition = (position: number) => position % MAX_POSITION == TEN_POSITION 31 | const isMillionsPosition = (position: number) => (position >= MAX_POSITION && position % MAX_POSITION == 0) 32 | const isLastPosition = (position: number, lengthOfDigits: number) => position + 1 < lengthOfDigits 33 | 34 | const reverseNumber = (number: number): string => { 35 | const numberStr = number.toString() 36 | return numberStr.split('').reverse().join('') 37 | } 38 | 39 | const getBathUnit = (position: number, number: string) => { 40 | let unitText = '' 41 | 42 | if (!isUnitPosition(position)) { 43 | unitText = UNIT_TEXTS[Math.abs(position - 1) % MAX_POSITION] 44 | } 45 | 46 | if (isZeroValue(number) && !isMillionsPosition(position)) { 47 | unitText = '' 48 | } 49 | 50 | return unitText 51 | } 52 | 53 | const getBathText = (position: number, number: string, lengthOfDigits: number) => { 54 | const _number: number = parseInt(number, 10) 55 | let numberText = NUMBER_TEXTS[_number] 56 | 57 | if (isZeroValue(_number)) { 58 | return '' 59 | } 60 | 61 | if (isTenPosition(position) && _number == 1) { 62 | numberText = '' 63 | } 64 | 65 | if (isTenPosition(position) && _number == 2) { 66 | numberText = 'ยี่' 67 | } 68 | 69 | if (isMillionsPosition(position) && isLastPosition(position, lengthOfDigits) && _number == 1) { 70 | numberText = 'เอ็ด' 71 | } 72 | 73 | if (lengthOfDigits > 1 && isUnitPosition(position) && _number == 1) { 74 | numberText = 'เอ็ด' 75 | } 76 | 77 | return numberText 78 | } 79 | 80 | const convert = (numberInput: number): string => { 81 | const numberReverse: string = reverseNumber(numberInput) 82 | let textOutput = '' 83 | 84 | numberReverse.split('') 85 | .forEach((number: string, i) => { 86 | textOutput = `${getBathText(i, number, numberReverse.length)}${getBathUnit(i, number)}${textOutput}` 87 | }) 88 | return textOutput 89 | } 90 | 91 | const parseFloatWithPrecision = (number: string, precision = 2): string => { 92 | const numberFloatStr = parseFloat(number).toString().split('.') 93 | const integerUnitStr = numberFloatStr[0] 94 | const fractionalUnitStr = (numberFloatStr.length == 2) ? numberFloatStr[1].substring(0, precision) : '00' 95 | return parseFloat(`${integerUnitStr}.${fractionalUnitStr}`).toFixed(precision) 96 | } 97 | 98 | 99 | const convertFullMoney = (numberInput: string) => { 100 | const numberStr: string = parseFloatWithPrecision(numberInput) 101 | 102 | const integerDigits: number = getIntegerDigits(numberStr) 103 | const fractionalDigits: number = getFractionalDigits(numberStr) 104 | 105 | const intTextOutput = convert(integerDigits) 106 | const textOutput = [] 107 | if (intTextOutput) { 108 | textOutput.push(`${[intTextOutput, PRIMARY_UNIT].join('')}`) 109 | } 110 | if (intTextOutput && !hasFractionalDigits(fractionalDigits)) { 111 | textOutput.push(WHOLE_NUMBER_TEXT) 112 | } 113 | if (hasFractionalDigits(fractionalDigits) && convert(fractionalDigits)) { 114 | textOutput.push(`${[convert(fractionalDigits), SECONDARY_UNIT].join('')}`) 115 | } 116 | 117 | return textOutput.join('') 118 | } 119 | 120 | function ThaiBahtText(stringNumberInput: string): string 121 | function ThaiBahtText(numberInput: number): string 122 | 123 | function ThaiBahtText(input: string | number): string { 124 | if (isNaN(Number(`${input}`))) { 125 | throw new TypeError('Invalid input. Expected a number or a string representing a number.') 126 | } 127 | return convertFullMoney(`${input}`) 128 | } 129 | 130 | interface Window { 131 | ThaiBahtText: typeof ThaiBahtText 132 | THBText: typeof ThaiBahtText 133 | } 134 | 135 | if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { 136 | module.exports = ThaiBahtText 137 | exports.ThaiBahtText = ThaiBahtText 138 | exports.THBText = ThaiBahtText 139 | exports.default = ThaiBahtText 140 | } else { 141 | window.ThaiBahtText = ThaiBahtText 142 | // Support legacy version 143 | window.THBText = window.ThaiBahtText 144 | } -------------------------------------------------------------------------------- /stryker.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json", 3 | "_comment": "This config was generated using 'stryker init'. Please take a look at: https://stryker-mutator.io/docs/stryker-js/configuration/ for more information.", 4 | "packageManager": "npm", 5 | "reporters": [ 6 | "html", 7 | "clear-text", 8 | "progress" 9 | ], 10 | "testRunner": "command", 11 | "testRunner_comment": "Take a look at (missing 'homepage' URL in package.json) for information about the command plugin.", 12 | "coverageAnalysis": "off", 13 | "buildCommand": "npm run build" 14 | } -------------------------------------------------------------------------------- /tests/unit/thai-baht-text.spec.ts: -------------------------------------------------------------------------------- 1 | 2 | /* eslint-disable import/no-extraneous-dependencies */ 3 | 4 | import { expect } from 'chai' 5 | 6 | import ThaiBahtText from '../../src/thai-baht-text' 7 | 8 | describe('Thai Baht Text', () => { 9 | it('should be a function', () => { 10 | expect(ThaiBahtText).to.be.a('function') 11 | }) 12 | 13 | it('should throw an error for not a number input', () => { 14 | expect(() => { ThaiBahtText('000e') }).to.throw( 15 | TypeError, 'Invalid input. Expected a number or a string representing a number.' 16 | ) 17 | expect(() => { ThaiBahtText('10a') }).to.throw( 18 | TypeError, 'Invalid input. Expected a number or a string representing a number.' 19 | ) 20 | }) 21 | 22 | it('should not convert very small amount', () => { 23 | expect(ThaiBahtText(0.0001)).to.equal('') 24 | expect(ThaiBahtText(0.001)).to.equal('') 25 | expect(ThaiBahtText(0.009)).to.equal('') 26 | }) 27 | 28 | it('should convert to Satang', () => { 29 | expect(ThaiBahtText(0.01)).to.equal('หนึ่งสตางค์') 30 | expect(ThaiBahtText(0.1)).to.equal('สิบสตางค์') 31 | expect(ThaiBahtText(0.10)).to.equal('สิบสตางค์') 32 | expect(ThaiBahtText(0.11)).to.equal('สิบเอ็ดสตางค์') 33 | expect(ThaiBahtText(0.12)).to.equal('สิบสองสตางค์') 34 | expect(ThaiBahtText(0.123)).to.equal('สิบสองสตางค์') 35 | expect(ThaiBahtText(0.2)).to.equal('ยี่สิบสตางค์') 36 | expect(ThaiBahtText(0.20)).to.equal('ยี่สิบสตางค์') 37 | expect(ThaiBahtText(0.21)).to.equal('ยี่สิบเอ็ดสตางค์') 38 | expect(ThaiBahtText(0.25)).to.equal('ยี่สิบห้าสตางค์') 39 | expect(ThaiBahtText(0.255)).to.equal('ยี่สิบห้าสตางค์') 40 | expect(ThaiBahtText(0.5)).to.equal('ห้าสิบสตางค์') 41 | expect(ThaiBahtText(0.50)).to.equal('ห้าสิบสตางค์') 42 | expect(ThaiBahtText(0.75)).to.equal('เจ็ดสิบห้าสตางค์') 43 | expect(ThaiBahtText(0.99)).to.equal('เก้าสิบเก้าสตางค์') 44 | expect(ThaiBahtText(0.999)).to.equal('เก้าสิบเก้าสตางค์') 45 | }) 46 | 47 | it('should convert to Baht', () => { 48 | expect(ThaiBahtText(1)).to.equal('หนึ่งบาทถ้วน') 49 | expect(ThaiBahtText(10)).to.equal('สิบบาทถ้วน') 50 | expect(ThaiBahtText(11)).to.equal('สิบเอ็ดบาทถ้วน') 51 | expect(ThaiBahtText(12)).to.equal('สิบสองบาทถ้วน') 52 | expect(ThaiBahtText(20)).to.equal('ยี่สิบบาทถ้วน') 53 | expect(ThaiBahtText(21)).to.equal('ยี่สิบเอ็ดบาทถ้วน') 54 | expect(ThaiBahtText(22)).to.equal('ยี่สิบสองบาทถ้วน') 55 | expect(ThaiBahtText(100)).to.equal('หนึ่งร้อยบาทถ้วน') 56 | expect(ThaiBahtText(101)).to.equal('หนึ่งร้อยเอ็ดบาทถ้วน') 57 | expect(ThaiBahtText(111)).to.equal('หนึ่งร้อยสิบเอ็ดบาทถ้วน') 58 | expect(ThaiBahtText(121)).to.equal('หนึ่งร้อยยี่สิบเอ็ดบาทถ้วน') 59 | }) 60 | 61 | it('should convert big number to Baht', () => { 62 | expect(ThaiBahtText(1000000)).to.equal('หนึ่งล้านบาทถ้วน') 63 | expect(ThaiBahtText(1000001)).to.equal('หนึ่งล้านเอ็ดบาทถ้วน') 64 | expect(ThaiBahtText(11000001)).to.equal('สิบเอ็ดล้านเอ็ดบาทถ้วน') 65 | expect(ThaiBahtText(11000000)).to.equal('สิบเอ็ดล้านบาทถ้วน') 66 | }) 67 | 68 | it('should convert multiple million round to Baht', () => { 69 | expect(ThaiBahtText(1000000000000000000)).to.equal('หนึ่งล้านล้านล้านบาทถ้วน') 70 | expect(ThaiBahtText(1000000000001)).to.equal('หนึ่งล้านล้านเอ็ดบาทถ้วน') 71 | expect(ThaiBahtText(1000000000000)).to.equal('หนึ่งล้านล้านบาทถ้วน') 72 | expect(ThaiBahtText(1001000000001)).to.equal('หนึ่งล้านหนึ่งพันล้านเอ็ดบาทถ้วน') 73 | expect(ThaiBahtText(1001000001001)).to.equal('หนึ่งล้านหนึ่งพันล้านหนึ่งพันเอ็ดบาทถ้วน') 74 | expect(ThaiBahtText(1001000000000)).to.equal('หนึ่งล้านหนึ่งพันล้านบาทถ้วน') 75 | expect(ThaiBahtText(1000000000)).to.equal('หนึ่งพันล้านบาทถ้วน') 76 | expect(ThaiBahtText(10000000)).to.equal('สิบล้านบาทถ้วน') 77 | expect(ThaiBahtText(100000000)).to.equal('หนึ่งร้อยล้านบาทถ้วน') 78 | }) 79 | 80 | it('should convert complex number to Baht', () => { 81 | expect(ThaiBahtText(6321298)).to.equal('หกล้านสามแสนสองหมื่นหนึ่งพันสองร้อยเก้าสิบแปดบาทถ้วน') 82 | expect(ThaiBahtText(10034567)).to.equal('สิบล้านสามหมื่นสี่พันห้าร้อยหกสิบเจ็ดบาทถ้วน') 83 | expect(ThaiBahtText(20034567)).to.equal('ยี่สิบล้านสามหมื่นสี่พันห้าร้อยหกสิบเจ็ดบาทถ้วน') 84 | expect(ThaiBahtText(30034567.00)).to.equal('สามสิบล้านสามหมื่นสี่พันห้าร้อยหกสิบเจ็ดบาทถ้วน') 85 | }) 86 | 87 | it('should convert number to Baht with Satang', () => { 88 | expect(ThaiBahtText(11.25)).to.equal('สิบเอ็ดบาทยี่สิบห้าสตางค์') 89 | expect(ThaiBahtText(100.50)).to.equal('หนึ่งร้อยบาทห้าสิบสตางค์') 90 | expect(ThaiBahtText(567.01)).to.equal('ห้าร้อยหกสิบเจ็ดบาทหนึ่งสตางค์') 91 | expect(ThaiBahtText(123456789.999)).to.equal('หนึ่งร้อยยี่สิบสามล้านสี่แสนห้าหมื่นหกพันเจ็ดร้อยแปดสิบเก้าบาทเก้าสิบเก้าสตางค์') 92 | }) 93 | }) 94 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["src/**/*.ts"], 3 | "exclude": ["node_modules", "tests"], 4 | "compilerOptions": { 5 | "target": "ES5", 6 | "lib": ["DOM"], 7 | "module": "UMD", 8 | "rootDir": "./src", 9 | "sourceMap": true, 10 | "outDir": "./dist", 11 | "removeComments": true, 12 | "esModuleInterop": true, 13 | "forceConsistentCasingInFileNames": true, 14 | "strict": true, 15 | "skipLibCheck": true 16 | } 17 | } 18 | --------------------------------------------------------------------------------