npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

curl-parser-ts

v0.3.0

Published

package to parse curl commands and return method, url, data, params

Readme

curl-parser-ts

npm version License: MIT TypeScript

A TypeScript library for parsing curl commands into structured objects. Convert curl commands from the command line into JavaScript objects that can be used in your code.

Features

  • 🚀 TypeScript Support: Built with TypeScript for better developer experience and type safety
  • 🔍 Comprehensive Parsing: Handles a wide range of curl options and flags
  • 🧩 Structured Output: Converts curl commands into well-structured JavaScript objects
  • 🔄 Query Parameter Parsing: Automatically extracts and parses URL query parameters
  • 🍪 Cookie Support: Parses cookie strings into structured objects
  • 📦 Zero Dependencies: Lightweight with no runtime dependencies

Installation

npm install curl-parser-ts
# or
yarn add curl-parser-ts

Usage

Basic Usage

import { parseCurlCommand } from 'curl-parser-ts';

const curlCommand = `curl -X POST 'https://api.example.com/data?id=123' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer token123' \
  -d '{"name": "John", "age": 30}'`;

const parsedCommand = parseCurlCommand(curlCommand);
console.log(parsedCommand);

Output:

{
  method: 'POST',
  url: 'https://api.example.com/data',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer token123'
  },
  query: {
    'id': '123'
  },
  data: '{"name": "John", "age": 30}',
  auth: null,
  cookies: {},
  timeout: null,
  proxy: null,
  followRedirects: false,
  insecure: false,
  compressed: false,
  formData: null,
  multipartFormData: null
}

Advanced Usage

import { parseCurlCommand, tokenizeFromCurl } from 'curl-parser-ts';

// If you need access to the raw tokens
const tokens = tokenizeFromCurl(`curl -H "Accept: application/json" https://api.example.com`);
console.log(tokens);

// Parse a more complex curl command
const complexCommand = `curl -X POST -H "Accept: application/json" -H "Authorization: Bearer token123" \
  -b "session=abc" -L -k --compressed -d "data=test" "https://api.example.com/update?id=123"`;

const parsed = parseCurlCommand(complexCommand);
console.log(parsed);

API Reference

parseCurlCommand(curlCommand: string): CurlParseResult

Parses a curl command string and returns a structured object.

Parameters

  • curlCommand - A string containing the curl command to parse

Return Value

Returns a CurlParseResult object with the following properties:

| Property | Type | Description | |----------|------|-------------| | url | string | The URL from the curl command | | method | string | The HTTP method (GET, POST, PUT, DELETE, etc.) | | headers | Record<string, string> | HTTP headers | | query | Record<string, string> | URL query parameters | | data | string \| null | Request body data | | auth | string \| null | Authentication credentials | | cookies | Record<string, string> | Cookies | | timeout | string \| null | Request timeout | | proxy | string \| null | Proxy settings | | followRedirects | boolean | Whether to follow redirects | | insecure | boolean | Whether to allow insecure connections | | compressed | boolean | Whether to request compressed response | | formData | Record<string, string> \| null | Form data for application/x-www-form-urlencoded | | multipartFormData | Record<string, string> \| null | Multipart form data |

tokenizeFromCurl(curlCommand: string): Token[]

Tokenizes a curl command string into an array of tokens.

Parameters

  • curlCommand - A string containing the curl command to tokenize

Return Value

Returns an array of Token objects with the following properties:

| Property | Type | Description | |----------|------|-------------| | type | 'OPTION' \| 'ARGUMENT' \| 'URL' | The type of token | | value | string | The value of the token | | raw | string | The raw string representation of the token |

Supported Curl Options

curl-parser-ts supports a wide range of curl options, including:

| Option | Description | |--------|-------------| | -X, --request | HTTP method (GET, POST, PUT, DELETE, etc.) | | -H, --header | HTTP headers | | -d, --data | Request body data | | -F, --form | Multipart form data | | -b, --cookie | Cookies | | -u, --user | Authentication credentials | | -A, --user-agent | User agent | | -L, --location | Follow redirects | | -k, --insecure | Allow insecure connections | | --compressed | Request compressed response | | -I | HEAD request | | --connect-timeout | Connection timeout | | -m | Maximum time allowed for the transfer |

Comparison with Similar Packages

| Feature | curl-parser-ts | parse-curl | |---------|---------------|------------| | TypeScript Support | ✅ | ❌ | | Query Parameter Parsing | ✅ | ❌ | | Cookie Parsing | ✅ | ✅ | | Multipart Form Data | ✅ | ❌ | | Follow Redirects | ✅ | ❌ | | Timeout Support | ✅ | ❌ | | Proxy Support | ✅ | ❌ | | Compressed Response | ✅ | ✅ | | Bundle Size | Smaller | Larger |

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements