@microsoft/kiota-serialization-text
Version:
Implementation of Kiota Serialization interfaces for text
36 lines • 1.43 kB
JavaScript
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { TextParseNode } from "./textParseNode.js";
export class TextParseNodeFactory {
/**
* Creates an instance of TextParseNode.
* @param backingStoreFactory - The factory to create backing stores.
*/
constructor(backingStoreFactory) {
this.backingStoreFactory = backingStoreFactory;
}
getValidContentType() {
return "text/plain";
}
getRootParseNode(contentType, content) {
if (!content) {
throw new Error("content cannot be undefined of empty");
}
else if (!contentType) {
throw new Error("content type cannot be undefined or empty");
}
else if (this.getValidContentType() !== contentType) {
throw new Error(`expected a ${this.getValidContentType()} content type`);
}
return new TextParseNode(this.convertArrayBufferToText(content));
}
convertArrayBufferToText(arrayBuffer) {
const decoder = new TextDecoder();
return decoder.decode(arrayBuffer);
}
}
//# sourceMappingURL=textParseNodeFactory.js.map