Skip to content

Commit

Permalink
Update RuleMorse.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
TMBilalTM authored Aug 6, 2024
1 parent 7e2669c commit 0abaf63
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions rules/RuleMorse/RuleMorse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ export default class RuleMorse extends Rule{

check(txt){
let letters = txt.match(/[A-Za-z]/g)?.slice(0, 3);
if(letters?.length===3)
{

if (letters?.length === 3) {
let code = `${morse[letters[0].toLowerCase()]} ${morse[letters[1].toLowerCase()]} ${morse[letters[2].toLowerCase()]}`;

let exp = `${code}`;
exp = exp.replaceAll(".", "\\.");
let exp = code.replace(/\./g, "\\.").replace(/-/g, "\\-");

console.log("morse:", exp);
let r = new RegExp(exp);


return r.test(txt);
}
return false;
}
}
}

0 comments on commit 0abaf63

Please sign in to comment.