From 8469e04a98eb8d6ac7bc1da692d9f7bd5d21aa91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Tue, 23 Jul 2019 08:49:52 -0300 Subject: [PATCH] lib with functions for utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- lib/formats/json/parser.js | 9 ++++++--- lib/utils/fun.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 lib/utils/fun.js diff --git a/lib/formats/json/parser.js b/lib/formats/json/parser.js index 4731b0c..02f068e 100644 --- a/lib/formats/json/parser.js +++ b/lib/formats/json/parser.js @@ -1,3 +1,9 @@ +const { + isString, + isObject, + isDefined +} = require("../../utils/fun.js"); + function JSONParser() { } @@ -9,9 +15,6 @@ const nullOrIndefinedPayload = new Error("null or undefined payload"); // Functions -const isString = (v) => (typeof v) === "string"; -const isObject = (v) => (typeof v) === "object"; -const isDefined = (v) => v && (typeof v) != "undefined"; const isDefinedOrThrow = (v) => (isDefined(v) ? () => true diff --git a/lib/utils/fun.js b/lib/utils/fun.js new file mode 100644 index 0000000..fbbd97b --- /dev/null +++ b/lib/utils/fun.js @@ -0,0 +1,10 @@ +// Functional approach +const isString = (v) => (typeof v) === "string"; +const isObject = (v) => (typeof v) === "object"; +const isDefined = (v) => v && (typeof v) != "undefined"; + +module.exports = { + isString : isString, + isObject : isObject, + isDefined : isDefined +};