Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kieranmueller/nearest-prime
A simple NPM Package that exports a function, which takes a number and returns the nearest prime number
https://github.com/kieranmueller/nearest-prime
javascript node npm package typescript
Last synced: about 1 month ago
JSON representation
A simple NPM Package that exports a function, which takes a number and returns the nearest prime number
- Host: GitHub
- URL: https://github.com/kieranmueller/nearest-prime
- Owner: KieranMueller
- License: mit
- Created: 2024-12-09T17:39:08.000Z (about 2 months ago)
- Default Branch: master
- Last Pushed: 2024-12-10T01:53:05.000Z (about 2 months ago)
- Last Synced: 2024-12-10T02:20:50.995Z (about 2 months ago)
- Topics: javascript, node, npm, package, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/nearest-prime
- Size: 2.46 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![npm (scoped)](https://img.shields.io/npm/v/nearest-prime?label=NPM) ![NPM](https://img.shields.io/npm/l/nearest-prime?label=License) ![npm](https://img.shields.io/npm/dt/nearest-prime?label=Downloads) [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&color=red&logo=GitHub)](https://github.com/KieranMueller)
# Nearest Prime
## Overview
- This package exports one function with the signature:
```ts
nearestPrime(input: number | string, allowInvalidInput: boolean = false): number | undefined
```- The function takes a number (including decimal numbers), and returns the nearest prime number, rounding up if necessary. (Ex. passing 6 will return 7, not 5)
- The function takes an optional argument `allowInvalidInput` which defaults to false. When passed as true, numbers less than 1 will return `2` instead of `undefined`## How to use
- In your project, run
```shell
npm install nearest-prime
```to install the latest version to your `node_modules` dependency folder
- In the file you'd like to use the `nearestPrime` function, add
```js
import { nearestPrime } from 'nearest-prime'
```to the top of the file
## In Action
![alt text](https://github.com/KieranMueller/nearest-prime/blob/master/assets/nearest-prime-install1.gif?raw=true 'package installation')
## Fixes & Improvements
Head over to the [GitHub Issues](https://github.com/KieranMueller/nearest-prime/issues) tab to report a bug or suggest an improvement. Feel free to contribute to the code or documentation by raising a pull request.