Skip to content

Commit

Permalink
Use Punctuation Blacklist for Typeahead Normalizer
Browse files Browse the repository at this point in the history
Summary:
This changes the Typeahead normalizer to use a punctuation blacklist instead of stripping all non-alphanumeric characters. As the normalizer stands now, any international characters (e.g. Japanese characters) are stripped.

Reviewers: epriestley, jg

Test Plan:
  > JX.TypeaheadNormalizer.normalize('Get rid of the periods...')
  "get rid of the periods"
  > JX.TypeaheadNormalizer.normalize('ラジオ')
  "ラジオ"

Differential Revision: 924
  • Loading branch information
yungsters committed Sep 13, 2011
1 parent eaefcdd commit 62ce6e6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lib/control/typeahead/normalizer/TypeaheadNormalizer.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
* @javelin
*/


/**
* @group control
*/
JX.install('TypeaheadNormalizer', {
statics : {
/**
* Normalizes a string by lowercasing it and stripping out extra spaces
* and punctuation.
*
* @param string
* @return string Normalized string.
*/
normalize : function(str) {
return ('' + str)
.toLowerCase()
.replace(/[^a-z0-9 ]/g, '')
.toLocaleLowerCase()
.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g, '')
.replace(/ +/g, ' ')
.replace(/^\s*|\s*$/g, '');
}
Expand Down

0 comments on commit 62ce6e6

Please sign in to comment.