Skip to content

Commit

Permalink
fix(end-with-one): correct text when number ending with 1, 1x, 2x, 11…
Browse files Browse the repository at this point in the history
…, 21
  • Loading branch information
jojoee committed Oct 18, 2021
1 parent 6b8a727 commit afe3cb4
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,16 @@ function num2Word (nums) {
}

/**
* @todo improve performance
* @param {string} str
* @returns {string}
*/
function grammarFix (str) {
let result = str

// "สิบ"
result = result.replace(//g, 'สิบ')
// "ยี่สิบ"
result = result.replace(//g, 'ยี่สิบ')
// "เอ็ด"
const neungLen = 5
if (result.length > neungLen &&
result.length - result.lastIndexOf('หนึ่ง') === neungLen) {
result = result.substr(0, result.length - neungLen) + 'เอ็ด'
}
result = result.replace(//g, 'สิบเอ็ด')

return result
}
Expand Down

0 comments on commit afe3cb4

Please sign in to comment.