diff --git a/README.md b/README.md index 34165a6..2768361 100644 --- a/README.md +++ b/README.md @@ -40,13 +40,6 @@ var keyboard = kle.Serial.deserialize([ { name: "Sample", author: "Your Name" }, ["Q", "W", "E", "R", "T", "Y"] ]); - -// or - -var keyboard = kle.Serial.parse(`[ - { name: "Sample", author: "Your Name" }, - ["Q", "W", "E", "R", "T", "Y"] -]`); ``` ## API @@ -59,16 +52,6 @@ kle.Serial.deserialize(rows: Array): Keyboard object. - The first entry is optionally a keyboard metadata object. -```ts -kle.Serial.parse(json5: string): Keyboard -``` - -- This function takes a JSON5-formatted string, parses it, then deserializes the - result into a `Keyboard` object. -- [JSON5](https://json5.org/) is a simplified / lenient version of JSON that is - easier for humans to type; in particular, it doesn't require quotes around - property names. Any valid JSON string should also be a valid JSON5 string. - ### Keyboard Objects ```ts diff --git a/index.ts b/index.ts index 260c357..85b49fc 100644 --- a/index.ts +++ b/index.ts @@ -1,5 +1,3 @@ -import * as JSON5 from "json5"; - export class Key { color: string = "#cccccc"; labels: string[] = []; @@ -92,7 +90,7 @@ export module Serial { } function deserializeError(msg, data?) { - throw "Error: " + msg + (data ? ":\n " + JSON5.stringify(data) : ""); + throw "Error: " + msg + (data ? ":\n " + JSON.stringify(data) : ""); } export function deserialize(rows: Array): Keyboard { @@ -204,8 +202,4 @@ export module Serial { } return kbd; } - - export function parse(json: string): Keyboard { - return deserialize(JSON5.parse(json)); - } } diff --git a/package.json b/package.json index 3e7a33c..3716110 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,5 @@ "mocha": "^6.1.4", "mocha-lcov-reporter": "^1.3.0", "typescript": "^3.5.3" - }, - "dependencies": { - "json5": "^2.1.0" } } diff --git a/test/test.js b/test/test.js index 8abd3dc..dc30ad5 100644 --- a/test/test.js +++ b/test/test.js @@ -449,31 +449,4 @@ describe("deserialization", function() { expect(result.keys[2].textSize[6]).to.equal("2"); }); }); - - describe("of strings", function() { - it("should be lenient about quotes", function() { - var result1 = () => - kbd.Serial.parse(`[ - { name: "Sample", author: "Your Name" }, - ["Q", "W", "E", "R", "T", "Y"] - ]`); - - var result2 = () => - kbd.Serial.parse(`[ - { "name": "Sample", "author": "Your Name" }, - ["Q", "W", "E", "R", "T", "Y"] - ]`); - - var result3 = () => - kbd.Serial.deserialize([ - { name: "Sample", author: "Your Name" }, - ["Q", "W", "E", "R", "T", "Y"] - ]); - - expect(result1).to.not.throw(); - expect(result2).to.not.throw(); - expect(result1(), "1<>2").to.deep.equal(result2()); - expect(result1(), "1<>3").to.deep.equal(result3()); - }); - }); });