@ozdemirburak/morse-code-translator 7.0.0 → 8.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/LICENSE +1 -1
- package/README.md +110 -7
- package/dist/index.d.ts +10 -11
- package/dist/morse-code-translator.es.js +448 -181
- package/dist/morse-code-translator.es.js.map +1 -1
- package/dist/morse-code-translator.umd.js +1 -1
- package/dist/morse-code-translator.umd.js.map +1 -1
- package/dist/types.d.ts +24 -22
- package/package.json +42 -29
- package/dist/audio.d.ts +0 -4
- package/dist/audio.d.ts.map +0 -1
- package/dist/characters.d.ts +0 -12
- package/dist/characters.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/options.d.ts +0 -4
- package/dist/options.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -13,6 +13,22 @@ Persian, Japanese, Korean, and Thai, with audio-generation functionality using t
|
|
|
13
13
|
$ npm install @ozdemirburak/morse-code-translator --save
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
```js
|
|
17
|
+
import morse from '@ozdemirburak/morse-code-translator'; // ES module
|
|
18
|
+
const morse = require('@ozdemirburak/morse-code-translator').default; // CommonJS (Node 22.12+, require(esm))
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The package is ESM-only and needs Node.js 22.12 or later (Node 22.12 itself prints an `ExperimentalWarning`
|
|
22
|
+
on `require()`; newer releases do not). TypeScript users need `moduleResolution` `bundler` or `nodenext`;
|
|
23
|
+
the CommonJS form `import morse = require(...)` in `.cts` files needs TypeScript 5.8 or later.
|
|
24
|
+
|
|
25
|
+
### Browser (CDN)
|
|
26
|
+
|
|
27
|
+
```html
|
|
28
|
+
<script src="https://cdn.jsdelivr.net/npm/@ozdemirburak/morse-code-translator@8/dist/morse-code-translator.umd.js"></script>
|
|
29
|
+
<script>MorseCodeTranslator.encode('SOS');</script>
|
|
30
|
+
```
|
|
31
|
+
|
|
16
32
|
## Usage
|
|
17
33
|
|
|
18
34
|
```js
|
|
@@ -20,7 +36,8 @@ import morse from '@ozdemirburak/morse-code-translator';
|
|
|
20
36
|
|
|
21
37
|
const encoded = morse.encode('SOS'); // ... --- ...
|
|
22
38
|
const decoded = morse.decode('... --- ...'); // SOS
|
|
23
|
-
const characters = morse.characters(); // {'1': {'A': '.-', ...}, ..., '
|
|
39
|
+
const characters = morse.characters(); // {'1': {'A': '.-', ...}, ..., '12': {'ก': '--.', ...}}
|
|
40
|
+
const withPriority = morse.characters({ priority: 5 }, true); // also includes the priority set as key '0'
|
|
24
41
|
|
|
25
42
|
const audio = morse.audio('SOS');
|
|
26
43
|
|
|
@@ -30,7 +47,7 @@ audio.pause(); // pause audio
|
|
|
30
47
|
await audio.play(); // resume from paused position
|
|
31
48
|
await audio.seek(1.5); // seek to 1.5 seconds
|
|
32
49
|
audio.stop(); // stop audio and reset to beginning
|
|
33
|
-
audio.
|
|
50
|
+
audio.stop(true); // stop and release the rendered audio (it re-renders on the next play/export)
|
|
34
51
|
|
|
35
52
|
// Playback state and info
|
|
36
53
|
audio.getState(); // 'ready', 'playing', 'paused', 'stopped', or 'disposed'
|
|
@@ -41,6 +58,11 @@ audio.getTotalTime(); // total duration in seconds
|
|
|
41
58
|
await audio.exportWave(); // download audio wave file (promise)
|
|
42
59
|
const url = await audio.getWaveUrl(); // get audio wave url (promise)
|
|
43
60
|
const blob = await audio.getWaveBlob(); // get audio wave blob (promise)
|
|
61
|
+
|
|
62
|
+
audio.dispose(); // release everything; the instance cannot be used after this
|
|
63
|
+
|
|
64
|
+
// Play your own Morse instead of encoding text (any whitespace separates characters)
|
|
65
|
+
const custom = morse.audio('', {}, '... --- ...');
|
|
44
66
|
```
|
|
45
67
|
|
|
46
68
|
### Options and localization
|
|
@@ -70,7 +92,7 @@ const cyrillic = morse.encode('Ленинград', { priority: 5 }); // .-.. .
|
|
|
70
92
|
const greek = morse.decode('... .- --. .- .--. .--', { priority: 6 }); // ΣΑΓΑΠΩ
|
|
71
93
|
const hebrew = morse.decode('.. ––– . –––', { dash: '–', dot: '.', priority: 7 }); // יהוה
|
|
72
94
|
const japanese = morse.encode('NEWS', { priority: 10, dash: '-', dot: '・', separator: ' ' }); // -・ ・ ・-- ・・・
|
|
73
|
-
const characters = morse.characters({ dash: '–', dot: '•' }); // {'1': {'A': '•–', ...}, ..., '11': {'ㄱ': '•–••', ...}}
|
|
95
|
+
const characters = morse.characters({ dash: '–', dot: '•' }); // {'1': {'A': '•–', ...}, ..., '11': {'ㄱ': '•–••', ...}, ...}
|
|
74
96
|
const arabicAudio = morse.audio('البراق', { // generates the Morse .- .-.. -... .-. .- --.- then generates the audio from it
|
|
75
97
|
wpm: 18, // sets the wpm based on the Paris method, note that setting this will override and set the unit and fwUnits accordingly
|
|
76
98
|
unit: 0.1, // period of one unit, in seconds, 1.2 / c where c is speed of transmission, in words per minute
|
|
@@ -90,10 +112,8 @@ const arabicAudio = morse.audio('البراق', { // generates the Morse .- .-..
|
|
|
90
112
|
}
|
|
91
113
|
});
|
|
92
114
|
|
|
93
|
-
//
|
|
94
|
-
const
|
|
95
|
-
const context = arabicAudio.context; // AudioContext
|
|
96
|
-
const gainNode = arabicAudio.gainNode; // GainNode
|
|
115
|
+
// The live AudioContext used for playback (created on first access)
|
|
116
|
+
const context = arabicAudio.context;
|
|
97
117
|
|
|
98
118
|
// Playback control
|
|
99
119
|
await arabicAudio.play(); // will start playing Morse audio
|
|
@@ -102,6 +122,89 @@ await arabicAudio.play(); // will resume from where it was paused
|
|
|
102
122
|
arabicAudio.stop(); // will stop and reset to beginning
|
|
103
123
|
```
|
|
104
124
|
|
|
125
|
+
### Options
|
|
126
|
+
|
|
127
|
+
| Option | Default | Notes |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| `dot` | `'.'` | Dot symbol. Must differ from `dash`, neither may start with the other, and it must not contain whitespace, `space` or `separator`. |
|
|
130
|
+
| `dash` | `'-'` | Dash symbol. Same rules as `dot`. |
|
|
131
|
+
| `separator` | `' '` | Between characters. A single character that is not itself encodable (so not a key such as `'X'` or `'?'`) and differs from `dot`/`dash`. |
|
|
132
|
+
| `space` | `'/'` | Word gap. A single, non-whitespace character that differs from `separator`, `dot` and `dash`. |
|
|
133
|
+
| `invalid` | `'#'` | Output for unknown characters; `''` drops them. Must not consist only of `dot`/`dash` symbols, or contain whitespace, `space` or `separator`. |
|
|
134
|
+
| `priority` | `1` | Character set to search first (1-12, number or numeric string). |
|
|
135
|
+
| `unit` | `0.08` | Length of one unit in seconds (15 wpm). |
|
|
136
|
+
| `fwUnit` | `unit` | Farnsworth unit for the gaps between characters and words. |
|
|
137
|
+
| `wpm` | – | Words per minute (PARIS); overrides `unit` and `fwUnit`. |
|
|
138
|
+
| `volume` | `100` | 0-100, out-of-range values are clamped. |
|
|
139
|
+
| `oscillator.type` | `'sine'` | `sine`, `square`, `sawtooth` or `triangle`. |
|
|
140
|
+
| `oscillator.frequency` | `500` | Hertz, up to 22050. |
|
|
141
|
+
| `events` | – | `onready`, `onstarted`, `onpaused`, `onstopped`, `onended`, `onseeked(time)`. |
|
|
142
|
+
|
|
143
|
+
Invalid symbol options throw an error (they would corrupt the output); invalid numeric options fall back
|
|
144
|
+
to their default. Text and symbol options must be strings (`TypeError` otherwise).
|
|
145
|
+
|
|
146
|
+
### Writing systems
|
|
147
|
+
|
|
148
|
+
Text is folded to the forms Morse operators send before it is encoded:
|
|
149
|
+
|
|
150
|
+
- Korean syllables are split into jamo (한 → ㅎㅏㄴ), double and compound jamo into basic jamo (ㄲ → ㄱㄱ, ㅘ → ㅗㅏ).
|
|
151
|
+
- Japanese hiragana, small kana and half-width kana are sent as full-size katakana (きゃ → キヤ); voiced kana as kana + ゛.
|
|
152
|
+
- Greek tonos is not transmitted (ή → Η); Russian Ё is sent as Е; Hebrew final forms as their base letters; ẞ as SS.
|
|
153
|
+
- Thai letters that share a sound share a code (ศ ษ ส).
|
|
154
|
+
- Hebrew points and cantillation, Arabic vowel marks, a leftover hamza or madda mark (such as the Persian
|
|
155
|
+
ezafe on ه) and the tatweel are not transmitted; letters such as أ that contain a hamza stay as they are.
|
|
156
|
+
Arabic-Indic, Persian and Thai digits are sent as digits (٣ → 3).
|
|
157
|
+
- Full-width Latin letters and digits are sent as ASCII (SOS → SOS); Thai ํ + า is sent as ำ; Arabic ؟ ، ؛
|
|
158
|
+
and the Hebrew maqaf ־ are sent as ? , ; and -.
|
|
159
|
+
- Invisible characters (Unicode default-ignorable code points: zero-width joiners, direction marks, soft
|
|
160
|
+
hyphens, the BOM, variation selectors, Hangul fillers) are ignored. An unknown visible character, such
|
|
161
|
+
as an emoji, gives one `invalid` marker (one per code point in engines without `Intl.Segmenter`).
|
|
162
|
+
- A run of whitespace gives one word gap.
|
|
163
|
+
|
|
164
|
+
Decoding returns the base forms.
|
|
165
|
+
|
|
166
|
+
### Audio
|
|
167
|
+
|
|
168
|
+
Audio is rendered in chunks of about 30 seconds, so long texts play and export in full without one huge
|
|
169
|
+
buffer. Tones have 5 ms attack and release ramps, and playback fades in and out on play, pause, seek and stop,
|
|
170
|
+
so there are no clicks. `onended` follows the audio clock. Playback and WAV export together render at most
|
|
171
|
+
two chunks at a time, so seeking through a long text stays cheap; a chunk that fails to render is tried
|
|
172
|
+
again before playback stops. While `seek()` resumes playback, `getState()` stays `'playing'`. `play()`
|
|
173
|
+
creates and resumes the live `AudioContext` at once, inside the user gesture that called it, and
|
|
174
|
+
`dispose()` closes it after the stop fade. WAV export is limited by the format to about 13.5 hours, and it
|
|
175
|
+
keeps the 16-bit samples in memory until the `Blob` is built (about 320 MB per hour of audio). In Node.js
|
|
176
|
+
or during server-side rendering `audio()` throws, because there is no Web Audio API.
|
|
177
|
+
|
|
178
|
+
## Upgrading from 7.x
|
|
179
|
+
|
|
180
|
+
- ESM-only; Node.js 22.12 or later. CommonJS code can `require()` the package through Node's
|
|
181
|
+
require(esm) support. The UMD build (`dist/morse-code-translator.umd.js`) is for browsers and CDNs only.
|
|
182
|
+
TypeScript users need `moduleResolution` `bundler` or `nodenext` (TypeScript 5.8+ for `.cts` files).
|
|
183
|
+
- `decode('..-..')` returns `É` (ITU), not `Ę`; Arabic `.` decodes to `ء` (U+0621), not U+FE80.
|
|
184
|
+
- `decode('.-/-...')` returns `A B`; runs of a custom separator and spaces around it are ignored. Each
|
|
185
|
+
word-gap symbol decodes to a space, also next to a code: `.- // -...` gives `A B` (was `A#B`) and
|
|
186
|
+
`.-/` gives `A ` (was `#`).
|
|
187
|
+
- Characters that encoded as `#` now encode (see Writing systems). An unknown visible character gives one
|
|
188
|
+
marker (an emoji with a variation selector used to give two), and invisible characters give none.
|
|
189
|
+
- A run of whitespace or separator characters in the text, also around a dropped unknown character
|
|
190
|
+
(`invalid: ''`), gives one word gap: `encode('I ❤ YOU', { invalid: '' })` keeps the gap before `YOU`.
|
|
191
|
+
- New errors: dot/dash that are prefixes of each other or contain whitespace, an `invalid` marker that
|
|
192
|
+
contains whitespace, `space` or `separator`, and non-string text or symbols. `space` and `invalid` may now
|
|
193
|
+
contain `0` and `1`. The new table keys (Ё, ء, Hebrew final forms, the added Thai letters) can no longer
|
|
194
|
+
be used as `separator`.
|
|
195
|
+
- A custom separator no longer interacts with the text: `separator: 'x'` keeps word gaps (it used to
|
|
196
|
+
turn them into the letter X).
|
|
197
|
+
- `priority` accepts numeric strings; `volume` is clamped; a frequency above 22050 Hz falls back to 500.
|
|
198
|
+
- `characters()` no longer includes the internal separator entry.
|
|
199
|
+
- Audio: no 1-hour limit, ramps at tone edges, unknown characters add no silence, whitespace in a custom
|
|
200
|
+
Morse string separates characters, an explicit `''` Morse string is honored, `onstopped` also fires
|
|
201
|
+
when stopping from pause, `stop(true)` re-renders on the next play, and a throwing event callback is
|
|
202
|
+
logged instead of breaking the instance.
|
|
203
|
+
- Removed: `audio.oscillator` and `audio.gainNode` (they never affected playback), the deprecated
|
|
204
|
+
`oscillator.onended` option (use `events.onended`), and the `webkitAudioContext` fallbacks.
|
|
205
|
+
- Types: new `MorseOptions` (the `Options` type is no longer exported); `oscillator.type` excludes
|
|
206
|
+
`'custom'`; `AudioResult` members are readonly.
|
|
207
|
+
|
|
105
208
|
## Contributions
|
|
106
209
|
|
|
107
210
|
[morse-code-translator](https://github.com/ozdemirburak/morse-code-translator) has been developed
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const encode: (text: string, opts?:
|
|
3
|
-
export declare const decode: (morse: string, opts?:
|
|
4
|
-
export declare const characters: (options?:
|
|
5
|
-
export declare const audio: (text: string, opts?:
|
|
6
|
-
export type {
|
|
1
|
+
import type { MorseOptions, Characters, AudioResult } from './types.js';
|
|
2
|
+
export declare const encode: (text: string, opts?: MorseOptions | null) => string;
|
|
3
|
+
export declare const decode: (morse: string, opts?: MorseOptions | null) => string;
|
|
4
|
+
export declare const characters: (options?: MorseOptions | null, usePriority?: boolean) => Characters;
|
|
5
|
+
export declare const audio: (text: string, opts?: MorseOptions | null, morseString?: string) => AudioResult;
|
|
6
|
+
export type { MorseOptions, Characters, AudioResult, Oscillator, OscillatorWaveform, AudioState, AudioEvents } from './types.js';
|
|
7
7
|
declare const _default: {
|
|
8
|
-
encode:
|
|
9
|
-
decode:
|
|
10
|
-
characters:
|
|
11
|
-
audio:
|
|
8
|
+
encode: typeof encode;
|
|
9
|
+
decode: typeof decode;
|
|
10
|
+
characters: typeof characters;
|
|
11
|
+
audio: typeof audio;
|
|
12
12
|
};
|
|
13
13
|
export default _default;
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|