@vexify-org/yaggs 6.12.0 → 6.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +4 -0
- package/lib/parser.js +42 -0
- package/package.json +1 -1
package/index.js
CHANGED
package/lib/parser.js
CHANGED
|
@@ -1055,6 +1055,48 @@ complete -c ${this.scriptName} `;
|
|
|
1055
1055
|
});
|
|
1056
1056
|
}
|
|
1057
1057
|
|
|
1058
|
+
async http(url, options = {}) {
|
|
1059
|
+
const https = require('https');
|
|
1060
|
+
const http = require('http');
|
|
1061
|
+
|
|
1062
|
+
const protocol = url.startsWith('https') ? https : http;
|
|
1063
|
+
const method = options.method || 'GET';
|
|
1064
|
+
const headers = options.headers || {};
|
|
1065
|
+
const body = options.body ? JSON.stringify(options.body) : null;
|
|
1066
|
+
|
|
1067
|
+
if (body && !headers['Content-Type']) {
|
|
1068
|
+
headers['Content-Type'] = 'application/json';
|
|
1069
|
+
}
|
|
1070
|
+
if (body && !headers['Content-Length']) {
|
|
1071
|
+
headers['Content-Length'] = Buffer.byteLength(body);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
return new Promise((resolve, reject) => {
|
|
1075
|
+
const req = protocol.request(url, { method, headers }, (res) => {
|
|
1076
|
+
let data = '';
|
|
1077
|
+
|
|
1078
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
1079
|
+
|
|
1080
|
+
res.on('end', () => {
|
|
1081
|
+
try {
|
|
1082
|
+
const parsed = JSON.parse(data);
|
|
1083
|
+
resolve({ status: res.statusCode, headers: res.headers, body: parsed });
|
|
1084
|
+
} catch {
|
|
1085
|
+
resolve({ status: res.statusCode, headers: res.headers, body: data });
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
});
|
|
1089
|
+
|
|
1090
|
+
req.on('error', reject);
|
|
1091
|
+
|
|
1092
|
+
if (body) {
|
|
1093
|
+
req.write(body);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
req.end();
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1058
1100
|
getHelp() {
|
|
1059
1101
|
let help = `\u001b[36m${this.scriptName}\u001b[0m`;
|
|
1060
1102
|
|