Morse code transforms a message using short and long impulses. It was one of the first telecommunication codes invented.
- Case sensitive? ❌
- Deterministic? ✓
- Alphabet:
ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 .,:;?-_()'=+/@
- Characters not in alphabet will be: preserved, omitted or throwing an error (default)
The options are the same for both methods, encode
and decode
const options = {
separator: ' ', // Custom delimiter or glue
failOnUnknownCharacter: true, // Should an error be thrown when a character is not included in the alphabet
omitUnknownCharacter: false // Should unknown character be omitted or preserverd? (Only if failOnUnknownCharacter is false)
}
import { morse } from 'cipher-collection'
console.log(morse.encode('SOS')) // ... --- ...
import { morse } from 'cipher-collection'
const options = { separator: '~' }
console.log(morse.encode('SOS', options)) // ...~---~...
There are two options when disabling errors:
import { morse } from 'cipher-collection'
const preserveOptions = {
separator: '',
failOnUnknownCharacter: false,
omitUnknownCharacter: false
}
// Preserve chraracters that can't get encoded
console.log(morse.encode('€€€', preserveOptions)) // €€€
const omitOptions = {
separator: '',
failOnUnknownCharacter: false,
omitUnknownCharacter: true
}
// omit chraracters that can't get encoded
console.log(morse.encode('€€€S', omitOptions)) // ...
import { morse } from 'cipher-collection'
console.log(morse.decode('... --- ...')) // SOS
import { morse } from 'cipher-collection'
const options = { separator: '~' }
console.log(morse.decode('...~---~...', options)) // SOS
Similar to encode
, there are two options when disabling errors:
import { morse } from 'cipher-collection'
const preserveOptions = {
failOnUnknownCharacter: false,
omitUnknownCharacter: false
}
// Preserve chraracters that can't get decoded
console.log(morse.decode('.-.-.-.-.-', preserveOptions)) // .-.-.-.-.-
const omitOptions = {
failOnUnknownCharacter: false,
omitUnknownCharacter: true
}
// omit chraracters that can't get decoded
console.log(morse.decode('.-.-.-.-.- ...', omitOptions)) // S