-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: isLogger and ensureLogger utils
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
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,9 @@ | ||
"use strict"; | ||
|
||
var toShortString = require("es5-ext/to-short-string-representation") | ||
, isLogger = require("./is-logger"); | ||
|
||
module.exports = function (logger) { | ||
if (isLogger(logger)) return logger; | ||
throw new TypeError(toShortString(logger) + " is not a logger"); | ||
}; |
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,9 @@ | ||
"use strict"; | ||
|
||
var isPlainFunction = require("es5-ext/object/is-plain-function"); | ||
|
||
module.exports = function (logger) { | ||
if (!isPlainFunction(logger)) return false; | ||
if (typeof logger.level !== "string") return false; | ||
return typeof logger.isNamespaceInitialized === "function"; | ||
}; |
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,17 @@ | ||
"use strict"; | ||
|
||
var test = require("tape") | ||
, log = require("../") | ||
, ensureLogger = require("../ensure-logger"); | ||
|
||
test("Ensure Logger", function (t) { | ||
t.equal(ensureLogger(log), log, "Should return logger when logger is an argument"); | ||
t.throws( | ||
function () { | ||
ensureLogger(function () { return "foo"; }); | ||
}, | ||
TypeError, | ||
"Should throw on non logger values" | ||
); | ||
t.end(); | ||
}); |
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,15 @@ | ||
"use strict"; | ||
|
||
var test = require("tape") | ||
, log = require("../") | ||
, isLogger = require("../is-logger"); | ||
|
||
test("Is Logger", function (t) { | ||
t.equal(isLogger(log), true, "Should return true on logger"); | ||
t.equal(isLogger(), false, "Should return false on non-value"); | ||
t.equal( | ||
isLogger(function () { return "foo"; }), false, | ||
"Should return false on non-logger function " | ||
); | ||
t.end(); | ||
}); |