diff --git a/static/js/common.js b/static/js/common.js index 27e6f98a6c..bfec346810 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -71,13 +71,13 @@ exports.phrase_match = function (query, phrase) { query = query.toLowerCase(); phrase = phrase.toLowerCase(); - if (phrase.indexOf(query) === 0) { + if (phrase.startsWith(query)) { return true; } const parts = phrase.split(' '); for (i = 0; i < parts.length; i += 1) { - if (parts[i].indexOf(query) === 0) { + if (parts[i].startsWith(query)) { return true; } } diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js index a4079f823f..99a4277d5e 100644 --- a/static/js/composebox_typeahead.js +++ b/static/js/composebox_typeahead.js @@ -958,7 +958,7 @@ exports.initialize = function () { // The matcher for "stream" is strictly prefix-based, // because we want to avoid mixing up streams. const q = this.query.trim().toLowerCase(); - return item.toLowerCase().indexOf(q) === 0; + return item.toLowerCase().startsWith(q); }, }); diff --git a/static/js/markdown.js b/static/js/markdown.js index e9177e0b38..ecd3b04947 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -170,7 +170,7 @@ exports.add_topic_links = function (message) { }; exports.is_status_message = function (raw_content) { - return raw_content.indexOf('/me ') === 0; + return raw_content.startsWith('/me '); }; function make_emoji_span(codepoint, title, alt_text) { @@ -251,7 +251,7 @@ function handleTex(tex, fullmatch) { try { return katex.renderToString(tex); } catch (ex) { - if (ex.message.indexOf('KaTeX parse error') === 0) { // TeX syntax error + if (ex.message.startsWith('KaTeX parse error')) { // TeX syntax error return '' + escape(fullmatch) + ''; } blueslip.error(ex); diff --git a/static/js/people.js b/static/js/people.js index 394930575a..446caa1924 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -824,7 +824,7 @@ exports.build_termlet_matcher = function (termlet) { const names = full_name.toLowerCase().split(' '); return _.any(names, function (name) { - if (name.indexOf(termlet) === 0) { + if (name.startsWith(termlet)) { return true; } }); @@ -840,7 +840,7 @@ exports.build_person_matcher = function (query) { return function (user) { const email = user.email.toLowerCase(); - if (email.indexOf(query) === 0) { + if (email.startsWith(query)) { return true; } diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js index f9064b3ef6..c93a4dd6a0 100644 --- a/static/js/search_suggestion.js +++ b/static/js/search_suggestion.js @@ -415,10 +415,11 @@ function get_special_filter_suggestions(last, operators, suggestions) { // returns the substring after the ":" symbol. const suggestion_operand = s.search_string.substring(s.search_string.indexOf(":") + 1); // e.g for `att` search query, `has:attachment` should be suggested. - const show_operator_suggestions = last.operator === 'search' && suggestion_operand.toLowerCase().indexOf(last_string) === 0; - return s.search_string.toLowerCase().indexOf(last_string) === 0 || + const show_operator_suggestions = last.operator === 'search' && + suggestion_operand.toLowerCase().startsWith(last_string); + return s.search_string.toLowerCase().startsWith(last_string) || show_operator_suggestions || - s.description.toLowerCase().indexOf(last_string) === 0; + s.description.toLowerCase().startsWith(last_string); }); // Only show home if there's an empty bar @@ -541,15 +542,20 @@ function get_sent_by_me_suggestions(last, operators) { return []; } - if (last.operator === '' || sender_query.indexOf(last_string) === 0 || - sender_me_query.indexOf(last_string) === 0 || last_string === sent_string) { + if (last.operator === '' || + sender_query.startsWith(last_string) || + sender_me_query.startsWith(last_string) || + last_string === sent_string + ) { return [ { search_string: sender_query, description: description, }, ]; - } else if (from_query.indexOf(last_string) === 0 || from_me_query.indexOf(last_string) === 0) { + } else if (from_query.startsWith(last_string) || + from_me_query.startsWith(last_string) + ) { return [ { search_string: from_query, @@ -567,7 +573,7 @@ function get_operator_suggestions(last) { let last_operand = last.operand; let negated = false; - if (last_operand.indexOf("-") === 0) { + if (last_operand.startsWith("-")) { negated = true; last_operand = last_operand.slice(1); } diff --git a/static/js/stream_sort.js b/static/js/stream_sort.js index d6082bff4a..61f9b44117 100644 --- a/static/js/stream_sort.js +++ b/static/js/stream_sort.js @@ -25,7 +25,7 @@ function filter_streams_by_search(streams, search_term) { const cands = lower_stream_name.split(" "); cands.push(lower_stream_name); return _.any(cands, function (name) { - return name.indexOf(search_term) === 0; + return name.startsWith(search_term); }); }); }); diff --git a/static/js/upload.js b/static/js/upload.js index 1115eb66f9..2d30894ba2 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -1,5 +1,5 @@ function make_upload_absolute(uri) { - if (uri.indexOf(compose.uploads_path) === 0) { + if (uri.startsWith(compose.uploads_path)) { // Rewrite the URI to a usable link return compose.uploads_domain + uri; } diff --git a/static/shared/js/typeahead.js b/static/shared/js/typeahead.js index f3502f1761..81390b8514 100644 --- a/static/shared/js/typeahead.js +++ b/static/shared/js/typeahead.js @@ -30,7 +30,7 @@ function query_matches_string(query, source_str, split_char) { if (sources[i] === undefined) { return false; } - return sources[i].indexOf(queries[i]) === 0; + return sources[i].startsWith(queries[i]); } // For a single token, the match can be anywhere in the string.