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

osrm-text-instructions

Package Overview
Dependencies
Maintainers
7
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

osrm-text-instructions - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

instructions.js

5

CHANGELOG.md

@@ -8,2 +8,7 @@ # Change Log

# 0.0.5 2016-10-26
- Add German Translation
- Put under Simplified BSD License
## 0.0.4 2016-10-20

@@ -10,0 +15,0 @@

17

index.js

@@ -1,10 +0,12 @@

var instructions = require('./instructions.json');
module.exports = function(version, language) {
var instructions = require('./instructions').get(language);
if (Object !== instructions.constructor) throw 'instructions must be object';
if (Object !== instructions.constructor) throw 'instructions must be object';
if (!instructions[version]) { throw 'invalid version ' + version; }
module.exports = function(_version) {
var version = _version || 'v5';
var o = {
instructions: instructions,
capitalizeFirstLetter: function(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
},
ordinalize: function(number) {

@@ -62,3 +64,2 @@ // Transform numbers to their translated ordinalized value

compile: function(step) {
if (!this.instructions[version]) { throw new Error('Invalid version'); }
if (!step.maneuver) throw new Error('No step maneuver provided');

@@ -165,2 +166,6 @@

if (this.instructions.meta.capitalize_first_letter) {
instruction = this.capitalizeFirstLetter(instruction);
}
return instruction;

@@ -167,0 +172,0 @@ }

@@ -6,3 +6,3 @@ {

"homepage": "http://project-osrm.org",
"version": "0.0.4",
"version": "0.0.5",
"main": "./index.js",

@@ -23,4 +23,4 @@ "license": "BSD-2-Clause",

"lint": "eslint *.js",
"test": "npm run lint && node test/*_test.js"
"test": "npm run lint && tape test/*_test.js"
}
}

@@ -1,3 +0,5 @@

# osrm-text-instructions.js
# osrm-text-instructions
[![Build Status](https://travis-ci.org/Project-OSRM/osrm-text-instructions.svg?branch=master)](https://travis-ci.org/Project-OSRM/osrm-text-instructions)
----

@@ -7,8 +9,15 @@

osrm-text-instructions.js is a library to transform OSRM steps into text instructions.
osrm-text-instructions transforms OSRM route responses into text instructions. It currently has only an implementation in JavaScript, with more to come.
### Usage
### Design goals
- __Cross platform__ Use a data-driven approach that makes implementations in other programming environments easy to write
- __Test suite__ Have a data-driven test suite with fixtures which can be used cross-platform
- __Translation__ Allow for translations via [Transifex](https://www.transifex.com/)
- __Customization__ Users should be able to easily fork or monkey patch the results to adjust to their own likings
### Javascript Usage
```
var osrmTextInstructions = require('osrm-text-instructions')('v5');
var osrmTextInstructions = require('osrm-text-instructions')('v5', 'en');

@@ -24,12 +33,37 @@ // make your request against the API

### Design goals
### Development
#### Architecture
- __Cross platform__ Use a data-driven approach that makes implementations in other programming environments easy to write
- __Test suite__ Have a data-driven test suite with fixtures which can be used cross-platform
- __Translation__ Allow for translations via [Transifex](https://www.transifex.com/)
- __Customization__ Users should be able to easily fork or monkey patch the results to adjust to their own likings
- `index.js` holds the main transformation logic in javascript
- `instructions/` holds the translateable strings
### Development
#### Generate Fixtures
#### Tests
Fixtures can be programatically created and updated via `scripts/generate_fixtures.js`.
Tests are data-driven integration tests for the english language.
To run them yourself for the JavaScript implementation:
```
npm install
npm test
```
##### Generate Fixtures
Fixtures can be programatically created and updated via `scripts/generate_fixtures.js`. To update the instructions in the fixture files, run `UPDATE=1 npm test`.
#### Translations
To add own translations:
- Create a new file in `instructions/`
- base it off of `instructions/en.json`
- use a [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) after [RFC 5646](https://en.wikipedia.org/wiki/IETF_language_tag) as name
- Translate
- Add the new instructions file to `instructions.js`
- Add the new instructions file to the `languages` array in `test/instructions_test.js`
- To manually look at the changes:
- Change the locale in `test/index_test.js`
- Run `UPDATE=1 npm test` and look at the changes in `git diff`
- When done, revert via `git checkout test`
- Make a PR

@@ -0,9 +1,8 @@

var path = require('path');
var fs = require('fs');
var tape = require('tape');
var path = require('path');
var instructions = require('../index.js');
var constants = require('./constants');
tape.test('v5 directionFromDegree', function(assert) {
var v5Instructions = instructions('v5');
var v5Instructions = instructions('v5', 'en');

@@ -53,3 +52,3 @@ assert.equal(

tape.test('v5 laneDiagram', function(assert) {
var v5Instructions = instructions('v5');
var v5Instructions = instructions('v5', 'en');

@@ -92,116 +91,11 @@ function makeStep(config) {

tape.test('v5 compile', function(t) {
var v5Instructions = instructions('v5');
t.test('fixtures exist for every type/modifier combinations', function(assert) {
var instructions = require('../instructions');
var basePath = path.join(__dirname, 'fixtures', 'v5');
function underscorify(input) {
return input.replace(/ /g, '_');
}
function checkModifiers(type) {
constants.modifiers.forEach(function(modifier) {
assert.ok(
fs.existsSync(path.join(basePath, underscorify(type), `${underscorify(modifier)}_default.json`)),
`${type}/${modifier}_default`);
assert.ok(
fs.existsSync(path.join(basePath, underscorify(type), `${underscorify(modifier)}_destination.json`)),
`${type}/${modifier}_destination`);
assert.ok(
fs.existsSync(path.join(basePath, underscorify(type), `${underscorify(modifier)}_name.json`)),
`${type}/${modifier}_name`);
});
}
function checkModifiersNoName(type) {
// TODO: Remove this function and replace it complately by checkModifiers
constants.modifiers.forEach(function(modifier) {
// check normal fixture
var p = path.join(basePath, underscorify(type), underscorify(modifier) + '.json');
assert.ok(fs.existsSync(p), type + '/' + modifier);
// check no_name fixture if should exist
var noNamePath = path.join(basePath, underscorify(type), underscorify(modifier) + '_no_name.json');
if (instructions.v5[type].default.name ||
instructions.v5[type].default.default.name
) {
assert.ok(fs.existsSync(noNamePath), type + '/' + modifier + '/no name');
}
});
}
var types = constants.types;
types.push('other');
types.forEach(function(type) {
switch(type) {
case 'other':
[
'invalid_type',
'way_name_ref',
'way_name_ref_name',
'way_name_ref_destinations',
'way_name_ref_mapbox_hack_1',
'way_name_ref_mapbox_hack_2'
].forEach((f) => {
assert.ok(
fs.existsSync(path.join(basePath, 'other', `${f}.json`)),
`${type}/${f}`);
});
break;
case 'turn':
checkModifiers(type);
break;
case 'rotary':
[ 'default', 'exit_1', 'name', 'name_exit' ].forEach((s) => {
assert.ok(
fs.existsSync(path.join(basePath, 'rotary', `${s}_default.json`)),
`${type}/${s}_default`);
assert.ok(
fs.existsSync(path.join(basePath, 'rotary', `${s}_destination.json`)),
`${type}/${s}_destination`);
assert.ok(
fs.existsSync(path.join(basePath, 'rotary', `${s}_name.json`)),
`${type}/${s}_name`);
});
// special fixtures for ordinalization
for (i = 2; i <= 11; i++) {
assert.ok(
fs.existsSync(path.join(basePath, 'rotary', `exit_${i}.json`)),
`${type}/exit_${i}_default`);
};
break;
case 'roundabout':
[ 'default', 'exit' ].forEach((s) => {
assert.ok(
fs.existsSync(path.join(basePath, 'roundabout', `${s}_default.json`)),
`${type}/${s}_default`);
assert.ok(
fs.existsSync(path.join(basePath, 'roundabout', `${s}_destination.json`)),
`${type}/${s}_destination`);
assert.ok(
fs.existsSync(path.join(basePath, 'roundabout', `${s}_name.json`)),
`${type}/${s}_name`);
});
break;
default:
checkModifiersNoName(type);
break
};
});
assert.end();
});
t.test('fixtures match generated instructions', function(assert) {
var v5Instructions = instructions('v5', 'en');
var basePath = path.join(__dirname, 'fixtures', 'v5/');
fs.readdirSync(basePath).forEach(function(type) {
if (type === '.DS_Store') return;
if (type.match(/^\./)) return; // ignore temporary files
fs.readdirSync(basePath + type).forEach(function(file) {
if (!file.match(/json$/)) return;
fs.readdirSync(path.join(basePath, type)).forEach(function(file) {
if (!file.match(/\.json$/)) return;

@@ -208,0 +102,0 @@ var p = path.join(basePath, type, file);

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