wikibase-sdk
Version:
utils functions to query a Wikibase instance and simplify its results
17 lines • 904 B
JavaScript
import { fixedEncodeURIComponent } from './utils.js';
const isBrowser = typeof location !== 'undefined' && typeof document !== 'undefined';
export function buildUrlFactory(instanceApiEndpoint) {
return queryObj => {
// Request CORS headers if the request is made from a browser
// See https://www.wikidata.org/w/api.php ('origin' parameter)
if (isBrowser)
queryObj = { ...queryObj, origin: '*' };
// Using a custom query stringifier instead of URLSearchParams to not get spaces encoded as "+"
// as that can mess with OAuth signature libraries
const queryParts = Object.entries(queryObj)
.filter(([, value]) => value != null)
.map(([key, value]) => `${key}=${fixedEncodeURIComponent(value.toString())}`);
return instanceApiEndpoint + '?' + queryParts.join('&');
};
}
//# sourceMappingURL=build_url.js.map