From 81ed450f6533f7eec24d423e8d75d265e4b90f16 Mon Sep 17 00:00:00 2001 From: BigBlueHat Date: Sat, 18 Sep 2021 14:50:31 -0400 Subject: [PATCH 1/2] Remove JSON5 as a requirement; simplify Folks wanting JSON5 handling for their data can add that in their application layer. This removes the one dependency this project had, making it much more sustainable, simpler, and faster. Huzzah! --- index.ts | 6 ++---- package.json | 3 --- test/test.js | 27 --------------------------- 3 files changed, 2 insertions(+), 34 deletions(-) diff --git a/index.ts b/index.ts index 260c357..b502af0 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 { @@ -206,6 +204,6 @@ export module Serial { } export function parse(json: string): Keyboard { - return deserialize(JSON5.parse(json)); + return deserialize(JSON.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()); - }); - }); }); From d30aad855a0a99dac7a375e0d3df0770f39fcbc9 Mon Sep 17 00:00:00 2001 From: BigBlueHat Date: Sat, 18 Sep 2021 14:54:33 -0400 Subject: [PATCH 2/2] Remove parse(); Leave it to others kle.Serial.deserialize(JSON.parse(`[]`)) is equivalent now. --- README.md | 17 ----------------- index.ts | 4 ---- 2 files changed, 21 deletions(-) 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 b502af0..85b49fc 100644 --- a/index.ts +++ b/index.ts @@ -202,8 +202,4 @@ export module Serial { } return kbd; } - - export function parse(json: string): Keyboard { - return deserialize(JSON.parse(json)); - } }