@boneskull/bargs 0.1.1

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 (91) hide show
  1. package/LICENSE +55 -0
  2. package/README.md +483 -0
  3. package/dist/bargs.cjs +167 -0
  4. package/dist/bargs.cjs.map +1 -0
  5. package/dist/bargs.d.cts +31 -0
  6. package/dist/bargs.d.cts.map +1 -0
  7. package/dist/bargs.d.ts +31 -0
  8. package/dist/bargs.d.ts.map +1 -0
  9. package/dist/bargs.js +163 -0
  10. package/dist/bargs.js.map +1 -0
  11. package/dist/errors.cjs +57 -0
  12. package/dist/errors.cjs.map +1 -0
  13. package/dist/errors.d.cts +40 -0
  14. package/dist/errors.d.cts.map +1 -0
  15. package/dist/errors.d.ts +40 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/errors.js +51 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/help.cjs +309 -0
  20. package/dist/help.cjs.map +1 -0
  21. package/dist/help.d.cts +21 -0
  22. package/dist/help.d.cts.map +1 -0
  23. package/dist/help.d.ts +21 -0
  24. package/dist/help.d.ts.map +1 -0
  25. package/dist/help.js +304 -0
  26. package/dist/help.js.map +1 -0
  27. package/dist/index.cjs +63 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +96 -0
  30. package/dist/index.d.cts.map +1 -0
  31. package/dist/index.d.ts +96 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +47 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/opt.cjs +205 -0
  36. package/dist/opt.cjs.map +1 -0
  37. package/dist/opt.d.cts +145 -0
  38. package/dist/opt.d.cts.map +1 -0
  39. package/dist/opt.d.ts +145 -0
  40. package/dist/opt.d.ts.map +1 -0
  41. package/dist/opt.js +202 -0
  42. package/dist/opt.js.map +1 -0
  43. package/dist/osc.cjs +190 -0
  44. package/dist/osc.cjs.map +1 -0
  45. package/dist/osc.d.cts +30 -0
  46. package/dist/osc.d.cts.map +1 -0
  47. package/dist/osc.d.ts +30 -0
  48. package/dist/osc.d.ts.map +1 -0
  49. package/dist/osc.js +181 -0
  50. package/dist/osc.js.map +1 -0
  51. package/dist/parser.cjs +293 -0
  52. package/dist/parser.cjs.map +1 -0
  53. package/dist/parser.d.cts +47 -0
  54. package/dist/parser.d.cts.map +1 -0
  55. package/dist/parser.d.ts +47 -0
  56. package/dist/parser.d.ts.map +1 -0
  57. package/dist/parser.js +285 -0
  58. package/dist/parser.js.map +1 -0
  59. package/dist/theme.cjs +203 -0
  60. package/dist/theme.cjs.map +1 -0
  61. package/dist/theme.d.cts +227 -0
  62. package/dist/theme.d.cts.map +1 -0
  63. package/dist/theme.d.ts +227 -0
  64. package/dist/theme.d.ts.map +1 -0
  65. package/dist/theme.js +198 -0
  66. package/dist/theme.js.map +1 -0
  67. package/dist/types.cjs +18 -0
  68. package/dist/types.cjs.map +1 -0
  69. package/dist/types.d.cts +244 -0
  70. package/dist/types.d.cts.map +1 -0
  71. package/dist/types.d.ts +244 -0
  72. package/dist/types.d.ts.map +1 -0
  73. package/dist/types.js +17 -0
  74. package/dist/types.js.map +1 -0
  75. package/dist/validate.cjs +452 -0
  76. package/dist/validate.cjs.map +1 -0
  77. package/dist/validate.d.cts +28 -0
  78. package/dist/validate.d.cts.map +1 -0
  79. package/dist/validate.d.ts +28 -0
  80. package/dist/validate.d.ts.map +1 -0
  81. package/dist/validate.js +448 -0
  82. package/dist/validate.js.map +1 -0
  83. package/dist/version.cjs +134 -0
  84. package/dist/version.cjs.map +1 -0
  85. package/dist/version.d.cts +27 -0
  86. package/dist/version.d.cts.map +1 -0
  87. package/dist/version.d.ts +27 -0
  88. package/dist/version.d.ts.map +1 -0
  89. package/dist/version.js +129 -0
  90. package/dist/version.js.map +1 -0
  91. package/package.json +149 -0
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Package version and metadata detection utilities.
3
+ *
4
+ * Provides functions to locate and read `package.json` files by walking up the
5
+ * directory tree, extracting version strings, and gathering package metadata
6
+ * (homepage, repository URLs) for automatic epilog generation in help output.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ /**
11
+ * Package info extracted from `package.json` for epilog generation.
12
+ */
13
+ interface PackageInfo {
14
+ homepage?: string;
15
+ repository?: string;
16
+ }
17
+ /**
18
+ * Detect version: use provided version or read from nearest package.json.
19
+ */
20
+ export declare const detectVersion: (providedVersion: string | undefined, startDir?: string) => Promise<string | undefined>;
21
+ /**
22
+ * Read package info (homepage, repository) from package.json synchronously.
23
+ * Returns only HTTPS URLs; other URL schemes are omitted.
24
+ */
25
+ export declare const readPackageInfoSync: (startDir?: string) => PackageInfo;
26
+ export {};
27
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH;;GAEG;AACH,UAAU,WAAW;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAqHD;;GAEG;AACH,eAAO,MAAM,aAAa,GACxB,iBAAiB,MAAM,GAAG,SAAS,EACnC,WAAU,MAAsB,KAC/B,OAAO,CAAC,MAAM,GAAG,SAAS,CAW5B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC9B,WAAU,MAAsB,KAC/B,WAiBF,CAAC"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Package version and metadata detection utilities.
3
+ *
4
+ * Provides functions to locate and read `package.json` files by walking up the
5
+ * directory tree, extracting version strings, and gathering package metadata
6
+ * (homepage, repository URLs) for automatic epilog generation in help output.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import { readFileSync } from 'node:fs';
11
+ import { readFile } from 'node:fs/promises';
12
+ import { dirname, join } from 'node:path';
13
+ /**
14
+ * Normalize a repository URL to clean HTTPS format. Strips leading `git+` and
15
+ * trailing `.git`.
16
+ */
17
+ const normalizeRepoUrl = (url) => {
18
+ return url.replace(/^git\+/, '').replace(/\.git$/, '');
19
+ };
20
+ /**
21
+ * Validate that a URL is HTTPS. Returns the URL if valid, undefined otherwise.
22
+ */
23
+ const validateHttpsUrl = (url) => {
24
+ if (!url) {
25
+ return undefined;
26
+ }
27
+ return url.startsWith('https://') ? url : undefined;
28
+ };
29
+ /**
30
+ * Extract repository URL from package.json repository field. Handles both
31
+ * string and object forms.
32
+ */
33
+ const extractRepoUrl = (repository) => {
34
+ if (!repository) {
35
+ return undefined;
36
+ }
37
+ const rawUrl = typeof repository === 'string' ? repository : repository.url;
38
+ if (!rawUrl) {
39
+ return undefined;
40
+ }
41
+ const normalized = normalizeRepoUrl(rawUrl);
42
+ return validateHttpsUrl(normalized);
43
+ };
44
+ /**
45
+ * Find package.json by walking up from startDir (async).
46
+ */
47
+ const findPackageJson = async (startDir) => {
48
+ let dir = startDir;
49
+ let prevDir = '';
50
+ while (dir !== prevDir) {
51
+ const pkgPath = join(dir, 'package.json');
52
+ try {
53
+ await readFile(pkgPath, 'utf-8');
54
+ return pkgPath;
55
+ }
56
+ catch {
57
+ prevDir = dir;
58
+ dir = dirname(dir);
59
+ }
60
+ }
61
+ return undefined;
62
+ };
63
+ /**
64
+ * Find package.json by walking up from startDir (sync).
65
+ */
66
+ const findPackageJsonSync = (startDir) => {
67
+ let dir = startDir;
68
+ let prevDir = '';
69
+ while (dir !== prevDir) {
70
+ const pkgPath = join(dir, 'package.json');
71
+ try {
72
+ readFileSync(pkgPath, 'utf-8');
73
+ return pkgPath;
74
+ }
75
+ catch {
76
+ prevDir = dir;
77
+ dir = dirname(dir);
78
+ }
79
+ }
80
+ return undefined;
81
+ };
82
+ /**
83
+ * Read version from package.json (async).
84
+ */
85
+ const readVersionFromPackageJson = async (pkgPath) => {
86
+ try {
87
+ const content = await readFile(pkgPath, 'utf-8');
88
+ const pkg = JSON.parse(content);
89
+ return pkg.version;
90
+ }
91
+ catch {
92
+ return undefined;
93
+ }
94
+ };
95
+ /**
96
+ * Detect version: use provided version or read from nearest package.json.
97
+ */
98
+ export const detectVersion = async (providedVersion, startDir = process.cwd()) => {
99
+ if (providedVersion) {
100
+ return providedVersion;
101
+ }
102
+ const pkgPath = await findPackageJson(startDir);
103
+ if (!pkgPath) {
104
+ return undefined;
105
+ }
106
+ return readVersionFromPackageJson(pkgPath);
107
+ };
108
+ /**
109
+ * Read package info (homepage, repository) from package.json synchronously.
110
+ * Returns only HTTPS URLs; other URL schemes are omitted.
111
+ */
112
+ export const readPackageInfoSync = (startDir = process.cwd()) => {
113
+ const pkgPath = findPackageJsonSync(startDir);
114
+ if (!pkgPath) {
115
+ return {};
116
+ }
117
+ try {
118
+ const content = readFileSync(pkgPath, 'utf-8');
119
+ const pkg = JSON.parse(content);
120
+ return {
121
+ homepage: validateHttpsUrl(pkg.homepage),
122
+ repository: extractRepoUrl(pkg.repository),
123
+ };
124
+ }
125
+ catch {
126
+ return {};
127
+ }
128
+ };
129
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AA4B1C;;;GAGG;AACH,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAU,EAAE;IAC/C,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAG,CAAC,GAAuB,EAAsB,EAAE;IACvE,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,GA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AI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAmB,CAAC;QAElD,OAAO;YACL,QAAQ,EAAE,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC;YACxC,UAAU,EAAE,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC;SAC3C,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,149 @@
1
+ {
2
+ "name": "@boneskull/bargs",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "A TypeScript-first CLI argument parser wrapping util.parseArgs() with full type inference",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/boneskull/bargs.git"
9
+ },
10
+ "homepage": "https://github.com/boneskull/bargs",
11
+ "author": "Christopher Hiller <boneskull@boneskull.com> (https://boneskull.com/)",
12
+ "license": "BlueOak-1.0.0",
13
+ "private": false,
14
+ "engines": {
15
+ "node": ">=22.0.0"
16
+ },
17
+ "main": "./dist/index.cjs",
18
+ "types": "./dist/index.d.cts",
19
+ "module": "./dist/index.js",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.cts",
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.cjs"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "keywords": [
32
+ "cli",
33
+ "args",
34
+ "arguments",
35
+ "parser",
36
+ "typescript",
37
+ "terminal",
38
+ "options",
39
+ "parseArgs"
40
+ ],
41
+ "scripts": {
42
+ "build": "zshy",
43
+ "commitlint": "commitlint",
44
+ "docs": "typedoc",
45
+ "fix": "run-s -sl fix:*",
46
+ "fix:eslint": "eslint --fix .",
47
+ "fix:markdown": "markdownlint-cli2 --fix \"**/*.md\"",
48
+ "fix:pkg": "npm pkg fix",
49
+ "fix:prettier": "prettier --write . && markdownlint-cli2 --fix \"**/*.md\"",
50
+ "lint": "run-p -sl --aggregate-output lint:*",
51
+ "lint-staged": "lint-staged",
52
+ "lint:eslint": "eslint .",
53
+ "lint:knip": "knip",
54
+ "lint:markdown": "markdownlint-cli2 \"**/*.md\"",
55
+ "lint:prettier": "prettier --check .",
56
+ "lint:spelling": "cspell . \"./.*/**\"",
57
+ "lint:types": "tsc --noEmit",
58
+ "prepare": "husky; run-s -s build",
59
+ "test": "run-s test:runtime",
60
+ "test:runtime": "node --import tsx --test --test-reporter=spec \"test/**/*.test.ts\"",
61
+ "test:watch": "node --import tsx --test --test-reporter=spec --watch \"test/**/*.test.ts\""
62
+ },
63
+ "devDependencies": {
64
+ "@commitlint/cli": "20.2.0",
65
+ "@commitlint/config-conventional": "20.2.0",
66
+ "@eslint/js": "9.39.2",
67
+ "@stylistic/eslint-plugin": "5.6.1",
68
+ "@types/node": "24.10.4",
69
+ "@types/wallabyjs": "0.0.15",
70
+ "bupkis": "0.14.0",
71
+ "cspell": "9.4.0",
72
+ "eslint": "9.39.2",
73
+ "eslint-plugin-jsonc": "2.21.0",
74
+ "eslint-plugin-perfectionist": "5.0.0",
75
+ "globals": "16.5.0",
76
+ "husky": "9.1.7",
77
+ "knip": "5.76.1",
78
+ "lint-staged": "16.2.7",
79
+ "markdownlint-cli2": "0.20.0",
80
+ "markdownlint-cli2-formatter-pretty": "0.0.9",
81
+ "npm-run-all2": "8.0.4",
82
+ "prettier": "3.7.4",
83
+ "prettier-plugin-jsdoc": "1.8.0",
84
+ "prettier-plugin-pkg": "0.21.2",
85
+ "prettier-plugin-sort-json": "4.1.1",
86
+ "tsx": "4.21.0",
87
+ "typedoc": "0.28.15",
88
+ "typescript": "5.9.3",
89
+ "typescript-eslint": "8.50.0",
90
+ "zshy": "0.6.0"
91
+ },
92
+ "publishConfig": {
93
+ "access": "public"
94
+ },
95
+ "knip": {
96
+ "ignoreDependencies": [
97
+ "markdownlint-cli2-formatter-pretty"
98
+ ],
99
+ "ignore": [
100
+ "**/*.d.ts",
101
+ ".worktrees/**/*",
102
+ "examples/**/*"
103
+ ],
104
+ "tags": [
105
+ "-knipignore"
106
+ ],
107
+ "node": {
108
+ "entry": [
109
+ "src/index.ts",
110
+ ".wallaby.js",
111
+ "test/**/*.test.ts"
112
+ ]
113
+ }
114
+ },
115
+ "lint-staged": {
116
+ "*.{ts,js,yml,json5}": [
117
+ "eslint --fix",
118
+ "prettier --write",
119
+ "cspell lint --no-must-find-files"
120
+ ],
121
+ "**/!(package-lock).json": [
122
+ "eslint --fix",
123
+ "prettier --write",
124
+ "cspell lint --no-must-find-files"
125
+ ],
126
+ "*.md": [
127
+ "markdownlint-cli2 --fix",
128
+ "prettier --write",
129
+ "cspell lint --no-must-find-files"
130
+ ]
131
+ },
132
+ "prettier": {
133
+ "jsdocCommentLineStrategy": "keep",
134
+ "jsdocPreferCodeFences": true,
135
+ "plugins": [
136
+ "prettier-plugin-jsdoc",
137
+ "prettier-plugin-pkg",
138
+ "prettier-plugin-sort-json"
139
+ ],
140
+ "singleQuote": true,
141
+ "tsdoc": true
142
+ },
143
+ "zshy": {
144
+ "exports": {
145
+ ".": "./src/index.ts",
146
+ "./package.json": "./package.json"
147
+ }
148
+ }
149
+ }