Skip to content

Commit

Permalink
feat(invalid): add more validation on invalid value e.g. boolean, obj…
Browse files Browse the repository at this point in the history
…ect, array, etc
  • Loading branch information
jojoee committed Oct 18, 2021
1 parent afe3cb4 commit 34c4e98
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,18 @@ function combine (baht, satang) {
* @returns {string}
*/
function bahttext (num) {
// no null
if (!num) return defaultResult
// no boolean
if (typeof num === 'boolean') return defaultResult
// must be number only
if (isNaN(Number(num))) return defaultResult
// no more than Number.MAX_SAFE_INTEGER
if (num >= Number.MAX_SAFE_INTEGER) return defaultResult

// set
let result = defaultResult

// 1. validate: invalid number
if (isNaN(num)) return result
// 1. validate: more than
if (num >= Number.MAX_SAFE_INTEGER) return result

// 2. sanitize: ????

// 3. split: baht and satang
// e.g. 432.21 >> 432, 21
// @todo optimize
Expand Down

0 comments on commit 34c4e98

Please sign in to comment.