Skip to content

Repository files navigation

@abdullahdewan/is-even

A tiny TypeScript utility to determine whether a value is an even or odd integer (including bigint).

Installation

npm install @abdullahdewan/is-even

or

pnpm add @abdullahdewan/is-even

or

yarn add @abdullahdewan/is-even

or

bun add @abdullahdewan/is-even

Usage

ESM

import { isEven, isOdd } from "@abdullahdewan/is-even";

console.log(isEven(2)); // true
console.log(isEven(3)); // false
console.log(isEven(10n)); // true

console.log(isOdd(3)); // true
console.log(isOdd(2)); // false
console.log(isOdd(7n)); // true

CommonJS

const { isEven, isOdd } = require("@abdullahdewan/is-even");

console.log(isEven(4)); // true
console.log(isOdd(5)); // true

API

isEven(value)

Returns true if the given value is an even integer or an even bigint. Returns false for any other type of value.

isEven(10); // true
isEven(10n); // true
isEven(5); // false
isEven(5n); // false
isEven(2.5); // false
isEven("2"); // false
isEven(null); // false

isOdd(value)

Returns true if the given value is an odd integer or an odd bigint. Returns false for any other type of value.

isOdd(3); // true
isOdd(7n); // true
isOdd(4); // false
isOdd(2n); // false
isOdd(1.5); // false
isOdd("1"); // false
isOdd(null); // false

License

MIT

About

A tiny TypeScript utility to check whether a number is even.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages