From aee5dffd8013f6f6a6b77e5d00edd981bcfcad48 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Fri, 12 Dec 2025 15:22:14 +0100 Subject: Use component/s instead of vert(ex/ices) and circle as default shape --- src/index.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/index.js b/src/index.js index 653de18..24a2c2e 100644 --- a/src/index.js +++ b/src/index.js @@ -9,13 +9,18 @@ * @typedef {Component|Dependency|Note|Stage|Group|Inertia|Evolution} Entity */ +/** + * Any of the potential shapes in a component. + * @typedef {"x"|"square"|"triangle"|"circle"} Shape + */ + /** * A component in the map. * @typedef {Object} Component * @property {'component'} type - Entity type * @property {string} label - Component label * @property {[number, number]} coordinates - X and Y coordinates - * @property {string|null} shape - Shape type (x, square, triangle, circle) or null + * @property {Shape} shape - Shape of the component */ /** @@ -47,21 +52,21 @@ * A group of components. * @typedef {Object} Group * @property {'group'} type - Entity type - * @property {string[]} vertices - Array of component labels in the group + * @property {string[]} components - Array of component labels in the group */ /** * Inertia associated with a component. * @typedef {Object} Inertia * @property {'inertia'} type - Entity type - * @property {string} vertex - Component label with inertia + * @property {string} component - Component label with inertia */ /** * Evolution associated with a component. * @typedef {Object} Evolution * @property {'evolution'} type - Entity type - * @property {string} vertex - Component label + * @property {string} component - Component label * @property {boolean} isPositive - Whether evolution is positive (+) or negative (-) * @property {number} value - Evolution value */ @@ -199,18 +204,18 @@ function parseKeywordEntity(line, start, length) { // Group: [Group] label1, label2, ... if (keyword === "group") { - const vertices = line + const components = line .substring(i) .split(",") .map(v => v.trim()) .filter(v => v); - return vertices.length > 0 ? { type: "group", vertices } : null; + return components.length > 0 ? { type: "group", components } : null; } // Inertia: [Inertia] label if (keyword === "inertia") { - const vertex = line.substring(i).trim(); - return vertex ? { type: "inertia", vertex } : null; + const component = line.substring(i).trim(); + return component ? { type: "inertia", component } : null; } // Evolution: [Evolution] label +/- number @@ -232,8 +237,8 @@ function parseKeywordEntity(line, start, length) { if (indexOfSign === -1 || indexOfSign === i) return null; - const vertex = line.substring(i, indexOfSign).trim(); - if (!vertex) return null; + const component = line.substring(i, indexOfSign).trim(); + if (!component) return null; // Read number after sign let indexOfNumber = indexOfSign + 1; @@ -244,7 +249,7 @@ function parseKeywordEntity(line, start, length) { return { type: "evolution", - vertex, + component, isPositive: signCharacter === "+", value: parseFloat(line.substring(numStart, indexOfNumber)), }; @@ -334,7 +339,7 @@ function parseComponent(line, indexOfParenthesis, length) { i++; // Optional shape: [shape] - let shape = null; + let shape = "circle"; while (i < length && isWhitespace(line[i])) i++; if (i < length && line[i] === "[") { i++; -- cgit