@vexify-org/yaggs 6.12.0 → 6.14.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 CHANGED
@@ -177,6 +177,14 @@ class Yaggs {
177
177
  return this.parser.password(message);
178
178
  }
179
179
 
180
+ async http(url, options = {}) {
181
+ return this.parser.http(url, options);
182
+ }
183
+
184
+ file(path, options = {}) {
185
+ return this.parser.file(path, options);
186
+ }
187
+
180
188
  check(fn) {
181
189
  this.middleware(fn);
182
190
  return this;
package/lib/parser.js CHANGED
@@ -1055,6 +1055,80 @@ 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
+
1100
+ file(path, options = {}) {
1101
+ const fs = require('fs');
1102
+ const pathMod = require('path');
1103
+
1104
+ return {
1105
+ read: () => {
1106
+ const encoding = options.encoding || 'utf8';
1107
+ return fs.readFileSync(path, encoding);
1108
+ },
1109
+ readJson: () => {
1110
+ const content = fs.readFileSync(path, 'utf8');
1111
+ return JSON.parse(content);
1112
+ },
1113
+ write: (content) => {
1114
+ const encoding = options.encoding || 'utf8';
1115
+ return fs.writeFileSync(path, content, encoding);
1116
+ },
1117
+ writeJson: (content, space = 2) => {
1118
+ const json = JSON.stringify(content, null, space);
1119
+ return fs.writeFileSync(path, json, 'utf8');
1120
+ },
1121
+ exists: () => fs.existsSync(path),
1122
+ mkdir: () => fs.mkdirSync(path, { recursive: true }),
1123
+ rm: () => fs.unlinkSync(path),
1124
+ stat: () => fs.statSync(path),
1125
+ dirname: () => pathMod.dirname(path),
1126
+ basename: () => pathMod.basename(path),
1127
+ extname: () => pathMod.extname(path),
1128
+ resolve: () => pathMod.resolve(path)
1129
+ };
1130
+ }
1131
+
1058
1132
  getHelp() {
1059
1133
  let help = `\u001b[36m${this.scriptName}\u001b[0m`;
1060
1134
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vexify-org/yaggs",
3
- "version": "6.12.0",
3
+ "version": "6.14.0",
4
4
  "description": "A powerful CLI argument parser, better than yargs",
5
5
  "main": "index.js",
6
6
  "scripts": {