is-odd
A minimal JavaScript utility that checks whether a number or numeric string is odd, with built-in type and integer-range validation.
Repository Health
Technical Analysis
is-odd is a zero-configuration validation utility for JavaScript and Node.js that answers a single question: is this value an odd number? It accepts both native numbers and numeric strings, normalizes the input with Math.abs, and delegates the underlying numeric-type check to its sole dependency, is-number, before testing integer parity with the modulo operator.
Rather than silently coercing bad input to false, it throws descriptive errors for non-numeric values, non-integers, and values outside JavaScript’s safe integer range (Number.MAX_SAFE_INTEGER) — making it a defensive building block for guard clauses, array filters, and conditional branching in codebases that need explicit odd/even checks without hand-rolling the validation each time.
What You Get
- A single exported function, isOdd(value), requiring zero configuration or setup.
- Built-in validation that throws typed errors for non-numeric, non-integer, or unsafe-integer input rather than silently returning false.
- Support for both native number and numeric-string inputs without needing to parseInt first.
- A companion sibling package, is-even, following the identical calling convention for the inverse check.
Common Use Cases
- Filtering arrays to odd-indexed or odd-valued entries without writing a modulo check inline.
- Validating form or API input where only odd numeric values are acceptable.
- Alternating row or column styling/logic in generated UI or reports based on parity.
- Guard clauses in utility functions that branch on numeric parity.
Under The Hood
Architecture is-odd is a single-file leaf module (index.js, 12 executable lines) with no internal layering: module.exports assigns one function that immediately delegates numeric-type validation to its one runtime dependency, is-number, then applies Math.abs, Number.isInteger, and Number.isSafeInteger from the JavaScript standard library before returning (n % 2) === 1. There is no separation of concerns beyond that single delegation boundary — the entire execution path is linear and traceable in one read, and the only thing that would break on a core-abstraction change is the is-number dependency’s return contract (a boolean type-check) that index.js trusts implicitly.
Tech Stack The package is plain CommonJS with no build step, bundler, or transpilation — main points directly at index.js. Its only runtime dependency is is-number (^6.0.0); devDependencies are mocha (^3.5.3) for the test suite and gulp-format-md (^1.0.0), invoked via the verb tool, to generate README.md from a .verb.md template. engines.node is pinned to >=4, reflecting the package’s 2015-era origin, and no TypeScript types are bundled — no .d.ts file and no @types devDependency ship with the package.
Code Quality test.js exercises the function with mocha/assert across three cases: valid odd/even numbers (including negative values and the safe-integer boundary), numeric strings, and invalid input (non-numeric, non-integer, and over-safe-integer values), asserting the exact thrown error messages — a reasonably thorough suite for a 12-line function. There is no linter run in CI despite an .eslintrc.json file being present in the repo, and the checked-in .travis.yml targets the now-defunct travis-ci.org endpoint, so CI is effectively stale today even though the badge is still advertised in the README. Error handling is explicit and typed (TypeError/Error with descriptive messages) rather than silently coercing invalid input to false, a deliberate and testable design choice.
API Design The public API is a single default export invoked as isOdd(value), with no configuration object or named exports — about as close to zero-boilerplate as a package can get, requiring only const isOdd = require(‘is-odd’) before first use. Accepting both numbers and numeric strings lowers friction for callers reading values out of JSON or form input, though it also slightly blurs the type contract compared to a strictly-numeric API. The calling convention is identical to the companion is-even package, making the two easy to learn together, but there is no way to opt out of the safe-integer guard or extend behavior (e.g. BigInt support) without wrapping the function yourself.