har-to-curl
Advanced tools
Comparing version 0.4.1 to 0.5.0
/** | ||
* HAR to cURL: a CommonJS utility for converting a HAR (HTTP Archive) format JSON object to a cURL command string for use on the command line. | ||
* | ||
* @author Matthew Caruana Galizia <m@m.cg> | ||
* @author Matthew Caruana Galizia <mattcg@gmail.com> | ||
* @license MIT license | ||
* @copyright Copyright (c) 2012, Matthew Caruana Galizia | ||
* @version 0.4.1 | ||
* @preserve | ||
*/ | ||
@@ -56,3 +52,3 @@ | ||
harToCurl.fromEntry = function(entry) { | ||
var command; | ||
var command, request; | ||
@@ -63,23 +59,30 @@ if (!entry || !entry.request) { | ||
command = 'curl -X ' + entry.request.method; | ||
request = entry.request; | ||
command = 'curl -X ' + request.method; | ||
if (entry.request.httpVersion === 'HTTP/1.0') { | ||
if (request.httpVersion === 'HTTP/1.0') { | ||
command += ' -0'; | ||
} | ||
if (entry.request.cookies.length) { | ||
command += ' -b "' + entry.request.cookies.map(function(cookie) { | ||
if (request.cookies.length) { | ||
command += ' -b \'' + request.cookies.map(function(cookie) { | ||
return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value); | ||
}).join('&') + '"'; | ||
}).join('&') + '\''; | ||
} | ||
command += entry.request.headers.map(function(header) { | ||
return ' -H "' + header.name + ': ' + header.value + '"'; | ||
command += request.headers.map(function(header) { | ||
return ' -H \'' + header.name + ': ' + header.value + '\''; | ||
}).join(''); | ||
if (entry.request.postData) { | ||
command += ' -d "' + entry.request.postData.text + '"'; | ||
if (request.postData) { | ||
if (request.postData.text) { | ||
command += ' -d \'' + request.postData.text + '\''; | ||
} else if (request.postData.params && request.postData.params.length > 0) { | ||
command += ' -d \'' + request.postData.params.map(function(param) { | ||
return param.name + '=' + param.value; | ||
}).join('&') + '\''; | ||
} | ||
} | ||
return command + ' ' + entry.request.url; | ||
return command + ' \'' + encodeURI(request.url) + '\''; | ||
}; |
{ | ||
"name": "har-to-curl", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "A CommonJS utility for converting a HAR (HTTP Archive) format JSON object to a cURL command string for use on the command line.", | ||
@@ -15,11 +15,6 @@ "main": "lib/har-to-curl.js", | ||
"name": "Matthew Caruana Galizia", | ||
"email": "m@m.cg" | ||
"email": "mattcg@gmail.com" | ||
} | ||
], | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://mattcg.mit-license.org/" | ||
} | ||
], | ||
"license": "MIT", | ||
"keywords": [ | ||
@@ -29,3 +24,18 @@ "curl", | ||
"convert" | ||
] | ||
], | ||
"files": [ | ||
"/lib" | ||
], | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"eslintConfig": { | ||
"parserOptions": { | ||
"ecmaVersion": 13, | ||
"sourceType": "module" | ||
}, | ||
"env": { | ||
"node": true | ||
} | ||
} | ||
} |
@@ -9,26 +9,5 @@ # HAR to cURL # | ||
You'll need [Component](https://github.com/component/component) and GNU make to build the standalone browser version. Then run: | ||
Use npm: | ||
```bash | ||
git clone https://github.com/mattcg/har-to-curl.git | ||
cd har-to-curl/ | ||
make | ||
ls -l build/ | ||
``` | ||
Alternatively, use Component to install to your project. | ||
```bash | ||
component install har-to-curl | ||
``` | ||
You can also use Bower. | ||
```bash | ||
bower install har-to-curl | ||
``` | ||
And npm. | ||
```bash | ||
npm install har-to-curl | ||
@@ -35,0 +14,0 @@ ``` |
3492
3
66
34