Jeremy’s put up describes the Net Platform Dashboard and its underlying API. If you do not know what I am speaking about, this is the Net Platform Dashboard. 👇
The Net Platform Dashboard is fantastic as a result of you possibly can question the information set for baseline standing, dates, and particular options. For those who’re into internet platform updates, this web site is there to get misplaced. Fortunately, the whole lot’s powered by an API, too.
Jeremy’s put up contains many instance snippets to provide you an concept of what to question.
I sat down, adjusted the examples, and this is my new script to entry all “newly” out there baseline options in my terminal through node index
.
import { styleText } from "node:util";
const API_BASE_URL = "https://api.webstatus.dev/v1/options";
async perform queryWebStatusDashboard(question, featureData = [], token) {
attempt {
const urlBase = `${API_BASE_URL}?q=`;
let queryUrl = `${urlBase}${encodeURIComponent(question)}`;
if (token) {
queryUrl += `&page_token=${encodeURIComponent(token)}`;
}
const response = await fetch(queryUrl);
if (!response.okay)
throw new Error(
`Failed to question dashboard ${queryUrl}: ${response.statusText}`
);
const { information, metadata } = await response.json();
featureData = [...featureData, ...data];
if ("next_page_token" in metadata) {
const { next_page_token } = metadata;
return await queryWebStatusDashboard(question, featureData, next_page_token);
} else {
return featureData;
}
} catch (error) {
throw new Error(`Failed to question dashboard: ${error.message}`);
}
}
const renderName = (textual content) => styleText(["bold"], textual content);
const renderLink = (textual content) => styleText(["underline"], textual content);
perform getFormatedFeatures(options) {
return options
.type((a, b) => a.feature_id.localeCompare(b.feature_id))
.map(
({ title, feature_id }) =>
`${renderName(`${title}`)}n - ${renderLink(
`https://webstatus.dev/options/${feature_id}`
)}`
)
.be a part of("nn");
}
async perform foremost() {
attempt {
const newFeatures = await queryWebStatusDashboard("baseline_status:newly");
const report = getFormatedFeatures(newFeatures);
console.log(report);
} catch (error) {
console.error("Error in foremost:", error);
course of.exit(1);
}
}
foremost();
It fetches the information, paginates if wanted, and applies fundamental formatting.
This tiny script could also be beneficial for somebody.