Skip to content

Commit

Permalink
Style: Update whitespace format
Browse files Browse the repository at this point in the history
  • Loading branch information
fvdm committed Dec 14, 2023
1 parent 11fcb55 commit cfe5ce3
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 95 deletions.
13 changes: 9 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"no-sequences": "error",
"no-shadow": "error",
"no-shadow-restricted-names": "error",
"no-spaced-func": "off",
"no-spaced-func": "error",
"no-sparse-arrays": "warn",
"no-sync": "warn",
"no-ternary": "off",
Expand All @@ -117,6 +117,7 @@
"no-undef": "error",
"no-undef-init": "error",
"no-undefined": "error",
"no-underscore-dangle": "off",
"no-unexpected-multiline": "error",
"no-unneeded-ternary": "error",
"no-unreachable": "error",
Expand All @@ -133,6 +134,7 @@
"one-var": ["error", "never"],
"operator-assignment": ["error", "always"],
"operator-linebreak": ["error", "before"],
"padded-blocks": "off",
"quote-props": ["error", "consistent"],
"quotes": ["error", "single", "avoid-escape"],
"radix": "error",
Expand All @@ -143,11 +145,14 @@
}],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", "always"],
"space-in-parens": ["error", "never"],
"space-in-parens": ["error", "always"],
"space-infix-ops": "error",
"space-unary-ops": ["error", {
"words": true,
"nonwords": false
"nonwords": false,
"overrides": {
"!": true,
}
}],
"spaced-comment": ["error", "always"],
"use-isnan": "error",
Expand All @@ -156,4 +161,4 @@
"wrap-regex": "off",
"yoda": ["error", "never"]
}
}
}
40 changes: 20 additions & 20 deletions europeana.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ module.exports = class Europeana {
* @param {number} [config.timeout=15000] Request timeout in ms
*/

constructor ({
constructor ( {
wskey,
timeout = 15000,
}) {
} ) {
this._config = {
wskey,
timeout,
Expand All @@ -43,11 +43,11 @@ module.exports = class Europeana {
* @return {Promise<array>}
*/

async search (parameters) {
return this._talk ({
async search ( parameters ) {
return this._talk( {
url: 'https://api.europeana.eu/record/v2/search.json',
parameters,
});
} );
}


Expand All @@ -59,10 +59,10 @@ module.exports = class Europeana {
* @return {Promise<object>}
*/

async getRecord ({ id }) {
return this._talk ({
async getRecord ( { id } ) {
return this._talk( {
url: `https://api.europeana.eu/record/v2/${id}.json`,
});
} );
}


Expand All @@ -76,8 +76,8 @@ module.exports = class Europeana {
* @return {Promise<string>}
*/

async getRecordThumbnailUrl ({ uri, type, size }) {
uri = encodeURIComponent (uri);
async getRecordThumbnailUrl ( { uri, type, size } ) {
uri = encodeURIComponent( uri );

return `https://api.europeana.eu/thumbnail/v2/url.json?uri=${uri}&type=${type}&size=${size}`;
}
Expand All @@ -93,13 +93,13 @@ module.exports = class Europeana {
* @return {Promise<object>}
*/

async _talk ({
async _talk ( {
url,
parameters = {},
timeout = this._config.timeout,
}) {
} ) {
const options = {
signal: AbortSignal.timeout (parseInt (timeout, 10)),
signal: AbortSignal.timeout( parseInt( timeout, 10 ) ),
method: 'GET',
headers: {
'Accept': 'application/json',
Expand All @@ -108,27 +108,27 @@ module.exports = class Europeana {
},
};

parameters = new URLSearchParams (parameters);
parameters = new URLSearchParams( parameters );
url += '?' + parameters;

const res = await fetch (url, options);
const res = await fetch( url, options );
const body = await res.text();

// HTML error
if (body.match (/^</)) {
if ( body.match( /^</ ) ) {
const msg = this._errors[res.status] || res.statusText;
const error = new Error (`API error: ${msg}`);
const error = new Error( `API error: ${msg}` );

error.code = res.status;
throw error;
}

// Parse JSON data
const data = JSON.parse (body);
const data = JSON.parse( body );

// API error
if (data.error) {
const error = new Error (`API error: ${data.error}`);
if ( data.error ) {
const error = new Error( `API error: ${data.error}` );

error.code = res.status;
throw error;
Expand Down
Loading

0 comments on commit cfe5ce3

Please sign in to comment.