Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nearby-sort

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nearby-sort

The library to sort array of objects by distance from a given point

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
55K
increased by2.8%
Maintainers
1
Weekly downloads
 
Created
Source

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

  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
// 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
Authored and maintained by Yousuf Kalim.

GitHub @yousufkalim · LinkedIn @yousufkalim

License

MIT

Keywords

FAQs

Package last updated on 24 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc