@microsoft/kiota-serialization-text
Advanced tools
Comparing version 1.0.0-preview.4 to 1.0.0-preview.5
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TextParseNodeFactory = void 0; | ||
const util_1 = require("util"); | ||
const textParseNode_1 = require("./textParseNode"); | ||
@@ -10,3 +11,6 @@ class TextParseNodeFactory { | ||
getRootParseNode(contentType, content) { | ||
if (!contentType) { | ||
if (!content) { | ||
throw new Error("content cannot be undefined of empty"); | ||
} | ||
else if (!contentType) { | ||
throw new Error("content type cannot be undefined or empty"); | ||
@@ -17,12 +21,9 @@ } | ||
} | ||
if (!content) { | ||
throw new Error("content cannot be undefined of empty"); | ||
} | ||
return new textParseNode_1.TextParseNode(this.convertArrayBufferToText(content)); | ||
} | ||
convertArrayBufferToText(arrayBuffer) { | ||
const uint8Array = new Uint8Array(arrayBuffer); | ||
return String.fromCharCode.apply(null, [...uint8Array]); | ||
const decoder = new util_1.TextDecoder(); | ||
return decoder.decode(arrayBuffer); | ||
} | ||
} | ||
exports.TextParseNodeFactory = TextParseNodeFactory; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const textParseNode_1 = require("../../src/textParseNode"); | ||
const index_1 = require("../../src/index"); | ||
describe("textParseNode", () => { | ||
it("textParseNode", async () => { | ||
const textParseNode = new textParseNode_1.TextParseNode("Test"); | ||
const textParseNode = new index_1.TextParseNode("Test"); | ||
chai_1.assert.isDefined(textParseNode); | ||
}); | ||
}); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
const textParseNodeFactory_1 = require("../../src/textParseNodeFactory"); | ||
const index_1 = require("../../src/index"); | ||
describe("textParseNodeFactory", () => { | ||
it("textParseNodeFactory", async () => { | ||
const textParseNodeFactory = new textParseNodeFactory_1.TextParseNodeFactory(); | ||
const textParseNodeFactory = new index_1.TextParseNodeFactory(); | ||
chai_1.assert.isDefined(textParseNodeFactory); | ||
}); | ||
it("textParseNodeFactory:convertArrayBufferToText should convert an array to text", async () => { | ||
const textParseNodeFactory = new textParseNodeFactory_1.TextParseNodeFactory(); | ||
const textParseNodeFactory = new index_1.TextParseNodeFactory(); | ||
const expectedText = "hello serializer"; | ||
@@ -13,0 +13,0 @@ const sampleArrayBuffer = new TextEncoder().encode(expectedText); |
@@ -0,1 +1,2 @@ | ||
import { TextDecoder } from "util"; | ||
import { TextParseNode } from "./textParseNode"; | ||
@@ -7,3 +8,6 @@ export class TextParseNodeFactory { | ||
getRootParseNode(contentType, content) { | ||
if (!contentType) { | ||
if (!content) { | ||
throw new Error("content cannot be undefined of empty"); | ||
} | ||
else if (!contentType) { | ||
throw new Error("content type cannot be undefined or empty"); | ||
@@ -14,11 +18,8 @@ } | ||
} | ||
if (!content) { | ||
throw new Error("content cannot be undefined of empty"); | ||
} | ||
return new TextParseNode(this.convertArrayBufferToText(content)); | ||
} | ||
convertArrayBufferToText(arrayBuffer) { | ||
const uint8Array = new Uint8Array(arrayBuffer); | ||
return String.fromCharCode.apply(null, [...uint8Array]); | ||
const decoder = new TextDecoder(); | ||
return decoder.decode(arrayBuffer); | ||
} | ||
} |
import { assert } from "chai"; | ||
import { TextParseNode } from "../../src/textParseNode"; | ||
import { TextParseNode } from "../../src/index"; | ||
describe("textParseNode", () => { | ||
@@ -4,0 +4,0 @@ it("textParseNode", async () => { |
import { assert } from "chai"; | ||
import { TextParseNodeFactory } from "../../src/textParseNodeFactory"; | ||
import { TextParseNodeFactory } from "../../src/index"; | ||
describe("textParseNodeFactory", () => { | ||
@@ -4,0 +4,0 @@ it("textParseNodeFactory", async () => { |
{ | ||
"name": "@microsoft/kiota-serialization-text", | ||
"version": "1.0.0-preview.4", | ||
"version": "1.0.0-preview.5", | ||
"description": "Implementation of Kiota Serialization interfaces for text", | ||
@@ -10,2 +10,6 @@ "files": [ | ||
"main": "dist/cjs/src/index.js", | ||
"browser": { | ||
"./dist/es/src/index.js": "./dist/es/src/browser/index.js", | ||
"./dist/es/src/textParseNodeFactory.js": "./dist/es/src/browser/textParseNodeFactory.js" | ||
}, | ||
"module": "dist/es/src/index.js", | ||
@@ -47,3 +51,3 @@ "types": "dist/cjs/src/index.d.ts", | ||
}, | ||
"gitHead": "a63f341363fbb46f1dfc85b03a5a270e5a2ded52" | ||
"gitHead": "5e793c70efdc69b446bb9641ddfc12818e54e968" | ||
} |
import { ParseNode, ParseNodeFactory } from "@microsoft/kiota-abstractions"; | ||
import { TextDecoder } from "util"; | ||
@@ -13,3 +14,5 @@ import { TextParseNode } from "./textParseNode"; | ||
): ParseNode { | ||
if (!contentType) { | ||
if (!content) { | ||
throw new Error("content cannot be undefined of empty"); | ||
} else if (!contentType) { | ||
throw new Error("content type cannot be undefined or empty"); | ||
@@ -19,5 +22,2 @@ } else if (this.getValidContentType() !== contentType) { | ||
} | ||
if (!content) { | ||
throw new Error("content cannot be undefined of empty"); | ||
} | ||
return new TextParseNode(this.convertArrayBufferToText(content)); | ||
@@ -27,5 +27,5 @@ } | ||
private convertArrayBufferToText(arrayBuffer: ArrayBuffer) { | ||
const uint8Array = new Uint8Array(arrayBuffer); | ||
return String.fromCharCode.apply(null, [...uint8Array]); | ||
const decoder = new TextDecoder(); | ||
return decoder.decode(arrayBuffer); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
508327
73
12231