Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I mean, it depends on context what “numbers” are acceptable. For an overly general solution:

  const allowNumbers = {
    all: () => true,
    notNaN: n => !Number.isNaN(n),
    finite: Number.isFinite,
    integer: Number.isInteger,
    smol: n => Math.abs(n) < Number.EPSILON,
    lorge: n => n > Number.MAX_SAFE_INTEGER || n < Number.MIN_SAFE_INTEGER,
  }

  function isNumber(n, allow = allowNumbers.all) {
    return ("number" === typeof n) && allow(n);
  }


This isn't bad, but for maintainability, it should be split into at least nine packages.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: