-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
29 lines (25 loc) · 798 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
const { readFileSync } = require('fs-extra')
const { join } = require('path')
const stylesPath = join(__dirname, 'styles.json')
const fontStyles = JSON.parse(readFileSync(stylesPath, 'utf8'))
const getAllFonts = Object.keys(fontStyles)
const fontStyle = (text, font = 'black-square') => {
if (!fontStyles.hasOwnProperty(font)) {
throw new Error(`Invalid font type: ${font}`)
}
const fontMapping = Object.fromEntries(
[...fontStyles[font]].map((char, index) => [String.fromCharCode(65 + index), char])
)
return [
...text
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toUpperCase()
]
.map((char) => fontMapping[char] || char)
.join('')
}
module.exports = {
fontStyle,
getAllFonts
}