/
index.js
36 lines (30 loc) · 817 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
class BoolEmojify {
constructor(option) {
this.option = option || {
truthy: '👆',
falsy: '👇'
};
}
isBoolean(val) {
return typeof val === 'boolean';
}
emojify(data, cb) {
const payload = {
error: null,
value: null
};
if (this.isBoolean(data) && data !== '') {
payload.value = data ? this.option.truthy : this.option.falsy;
} else {
if(data === '') {
payload.error = 'Data is empty';
} else {
payload.error = 'Data is not boolean type';
}
}
if (cb) return cb(payload);
else return payload;
}
}
module.exports = Object.assign(new BoolEmojify(), { BoolEmojify });