I am trying to make a small node application that lets me convert text to double-struck "letters". I am fairly new to JavaScript, and I was wondering what the best way to do this?
I could use: string.replace("A", doublestruck.uppercase.A)
(see below) 62 (26 uppercase, 26 lowercase, 10 number), but I feel like there is definitely a better way to do this.
// specialcharacters.js
const doubleStruckUpper = {
A: "", B: "", C: "ℂ", D: "", E: "",
F: "", G: "", H: "ℍ", I: "", J: "",
K: "", L: "", M: "", N: "ℕ", O: "",
P: "ℙ", Q: "ℚ", R: "ℝ", S: "", T: "",
U: "", V: "", W: "", X: "", Y: "",
Z: "ℤ"
};
const doubleStruckLower = { ... };
const doubleStruckNumbers = { ... };
module.exports.doubleStruck = {
uppercase: doubleStruckUpper,
lowercase: doubleStruckLower,
numbers: doubleStruckNumbers,
};
// index.js
const { doubleStruck } = require("./specialcharacters");
var string = "Change this to double-struck characters";
string
.replace("A", doubleStruck.uppercase.A)
.replace("B", doubleStruck.uppercase.B)
// and so on
This would work, but it would have to be so long and there is probably a better way to do this.
Thanks in advance!