add logging function
This commit is contained in:
parent
6694c7eb9a
commit
95ac45b5aa
2 changed files with 25 additions and 0 deletions
|
@ -21,3 +21,19 @@ export function next<T>(iterator: Iterator<T>) {
|
|||
export function* range(from: number, to: number) {
|
||||
while (from < to) yield from++;
|
||||
}
|
||||
|
||||
/**
|
||||
* usage:
|
||||
* ```ts
|
||||
* const log = log_from(import.meta)
|
||||
*
|
||||
* const a = 4
|
||||
* log("a", a)
|
||||
* // [module.ts] a 4
|
||||
* ```
|
||||
*/
|
||||
export function log_from(meta: ImportMeta, logging_function = console.log) {
|
||||
const path = new URL(meta.url).pathname;
|
||||
const prefix = `[${path}]`;
|
||||
return (...args: unknown[]) => logging_function(prefix, ...args);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue