mirror of
https://github.com/huhu/rust-search-extension
synced 2024-11-14 15:47:12 +00:00
Use optional chaining syntax
This commit is contained in:
parent
9dcdd5938a
commit
93e54515a0
7 changed files with 8 additions and 8 deletions
2
core
2
core
|
@ -1 +1 @@
|
|||
Subproject commit 880688c2b48c361489dacd3b4538daf1ee23cc72
|
||||
Subproject commit 7afe377eb0d8db25aaed88bf61318da3dd2a5636
|
|
@ -143,7 +143,7 @@ function getPlatformOs() {
|
|||
},
|
||||
afterNavigated: async (query, result) => {
|
||||
// Ignore the command history
|
||||
if (query && query.startsWith(":")) return;
|
||||
if (query?.startsWith(":")) return;
|
||||
|
||||
// Only keep the latest 100 of search history.
|
||||
let historyItem = await HistoryCommand.record(query, result, maxSize = 100);
|
||||
|
@ -183,7 +183,7 @@ function getPlatformOs() {
|
|||
},
|
||||
onAppend: (query) => {
|
||||
query = query.replaceAll("/", "").trim();
|
||||
if (rustcSearcher.searchIndex && rustcSearcher.searchIndex.length > 0) {
|
||||
if (rustcSearcher?.searchIndex?.length > 0) {
|
||||
return [{
|
||||
content: rustcSearcher.getSearchUrl(query),
|
||||
description: `Search nightly rustc docs ${c.match(query)} on ${rustcSearcher.getRootPath()}`,
|
||||
|
|
|
@ -189,7 +189,7 @@ function getState(version) {
|
|||
function insertAddToExtensionElement(state) {
|
||||
// Remove previous element.
|
||||
let el = document.querySelector(".add-to-extension");
|
||||
if (el && el.parentElement) {
|
||||
if (el?.parentElement) {
|
||||
el.parentElement.remove();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
let fixVersions = versions
|
||||
.filter(v => v.minor === version.minor && v.major === version.major && v.fix !== "0")
|
||||
.sort((a, b) => parseInt(a.fix) - parseInt(b.fix));
|
||||
if (fixVersions && fixVersions.length > 0) {
|
||||
if (fixVersions?.length > 0) {
|
||||
fixVersions = fixVersions.map(fv => `<a href="${fv.anchor}"><small>${fv.number}</small></a>`).join(" , ");
|
||||
html += `<div style="margin-top: 0.3rem">${fixVersions}</div>`;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
response => {
|
||||
let now = new Date();
|
||||
let today = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
|
||||
if (response && response.version && today <= Date.parse(response.version)) {
|
||||
if (response?.version && today <= Date.parse(response.version)) {
|
||||
// Check version to ensure update search index once a day.
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class CrateDocSearch {
|
|||
let [crateName, keyword] = CrateDocSearch.parseCrateDocsSearchKeyword(query);
|
||||
|
||||
let searcher = null;
|
||||
if (this.cachedCrateSearcher && this.cachedCrateSearcher.name === crateName) {
|
||||
if (this.cachedCrateSearcher?.name === crateName) {
|
||||
searcher = this.cachedCrateSearcher;
|
||||
} else {
|
||||
let crates = await CrateDocManager.getCrates();
|
||||
|
|
|
@ -157,7 +157,7 @@ class Statistics {
|
|||
* @returns {string|*} return the search type result if matched, otherwise return null.
|
||||
*/
|
||||
static parseSearchType({ query, content, description }) {
|
||||
let stat = STATS_PATTERNS.find(item => item.pattern && item.pattern.test(query));
|
||||
let stat = STATS_PATTERNS.find(item => item.pattern?.test(query));
|
||||
if (stat) {
|
||||
return stat;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue