Skip to content

Commit 2301f9a

Browse files
committed
Replace hasOwnProperty check with in operator
1 parent e21ceb2 commit 2301f9a

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

extension/crate-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class CrateDocManager {
88
}
99

1010
static async addCrate(name, version, searchIndex) {
11-
if (searchIndex.hasOwnProperty(name)) {
11+
if (name in searchIndex) {
1212
await storage.setItem(`@${name}`, searchIndex);
1313
let doc = searchIndex[name]["doc"];
1414
let crates = await CrateDocManager.getCrates();

extension/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ function getPlatformOs() {
204204
return await crateDocSearcher.search(query);
205205
},
206206
onFormat: (index, item) => {
207-
if (item.hasOwnProperty("content")) {
207+
if ('content' in item) {
208208
// 1. Crate list header.
209209
// 2. Crate result footer
210210
return item;
211-
} else if (item.hasOwnProperty("href")) {
211+
} else if ('href' in item) {
212212
return formatDoc(index, item);
213213
} else {
214214
// Crate name list.

extension/search/book.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
class BookSearch {
22
constructor(bookIndex) {
33
this.pages = {};
4-
bookIndex.forEach(({name, url, pages}) => {
4+
bookIndex.forEach(({ name, url, pages }) => {
55
pages.forEach(([title, path, parentTitles]) => {
66
let cleanedTitle = cleanChapterTitle(title);
7-
if (!this.pages.hasOwnProperty(cleanedTitle)) {
7+
if (!(cleanedTitle in this.pages)) {
88
this.pages[cleanedTitle] = [];
99
}
10-
this.pages[cleanedTitle].push({title, name, url: `${url}${path}.html`, parentTitles});
10+
this.pages[cleanedTitle].push({ title, name, url: `${url}${path}.html`, parentTitles });
1111
});
1212
});
1313
this.titles = Object.keys(this.pages);
@@ -20,7 +20,7 @@ class BookSearch {
2020
if (title.length < query.length) continue;
2121
let index = title.indexOf(query);
2222
if (index > -1) {
23-
results.push({title, matchIndex: index});
23+
results.push({ title, matchIndex: index });
2424
}
2525
}
2626
return results.sort((a, b) => a.title.length - b.title.length)

0 commit comments

Comments
 (0)