Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yousufkalim/nearby-sort
This is very small and lightweight library that is capable to sort the given array by provided location coordinates
https://github.com/yousufkalim/nearby-sort
distance geo geolocation nearby sort
Last synced: 14 days ago
JSON representation
This is very small and lightweight library that is capable to sort the given array by provided location coordinates
- Host: GitHub
- URL: https://github.com/yousufkalim/nearby-sort
- Owner: yousufkalim
- License: mit
- Created: 2022-11-30T07:56:13.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-24T06:26:39.000Z (over 1 year ago)
- Last Synced: 2024-10-17T13:33:43.134Z (21 days ago)
- Topics: distance, geo, geolocation, nearby, sort
- Language: TypeScript
- Homepage:
- Size: 31.3 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOGS.md
- License: LICENSE
Awesome Lists containing this project
README
# Nearby Sort
This is very small and lightweight library that is capable to sort the given array by provided location coordinates.
## Installation
Install nearby-sort with npm
```bash
npm install nearby-sort // npm
yarn add nearby-sort // yarn
```
## Usage/Examples#### Import
```
import nearbySort from 'nearby-sort'; // ES6
const nearbySort = require("nearby-sort"); // CommonJS
```#### Data
```javascript
// User's location
const coordinates = {
lat: 31.442907,
long: 74.271519,
};// Array need to be sorted
const arr = [
{
name: 'Kudos',
lat: 31.460443680085763,
long: 74.26974289747655,
},
{
name: 'Dr Hospital',
lat: 31.480616187193373,
long: 74.28008468009904,
},
{
name: 'Steak Studio',
lat: 31.446620698317826,
long: 74.2704643576623,
},
];
```#### Usage
```
// Asc Sort
let ascSortedData = await nearbySort(coordinates, arr);// Desc Sort
let descSortedData = await nearbySort(coordinates, arr, false);
```
## Contributing- Fork it!
- Create your feature branch: `git checkout -b my-new-feature`
- Commit your changes: `git commit -am 'Add some feature'`
- Push to the branch: `git push origin my-new-feature`
- Submit a pull request :D## Author
**nearby-sort** © [Yousuf](https://github.com/yousufkalim)
Authored and maintained by Yousuf Kalim.> GitHub [@yousufkalim](https://github.com/yousufkalim) · LinkedIn [@yousufkalim](https://www.linkedin.com/in/yousufkalim/)
## License[MIT](https://choosealicense.com/licenses/mit/)