npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

osrm-rest-client

v0.1.7

Published

REST client for OSRM v5, the Open Street Map routing service. Supports async, promises or regular callbacks.

Downloads

272

Readme

osrm-rest-client

TypeScript/JavaScript REST client for the Open Source Routing Machine v5, based on Open Street Map data. Supports async, promises or regular callbacks. For detailed OSRM documentation, see here.

The code is based on OSRM-client or OSRM-js, which are basically the same. The main differences between this version and those others are:

  • It is developed in TypeScript, so you have Intellisense support.
  • It supports regular callbacks, as well as Promises or async calls.
  • Profile can be specified per call, i.e. the others only supported the driving profile.
  • It is bundled using microbundle, so you can pick your flavour: ESM, UMD, etc.

Playground

Please visit the online playground to give it a go.

Installation

For debugging, run:

npm install
npm test

Or to build it, run:

npm run build

Usage

TypeScript async examples

import { OSRM, IOsrmWaypoint } from 'osrm-rest-client';

// Examples using async
const osrm = OSRM(); // Using online OSRM service at https://router.project-osrm.org
// Alternatively, supply your own `new OSRM('https://router.project-osrm.org')`
// Default search profile is `driving`, but you can override this.

const nearest = await osrm.nearest({
  coordinates: [[4.32734, 52.109428]],
  number: 3,
});
const waypoints = result?.waypoints || ({} as IOsrmWaypoint[]);
console.log(JSON.stringify(waypoints, null, 2));

const tile = await osrm.tile([17603, 10747, 15]);

const table = await osrm.table({
  coordinates: [
    [13.43864, 52.51993],
    [13.415852, 52.513191],
    [13.333086, 52.4224],
  ],
  sources: [0],
  destinations: [1, 2],
});

const match = await osrm.match({
  coordinates: [
    [8.610048, 46.99917],
    [8.620048, 46.99917],
  ],
  timestamps: [1460585940, 1460585945],
  steps: true,
  overview: 'full',
  geometries: 'polyline',
  annotations: false,
  radiuses: [49, 49],
});

const trip = await osrm.trip({
  coordinates: [
    [13.43864, 52.51993],
    [13.415852, 52.513191],
  ],
  steps: true,
  overview: 'simplified',
  geometries: 'polyline',
});

const route = await osrm.route({
  coordinates: [
    [13.43864, 52.51993],
    [13.415852, 52.513191],
  ],
  steps: true,
  alternatives: false,
  overview: 'simplified',
  geometries: 'polyline',
});

JavaScript callback examples

In modern JavaScript versions, you can also use the async version provided above.

var OSRM = require('osrm-rest-client');

var osrm = OSRM(); // Using online OSRM service at https://router.project-osrm.org
// Alternatively, supply your own `new OSRM('https://router.project-osrm.org')`
// Default search profile is `driving`, but you can override this.

// Examples using callbacks
osrm.route(
  {
    coordinates: [
      [13.43864, 52.51993],
      [13.415852, 52.513191],
    ],
    steps: true,
    alternatives: false,
    overview: 'simplified',
    geometries: 'polyline',
  },
  function (err, result) {
    console.log(result);
  }
);

osrm.trip(
  {
    coordinates: [
      [13.43864, 52.51993],
      [13.415852, 52.513191],
    ],
    steps: true,
    overview: 'simplified',
    geometries: 'polyline',
  },
  function (err, result) {
    console.log(result);
  }
);

osrm.match(
  {
    coordinates: [
      [8.610048, 46.99917],
      [8.620048, 46.99917],
    ],
    timestamps: [1460585940, 1460585945],
    steps: true,
    overview: 'full',
    geometries: 'polyline',
    annotations: false,
    radiuses: [49, 49],
  },
  function (err, result) {
    console.log(result);
  }
);

osrm.table(
  {
    coordinates: [
      [13.43864, 52.51993],
      [13.415852, 52.513191],
      [13.333086, 52.4224],
    ],
    sources: [0],
    destinations: [1, 2],
  },
  function (err, result) {
    console.log(result);
  }
);

osrm.tile([17603, 10747, 15], function (err, result) {
  console.log(result); // pbf encoded vector tile
});