ESLint Unexpected use of isNaN

前端 未结 5 1069
滥情空心
滥情空心 2021-01-30 09:47

I\'m trying to use the isNaN global function inside an arrow function in a Node.js module but I\'m getting this error:

[eslint] Unexpected use of \'is

5条回答
  •  轮回少年
    2021-01-30 10:33

    @Andy Gaskell isNumber('1.2.3') return true, you might want to edit your answer and use Number() in place of parseFloat()

        const isEmpty = value => typeof value === 'undefined' || value === null || value === false;
        const isNumeric = value => !isEmpty(value) && !Number.isNaN(Number(value));
    
      console.log(isNumeric('5')); // true
      console.log(isNumeric('-5')); // true
      console.log(isNumeric('5.5')); // true
      console.log(isNumeric('5.5.5')); // false
      console.log(isNumeric(null)); // false
      console.log(isNumeric(undefined)); // false
    

提交回复
热议问题