ng2-bootstrap
Version:
Native Angular Bootstrap Components
60 lines • 2.6 kB
JavaScript
import { latinMap } from './latin-map';
export var TypeaheadUtils = (function () {
function TypeaheadUtils() {
}
TypeaheadUtils.latinize = function (str) {
if (!str) {
return '';
}
return str.replace(/[^A-Za-z0-9\[\] ]/g, function (a) {
return TypeaheadUtils.latinMap[a] || a;
});
};
TypeaheadUtils.escapeRegexp = function (queryToEscape) {
// Regex: capture the whole query string and replace it with the string
// that will be used to match the results, for example if the capture is
// 'a' the result will be \a
return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
};
/* tslint:disable */
TypeaheadUtils.tokenize = function (str, wordRegexDelimiters, phraseRegexDelimiters) {
if (wordRegexDelimiters === void 0) { wordRegexDelimiters = ' '; }
if (phraseRegexDelimiters === void 0) { phraseRegexDelimiters = ''; }
/* tslint:enable */
var regexStr = '(?:[' + phraseRegexDelimiters + '])([^' + phraseRegexDelimiters + ']+)(?:[' + phraseRegexDelimiters + '])|([^' + wordRegexDelimiters + ']+)';
var preTokenized = str.split(new RegExp(regexStr, 'g'));
var result = [];
var preTokenizedLength = preTokenized.length;
var token;
var replacePhraseDelimiters = new RegExp('[' + phraseRegexDelimiters + ']+', 'g');
for (var i = 0; i < preTokenizedLength; i += 1) {
token = preTokenized[i];
if (token && token.length && token !== wordRegexDelimiters) {
result.push(token.replace(replacePhraseDelimiters, ''));
}
}
return result;
};
TypeaheadUtils.getValueFromObject = function (object, option) {
if (!option || typeof object !== 'object') {
return object.toString();
}
if (option.endsWith('()')) {
var functionName = option.slice(0, option.length - 2);
return object[functionName]().toString();
}
var properties = option.replace(/\[(\w+)\]/g, '.$1')
.replace(/^\./, '');
var propertiesArray = properties.split('.');
for (var _i = 0, propertiesArray_1 = propertiesArray; _i < propertiesArray_1.length; _i++) {
var property = propertiesArray_1[_i];
if (property in object) {
object = object[property];
}
}
return object.toString();
};
TypeaheadUtils.latinMap = latinMap;
return TypeaheadUtils;
}());
//# sourceMappingURL=typeahead-utils.js.map