-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba04131
commit 1fac45c
Showing
4 changed files
with
62 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const isNil = (x) => x === undefined || x === null; | ||
|
||
const when = (pred, f) => (x) => (pred(x) ? f(x) : x); | ||
|
||
const hasInspect = (x) => !isNil(x) && typeof x.inspect === "function"; | ||
|
||
const inspect = when(hasInspect, (x) => x.inspect()); | ||
|
||
// eslint-disable-next-line no-global-assign | ||
console = ((clog) => ({ | ||
...clog, | ||
log(...args) { | ||
const writeLog = (arg) => { | ||
if (typeof arg === "string") { | ||
return `\x1b[1;33m${arg}\x1b[0m`; | ||
} | ||
if (typeof arg === "number") { | ||
return `\x1b[1;34m${arg}\x1b[0m`; | ||
} | ||
if (typeof arg === "boolean") { | ||
return `\x1b[1;36m${arg}\x1b[0m`; | ||
} | ||
if (hasInspect(arg)) { | ||
return `\x1b[1;35m${inspect(arg)}\x1b[0m`; | ||
} | ||
if (typeof args === "object") { | ||
return JSON.stringify(arg, null, 2); | ||
} | ||
return args; | ||
}; | ||
if (!args.length) { | ||
clog.log(undefined); | ||
} else if (args.length > 1) { | ||
clog.log( | ||
args.reduce((acc, curr) => acc.concat(writeLog(curr)), []).join(" ") | ||
); | ||
} else { | ||
clog.log(writeLog(args[0])); | ||
} | ||
}, | ||
}))(console); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters