MCPcopy Create free account
hub / github.com/Kong/insomnia / httpMethodSort

Function httpMethodSort

packages/insomnia/src/common/sorting.ts:44–77  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

42};
43
44export const httpMethodSort: SortFunction<Pick<SortableModel, 'type' | 'metaSortKey' | '_id'>> = (a, b) => {
45 // Sort Requests and GrpcRequests to top, in that order
46 if (a.type !== b.type) {
47 if (isRequest(a) || isRequest(b)) {
48 return isRequest(a) ? -1 : 1;
49 }
50
51 if (models.grpcRequest.isGrpcRequest(a) || models.grpcRequest.isGrpcRequest(b)) {
52 return models.grpcRequest.isGrpcRequest(a) ? -1 : 1;
53 }
54 }
55
56 // Sort Requests by HTTP method
57 if (isRequest(a)) {
58 const aIndex = HTTP_METHODS.indexOf(a.method);
59 // @ts-expect-error -- TSCONVERSION
60 const bIndex = HTTP_METHODS.indexOf(b.method);
61
62 if (aIndex !== bIndex) {
63 return aIndex < bIndex ? -1 : 1;
64 }
65
66 // Sort by ascending method name if comparing two custom methods
67 // @ts-expect-error -- TSCONVERSION
68 if (aIndex === -1 && a.method.localeCompare(b.method) !== 0) {
69 // @ts-expect-error -- TSCONVERSION
70 return a.method.localeCompare(b.method);
71 }
72 }
73
74 // Sort by metaSortKey if comparing two Requests with the same method,
75 // two GrpcRequests, or two RequestGroups
76 return metaSortKeySort(a, b);
77};
78
79export const ascendingTypeSort: SortFunction<Pick<SortableModel, 'type' | 'metaSortKey' | '_id'>> = (a, b) => {
80 if (a.type !== b.type && (isRequestGroup(a) || isRequestGroup(b))) {

Callers 1

sorting.test.tsFile · 0.85

Calls 3

isRequestFunction · 0.85
metaSortKeySortFunction · 0.85
indexOfMethod · 0.80

Tested by

no test coverage detected