is-prime-value
v1.0.1
Published
small package to check if given number is a prime number.
Maintainers
Readme
is-prime-value
Small utility to check whether a value is a prime number. Returns true for prime integers, false otherwise.
This package now ships TypeScript sources (src/) and builds to lib/ during publishing or when running the included prepare script.
Installation
From npm (recommended):
npm install is-prime-valueIf you install directly from this Git repository, build artifacts are not committed — run the build step locally after installing:
npm install
npm run buildWhen publishing, the prepare script will run automatically to generate lib/ and type declarations.
Usage (JavaScript)
const isPrime = require("is-prime-value");
console.log(isPrime(47)); // true
console.log(isPrime(1)); // false
console.log(isPrime(100)); // false
console.log(isPrime("2")); // true (numeric string accepted)Usage (TypeScript)
Type definitions are provided. Example:
import isPrime = require("is-prime-value");
isPrime(7); // true
// or with esModuleInterop enabled
// import isPrime from 'is-prime-value';Behavior & validation
- Accepts numbers and numeric strings (uses
is-numberinternally). - Throws
TypeErrorfor non-numeric values. - Throws
Errorfor non-integer numeric values. - Throws
RangeErrorfor values outsideNumber.MAX_SAFE_INTEGER. - Negative numbers are treated by absolute value (e.g.,
-3is prime).
Algorithm: trial division up to sqrt(n) with even-number short-circuiting (O(sqrt(n))).
Development
Build and test locally:
npm install
npm run build
npm testNotes
- The repository keeps TypeScript sources in
src/. Thelib/directory is a build artifact and is ignored by.gitignore. - The package includes a
preparescript sonpm publishand installs from git will build before publish.
License
ISC
