forked from twitter/typeahead.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jake Harding
committed
Mar 10, 2014
1 parent
a49d6d1
commit 255c3c6
Showing
5 changed files
with
56 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* typeahead.js | ||
* https://github.com/twitter/typeahead.js | ||
* Copyright 2013-2014 Twitter, Inc. and other contributors; Licensed MIT | ||
*/ | ||
|
||
var tokenizers = (function(root) { | ||
|
||
return { | ||
nonword: nonword, | ||
whitespace: whitespace, | ||
obj: { | ||
nonword: getObjTokenizer(nonword), | ||
whitespace: getObjTokenizer(whitespace) | ||
} | ||
}; | ||
|
||
function whitespace(s) { return s.split(/\s+/); } | ||
|
||
function nonword(s) { return s.split(/\W+/); } | ||
|
||
function getObjTokenizer(tokenizer) { | ||
return function setKey(key) { | ||
return function tokenize(o) { return tokenizer(o[key]); }; | ||
}; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
describe('tokenizers', function() { | ||
|
||
it('.whitespace should tokenize on whitespace', function() { | ||
var tokens = tokenizers.whitespace('big-deal ok'); | ||
expect(tokens).toEqual(['big-deal', 'ok']); | ||
}); | ||
|
||
it('.nonword should tokenize on non-word characters', function() { | ||
var tokens = tokenizers.nonword('big-deal ok'); | ||
expect(tokens).toEqual(['big', 'deal', 'ok']); | ||
}); | ||
|
||
it('.obj.whitespace should tokenize on whitespace', function() { | ||
var t = tokenizers.obj.whitespace('val'); | ||
var tokens = t({ val: 'big-deal ok' }); | ||
|
||
expect(tokens).toEqual(['big-deal', 'ok']); | ||
}); | ||
|
||
it('.obj.nonword should tokenize on non-word characters', function() { | ||
var t = tokenizers.obj.nonword('val'); | ||
var tokens = t({ val: 'big-deal ok' }); | ||
|
||
expect(tokens).toEqual(['big', 'deal', 'ok']); | ||
}); | ||
}); |