Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Clean up typeof … === "undefined" checks.
Anders Kaseorg6de39ae92d65
diff --git a/static/js/bot_data.js b/static/js/bot_data.jsindex 06105424f29..381691d0f0c 100644--- a/static/js/bot_data.js+++ b/static/js/bot_data.js@@ -48,7 +48,7 @@ export function update(bot_id, bot_update) {// We currently only support one service per bot.const service = services.get(bot_id)[0];- if (typeof bot_update.services !== "undefined" && bot_update.services.length > 0) {+ if (bot_update.services !== undefined && bot_update.services.length > 0) {Object.assign(service, _.pick(bot_update.services[0], services_fields));}}diff --git a/static/js/browser_history.js b/static/js/browser_history.jsindex c254235809f..18f94c5fa24 100644--- a/static/js/browser_history.js+++ b/static/js/browser_history.js@@ -5,7 +5,7 @@ import * as ui_util from "./ui_util";const state = {is_internal_change: false,hash_before_overlay: null,- old_hash: typeof window !== "undefined" ? window.location.hash : "#",+ old_hash: window.location.hash,};export function clear_for_testing() {diff --git a/static/js/local_message.js b/static/js/local_message.jsindex 6ef74f963a8..42847e9353f 100644--- a/static/js/local_message.js+++ b/static/js/local_message.js@@ -19,7 +19,7 @@ export const get_next_id_float = (function () {return function () {const local_id_increment = 0.01;let latest = page_params.max_message_id;- if (typeof message_list.all !== "undefined" && message_list.all.last() !== undefined) {+ if (message_list.all.last() !== undefined) {latest = message_list.all.last().id;}latest = Math.max(0, latest);diff --git a/static/js/localstorage.js b/static/js/localstorage.jsindex ad261478e8c..68dcdf59303 100644--- a/static/js/localstorage.js+++ b/static/js/localstorage.js@@ -120,7 +120,7 @@ export const localstorage = function () {},set(name, data) {- if (typeof _data.VERSION !== "undefined") {+ if (_data.VERSION !== undefined) {ls.setData(_data.VERSION, name, data, _data.expires);// if the expires attribute was not set as a global, thendiff --git a/static/js/settings_invites.js b/static/js/settings_invites.jsindex 8ee2c12c31f..a6e08219567 100644--- a/static/js/settings_invites.js+++ b/static/js/settings_invites.js@@ -122,11 +122,8 @@ function do_revoke_invite() {});}-export function set_up(initialize_event_handlers) {+export function set_up(initialize_event_handlers = true) {meta.loaded = true;- if (typeof initialize_event_handlers === "undefined") {- initialize_event_handlers = true;- }// create loading indicatorsloading.make_indicator($("#admin_page_invites_loading_indicator"));diff --git a/static/js/setup.js b/static/js/setup.jsindex 55afa8980f9..79d0a5f8928 100644--- a/static/js/setup.js+++ b/static/js/setup.js@@ -64,12 +64,10 @@ $(() => {}});- if (typeof $ !== "undefined") {- $.fn.expectOne = function () {- if (blueslip && this.length !== 1) {- blueslip.error("Expected one element in jQuery set, " + this.length + " found");- }- return this;- };- }+ $.fn.expectOne = function () {+ if (blueslip && this.length !== 1) {+ blueslip.error("Expected one element in jQuery set, " + this.length + " found");+ }+ return this;+ };});diff --git a/static/js/stream_data.js b/static/js/stream_data.jsindex c9890b75db3..b95a37d3665 100644--- a/static/js/stream_data.js+++ b/static/js/stream_data.js@@ -679,7 +679,7 @@ export function maybe_get_stream_name(stream_id) {export function is_user_subscribed(stream_id, user_id) {const sub = get_sub_by_id(stream_id);- if (typeof sub === "undefined" || !sub.can_access_subscribers) {+ if (sub === undefined || !sub.can_access_subscribers) {// If we don't know about the stream, or we ourselves cannot access subscriber list,// so we return undefined (treated as falsy if not explicitly handled).blueslip.warn(@@ -687,7 +687,7 @@ export function is_user_subscribed(stream_id, user_id) {);return undefined;}- if (typeof user_id === "undefined") {+ if (user_id === undefined) {blueslip.warn("Undefined user_id passed to function is_user_subscribed");return undefined;}diff --git a/static/js/subs.js b/static/js/subs.jsindex 70db24a62db..5667abd7e42 100644--- a/static/js/subs.js+++ b/static/js/subs.js@@ -111,7 +111,7 @@ export function get_active_data() {}function get_hash_safe() {- if (typeof window !== "undefined" && typeof window.location.hash === "string") {+ if (typeof window.location.hash === "string") {return window.location.hash.slice(1);}diff --git a/static/js/timerender.js b/static/js/timerender.jsindex 2e967aedfcc..dfef6661021 100644--- a/static/js/timerender.js+++ b/static/js/timerender.js@@ -286,10 +286,7 @@ export const absolute_time = (function () {return str;};- return function (timestamp, today) {- if (typeof today === "undefined") {- today = new Date();- }+ return function (timestamp, today = new Date()) {const date = new Date(timestamp);const is_older_year = today.getFullYear() - date.getFullYear() > 0;const H_24 = page_params.twenty_four_hour_time;diff --git a/static/js/ui_util.js b/static/js/ui_util.jsindex b9c282f5350..6047c7b2293 100644--- a/static/js/ui_util.js+++ b/static/js/ui_util.js@@ -11,14 +11,14 @@ export function change_tab_to(tabname) {export function place_caret_at_end(el) {el.focus();- if (typeof window.getSelection !== "undefined" && typeof document.createRange !== "undefined") {+ if (window.getSelection !== undefined && document.createRange !== undefined) {const range = document.createRange();range.selectNodeContents(el);range.collapse(false);const sel = window.getSelection();sel.removeAllRanges();sel.addRange(range);- } else if (typeof document.body.createTextRange !== "undefined") {+ } else if (document.body.createTextRange !== undefined) {const textRange = document.body.createTextRange();textRange.moveToElementText(el);textRange.collapse(false);