Skip to content

Commit a9c0e28

Browse files
committed
feat: initial commit
0 parents  commit a9c0e28

File tree

10 files changed

+3329
-0
lines changed

10 files changed

+3329
-0
lines changed

.gitignore

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
dist
2+
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
lerna-debug.log*
10+
.pnpm-debug.log*
11+
12+
# Diagnostic reports (https://nodejs.org/api/report.html)
13+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
14+
15+
# Runtime data
16+
pids
17+
*.pid
18+
*.seed
19+
*.pid.lock
20+
21+
# Directory for instrumented libs generated by jscoverage/JSCover
22+
lib-cov
23+
24+
# Coverage directory used by tools like istanbul
25+
coverage
26+
*.lcov
27+
28+
# nyc test coverage
29+
.nyc_output
30+
31+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
32+
.grunt
33+
34+
# Bower dependency directory (https://bower.io/)
35+
bower_components
36+
37+
# node-waf configuration
38+
.lock-wscript
39+
40+
# Compiled binary addons (https://nodejs.org/api/addons.html)
41+
build/Release
42+
43+
# Dependency directories
44+
node_modules/
45+
jspm_packages/
46+
47+
# Snowpack dependency directory (https://snowpack.dev/)
48+
web_modules/
49+
50+
# TypeScript cache
51+
*.tsbuildinfo
52+
53+
# Optional npm cache directory
54+
.npm
55+
56+
# Optional eslint cache
57+
.eslintcache
58+
59+
# Optional stylelint cache
60+
.stylelintcache
61+
62+
# Microbundle cache
63+
.rpt2_cache/
64+
.rts2_cache_cjs/
65+
.rts2_cache_es/
66+
.rts2_cache_umd/
67+
68+
# Optional REPL history
69+
.node_repl_history
70+
71+
# Output of 'npm pack'
72+
*.tgz
73+
74+
# Yarn Integrity file
75+
.yarn-integrity
76+
77+
# dotenv environment variable files
78+
.env
79+
.env.development.local
80+
.env.test.local
81+
.env.production.local
82+
.env.local
83+
84+
# parcel-bundler cache (https://parceljs.org/)
85+
.cache
86+
.parcel-cache
87+
88+
# Next.js build output
89+
.next
90+
out
91+
92+
# Nuxt.js build / generate output
93+
.nuxt
94+
95+
96+
# Gatsby files
97+
.cache/
98+
# Comment in the public line in if your project uses Gatsby and not Next.js
99+
# https://nextjs.org/blog/next-9-1#public-directory-support
100+
# public
101+
102+
# vuepress build output
103+
.vuepress/dist
104+
105+
# vuepress v2.x temp and cache directory
106+
.temp
107+
.cache
108+
109+
# vitepress build output
110+
**/.vitepress/dist
111+
112+
# vitepress cache directory
113+
**/.vitepress/cache
114+
115+
# Docusaurus cache and generated files
116+
.docusaurus
117+
118+
# Serverless directories
119+
.serverless/
120+
121+
# FuseBox cache
122+
.fusebox/
123+
124+
# DynamoDB Local files
125+
.dynamodb/
126+
127+
# TernJS port file
128+
.tern-port
129+
130+
# Stores VSCode versions used for testing VSCode extensions
131+
.vscode-test
132+
133+
# yarn v2
134+
.yarn/cache
135+
.yarn/unplugged
136+
.yarn/build-state.yml
137+
.yarn/install-state.gz
138+
.pnp.*

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2025 scrape.do
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# curl-parser
2+
3+
This module parses `curl` commands into JavaScript objects. That's used in [our playground](https://dashboard.scrape.do/playground)(You may create a free account to try it out).
4+
5+
### Installation
6+
7+
```sh
8+
npm i -S @scrape-do/curl-parser
9+
```
10+
11+
#### Documentation
12+
13+
Usage:
14+
15+
```ts
16+
import { parse, stringify } from "@scrape-do/curl-parser";
17+
18+
const command = parse(
19+
"curl -X POST -H x-foo:bar -X baz:zap https://httpbin.org"
20+
);
21+
22+
console.log("serialized:", stringify(command));
23+
```
24+
25+
**NOT** all the curl options are supported, we recognize only a small subset of the commands. The purpose of this module is to parse some of the common curl options in order to populate our playground. You may refer to `index.ts` to see the currently known curl options by this module.

index.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { parse } from ".";
2+
3+
describe("curl parser", () => {
4+
it("should parse basic curl command", () => {
5+
const command = parse("curl https://example.com");
6+
7+
expect(command.method).toBe("get");
8+
expect(command.url).toBe("https://example.com");
9+
});
10+
11+
it("should parse multiple flags", () => {
12+
const command = parse("curl -fsSL https://bun.sh/install");
13+
14+
expect(command.url).toBe("https://bun.sh/install");
15+
expect(command.flags.fail).toBe(true);
16+
expect(command.flags.showError).toBe(true);
17+
expect(command.flags.silent).toBe(true);
18+
});
19+
20+
it("should parse headers", () => {
21+
const command = parse(
22+
"curl -H x-foo:bar --header x-baz:zap https://example.com"
23+
);
24+
25+
expect(command.headers).toHaveLength(2);
26+
expect(command.headers).toMatchObject([
27+
{ key: "x-foo", value: "bar" },
28+
{ key: "x-baz", value: "zap" },
29+
]);
30+
});
31+
32+
it("should parse complex request from chrome developer tools", () => {
33+
const command = parse(`curl 'https://bun.sh/' \
34+
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8' \
35+
-H 'accept-language: en-US,en;q=0.5' \
36+
-H 'cache-control: max-age=0' \
37+
-b 'ph_phc=abc' \
38+
-H 'if-modified-since: Thu, 01 May 2025 19:46:28 GMT' \
39+
-H 'priority: u=0, i' \
40+
-H 'sec-ch-ua: "Brave";v="135", "Not-A.Brand";v="8", "Chromium";v="135"' \
41+
-H 'sec-ch-ua-mobile: ?0' \
42+
-H 'sec-ch-ua-platform: "macOS"' \
43+
-H 'sec-fetch-dest: document' \
44+
-H 'sec-fetch-mode: navigate' \
45+
-H 'sec-fetch-site: none' \
46+
-H 'sec-fetch-user: ?1' \
47+
-H 'sec-gpc: 1' \
48+
-H 'upgrade-insecure-requests: 1' \
49+
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36'`);
50+
51+
expect(command.url).toBe("https://bun.sh/");
52+
expect(command.cookies).toBe("ph_phc=abc");
53+
expect(command.headers).toHaveLength(15);
54+
});
55+
});

0 commit comments

Comments
 (0)