UNPKG

log-mess

Version:

Log messages with tags and configuration

26 lines 980 B
import { isLog, isVariable } from "./availability.js"; import { getId } from "./id.js"; import { store } from "./persistent.js"; import { getTag } from "./tag.js"; export function logMessage(tagOrMeta, ...value) { const omode = typeof tagOrMeta === "object"; const tag = omode ? tagOrMeta.tag : tagOrMeta; const meta = omode ? tagOrMeta : undefined; const id = getId(); if (isVariable()) store.messages.value.push({ id, tag, timestamp: Date.now(), value }); if (isLog(tag, meta?.silent)) console.log(...getTag(tag, meta), ...value); return { update: (...value) => { const index = store.messages.value.findIndex((x) => x.id === id); if (index === -1) return; store.messages.value[index].value = value; }, remove: () => { store.messages.value = store.messages.$value.filter((x) => x.id !== id); }, }; } //# sourceMappingURL=message.js.map