Skip to content

Commit

Permalink
Merge pull request #5649 from caugner/sort-bcd-history-by-version
Browse files Browse the repository at this point in the history
fix(bcd): show history chronologically + sort
  • Loading branch information
caugner committed Mar 17, 2022
2 parents 1293104 + 34cb4e4 commit 548376c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
57 changes: 57 additions & 0 deletions build/document-extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ function _addSingleSpecialSection($) {
}
}
}
info.sort((a, b) =>
_compareVersions(_getFirstVersion(b), _getFirstVersion(a))
);
}
}
}
Expand All @@ -460,6 +463,60 @@ function _addSingleSpecialSection($) {
];
}

/**
* @param {object} support - {bcd.SimpleSupportStatement}
* @returns {string}
*/
function _getFirstVersion(support) {
if (typeof support.version_added === "string") {
return support.version_added;
} else if (typeof support.version_removed === "string") {
return support.version_removed;
} else {
return "0";
}
}

/**
* @param {string} a
* @param {string} b
*/
function _compareVersions(a, b) {
const x = _splitVersion(a);
const y = _splitVersion(b);

return _compareNumberArray(x, y);
}

/**
* @param {number[]} a
* @param {number[]} b
* @return {number}
*/
function _compareNumberArray(a, b) {
while (a.length || b.length) {
const x = a.shift() || 0;
const y = b.shift() || 0;
if (x !== y) {
return x - y;
}
}

return 0;
}

/**
* @param {string} version
* @return {number[]}
*/
function _splitVersion(version) {
if (version.startsWith("≤")) {
version = version.slice(1);
}

return version.split(".").map(Number);
}

function _buildSpecialSpecSection() {
// Collect spec URLs from a BCD feature, a 'spec-urls' value, or both;
// For a BCD feature, it can either be a string or an array of strings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ function getNotes(
) {
if (support) {
return asList(support)
.slice()
.reverse()
.flatMap((item, i) => {
const supportNotes = [
item.version_removed
Expand Down

0 comments on commit 548376c

Please sign in to comment.