Comparing version 0.1.2 to 0.1.3
@@ -5,2 +5,3 @@ import { IR2CurlOptions } from '../interface/IR2CurlOptions'; | ||
private readonly _method; | ||
private readonly _option; | ||
private headers; | ||
@@ -7,0 +8,0 @@ private keys; |
@@ -13,5 +13,10 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var debug_1 = __importDefault(require("debug")); | ||
var HTTP_METHOD_1 = require("../enum/HTTP_METHOD"); | ||
var isEmpty_1 = require("./isEmpty"); | ||
var log = debug_1.default('r2curl:HeaderHelper'); | ||
var HeaderHelper = /** @class */ (function () { | ||
@@ -21,3 +26,4 @@ function HeaderHelper(_rawHeaders, _method, _option) { | ||
this._method = _method; | ||
this.defaultContentType = _option.defaultContentType || null; | ||
this._option = _option; | ||
this.defaultContentType = _option.defaultContentType === false ? null : _option.defaultContentType; | ||
this.keys = Object.keys(_rawHeaders).map(function (key) { return key.toLowerCase(); }); | ||
@@ -33,2 +39,4 @@ this.headers = this.parseHeader(); | ||
HeaderHelper.prototype.parseHeader = function () { | ||
log('_rawHeaders', this._rawHeaders); | ||
log('defaultContentType', this.defaultContentType); | ||
if (isEmpty_1.isEmpty(this._rawHeaders) && isEmpty_1.isEmpty(this.defaultContentType)) { | ||
@@ -38,3 +46,4 @@ return null; | ||
var rawHeaderContentType = this.keys.find(function (key) { return key === 'content-type'; }); | ||
var isNeedContentType = [HTTP_METHOD_1.HTTP_METHOD.POST, HTTP_METHOD_1.HTTP_METHOD.PUT].includes(this._method); | ||
var isNeedContentType = [HTTP_METHOD_1.HTTP_METHOD.POST, HTTP_METHOD_1.HTTP_METHOD.PUT].includes(this._method) || this._option.forceBody === true; | ||
log('isNeedContentType', [HTTP_METHOD_1.HTTP_METHOD.POST, HTTP_METHOD_1.HTTP_METHOD.PUT].includes(this._method), this._option.forceBody === true, 'OR CALC', isNeedContentType); | ||
var headers = {}; | ||
@@ -41,0 +50,0 @@ if (isNeedContentType && isEmpty_1.isEmpty(rawHeaderContentType) && isEmpty_1.isNotEmpty(this.defaultContentType)) { |
{ | ||
"name": "r2curl", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Node.js Request Wrapper (axios, fetch, ..) to cURL Command String", | ||
@@ -12,3 +12,3 @@ "main": "dist/index.js", | ||
"test": "npx jest --coverage", | ||
"test:log": "npx cross-env DEBUG=r2curl:tc:* npx jest --coverage", | ||
"test:log": "npx cross-env DEBUG=r2curl:* npx jest", | ||
"test:watch": "npx cross-env DEBUG=r2curl:tc:* npx jest --watch", | ||
@@ -28,4 +28,4 @@ "lint": "npx tslint -c ./tslint.json \"./src/**/*.ts\"", | ||
"curl", | ||
"fetch", | ||
"axios" | ||
"axios", | ||
"debug" | ||
], | ||
@@ -39,3 +39,2 @@ "author": "Yowu Yu <me@yowu.dev>", | ||
"dependencies": { | ||
"axios": "^0.18.0", | ||
"debug": "^4.1.1" | ||
@@ -48,2 +47,3 @@ }, | ||
"@types/shelljs": "^0.8.5", | ||
"axios": "^0.18.0", | ||
"cross-env": "^5.2.0", | ||
@@ -50,0 +50,0 @@ "jest": "^24.8.0", |
# r2curl | ||
[![npm version](https://badge.fury.io/js/r2curl.svg)](https://badge.fury.io/js/r2curl) [![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php) [![CircleCI](https://circleci.com/gh/uyu423/r2curl.svg?style=svg)](https://circleci.com/gh/uyu423/r2curl) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f74cdea970d44550a0bff9319e467256)](https://www.codacy.com/app/uyu423/r2curl?utm_source=github.com&utm_medium=referral&utm_content=uyu423/r2curl&utm_campaign=Badge_Grade) [![Code Climate](https://codeclimate.com/github/uyu423/r2curl.svg)](https://codeclimate.com/github/uyu423/r2curl) [![Test Coverage](https://api.codeclimate.com/v1/badges/bb19fbd2394b545aefb2/test_coverage)](https://codeclimate.com/github/uyu423/r2curl/test_coverage) | ||
[![npm version](https://badge.fury.io/js/r2curl.svg)](https://badge.fury.io/js/r2curl) [![Download Status](https://img.shields.io/npm/dw/r2curl.svg)](https://npmcharts.com/compare/r2curl?minimal=true) [![Github Star](https://img.shields.io/github/stars/uyu423/r2curl.svg?style=popout)](https://github.com/uyu423/r2curl) [![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php) [![CircleCI](https://circleci.com/gh/uyu423/r2curl.svg?style=svg)](https://circleci.com/gh/uyu423/r2curl) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f74cdea970d44550a0bff9319e467256)](https://www.codacy.com/app/uyu423/r2curl?utm_source=github.com&utm_medium=referral&utm_content=uyu423/r2curl&utm_campaign=Badge_Grade) [![Code Climate](https://codeclimate.com/github/uyu423/r2curl.svg)](https://codeclimate.com/github/uyu423/r2curl) [![Test Coverage](https://api.codeclimate.com/v1/badges/bb19fbd2394b545aefb2/test_coverage)](https://codeclimate.com/github/uyu423/r2curl/test_coverage) | ||
@@ -9,16 +9,35 @@ <p align="center"> | ||
## Background | ||
- [r2curl](https://github.com/uyu423/r2curl) was inspired by [@delirius325/axios-curlirize](https://github.com/delirius325/axios-curlirize). | ||
- axios-curlirize is very convenient. but works as a middleware for axios, and I think this part is black box logic | ||
- it contains potentially asynchronous concurrency issues and difficult-to-manage elements. | ||
- So I created a new 'Request to cURL' package that is completely independent of the dependencies of axios. | ||
## Feature | ||
- Generates cURL commands completely independently from the outside of the request wrapper package. | ||
- Provides additional options involved in generating the cURL command. | ||
- It will be updated soon to be available in packages like [node-fetch](https://www.npmjs.com/package/node-fetch) or [request](https://www.npmjs.com/package/request). | ||
## Roadmap | ||
- [x] axios | ||
- [x] [axios](https://www.npmjs.com/package/axios) | ||
- [x] AxiosRequestConfig | ||
- [x] AxiosResposne | ||
- [ ] node-fetch | ||
- [ ] request | ||
- [ ] [node-fetch](https://www.npmjs.com/package/node-fetch) | ||
- [ ] [request](https://www.npmjs.com/package/request) | ||
- [ ] ... | ||
## Install | ||
```bash | ||
npm install r2curl --save | ||
``` | ||
## Usage | ||
### Basic | ||
### axios | ||
### `AxiosResponse` | ||
#### `AxiosResponse` | ||
@@ -36,3 +55,3 @@ ```typescript | ||
### `AxiosRequestConfig` | ||
#### `AxiosRequestConfig` | ||
@@ -62,6 +81,16 @@ ```typescript | ||
### More `r2curl` Options | ||
### node-fetch | ||
#### `option.quote` | ||
- update soon (target 0.2.0) | ||
- see [github project board](https://github.com/uyu423/r2curl/projects/1) | ||
### request | ||
- update soon (target 0.2.0) | ||
- see [github project board](https://github.com/uyu423/r2curl/projects/1) | ||
## More `r2curl` Options | ||
### `option.quote` | ||
- Determines the type of quota around the body and uri. | ||
@@ -83,3 +112,3 @@ - default is `single` | ||
#### `option.defaultContentType` | ||
### `option.defaultContentType` | ||
@@ -107,3 +136,3 @@ - Determines the default Content-Type header value for `POST` and `PUT` requests. | ||
#### `option.forceBody` | ||
### `option.forceBody` | ||
@@ -110,0 +139,0 @@ - Accept Body all HTTP Method. |
Sorry, the diff of this file is not supported yet
24942
1
454
156
16
- Removedaxios@^0.18.0
- Removedaxios@0.18.1(transitive)
- Removedfollow-redirects@1.5.10(transitive)
- Removedis-buffer@2.0.5(transitive)