1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export class TextMessageFormat {
|
7 | public static RecordSeparatorCode = 0x1e;
|
8 | public static RecordSeparator = String.fromCharCode(TextMessageFormat.RecordSeparatorCode);
|
9 |
|
10 | public static write(output: string): string {
|
11 | return `${output}${TextMessageFormat.RecordSeparator}`;
|
12 | }
|
13 |
|
14 | public static parse(input: string): string[] {
|
15 | if (input[input.length - 1] !== TextMessageFormat.RecordSeparator) {
|
16 | throw new Error("Message is incomplete.");
|
17 | }
|
18 |
|
19 | const messages = input.split(TextMessageFormat.RecordSeparator);
|
20 | messages.pop();
|
21 | return messages;
|
22 | }
|
23 | }
|