/**
 * @requires javelin-install
 * @provides javelin-typeahead-normalizer
 * @javelin
 */


/**
 * @group control
 */
JX.install('TypeaheadNormalizer', {
  statics : {
    normalize : function(str) {
      return ('' + str)
        .toLowerCase()
        .replace(/[^a-z0-9 ]/g, '')
        .replace(/ +/g, ' ')
        .replace(/^\s*|\s*$/g, '');
    }
  }
});

/**
 * @requires javelin-install
 * @provides javelin-typeahead-normalizer
 * @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)
        .toLocaleLowerCase()
        .replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g, '')
        .replace(/ +/g, ' ')
        .replace(/^\s*|\s*$/g, '');
    }
  }
});

Use Punctuation Blacklist for Typeahead Normalizer
Use Punctuation Blacklist for Typeahead Normalizer

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.

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

Reviewers: epriestley, jg

Reviewed By: epriestley

CC: aran, epriestley, yungsters

Differential Revision: 924
