@gowiz/searchbar
Version:
Different search bars powered by Gowiz search engine technology
50 lines • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.format_index = exports.string_contains_html_tags = exports.domain_to_host = exports.url_is_valid = exports.reformat_url = exports.reformatQueryForSearch = void 0;
function reformatQueryForSearch(query) {
query = query.trim();
return query;
}
exports.reformatQueryForSearch = reformatQueryForSearch;
function reformat_url(base, query) {
return base + encodeURIComponent(reformatQueryForSearch(query));
}
exports.reformat_url = reformat_url;
function url_is_valid(domain) {
const pattern = new RegExp('^(https?:\\/\\/)?' +
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
'((\\d{1,3}\\.){3}\\d{1,3}))' +
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
'(\\?[;&a-z\\d%_.~+=-]*)?' +
'(\\#[-a-z\\d_]*)?$', 'i');
return pattern.test(domain);
}
exports.url_is_valid = url_is_valid;
function domain_to_host(domain) {
return domain.replace(/^(?:https?:\/\/)?(?:www\.)?/i, '').split('/')[0];
}
exports.domain_to_host = domain_to_host;
function string_contains_html_tags(str) {
const pattern = new RegExp(/<([A-Za-z][A-Za-z0-9]*)\b[^>]*>(.*?)<\/\1>/, 'i');
return pattern.test(str);
}
exports.string_contains_html_tags = string_contains_html_tags;
function format_index(index) {
if (index < 0) {
throw new Error('Array index smaller than 0 can not be formatted');
}
const j = index % 10;
const k = index % 100;
if (j == 1 && k != 11) {
return index + 'st';
}
else if (j == 2 && k != 12) {
return index + 'nd';
}
else if (j == 3 && k != 13) {
return index + 'rd';
}
return index + 'th';
}
exports.format_index = format_index;
//# sourceMappingURL=string_util.js.map