Created
April 11, 2020 14:05
-
-
Save kewang/95a300bf189c4573b5b6405eddc9cd9b to your computer and use it in GitHub Desktop.
Transform Xcode log to curl header and body
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const buildHeaders = (str) => { | |
const headers = str | |
.split("\n") | |
.map((part) => { | |
const elem = part.split("="); | |
let key = elem[0].trim(); | |
key = key.replace(/"/g, ""); | |
let value = elem[1].trim(); | |
value = value.replace(";", "").replace(/"/g, ""); | |
return `-H "${key}: ${value}"`; | |
}) | |
.join(" "); | |
return headers; | |
}; | |
const buildBody = (str) => { | |
const body = str | |
.split("\n") | |
.map((part) => { | |
const elem = part.split("="); | |
let key = elem[0].trim(); | |
key = key.replace(/"/g, ""); | |
let value = elem[1].trim(); | |
value = value.replace(";", "").replace(/"/g, ""); | |
return `"${key}": "${value}"`; | |
}) | |
.join(","); | |
return `{${body}}`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment