@rulecad/keyboard-layout 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/keyboard-layout.mjs +4 -2
- package/package.json +1 -1
package/keyboard-layout.mjs
CHANGED
|
@@ -90,9 +90,11 @@ export function fromKLE(kle) {
|
|
|
90
90
|
|
|
91
91
|
// "Raw data" from keyboard-layout-editor.com is JSON with its object keys unquoted and the outer brackets left off
|
|
92
92
|
function parseRaw(text) {
|
|
93
|
-
|
|
93
|
+
// (one row on its own is a list with no lists in it: a three-key macropad's raw data. It is a layout of one row)
|
|
94
|
+
const rows = (data) => (Array.isArray(data) && data.length && !data.some(Array.isArray) ? [data] : data);
|
|
95
|
+
try { return rows(JSON.parse(text)); } catch {}
|
|
94
96
|
const quoted = `[${text}]`.replace(/([{,]\s*)([A-Za-z_][\w]*)\s*:/g, '$1"$2":');
|
|
95
|
-
try { return JSON.parse(quoted); } catch { throw new Error("this isn't keyboard-layout-editor data: paste its Raw data, or use its JSON download"); }
|
|
97
|
+
try { return rows(JSON.parse(quoted)); } catch { throw new Error("this isn't keyboard-layout-editor data: paste its Raw data, or use its JSON download"); }
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
// A key's legends: "Q", or "!\n1" (top-left shifted, bottom-left main), up to twelve positions
|