Skip to content

Commit

Permalink
Merge pull request #243 from AnandChowdhary/typescript
Browse files Browse the repository at this point in the history
♻️ Use fetch endpoint function
  • Loading branch information
AnandChowdhary authored Aug 13, 2019
2 parents 52bfc46 + 7558d24 commit 8251759
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface Settings {
template?: (result?: TextResult) => string;
wikipediaLanguage?: string;
noCache?: boolean;
fetchEndpoint?: string;
getFetchEndpoint?: (word: string) => string;
fetchConfig?: any;
storage?: {
getItem(key: string): string;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hovercard",
"version": "2.0.0",
"version": "2.0.1",
"description": "Hover summary cards for the web",
"main": "docs/index.js",
"module": "docs/index.js",
Expand Down
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ export default class Hovercard extends TypeStart {
if (typeof this.settings.getData === "function")
result = await this.settings.getData(word);
const fetched = await fetch(
this.settings.fetchEndpoint ||
`https://${this.settings.wikipediaLanguage ||
"en"}.wikipedia.org/api/rest_v1/page/summary/${encode(word)}`,
typeof this.settings.getFetchEndpoint === "function"
? this.settings.getFetchEndpoint(word)
: `https://${this.settings.wikipediaLanguage ||
"en"}.wikipedia.org/api/rest_v1/page/summary/${encode(word)}`,
this.settings.fetchConfig
);
if (fetched.status >= 300) throw new Error(fetched.statusText);
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface Settings {
template?: (result?: TextResult) => string;
wikipediaLanguage?: string;
noCache?: boolean;
fetchEndpoint?: string;
getFetchEndpoint?: (word: string) => string;
fetchConfig?: any;
storage?: {
getItem(key: string): string;
Expand Down

0 comments on commit 8251759

Please sign in to comment.