({
take: [
{ type: "text" },
{ type: "dropdown", options: ["Encode", "Decode"], label: "Direction" },
{
type: "dropdown",
options: ["··· ——— ···", ".../---/...", "dot space dash"],
label: "Format",
},
{
type: "import",
value: "https://cdn.jsdelivr.net/npm/morse-browser@1.0.1/morse.js",
},
],
make: ([text, dir, format]) => {
let result, key, mE, mD
if (format.match("·")) key = ["·", "—", " "]
if (format.match("d")) key = ["dot ", "dash ", "space "]
if (key) {
mE = { ".": key[0], "-": key[1], "/": key[2] }
mD = Object.fromEntries(Object.entries(mE).map(([k, v]) => [v, k]))
}
const fn = dir === "Encode" ? morse.encode : morse.decode
if (fn === morse.decode && mD) {
text = [...text].map((c) => mD[c] || c).join("")
}
result = fn(text)
if (fn === morse.encode && mE) {
result = [...result].map((c) => mE[c] || c).join("")
}
return result
},
})