New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

random-location

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

random-location - npm Package Compare versions

Comparing version

to
1.1.2

2

package.json
{
"name": "random-location",
"version": "1.1.1",
"version": "1.1.2",
"description": "Random coordinates within a circle (or on a circumference) given a center point and radius.",

@@ -5,0 +5,0 @@ "author": "Sagi Kedmi (https://sagi.io) <git@sagi.io>",

@@ -34,3 +34,3 @@ # random-location

// Using CommonJS modules
var randomLocation = require('random-location')
const randomLocation = require('random-location')
```

@@ -41,8 +41,44 @@

```html
<script src="https://unpkg.com/random-location/dist/randomLocation.umd.min.js"></script>
<script src="https://unpkg.com/random-location/dist/randomLocation.umd.js"></script>
```
## API
### `randomLocation.randomCirclePoint(...)`
Outputs a Point ( `{ latitude: ..., longitude: ... }`) of random coordinates within a circle.
Function definition:
```js
const randomCirclePoint = (centerPoint, radius, randomFn = Math.random) => { ... }
```
Where:
- **`centerPoint`** *required* An object with a `latitude` and `longitude` fields.
- **`radius`** *required* The maximum distance (meters) from `centerPoint`.
- **`randomFn`** *optional* A random function. Output is >=0 and <=1. Allows usage of seeded random number generators (see [`seedrandom`](https://www.npmjs.com/package/seedrandom)) - more predictability when testing.
### `randomLocation.randomCircumferencePoint(...)`
Outputs a Point ( `{ latitude: ..., longitude: ... }`) of random coordinates on a circle's circumference.
Function definition:
```js
const randomCircumferencePoint= (centerPoint, radius, randomFn = Math.random) => { ... }
```
Where:
- **`centerPoint`** *required* An object with a `latitude` and `longitude` fields.
- **`radius`** *required* The distance (meters) from `centerPoint`.
- **`randomFn`** *optional* A random function. Output is >=0 and <=1. Allows usage of seeded random number generators (see [`seedrandom`](https://www.npmjs.com/package/seedrandom)) - more predictability when testing.
## Usage
### Generating random coordinates within a circle
Lets say we'd like to get a random location that its distance from

@@ -67,2 +103,3 @@ [Twitter's HQ](https://www.google.co.il/maps/place/Twitter+HQ/@37.7768006,-122.4187928,17z/data=!3m1!4b1!4m5!3m4!1s0x8085809c6c8f4459:0xb10ed6d9b5050fa5!8m2!3d37.7767964!4d-122.4166041?hl=en)

### Generating random coordinates on a circle circumference
Lets say we'd like to get a random location that its distance from

@@ -107,13 +144,6 @@ [Twitter's HQ](https://www.google.co.il/maps/place/Twitter+HQ/@37.7768006,-122.4187928,17z/data=!3m1!4b1!4m5!3m4!1s0x8085809c6c8f4459:0xb10ed6d9b5050fa5!8m2!3d37.7767964!4d-122.4166041?hl=en)

### Developing
Verify tests and coverage:
~~~
$ npm run test
$ npm run cover
~~~
Clone. Install. Hack. Open a **PR**.
### Publishing
~~~
$ npm run build
$ npm publish
~~~
## License
MIT.