@vexify-org/yaggs 5.1.0 → 5.3.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.
Files changed (2) hide show
  1. package/lib/parser.js +37 -0
  2. package/package.json +1 -1
package/lib/parser.js CHANGED
@@ -378,6 +378,43 @@ class ArgumentParser {
378
378
  } catch {
379
379
  this._handleError(`Invalid JSON for option '${name}'`);
380
380
  }
381
+ } else if (opt.type === 'url') {
382
+ try {
383
+ result[name] = new URL(value);
384
+ } catch {
385
+ this._handleError(`Invalid URL for option '${name}'`);
386
+ }
387
+ } else if (opt.type === 'email') {
388
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
389
+ if (!emailRegex.test(value)) {
390
+ this._handleError(`Invalid email for option '${name}'`);
391
+ }
392
+ } else if (opt.type === 'ip') {
393
+ const ipRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
394
+ if (!ipRegex.test(value)) {
395
+ this._handleError(`Invalid IP address for option '${name}'`);
396
+ }
397
+ } else if (opt.type === 'file') {
398
+ const fs = require('fs');
399
+ const path = require('path');
400
+ const fullPath = path.resolve(value);
401
+ if (!fs.existsSync(fullPath)) {
402
+ this._handleError(`File not found: ${fullPath}`);
403
+ }
404
+ result[name] = fullPath;
405
+ } else if (opt.type === 'directory') {
406
+ const fs = require('fs');
407
+ const path = require('path');
408
+ const fullPath = path.resolve(value);
409
+ if (!fs.existsSync(fullPath)) {
410
+ this._handleError(`Directory not found: ${fullPath}`);
411
+ }
412
+ if (!fs.statSync(fullPath).isDirectory()) {
413
+ this._handleError(`Not a directory: ${fullPath}`);
414
+ }
415
+ result[name] = fullPath;
416
+ } else if (opt.type === 'custom' && opt._customType) {
417
+ result[name] = opt._customType(value);
381
418
  }
382
419
  }
383
420
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vexify-org/yaggs",
3
- "version": "5.1.0",
3
+ "version": "5.3.0",
4
4
  "description": "A powerful CLI argument parser, better than yargs",
5
5
  "main": "index.js",
6
6
  "scripts": {