steamapi
Version:
A nice Steam API wrapper.
37 lines (36 loc) • 1 kB
JavaScript
// Use custom fetch implementation
import { lazyFetch } from './fetch-impl.js';
const reg = /<h1>(.*)<\/h1>/;
/**
*
* @param url
* @param options
* @returns
*/
export async function fetch(url, options) {
// console.log(url);
const res = await lazyFetch(url, options);
if (res.status === 400) {
const data = await res.text();
throw new Error(data.match(reg)?.[1] || data);
}
if (res.status !== 200)
throw new Error(res.statusText);
return res.json();
}
;
// App IDs are positive integers that are divisible by 10
const reID = /^\d{17}$/;
export function assertApp(apps) {
if (!Array.isArray(apps))
apps = [apps];
if (apps.some(app => !(app > 0 && app % 1 === 0)))
throw new TypeError('Invalid app ID provided');
}
// User IDs are 17 digit numbers
export function assertID(ids) {
if (!Array.isArray(ids))
ids = [ids];
if (ids.some(id => !reID.test(id)))
throw new TypeError('Invalid user ID provided');
}