This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
71 lines (68 loc) · 1.54 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {
__,
always,
curry,
defaultTo,
has,
ifElse,
is,
join,
map,
pipe,
prop,
replace,
split,
toUpper,
transpose,
unless
} from 'ramda'
import contract from 'neat-contract'
import characters from './characters'
/**
* Convert boring text to wonderful emojis.
*
* @param {String} background Character to print as background
* @param {String} foreground Character to print as foreground
* @param {String} bg Alias for background
* @param {String} fg Alias for foreground
* @param {JSON} [dictionary=characters] Custom dictionary for rendering
* @param {Boolean} [row=false] Print in single row or not
* @param {String} text Text to process through transformer
* @return {String} The result of processing
*/
function emojifyText({
bg,
fg,
background,
foreground,
dictionary = characters,
row = false
}, input) {
return pipe(
contract('input', String),
toUpper,
split(''),
map(
ifElse(
has(__, dictionary),
prop(__, dictionary),
always(defaultTo([], dictionary.nochar))
)
),
map(
map(join(''))
),
ifElse(
always(row),
pipe(
transpose(),
map(join(''))
),
map(join('\n'))
),
join('\n'),
replace(/0/g, defaultTo(defaultTo('0', bg), background)),
replace(/1/g, defaultTo(defaultTo('1', fg), foreground))
)(input)
}
export default curry(emojifyText)