diff --git a/src/topdoc-parser.js b/src/topdoc-parser.js index 512864d..1b57f16 100644 --- a/src/topdoc-parser.js +++ b/src/topdoc-parser.js @@ -24,6 +24,15 @@ function _parseTopdocComment(node, regex, includeNodes) { return component; } +/** + * Private: A compare function that sorts array members by their 'name' property. + */ +function _nameCompareFunction(a, b) { + if (a.name < b.name) return -1; + if (a.name > b.name) return 1; + return 0; +} + /** * Private: goes through each css node and finds Topdoc comments. * @@ -47,10 +56,11 @@ function _findTopdocComments(css, regex, includeNodes) { debug(`Added ${node.type} to ${components[currentComponentIndex].name}`); } }); - return components; + // TODO: sort function could be passed as an option + // if someone needs that but for now alpha is a good default + return components.sort(_nameCompareFunction); } - -/** +/* * TopdocParser Class */ export default class TopdocParser {