MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / reorderGroups

Function reorderGroups

scripts/format-changelog.js:225–250  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

223}
224
225function reorderGroups(a, b) {
226 const changeTypeDiff = ChangeTypes.indexOf(a.changeType) - ChangeTypes.indexOf(b.changeType);
227 if (changeTypeDiff != 0) {
228 return changeTypeDiff;
229 }
230 // If changeType is identical, sort based on reference
231 const hasMainRefA = a.refs.length > 0 && a.refs[0].startsWith("#");
232 const hasMainRefB = b.refs.length > 0 && b.refs[0].startsWith("#");
233 // Sort by main reference number.
234 if (hasMainRefA && hasMainRefB) {
235 const numA = parseInt(a.refs[0].replace(/\D/g, ''), 10);
236 const numB = parseInt(b.refs[0].replace(/\D/g, ''), 10);
237 return numA - numB;
238 } else if (hasMainRefA && !hasMainRefB) {
239 return -1;
240 } else if (!hasMainRefA && hasMainRefB) {
241 return 1;
242 } else {
243 // Sort by reference name.
244 const nameA = a.refs.length > 0 ? a.refs[0].split('#')[0] : "";
245 const nameB = b.refs.length > 0 ? b.refs[0].split('#')[0] : "";
246 if (nameA.toLowerCase() < nameB.toLowerCase()) return -1;
247 if (nameA.toLowerCase() > nameB.toLowerCase()) return 1;
248 return 0;
249 }
250}
251
252function cleanupVersionBlock(version) {
253 // Sort the references first, numbers come before sub project refs.

Callers 1

cleanupVersionBlockFunction · 0.85

Calls 1

indexOfMethod · 0.80

Tested by

no test coverage detected