update .gitignore

This commit is contained in:
anon 2023-01-15 19:24:20 +01:00
parent e6b9c3c1a2
commit 06090e27d3
6 changed files with 0 additions and 122 deletions

View File

@ -1 +0,0 @@
../curl-headers-to-json/index.js

15
node_modules/.package-lock.json generated vendored
View File

@ -1,15 +0,0 @@
{
"name": "shallot",
"lockfileVersion": 3,
"requires": true,
"packages": {
"node_modules/curl-headers-to-json": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/curl-headers-to-json/-/curl-headers-to-json-1.0.1.tgz",
"integrity": "sha512-PNbfCuu4UdsTmSAHwN4R0m34KzvOvDjP3mJ6XNfHzOdeTskUb/eaVV110y/SnT6h6HDA7fisCNgQvRP/vH9obQ==",
"bin": {
"curl-headers-to-json": "index.js"
}
}
}
}

View File

@ -1,12 +0,0 @@
# curl-headers-to-json
A tool to format the output of cURL headers into JSON.
Example:
```
curl -sSL -D - https://api.github.com -o /dev/null | npx curl-headers-to-json | jq
```
or if you grabbed the output already:
```
npx curl-headers-to-json headers.txt | jq
```

View File

@ -1,56 +0,0 @@
#!/usr/bin/env node
const fs = require('fs');
const util = require('util');
const readFile = util.promisify(fs.readFile);
const args = process.argv.slice(2);
const shellParam = args[0];
const isTTY = process.stdin.isTTY;
const stdin = process.stdin;
const stdout = process.stdout;
if (isTTY && args.length === 0) {
console.log('Usage: ');
} else if (isTTY && args.length !== 0) {
handleShellArguments();
} else {
handleStdin();
}
function handleStdin() {
let headersData = '';
stdin.setEncoding('utf8');
stdin.on('readable', () => {
const chuck = stdin.read();
if(chuck !== null){
headersData += chuck;
}
});
stdin.on('end', () => process.stdout.write(JSON.stringify(format(headersData))));
}
function format(data) {
const lines = data.split(/\r?\n|\r/g);
const result = {};
lines.shift();
for(let line of lines) {
if(line.trim() === '') {
continue;
}
const [key, value] = line.split(': ');
result[key] = value.replace(/\\r/g, '');
}
return result;
}
async function handleShellArguments(){
try {
const input = await readFile(shellParam, { encoding: 'utf8' });
process.stdout.write(JSON.stringify(format(input)))
} catch (e) {
console.log(`An error ocurred while trying to open the file: ${e.message}`);
}
}

View File

@ -1,18 +0,0 @@
{
"name": "curl-headers-to-json",
"bin": {
"curl-headers-to-json": "./index.js"
},
"version": "1.0.1",
"description": "Formats cURL headers into JSON format",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 0"
},
"keywords": [
"curl",
"json"
],
"author": "Alejandro Oviedo <alejandro.oviedo.g@gmail.com>",
"license": "MIT"
}

20
package-lock.json generated
View File

@ -1,20 +0,0 @@
{
"name": "shallot",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"curl-headers-to-json": "^1.0.1"
}
},
"node_modules/curl-headers-to-json": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/curl-headers-to-json/-/curl-headers-to-json-1.0.1.tgz",
"integrity": "sha512-PNbfCuu4UdsTmSAHwN4R0m34KzvOvDjP3mJ6XNfHzOdeTskUb/eaVV110y/SnT6h6HDA7fisCNgQvRP/vH9obQ==",
"bin": {
"curl-headers-to-json": "index.js"
}
}
}
}