isBase64 and clone functions

Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2019-08-04 09:35:19 -03:00
parent 5b132feabe
commit 29bc8b9e17
2 changed files with 24 additions and 1 deletions

View File

@ -25,6 +25,13 @@ const equalsOrThrow = (v1, v2, t) =>
? true
: (() => {throw t;})());
const isBase64 = (value) =>
Buffer.from(value, "base64").toString("base64") === value;
const clone = (o) =>
JSON.parse(JSON.stringify(o));
module.exports = {
isString,
isStringOrThrow,
@ -34,5 +41,7 @@ module.exports = {
isDefinedOrThrow,
isStringOrObjectOrThrow,
equalsOrThrow
equalsOrThrow,
isBase64,
clone
};

View File

@ -29,4 +29,18 @@ describe("Functional approach", () => {
.equals(true);
});
});
describe("isBase64", () => {
it("should return false when is not base64 string", () => {
let actual = fun.isBase64("non base 64");
expect(actual).to.equal(false);
});
it("should return true when is a base64 string", () => {
let actual = fun.isBase64("Y2xvdWRldmVudHMK");
expect(actual).to.equal(true);
});
});
});