Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,9 @@ kle.Serial.deserialize(rows: Array<any>): Keyboard
- The first entry is optionally a keyboard metadata object.

```ts
kle.Serial.parse(json5: string): Keyboard
kle.Serial.parse(json: 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
Expand Down
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@
},
"homepage": "https://github.com/qmk-helper/kle-serial/#readme",
"devDependencies": {
"@types/json5": "0.0.30",
"chai": "^4.2.0",
"coveralls": "^3.1.0",
"mocha": "^8.1.3",
"typescript": "^3.9.7",
"nyc": "^15.1.0"
},
"dependencies": {
"json5": "^2.1.3"
"nyc": "^15.1.0",
"typescript": "^3.9.7"
}
}
3 changes: 1 addition & 2 deletions src/deserialize.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as JSON5 from "json5";
import { labelMap } from "./helper";
import { Key, Keyboard } from "./interfaces";

function deserializeError(msg, data?) {
throw "Error: " + msg + (data ? ":\n " + JSON5.stringify(data) : "");
throw "Error: " + msg + (data ? ":\n " + JSON.stringify(data) : "");
}

// Map from serialized label position to normalized position,
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as JSON5 from "json5";
import { deserialize } from "./deserialize";
import { Keyboard } from "./interfaces";
import { serialize } from "./serialize";
Expand All @@ -12,7 +11,7 @@ export {
export { serialize } from "./serialize";

export function parse(json: string): Keyboard {
return deserialize(JSON5.parse(json));
return deserialize(JSON.parse(json));
}
export function stringify(keyboard: Keyboard): string {
return JSON.stringify(serialize(keyboard));
Expand Down
3 changes: 1 addition & 2 deletions src/serialize.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as JSON5 from "json5";
import { labelMap } from "./helper";
import { Key, Keyboard, KeyboardMetadata } from "./interfaces";

Expand All @@ -10,7 +9,7 @@ function serializeProp(props, nname, val, defval) {
return val;
}
function serializeError(msg: string, data?: any) {
throw "Error: " + msg + (data ? ":\n " + JSON5.stringify(data) : "");
throw "Error: " + msg + (data ? ":\n " + JSON.stringify(data) : "");
}
function isEmptyObject(o) {
for (var prop in o) return false;
Expand Down