26 lines
601 B
JavaScript
26 lines
601 B
JavaScript
export const logger = ({ name, color }) => (...args) =>
|
|
console.log(
|
|
`%c[${name}]%c`,
|
|
`color: ${color}; font-weight: bold`,
|
|
'color: inherit; font-weight: inherit',
|
|
...args
|
|
)
|
|
|
|
export const log = logger({ name: 'elstat', color: 'purple' })
|
|
|
|
export function objectFromEntries (entries) {
|
|
return entries.reduce(
|
|
(object, [key, value]) => ({ ...object, [key]: value }),
|
|
{}
|
|
)
|
|
}
|
|
|
|
export async function strictFetch (...args) {
|
|
const resp = await fetch(...args)
|
|
|
|
if (!resp.ok) {
|
|
throw new Error(`Failed to fetch: ${resp.status} ${resp.statusText}`)
|
|
}
|
|
|
|
return resp
|
|
}
|