Skip to content

Commit 3049296

Browse files
authored
feat(DocumentParser): sort headers + meta-tags (#45)
* feat(DocumentParser): sort headers + meta-tags * chore(version): bump
1 parent 9f96b8f commit 3049296

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,30 +130,30 @@ So a perfect request would look like this:
130130
@variables1 = value1
131131
132132
133+
### REQUEST_NAME_ONE
134+
133135
# This is a comment
134136
# This is another comment
135137
# @someother metatag
136-
# @name REQUEST_NAME_ONE
137138
GET http://localhost:8080/api/v1/health HTTP/1.1
138139
Content-Type: application/json
139140
140141
{
141142
"key": "value"
142143
}
143-
144-
###
145144
```
146145

147146
or this:
148147

149148
```http
150-
@variables1=value1
149+
@variables1 = value1
150+
151151
152+
### REQUEST_NAME_ONE
152153
153154
# This is a comment
154155
# This is another comment
155156
# @someother metatag
156-
# @name REQUEST_NAME_ONE
157157
GET http://localhost:8080/api/v1/health HTTP/2
158158
content-type: application/json
159159

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mistweaverco/kulala-fmt",
3-
"version": "2.9.1",
3+
"version": "2.10.0",
44
"type": "module",
55
"scripts": {
66
"build": "rollup -c",

src/lib/parser/DocumentParser.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@ const parse = (content: string): Document | null => {
279279
block.metadata.length > 0 ||
280280
block.comments.length > 0
281281
) {
282+
// sort headers by key
283+
block.request?.headers.sort((a, b) => {
284+
return a.key.localeCompare(b.key);
285+
});
286+
// sort metadata by key
287+
block.metadata.sort((a, b) => {
288+
return a.key.localeCompare(b.key);
289+
});
282290
blocks.push(block);
283291
}
284292
});
@@ -308,6 +316,11 @@ const parse = (content: string): Document | null => {
308316
}
309317
});
310318

319+
// sort variables by key
320+
variables.sort((a, b) => {
321+
return a.key.localeCompare(b.key);
322+
});
323+
311324
return { blocks, variables };
312325
};
313326

0 commit comments

Comments
 (0)