Skip to content

Commit 8d8793d

Browse files
iskolbinazu
authored andcommitted
feat: Added remove query string flag (#2)
1 parent 5e3c4cd commit 8d8793d

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Install with [npm](https://www.npmjs.com/):
1919

2020
Options:
2121
--output, -o Output directory
22+
--remove-query-string, -r Remove query string from file path
2223
--dry-run Enable dry run mode
2324
--verbose Show processing file path
2425

bin/cmd.js

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const cli = meow(
1111
1212
Options:
1313
--output, -o Output directory
14+
--remove-query-string, -r Remove query string from file path
1415
--dry-run Enable dry run mode
1516
--verbose Show processing file path
1617
@@ -23,6 +24,11 @@ const cli = meow(
2324
type: "string",
2425
alias: "o"
2526
},
27+
removeQueryString: {
28+
type: "boolean",
29+
alias: "r",
30+
default: false
31+
},
2632
verbose: {
2733
type: "boolean",
2834
default: true
@@ -45,6 +51,7 @@ try {
4551
extract(harContent, {
4652
verbose: cli.flags.verbose,
4753
dryRun: cli.flags.dryRun,
54+
removeQueryString: cli.flags.removeQueryString,
4855
outputDir: cli.flags.output
4956
});
5057
} catch (error) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "har-extractor",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "A CLI that extract har file to directory.",
55
"keywords": [
66
"archieve",

src/har-extractor.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export const getEntryContentAsBuffer = (entry: Entry): Buffer | undefined => {
1818
}
1919
};
2020

21-
export const convertEntryAsFilePathFormat = (entry: Entry): string => {
21+
export const convertEntryAsFilePathFormat = (entry: Entry, removeQueryString: boolean = false): string => {
2222
const requestURL = entry.request.url;
23-
const stripSchemaURL: string = humanizeUrl(requestURL);
23+
const stripSchemaURL: string = humanizeUrl(removeQueryString ? requestURL.split("?")[0] : requestURL);
2424
const dirnames: string[] = stripSchemaURL.split("/").map(pathname => {
2525
return filenamify(pathname);
2626
});
@@ -35,6 +35,7 @@ export interface ExtractOptions {
3535
outputDir: string;
3636
verbose?: boolean;
3737
dryRun?: boolean;
38+
removeQueryString?: boolean;
3839
}
3940

4041
export const extract = (harContent: Har, options: ExtractOptions) => {
@@ -43,7 +44,7 @@ export const extract = (harContent: Har, options: ExtractOptions) => {
4344
if (!buffer) {
4445
return;
4546
}
46-
const outputPath = path.join(options.outputDir, convertEntryAsFilePathFormat(entry));
47+
const outputPath = path.join(options.outputDir, convertEntryAsFilePathFormat(entry, options.removeQueryString));
4748
if (!options.dryRun) {
4849
makeDir.sync(path.dirname(outputPath));
4950
}

0 commit comments

Comments
 (0)