https://github.com/rootslab/nprime
Nprime, a simple and fast naive module for testing/calculating primes on the fly.
https://github.com/rootslab/nprime
calculating-primes naive nodejs prime-numbers
Last synced: 7 months ago
JSON representation
Nprime, a simple and fast naive module for testing/calculating primes on the fly.
- Host: GitHub
- URL: https://github.com/rootslab/nprime
- Owner: rootslab
- License: mit
- Created: 2015-02-02T21:54:29.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-02-10T14:41:06.000Z (over 7 years ago)
- Last Synced: 2025-02-27T03:25:52.094Z (7 months ago)
- Topics: calculating-primes, naive, nodejs, prime-numbers
- Language: JavaScript
- Homepage:
- Size: 241 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
### Nprime
[](https://www.npmjs.org/package/nprime)
[](https://www.codacy.com/public/44gatti/nprime)
[](https://codeclimate.com/github/rootslab/nprime)
[](https://github.com/rootslab/nprime#mit-license)
[](http://travis-ci.org/rootslab/nprime)
[](https://david-dm.org/rootslab/nprime)
[](https://david-dm.org/rootslab/nprime#info=devDependencies)[](http://npm-stat.com/charts.html?package=nprime)
[](https://nodei.co/npm/nprime/)
> __Nprime__, a simple and fast __naive__ module for testing/calculating primes on the fly.
### Install
```bash
$ npm install nprime [-g]
```> __require__:
```javascript
var Nprime = require( 'nprime' );
```
### Run Tests> __to run all test files, install devDependecies:__
```bash
$ cd nprime/
# install or update devDependecies
$ npm install --dev
# run tests
$ npm test
```
> __to execute a single test file simply do__:```bash
$ node test/file-name.js
```
### Run Benchmarks> run benchmark (find the first million of primes):
```bash
$ cd nprime/
$ npm run bench
# or to run a single file
$ node bench/file-name-bench.js
```
----------------------------------------------------------------------------------------------### Methods
> Arguments within [ ] are optional.
```javascript
/*
* Check if the number is composite.
* It returns the value of first divisor,
* or -1 if number is a prime.
*/
Nprime#test : function () : Number/*
* Get the next prime p >= n, use strict for >.
*/
Nprime#next : function ( Number n [, Boolean strict ] ) : Number/*
* Get the previous prime p <= n, use strict for <.
*/
Nprime#prev : function ( Number n [, Boolean strict ] ) : Number
```### MIT License
> Copyright (c) 2014-present < Guglielmo Ferri : 44gatti@gmail.com >
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
> 'Software'), to deal in the Software without restriction, including
> without limitation the rights to use, copy, modify, merge, publish,
> distribute, sublicense, and/or sell copies of the Software, and to
> permit persons to whom the Software is furnished to do so, subject to
> the following conditions:> __The above copyright notice and this permission notice shall be
> included in all copies or substantial portions of the Software.__> THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
> CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.