Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap arguments to tokenize #149

Merged
merged 1 commit into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file. For change log formatting, see http://keepachangelog.com/

# master

- `language` is now the first argument of `tokenize` instead of the last. [#149](https://github.com/Project-OSRM/osrm-text-instructions/pull/149)

# 0.6.1

- Updates `continue` maneuvers in en to read as turns when the road you are staying on turns at the intersection. [#145](https://github.com/Project-OSRM/osrm-text-instructions/pull/145)
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ module.exports = function(version, _options) {
'nth': nthWaypoint
};

return this.tokenize(instruction, replaceTokens, language);
return this.tokenize(language, instruction, replaceTokens);
},
tokenize: function(instruction, tokens, language) {
tokenize: function(language, instruction, tokens) {
var output = Object.keys(tokens).reduce(function(memo, token) {
return memo.replace('{' + token + '}', tokens[token]);
}, instruction)
Expand Down
16 changes: 8 additions & 8 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ tape.test('v5 tokenize', function(assert) {

var tokenString = 'Can {first} {second}';

var hasBoth = v5Instructions.tokenize(tokenString, {
var hasBoth = v5Instructions.tokenize('en', tokenString, {
first: 'osrm',
second: 'do routing'
}, 'en');
});
assert.equal(hasBoth, 'Can osrm do routing', 'does find and replace');

var hasFirst = v5Instructions.tokenize(tokenString, {
var hasFirst = v5Instructions.tokenize('en', tokenString, {
first: 'osrm',
second: ''
}, 'en');
});
assert.equal(hasFirst, 'Can osrm ', 'does find and replace and does not drop trailing spaces');

var hasSecond = v5Instructions.tokenize(tokenString, {
var hasSecond = v5Instructions.tokenize('en', tokenString, {
second: 'swim',
first: ''
}, 'en');
});
assert.equal(hasSecond, 'Can swim', 'does find and replace and drops internal extra spaces');

var missingSecond = v5Instructions.tokenize(tokenString, {
var missingSecond = v5Instructions.tokenize('en', tokenString, {
first: 'osrm'
}, 'en');
});
assert.equal(missingSecond, 'Can osrm {second}', 'does not replace tokens which are not provided');


Expand Down