UNPKG

858 BPlain TextView Raw
1// Copyright (c) .NET Foundation. All rights reserved.
2// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
4// Not exported from index
5/** @private */
6export 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}