morse-utils 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/dictionary.d.ts +2 -0
- package/dist/dictionary.js +17 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +26 -0
- package/dist/src/dictionary.d.ts +2 -0
- package/dist/src/dictionary.js +17 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +26 -0
- package/package.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# morse-utils 🚀
|
|
2
|
+
|
|
3
|
+
Um pacote utilitário leve, moderno e extremamente rápido para codificação e decodificação de Código Morse. Escrito em TypeScript com suporte nativo a ES Modules (ESM) e tipagem completa.
|
|
4
|
+
|
|
5
|
+
## ✨ Funcionalidades
|
|
6
|
+
|
|
7
|
+
* **Codificação:** Transforma textos alfanuméricos em Código Morse.
|
|
8
|
+
* **Decodificação:** Transforma Código Morse de volta em texto legível.
|
|
9
|
+
* **Preservação de caracteres:** Caracteres desconhecidos não são descartados, facilitando o tratamento de pontuações.
|
|
10
|
+
* **TypeScript Nativo:** Autocompletar completo e validação de tipos diretamente no seu editor de código.
|
|
11
|
+
* **Zero Dependências:** Código limpo e sem pacotes de terceiros pesando no seu projeto.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 📦 Instalação
|
|
16
|
+
|
|
17
|
+
Instale o pacote facilmente usando o npm:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install morse-utils
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const MORSE_MAP = {
|
|
2
|
+
'A': '.-', 'B': '-...', 'C': '-.-.',
|
|
3
|
+
'D': '-..', 'E': '.', 'F': '..-.',
|
|
4
|
+
'G': '--.', 'H': '....', 'I': '..',
|
|
5
|
+
'J': '.---', 'K': '-.-', 'L': '.-..',
|
|
6
|
+
'M': '--', 'N': '-.', 'O': '---',
|
|
7
|
+
'P': '.--.', 'Q': '--.-', 'R': '.-.',
|
|
8
|
+
'S': '...', 'T': '-', 'U': '..-',
|
|
9
|
+
'V': '...-', 'W': '.--', 'X': '-..-',
|
|
10
|
+
'Y': '-.--', 'Z': '--..',
|
|
11
|
+
'0': '-----', '1': '.----', '2': '..---',
|
|
12
|
+
'3': '...--', '4': '....-', '5': '.....',
|
|
13
|
+
'6': '-....', '7': '--...', '8': '---..',
|
|
14
|
+
'9': '----.',
|
|
15
|
+
' ': '/'
|
|
16
|
+
};
|
|
17
|
+
export const REVERSE_MORSE_MAP = Object.fromEntries(Object.entries(MORSE_MAP).map(([char, morse]) => [morse, char]));
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MORSE_MAP, REVERSE_MORSE_MAP } from "./dictionary.js";
|
|
2
|
+
export function encode(text) {
|
|
3
|
+
if (!text)
|
|
4
|
+
return "";
|
|
5
|
+
return text
|
|
6
|
+
.toUpperCase()
|
|
7
|
+
.split('')
|
|
8
|
+
.map(char => MORSE_MAP[char] || char)
|
|
9
|
+
.join(' ')
|
|
10
|
+
.replace(/\s+/g, ' ')
|
|
11
|
+
.trim();
|
|
12
|
+
}
|
|
13
|
+
export function decode(morse) {
|
|
14
|
+
if (!morse)
|
|
15
|
+
return "";
|
|
16
|
+
return morse
|
|
17
|
+
.trim()
|
|
18
|
+
.split(' ')
|
|
19
|
+
.map(symbol => {
|
|
20
|
+
if (symbol === '/')
|
|
21
|
+
return ' ';
|
|
22
|
+
return REVERSE_MORSE_MAP[symbol] || symbol;
|
|
23
|
+
})
|
|
24
|
+
.join('')
|
|
25
|
+
.replace(/\s+/g, ' ');
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const MORSE_MAP = {
|
|
2
|
+
'A': '.-', 'B': '-...', 'C': '-.-.',
|
|
3
|
+
'D': '-..', 'E': '.', 'F': '..-.',
|
|
4
|
+
'G': '--.', 'H': '....', 'I': '..',
|
|
5
|
+
'J': '.---', 'K': '-.-', 'L': '.-..',
|
|
6
|
+
'M': '--', 'N': '-.', 'O': '---',
|
|
7
|
+
'P': '.--.', 'Q': '--.-', 'R': '.-.',
|
|
8
|
+
'S': '...', 'T': '-', 'U': '..-',
|
|
9
|
+
'V': '...-', 'W': '.--', 'X': '-..-',
|
|
10
|
+
'Y': '-.--', 'Z': '--..',
|
|
11
|
+
'0': '-----', '1': '.----', '2': '..---',
|
|
12
|
+
'3': '...--', '4': '....-', '5': '.....',
|
|
13
|
+
'6': '-....', '7': '--...', '8': '---..',
|
|
14
|
+
'9': '----.',
|
|
15
|
+
' ': '/'
|
|
16
|
+
};
|
|
17
|
+
export const REVERSE_MORSE_MAP = Object.fromEntries(Object.entries(MORSE_MAP).map(([char, morse]) => [morse, char]));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MORSE_MAP, REVERSE_MORSE_MAP } from "./dictionary";
|
|
2
|
+
export function encode(text) {
|
|
3
|
+
if (!text)
|
|
4
|
+
return "";
|
|
5
|
+
return text
|
|
6
|
+
.toUpperCase()
|
|
7
|
+
.split('')
|
|
8
|
+
.map(char => MORSE_MAP[char] || char)
|
|
9
|
+
.join(' ')
|
|
10
|
+
.replace(/\s+/g, ' ')
|
|
11
|
+
.trim();
|
|
12
|
+
}
|
|
13
|
+
export function decode(morse) {
|
|
14
|
+
if (!morse)
|
|
15
|
+
return "";
|
|
16
|
+
return morse
|
|
17
|
+
.trim()
|
|
18
|
+
.split(' ')
|
|
19
|
+
.map(symbol => {
|
|
20
|
+
if (symbol === '/')
|
|
21
|
+
return ' ';
|
|
22
|
+
return REVERSE_MORSE_MAP[symbol] || symbol;
|
|
23
|
+
})
|
|
24
|
+
.join('')
|
|
25
|
+
.replace(/\s+/g, ' ');
|
|
26
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "morse-utils",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Utilitários para codificação e decodificação de Código Morse",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Caio M. Santos",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"keywords": ["morse", "typescript", "utils"],
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^26.0.1",
|
|
21
|
+
"typescript": "^6.0.3"
|
|
22
|
+
}
|
|
23
|
+
}
|