isBase64 and clone functions
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
5b132feabe
commit
29bc8b9e17
|
@ -25,6 +25,13 @@ const equalsOrThrow = (v1, v2, t) =>
|
||||||
? true
|
? true
|
||||||
: (() => {throw t;})());
|
: (() => {throw t;})());
|
||||||
|
|
||||||
|
const isBase64 = (value) =>
|
||||||
|
Buffer.from(value, "base64").toString("base64") === value;
|
||||||
|
|
||||||
|
|
||||||
|
const clone = (o) =>
|
||||||
|
JSON.parse(JSON.stringify(o));
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
isString,
|
isString,
|
||||||
isStringOrThrow,
|
isStringOrThrow,
|
||||||
|
@ -34,5 +41,7 @@ module.exports = {
|
||||||
isDefinedOrThrow,
|
isDefinedOrThrow,
|
||||||
isStringOrObjectOrThrow,
|
isStringOrObjectOrThrow,
|
||||||
|
|
||||||
equalsOrThrow
|
equalsOrThrow,
|
||||||
|
isBase64,
|
||||||
|
clone
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,4 +29,18 @@ describe("Functional approach", () => {
|
||||||
.equals(true);
|
.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);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue