Primality has been tested in:
$ component install KenanY/primality
$ bower install primality
$ npm install primality
In Node.js and RingoJS v0.8.0+:
var primality = require'primality';
In RingoJS v0.7.0-:
var primality = require'primality'primality;
In an AMD loader like RequireJS:
Primality's flagship method is
primality(), which works as you might expect it
primality7;// => trueprimality6;// => false
Of course, you can pass strings instead of numbers if you'd like:
primality'13';// => true
Primality can even do arrays. If any of the values in an array are not prime,
false is returned.
primality17 19 23;// => trueprimality17 20 23;// => false
Beyond primality testing, Primality can also tell you if a pair of numbers are twin, cousin, or sexy primes. Twin primes are prime numbers that differ from each other by two. Similarly, cousin primes differ by four and sexy primes differ by six.
primalityareTwinPrimes3 5;// => trueprimalityareCousinPrimes3 7;// => trueprimalityareSexyPrimes5 11;// => true
You can also check for Wilson primes. Only three Wilson primes are known at the moment: 5, 13, and 563.
primalityisWilsonPrime563;// => true
The full changelog is available here.