Differential D12444 Diff 29887 webroot/rsrc/externals/javelin/lib/control/typeahead/normalizer/TypeaheadNormalizer.js
Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/externals/javelin/lib/control/typeahead/normalizer/TypeaheadNormalizer.js
/** | /** | ||||
* @requires javelin-install | * @requires javelin-install | ||||
* @provides javelin-typeahead-normalizer | * @provides javelin-typeahead-normalizer | ||||
* @javelin | * @javelin | ||||
*/ | */ | ||||
JX.install('TypeaheadNormalizer', { | JX.install('TypeaheadNormalizer', { | ||||
statics : { | statics : { | ||||
/** | /** | ||||
* Normalizes a string by lowercasing it and stripping out extra spaces | * Normalizes a string by lowercasing it and stripping out extra spaces | ||||
* and punctuation. | * and punctuation. | ||||
* | * | ||||
* @param string | * @param string | ||||
* @return string Normalized string. | * @return string Normalized string. | ||||
*/ | */ | ||||
normalize : function(str) { | normalize : function(str) { | ||||
// NOTE: We specifically normalize "(" and ")" into spaces so that | |||||
// we can match tokenizer functions like "members(project)". | |||||
return ('' + str) | return ('' + str) | ||||
.toLocaleLowerCase() | .toLocaleLowerCase() | ||||
.replace(/[\.,\/#!$%\^&\*;:{}=_`~()]/g, '') | .replace(/[\.,\/#!$%\^&\*;:{}=_`~]/g, '') | ||||
.replace(/[-\[\]]/g, ' ') | .replace(/[-\[\]\(\)]/g, ' ') | ||||
.replace(/ +/g, ' ') | .replace(/ +/g, ' ') | ||||
.replace(/^\s*|\s*$/g, ''); | .replace(/^\s*|\s*$/g, ''); | ||||
} | } | ||||
} | } | ||||
}); | }); |