mongoku
Version:
[](https://github.com/huggingface/Mongoku/actions/workflows/ci.yml)
33 lines (30 loc) • 988 B
JavaScript
import z from 'zod';
let notifications = [];
let nextId = 1;
const notificationStore = {
get items() {
return notifications;
},
notify(message, type = "info") {
const id = nextId++;
notifications = [...notifications, { id, message, type }];
setTimeout(
() => {
this.remove(id);
},
5e3
);
},
async notifyError(message, fallbackMessage) {
const finalMessage = typeof message === "string" ? message : z.object({ message: z.string() }).safeParse(message).data?.message ?? z.object({ body: z.object({ message: z.string() }), status: z.number() }).safeParse(message).data?.body?.message ?? fallbackMessage ?? "An unexpected error occurred";
this.notify(finalMessage, "error");
},
notifySuccess(message) {
this.notify(message, "success");
},
remove(id) {
notifications = notifications.filter((n) => n.id !== id);
}
};
export { notificationStore as n };
//# sourceMappingURL=notifications.svelte-CIqkoPWX.js.map