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

osrm-text-instructions

Package Overview
Dependencies
Maintainers
11
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

osrm-text-instructions

OSRM Text Instructions

  • 0.13.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-0.96%
Maintainers
11
Weekly downloads
 
Created
Source

Build status

OSRM Text Instructions

OSRM Text Instructions is a Node.js library that transforms route data generated by OSRM into localized turn instructions to be displayed visually or read aloud by a text-to-speech engine. OSRM Text Instructions is the basis of guidance instructions in osrm-frontend, the Mapbox Directions API, and the Mapbox Navigation SDK.

  • Global: Text instructions are available in over a dozen languages via Transifex. Abbreviations and advanced grammatical transformations are available in some languages.
  • Customizable: Flexible options allow you to format and tweak the results to your liking.
  • Cross-platform: A data-driven approach facilitates implementations in other programming languages. OSRM Text Instructions is also available in Swift and Objective-C (for iOS, macOS, tvOS, and watchOS) and in Java (for Android and Java SE).
  • Well-tested: A data-driven test suite ensures compatibility across languages and platforms.

Usage

NPM

var version = 'v5';
var osrmTextInstructions = require('osrm-text-instructions')(version);

response.legs.forEach(function(leg) {
  leg.steps.forEach(function(step) {
    instruction = osrmTextInstructions.compile('en', step, options)
  });
});

If you are unsure if the user's locale is supported by osrm-text-inustrctions, use @mapbox/locale-utils for finding the best fitting language.

Parameters require('osrm-text-instructions')(version)
parameterrequired?valuesdescription
versionrequiredv5Major OSRM version
Parameters compile(language, step, options)
parameterrequired?valuesdescription
languagerequireden de zh-Hans fr nl ru and moreCompiling instructions for the selected language code.
steprequiredOSRM route step objectThe RouteStep as it comes out of OSRM
optionsoptionalObjectSee below
Options
keytypedescription
legCountintegerNumber of legs in the route
legIndexintegerZero-based index of the leg containing the step; together with legCount, this option determines which waypoint the user has arrived at
formatTokenfunctionFunction that formats the given token value after grammaticalization and capitalization but before the value is inserted into the instruction string; useful for wrapping tokens in markup
waypointNamestringOptional custom name for the leg's destination, replaces "your {nth} destination"

formatToken takes two parameters:

  • token: A string that indicates the kind of token, such as way_name or direction
  • value: A grammatical string for this token, capitalized if the token appears at the beginning of the instruction

and returns a string.

Architecture

  • index.js contains the main transformation logic in JavaScript.
  • languages/ contains the localization files, including raw format strings, abbreviation files, and grammar rules.
  • languages.js loads the localizations and contains some localization-related helper functions.
  • test/ contains data-driven integration tests and test fixtures for all supported languages.

Contributing

We welcome feedback, code contributions, and translations! Please see CONTRIBUTING.md for details.

Transifex

FAQs

Package last updated on 29 Mar 2019

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