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

Function referenceSort

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

Source from the content-addressed store, hash-verified

197}
198
199function referenceSort(a, b) {
200 // Extract the number from the reference
201 const numA = parseInt(a.replace(/\D/g, ''), 10);
202 const numB = parseInt(b.replace(/\D/g, ''), 10);
203
204 // Check if both are direct references or subproject references
205 const isDirectA = a.startsWith('#');
206 const isDirectB = b.startsWith('#');
207
208 if (isDirectA && isDirectB) {
209 // If both are direct references, sort by the number
210 return numA - numB;
211 } else if (!isDirectA && !isDirectB) {
212 // If both are subproject references, sort by the name and then the number
213 const nameA = a.split('#')[0];
214 const nameB = b.split('#')[0];
215 if (nameA.toLowerCase() < nameB.toLowerCase()) return -1;
216 if (nameA.toLowerCase() > nameB.toLowerCase()) return 1;
217 return numA - numB;
218 } else {
219 // If one is a direct reference and the other is a subproject reference,
220 // the direct reference should come first
221 return isDirectA ? -1 : 1;
222 }
223}
224
225function reorderGroups(a, b) {
226 const changeTypeDiff = ChangeTypes.indexOf(a.changeType) - ChangeTypes.indexOf(b.changeType);

Callers 1

cleanupVersionBlockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected