MCPcopy
hub / github.com/webpack/webpack / sortByField

Function sortByField

lib/stats/DefaultStatsFactoryPlugin.js:2568–2593  ·  view source on GitHub ↗
(field)

Source from the content-addressed store, hash-verified

2566 * @returns {(a: T, b: T) => 0 | 1 | -1} comparators
2567 */
2568const sortByField = (field) => {
2569 if (!field) {
2570 /**
2571 * Returns zero.
2572 * @param {T} a first
2573 * @param {T} b second
2574 * @returns {-1 | 0 | 1} zero
2575 */
2576 const noSort = (a, b) => 0;
2577 return noSort;
2578 }
2579
2580 const fieldKey = normalizeFieldKey(field);
2581
2582 let sortFn = compareSelect((m) => m[fieldKey], compareIds);
2583
2584 // if a field is prefixed with a "!" the sort is reversed!
2585 const sortIsRegular = sortOrderRegular(field);
2586
2587 if (!sortIsRegular) {
2588 const oldSortFn = sortFn;
2589 sortFn = (a, b) => oldSortFn(b, a);
2590 }
2591
2592 return sortFn;
2593};
2594
2595/**
2596 * Describes the asset sorters shape.

Callers 1

Calls 3

normalizeFieldKeyFunction · 0.85
compareSelectFunction · 0.85
sortOrderRegularFunction · 0.85

Tested by

no test coverage detected