{"id":30060092,"url":"https://github.com/tiaanduplessis/sort-by-distance","last_synced_at":"2025-08-08T01:42:03.781Z","repository":{"id":18055614,"uuid":"83243913","full_name":"tiaanduplessis/sort-by-distance","owner":"tiaanduplessis","description":"Sort array of points based on how close they are to a givin point","archived":false,"fork":false,"pushed_at":"2022-06-04T10:54:03.000Z","size":137,"stargazers_count":19,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-23T12:08:48.608Z","etag":null,"topics":["distance","points"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tiaanduplessis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-26T22:03:18.000Z","updated_at":"2024-01-08T00:23:15.000Z","dependencies_parsed_at":"2022-07-26T20:32:05.278Z","dependency_job_id":null,"html_url":"https://github.com/tiaanduplessis/sort-by-distance","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/tiaanduplessis/sort-by-distance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiaanduplessis%2Fsort-by-distance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiaanduplessis%2Fsort-by-distance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiaanduplessis%2Fsort-by-distance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiaanduplessis%2Fsort-by-distance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tiaanduplessis","download_url":"https://codeload.github.com/tiaanduplessis/sort-by-distance/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiaanduplessis%2Fsort-by-distance/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269352341,"owners_count":24402672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-07T02:00:09.698Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distance","points"],"created_at":"2025-08-08T01:41:46.972Z","updated_at":"2025-08-08T01:42:03.762Z","avatar_url":"https://github.com/tiaanduplessis.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# sort-by-distance\n[![package version](https://img.shields.io/npm/v/sort-by-distance.svg?style=flat-square)](https://npmjs.org/package/sort-by-distance)\n[![package downloads](https://img.shields.io/npm/dm/sort-by-distance.svg?style=flat-square)](https://npmjs.org/package/sort-by-distance)\n[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)\n[![package license](https://img.shields.io/npm/l/sort-by-distance.svg?style=flat-square)](https://npmjs.org/package/sort-by-distance)\n[![make a pull request](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\nSort array of points based on how close they are to a givin point\n\n## Table of Contents\n\n- [sort-by-distance](#sort-by-distance)\n\t- [Table of Contents](#table-of-contents)\n\t- [Install](#install)\n\t- [Usage](#usage)\n\t- [API](#api)\n\t\t- [originPoint](#originpoint)\n\t\t- [arrayOfPoints](#arrayofpoints)\n\t\t- [options](#options)\n\t- [Contributing](#contributing)\n\t- [License](#license)\n\n## Install\n\nInstall the package locally within you project folder with your package manager:\n\nWith `npm`:\n```sh\nnpm install sort-by-distance\n```\n\nWith `yarn`:\n```sh\nyarn add sort-by-distance\n```\n\nWith `pnpm`:\n```sh\npnpm add sort-by-distance\n```\n\n## Usage\n\nCall the function providing the `origin` point and an array of other points as arguments:\n\n```js\nimport { sortByDistance } from 'sort-by-distance'\n\nconst points = [\n\t{ x: 3, y: 5},\n\t{ x: 80, y: 34},\n\t{ x: 3, y: 7},\n\t{ x: 22, y: 88},\n\t{ x: 100, y: 60},\n]\n\nconst origin = { x: 50, y: 50}\n\nconsole.log(sortByDistance(origin, points))\n\n//[ { x: 80, y: 34, distance: 34 },\n//  { x: 22, y: 88, distance: 47.20169488482379 },\n//  { x: 100, y: 60, distance: 50.99019513592785 },\n//  { x: 3, y: 7, distance: 63.702433234531945 },\n//  { x: 3, y: 5, distance: 65.06919393998976 } ]\n\n```\n\nYou can also change the name of the `x` and `y`:\n\n\n```js\nimport { sortByDistance } from 'sort-by-distance'\n\nconst points = [\n\t{ longitude: 3, latitude: 5},\n\t{ longitude: 80, latitude: 34},\n\t{ longitude: 3, latitude: 7},\n\t{ longitude: 22, latitude: 88},\n\t{ longitude: 100, latitude: 60},\n]\n\nconst opts = {\n\tyName: 'latitude',\n\txName: 'longitude'\n}\n\nconst origin = { longitude: 4, latitude: 22}\n\nconsole.log(sortByDistance(origin, points, opts))\n\n//[ { longitude: 3, latitude: 7, distance: 15.033296378372908 },\n//  { longitude: 3, latitude: 5, distance: 17.029386365926403 },\n//  { longitude: 22, latitude: 88, distance: 68.41052550594829 },\n//  { longitude: 80, latitude: 34, distance: 76.94153624668537 },\n//  { longitude: 100, latitude: 60, distance: 103.24727599312246 } ]\n\n```\n\nThe object is cloned and the `distance` from the `origin` point is added as an property of the new object.\n\n## API\n\nThe module exports a single function with the signature:\n```js\nsortByDistance(originPoint, arrayOfPoints, options)\n```\n\n### originPoint\n\nIs an object containing `x` and `y` properties.\n\n### arrayOfPoints\n\nIs an array of objects containing `x` and `y` properties.\n\n### options\n\nThe options available and their defaults:\n\n```js\n\n{\n\tyName: 'y', // Name of the y property to look for on the object\n\txName: 'x' // Name of the x property to look for on the object\n\ttype: 'linear' // \"linear\" or \"haversine\";\n}\n\n```\n\nFor all configuration options, please see the [API docs](https://paka.dev/npm/sort-by-distance).\n\n## Contributing\n\nGot an idea for a new feature? Found a bug? Contributions are welcome! Please [open up an issue](https://github.com/tiaanduplessis/sort-by-distance/issues) or [make a pull request](https://makeapullrequest.com/).\n\n## License\n\n[MIT © Tiaan du Plessis](./LICENSE)\n    ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiaanduplessis%2Fsort-by-distance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiaanduplessis%2Fsort-by-distance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiaanduplessis%2Fsort-by-distance/lists"}