1.0.3 • Published 5 years ago

parse-curl-js v1.0.3

Weekly downloads
13
License
ISC
Repository
github
Last release
5 years ago

parse-curl-js

An better cURL string parser

Based on curlconverter

Usage

const { CURLParser } = require('parse-curl-js')
// or es6
import { CURLParser } from 'parse-curl-js'


const cURLParser = new CURLParser(`curl 'http://127.0.0.1:8080' -X POST -H "content-type: application/json" -d '{"data": true}'`)

console.log(cURLParser.parse())

Result

type RequestBodyType = 'text/plain' | 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'

interface RequestBody {
    type: RequestBodyType
    data: any
}


interface ParsedCURL {
    /** url */
    url: string
    /** query */
    query: ParsedUrlQuery
    /** request method uppercase */
    method: string
    /** request header ...... includes cookies */
    headers: {
        [props: string]: string
    }
    /** request body ...... parsed */
    body: RequestBody
}

LICENSE

MIT