Add prefer optional chaining rule
This commit is contained in:
@@ -12,7 +12,7 @@ export function enable(enabled) {
|
||||
if (enabled) {
|
||||
const currentPlayerInfo = playbackManager.getPlayerInfo();
|
||||
|
||||
if (currentPlayerInfo && currentPlayerInfo.id) {
|
||||
if (currentPlayerInfo?.id) {
|
||||
localStorage.setItem('autocastPlayerId', currentPlayerInfo.id);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as userSettings from './settings/userSettings';
|
||||
import browser from './browser';
|
||||
|
||||
function canPlayH264(videoTestElement) {
|
||||
return !!(videoTestElement.canPlayType && videoTestElement.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, ''));
|
||||
return !!(videoTestElement.canPlayType?.('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, ''));
|
||||
}
|
||||
|
||||
function canPlayHevc(videoTestElement, options) {
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ export function parentWithAttribute(elem, name, value) {
|
||||
while ((value ? elem.getAttribute(name) !== value : !elem.getAttribute(name))) {
|
||||
elem = elem.parentNode;
|
||||
|
||||
if (!elem || !elem.getAttribute) {
|
||||
if (!elem?.getAttribute) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ function isGamepadConnected() {
|
||||
const gamepads = navigator.getGamepads(); /* eslint-disable-line compat/compat */
|
||||
for (let i = 0, len = gamepads.length; i < len; i++) {
|
||||
const gamepad = gamepads[i];
|
||||
if (gamepad && gamepad.connected) {
|
||||
if (gamepad?.connected) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ function getDefaultLanguage() {
|
||||
if (navigator.userLanguage) {
|
||||
return navigator.userLanguage;
|
||||
}
|
||||
if (navigator.languages && navigator.languages.length) {
|
||||
if (navigator.languages?.length) {
|
||||
return navigator.languages[0];
|
||||
}
|
||||
|
||||
@@ -217,12 +217,12 @@ function translateKey(key) {
|
||||
|
||||
function translateKeyFromModule(key, module) {
|
||||
let dictionary = getDictionary(module, getCurrentLocale());
|
||||
if (dictionary && dictionary[key]) {
|
||||
if (dictionary?.[key]) {
|
||||
return dictionary[key];
|
||||
}
|
||||
|
||||
dictionary = getDictionary(module, fallbackCulture);
|
||||
if (dictionary && dictionary[key]) {
|
||||
if (dictionary?.[key]) {
|
||||
return dictionary[key];
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ function renderHeader() {
|
||||
}
|
||||
|
||||
function getCurrentApiClient() {
|
||||
if (currentUser && currentUser.localUser) {
|
||||
if (currentUser?.localUser) {
|
||||
return ServerConnections.getApiClient(currentUser.localUser.ServerId);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ function updateUserInHeader(user) {
|
||||
|
||||
let hasImage;
|
||||
|
||||
if (user && user.name) {
|
||||
if (user?.name) {
|
||||
if (user.imageUrl) {
|
||||
const url = user.imageUrl;
|
||||
updateHeaderUserButton(url);
|
||||
@@ -143,7 +143,7 @@ function updateUserInHeader(user) {
|
||||
updateHeaderUserButton(null);
|
||||
}
|
||||
|
||||
if (user && user.localUser) {
|
||||
if (user?.localUser) {
|
||||
if (headerHomeButton) {
|
||||
headerHomeButton.classList.remove('hide');
|
||||
}
|
||||
@@ -322,7 +322,7 @@ function refreshLibraryInfoInDrawer(user) {
|
||||
// libraries are added here
|
||||
html += '<div class="libraryMenuOptions"></div>';
|
||||
|
||||
if (user.localUser && user.localUser.Policy.IsAdministrator) {
|
||||
if (user.localUser?.Policy.IsAdministrator) {
|
||||
html += '<div class="adminMenuOptions">';
|
||||
html += '<h3 class="sidebarHeader">';
|
||||
html += globalize.translate('HeaderAdmin');
|
||||
|
||||
@@ -94,7 +94,7 @@ function ScreenSaverManager() {
|
||||
let isLoggedIn;
|
||||
const apiClient = ServerConnections.currentApiClient();
|
||||
|
||||
if (apiClient && apiClient.isLoggedIn()) {
|
||||
if (apiClient?.isLoggedIn()) {
|
||||
isLoggedIn = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user