@socketsecurity/lib 5.14.0 → 5.16.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 (85) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +2 -2
  3. package/dist/abort.d.ts +13 -0
  4. package/dist/agent.d.ts +81 -0
  5. package/dist/ansi.d.ts +13 -0
  6. package/dist/archives.d.ts +31 -0
  7. package/dist/argv/flags.d.ts +91 -0
  8. package/dist/argv/parse.d.ts +31 -0
  9. package/dist/bin.d.ts +54 -0
  10. package/dist/cacache.d.ts +38 -0
  11. package/dist/cache-with-ttl.d.ts +7 -0
  12. package/dist/colors.d.ts +12 -0
  13. package/dist/cover/formatters.d.ts +18 -0
  14. package/dist/debug.d.ts +6 -0
  15. package/dist/dlx/binary.d.ts +84 -0
  16. package/dist/dlx/cache.d.ts +6 -0
  17. package/dist/dlx/detect.d.ts +33 -0
  18. package/dist/dlx/dir.d.ts +34 -0
  19. package/dist/dlx/manifest.d.ts +16 -0
  20. package/dist/dlx/package.d.ts +43 -0
  21. package/dist/dlx/packages.d.ts +36 -0
  22. package/dist/dlx/paths.d.ts +20 -0
  23. package/dist/dlx/paths.js +1 -1
  24. package/dist/effects/pulse-frames.d.ts +6 -0
  25. package/dist/effects/text-shimmer.d.ts +9 -0
  26. package/dist/effects/ultra.d.ts +6 -0
  27. package/dist/env/ci.d.ts +14 -0
  28. package/dist/env/debug.d.ts +13 -0
  29. package/dist/env/github.d.ts +80 -0
  30. package/dist/env/helpers.d.ts +45 -0
  31. package/dist/env/home.d.ts +13 -0
  32. package/dist/env/locale.d.ts +30 -0
  33. package/dist/env/node-auth-token.d.ts +13 -0
  34. package/dist/env/node-env.d.ts +13 -0
  35. package/dist/env/npm.d.ts +50 -0
  36. package/dist/env/path.d.ts +13 -0
  37. package/dist/env/pre-commit.d.ts +14 -0
  38. package/dist/env/rewire.d.ts +38 -0
  39. package/dist/env/shell.d.ts +13 -0
  40. package/dist/env/socket-cli-shadow.d.ts +43 -0
  41. package/dist/env/socket-cli.d.ts +116 -0
  42. package/dist/env/socket.d.ts +153 -0
  43. package/dist/env/temp-dir.d.ts +30 -0
  44. package/dist/env/term.d.ts +13 -0
  45. package/dist/env/test.d.ts +32 -0
  46. package/dist/env/windows.d.ts +40 -0
  47. package/dist/env/xdg.d.ts +30 -0
  48. package/dist/env.d.ts +40 -0
  49. package/dist/external/npm-pack.js +202 -291
  50. package/dist/external/tar-fs.js +27 -7
  51. package/dist/fs.d.ts +13 -0
  52. package/dist/functions.d.ts +30 -0
  53. package/dist/globs.d.ts +27 -0
  54. package/dist/http-request.d.ts +40 -18
  55. package/dist/http-request.js +84 -129
  56. package/dist/json/format.d.ts +18 -0
  57. package/dist/memoization.d.ts +5 -0
  58. package/dist/packages/edit.d.ts +28 -0
  59. package/dist/packages/exports.d.ts +40 -0
  60. package/dist/packages/licenses.d.ts +59 -0
  61. package/dist/packages/manifest.d.ts +18 -0
  62. package/dist/packages/normalize.d.ts +22 -0
  63. package/dist/packages/operations.d.ts +51 -0
  64. package/dist/packages/provenance.d.ts +11 -0
  65. package/dist/packages/specs.d.ts +30 -0
  66. package/dist/packages/validation.d.ts +18 -0
  67. package/dist/paths/normalize.d.ts +49 -5
  68. package/dist/paths/normalize.js +13 -0
  69. package/dist/paths/rewire.js +12 -3
  70. package/dist/regexps.d.ts +7 -0
  71. package/dist/releases/github.d.ts +63 -0
  72. package/dist/releases/socket-btm.d.ts +31 -0
  73. package/dist/sea.d.ts +15 -0
  74. package/dist/shadow.d.ts +7 -0
  75. package/dist/signal-exit.d.ts +27 -0
  76. package/dist/sorts.d.ts +33 -0
  77. package/dist/spawn.d.ts +9 -0
  78. package/dist/stdio/mask.d.ts +26 -0
  79. package/dist/streams.d.ts +28 -0
  80. package/dist/suppress-warnings.d.ts +7 -0
  81. package/dist/temporary-executor.d.ts +7 -0
  82. package/dist/url.d.ts +59 -0
  83. package/dist/versions.d.ts +119 -0
  84. package/dist/words.d.ts +20 -0
  85. package/package.json +8 -58
package/CHANGELOG.md CHANGED
@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [5.16.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.16.0) - 2026-04-14
9
+
10
+ ### Added — paths
11
+
12
+ - `fromUnixPath()` — convert MSYS/Git Bash Unix-style paths (`/c/path`) back to native Windows format (`C:/path`), inverse of `toUnixPath` (#168)
13
+
14
+ ### Fixed — dlx
15
+
16
+ - Normalize dlx directory path in `isInSocketDlx` for Windows compatibility
17
+
18
+ ## [5.15.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.15.0) - 2026-04-06
19
+
20
+ ### Added — http-request
21
+
22
+ - `stream` option on `HttpRequestOptions` — resolves with `HttpResponse` immediately after headers arrive, leaving `rawResponse` unconsumed for piping to files
23
+ - `headers`, `ok`, `status`, `statusText` fields on `HttpDownloadResult`
24
+
25
+ ### Changed — http-request
26
+
27
+ - `httpDownload` now uses `httpRequest` with `stream: true` internally, eliminating ~120 lines of duplicated HTTP plumbing
28
+
8
29
  ## [5.14.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.14.0) - 2026-04-06
9
30
 
10
31
  ### Added — http-request
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Socket Badge](https://socket.dev/api/badge/npm/package/@socketsecurity/lib)](https://socket.dev/npm/package/@socketsecurity/lib)
4
4
  [![CI](https://github.com/SocketDev/socket-lib/actions/workflows/ci.yml/badge.svg)](https://github.com/SocketDev/socket-lib/actions/workflows/ci.yml)
5
- ![Coverage](https://img.shields.io/badge/coverage-84.10%25-brightgreen)
5
+ ![Coverage](https://img.shields.io/badge/coverage-81%25-brightgreen)
6
6
 
7
7
  [![Follow @SocketSecurity](https://img.shields.io/twitter/follow/SocketSecurity?style=social)](https://twitter.com/SocketSecurity)
8
8
  [![Follow @socket.dev on Bluesky](https://img.shields.io/badge/Follow-@socket.dev-1DA1F2?style=social&logo=bluesky)](https://bsky.app/profile/socket.dev)
@@ -141,7 +141,7 @@ Helpers for arrays, objects, strings, promises, sorting, and more.
141
141
  - **Cross-platform** - Works on Windows, macOS, and Linux
142
142
  - **TypeScript-first** - Full type safety with .d.ts files
143
143
  - **Zero dependencies** (for core HTTP - uses Node.js native modules)
144
- - **Well-tested** - 84% coverage with comprehensive test suite
144
+ - **Well-tested** - 6600+ tests across 145 test files
145
145
  - **Security-focused** - Safe defaults, command injection protection
146
146
  - **CommonJS output** - Compatible with Node.js tooling
147
147
 
package/dist/abort.d.ts CHANGED
@@ -3,9 +3,22 @@
3
3
  */
4
4
  /**
5
5
  * Create a composite AbortSignal from multiple signals.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const ac1 = new AbortController()
10
+ * const ac2 = new AbortController()
11
+ * const signal = createCompositeAbortSignal(ac1.signal, ac2.signal)
12
+ * ```
6
13
  */
7
14
  export declare function createCompositeAbortSignal(...signals: Array<AbortSignal | null | undefined>): AbortSignal;
8
15
  /**
9
16
  * Create an AbortSignal that triggers after a timeout.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const signal = createTimeoutSignal(5000) // aborts after 5 seconds
21
+ * fetch('https://example.com', { signal })
22
+ * ```
10
23
  */
11
24
  export declare function createTimeoutSignal(ms: number): AbortSignal;
package/dist/agent.d.ts CHANGED
@@ -4,6 +4,12 @@ import type { SpawnOptions } from './spawn';
4
4
  *
5
5
  * SECURITY: Uses array-based arguments to prevent command injection. All elements
6
6
  * in the args array are properly escaped by Node.js when passed to spawn().
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * await execNpm(['install', '--save', 'lodash'])
11
+ * await execNpm(['run', 'build'], { cwd: '/tmp/project' })
12
+ * ```
7
13
  */
8
14
  export declare function execNpm(args: string[], options?: SpawnOptions | undefined): import("./spawn").PromiseSpawnResult;
9
15
  export interface PnpmOptions extends SpawnOptions {
@@ -14,6 +20,12 @@ export interface PnpmOptions extends SpawnOptions {
14
20
  *
15
21
  * SECURITY: Uses array-based arguments to prevent command injection. All elements
16
22
  * in the args array are properly escaped by Node.js when passed to execBin().
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * await execPnpm(['install'])
27
+ * await execPnpm(['add', 'lodash'], { allowLockfileUpdate: true })
28
+ * ```
17
29
  */
18
30
  export declare function execPnpm(args: string[], options?: PnpmOptions | undefined): Promise<{
19
31
  cmd: string;
@@ -28,6 +40,12 @@ export declare function execPnpm(args: string[], options?: PnpmOptions | undefin
28
40
  *
29
41
  * SECURITY: Uses array-based arguments to prevent command injection. All elements
30
42
  * in the args array are properly escaped by Node.js when passed to execBin().
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * await execYarn(['install'])
47
+ * await execYarn(['add', 'lodash'], { cwd: '/tmp/project' })
48
+ * ```
31
49
  */
32
50
  export declare function execYarn(args: string[], options?: import('./spawn').SpawnOptions): Promise<{
33
51
  cmd: string;
@@ -39,41 +57,98 @@ export declare function execYarn(args: string[], options?: import('./spawn').Spa
39
57
  }>;
40
58
  /**
41
59
  * Check if a command argument is an npm audit flag.
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * isNpmAuditFlag('--no-audit') // true
64
+ * isNpmAuditFlag('--audit') // true
65
+ * isNpmAuditFlag('--save') // false
66
+ * ```
42
67
  */
43
68
  /*@__NO_SIDE_EFFECTS__*/
44
69
  export declare function isNpmAuditFlag(cmdArg: string): boolean;
45
70
  /**
46
71
  * Check if a command argument is an npm fund flag.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * isNpmFundFlag('--no-fund') // true
76
+ * isNpmFundFlag('--fund') // true
77
+ * isNpmFundFlag('--save') // false
78
+ * ```
47
79
  */
48
80
  /*@__NO_SIDE_EFFECTS__*/
49
81
  export declare function isNpmFundFlag(cmdArg: string): boolean;
50
82
  /**
51
83
  * Check if a command argument is an npm loglevel flag.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * isNpmLoglevelFlag('--loglevel') // true
88
+ * isNpmLoglevelFlag('--silent') // true
89
+ * isNpmLoglevelFlag('-s') // true
90
+ * isNpmLoglevelFlag('--save') // false
91
+ * ```
52
92
  */
53
93
  /*@__NO_SIDE_EFFECTS__*/
54
94
  export declare function isNpmLoglevelFlag(cmdArg: string): boolean;
55
95
  /**
56
96
  * Check if a command argument is an npm node-options flag.
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * isNpmNodeOptionsFlag('--node-options') // true
101
+ * isNpmNodeOptionsFlag('--node-options=--max-old-space-size=4096') // true
102
+ * isNpmNodeOptionsFlag('--save') // false
103
+ * ```
57
104
  */
58
105
  /*@__NO_SIDE_EFFECTS__*/
59
106
  export declare function isNpmNodeOptionsFlag(cmdArg: string): boolean;
60
107
  /**
61
108
  * Check if a command argument is an npm progress flag.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * isNpmProgressFlag('--no-progress') // true
113
+ * isNpmProgressFlag('--progress') // true
114
+ * isNpmProgressFlag('--save') // false
115
+ * ```
62
116
  */
63
117
  /*@__NO_SIDE_EFFECTS__*/
64
118
  export declare function isNpmProgressFlag(cmdArg: string): boolean;
65
119
  /**
66
120
  * Check if a command argument is a pnpm ignore-scripts flag.
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * isPnpmIgnoreScriptsFlag('--ignore-scripts') // true
125
+ * isPnpmIgnoreScriptsFlag('--no-ignore-scripts') // true
126
+ * isPnpmIgnoreScriptsFlag('--save') // false
127
+ * ```
67
128
  */
68
129
  /*@__NO_SIDE_EFFECTS__*/
69
130
  export declare function isPnpmIgnoreScriptsFlag(cmdArg: string): boolean;
70
131
  /**
71
132
  * Check if a command argument is a pnpm frozen-lockfile flag.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * isPnpmFrozenLockfileFlag('--frozen-lockfile') // true
137
+ * isPnpmFrozenLockfileFlag('--no-frozen-lockfile') // true
138
+ * isPnpmFrozenLockfileFlag('--save') // false
139
+ * ```
72
140
  */
73
141
  /*@__NO_SIDE_EFFECTS__*/
74
142
  export declare function isPnpmFrozenLockfileFlag(cmdArg: string): boolean;
75
143
  /**
76
144
  * Check if a command argument is a pnpm install command.
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * isPnpmInstallCommand('install') // true
149
+ * isPnpmInstallCommand('i') // true
150
+ * isPnpmInstallCommand('run') // false
151
+ * ```
77
152
  */
78
153
  /*@__NO_SIDE_EFFECTS__*/
79
154
  export declare function isPnpmInstallCommand(cmdArg: string): boolean;
@@ -84,6 +159,12 @@ export declare const isPnpmLoglevelFlag: typeof isNpmLoglevelFlag;
84
159
  /**
85
160
  * Execute a package.json script using the appropriate package manager.
86
161
  * Automatically detects pnpm, yarn, or npm based on lockfiles.
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * await execScript('build')
166
+ * await execScript('test', ['--coverage'], { cwd: '/tmp/project' })
167
+ * ```
87
168
  */
88
169
  export interface ExecScriptOptions extends SpawnOptions {
89
170
  prepost?: boolean | undefined;
package/dist/ansi.d.ts CHANGED
@@ -16,6 +16,13 @@ export declare const ANSI_STRIKETHROUGH = "\u001B[9m";
16
16
  * https://socket.dev/npm/package/ansi-regexp/overview/6.2.2
17
17
  * MIT License
18
18
  * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const regex = ansiRegex()
23
+ * '\u001b[31mHello\u001b[0m'.match(regex) // ['\u001b[31m', '\u001b[0m']
24
+ * ansiRegex({ onlyFirst: true }) // matches only the first code
25
+ * ```
19
26
  */
20
27
  /*@__NO_SIDE_EFFECTS__*/
21
28
  export declare function ansiRegex(options?: {
@@ -24,6 +31,12 @@ export declare function ansiRegex(options?: {
24
31
  /**
25
32
  * Strip ANSI escape codes from text.
26
33
  * Uses the inlined ansi-regex for matching.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * stripAnsi('\u001b[31mError\u001b[0m') // 'Error'
38
+ * stripAnsi('\u001b[1mBold\u001b[0m') // 'Bold'
39
+ * ```
27
40
  */
28
41
  /*@__NO_SIDE_EFFECTS__*/
29
42
  export declare function stripAnsi(text: string): string;
@@ -22,6 +22,13 @@ export interface ExtractOptions {
22
22
  *
23
23
  * @param filePath - Path to archive file
24
24
  * @returns Archive format or null if unknown
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * detectArchiveFormat('package.tar.gz') // 'tar.gz'
29
+ * detectArchiveFormat('archive.zip') // 'zip'
30
+ * detectArchiveFormat('data.csv') // null
31
+ * ```
25
32
  */
26
33
  export declare function detectArchiveFormat(filePath: string): ArchiveFormat | null;
27
34
  /**
@@ -30,6 +37,12 @@ export declare function detectArchiveFormat(filePath: string): ArchiveFormat | n
30
37
  * @param archivePath - Path to tar file
31
38
  * @param outputDir - Directory to extract to
32
39
  * @param options - Extraction options
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * await extractTar('/tmp/archive.tar', '/tmp/output')
44
+ * await extractTar('/tmp/archive.tar', '/tmp/output', { strip: 1 })
45
+ * ```
33
46
  */
34
47
  export declare function extractTar(archivePath: string, outputDir: string, options?: ExtractOptions): Promise<void>;
35
48
  /**
@@ -38,6 +51,12 @@ export declare function extractTar(archivePath: string, outputDir: string, optio
38
51
  * @param archivePath - Path to tar.gz or tgz file
39
52
  * @param outputDir - Directory to extract to
40
53
  * @param options - Extraction options
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * await extractTarGz('/tmp/archive.tar.gz', '/tmp/output')
58
+ * await extractTarGz('/tmp/archive.tgz', '/tmp/output', { strip: 1 })
59
+ * ```
41
60
  */
42
61
  export declare function extractTarGz(archivePath: string, outputDir: string, options?: ExtractOptions): Promise<void>;
43
62
  /**
@@ -46,6 +65,12 @@ export declare function extractTarGz(archivePath: string, outputDir: string, opt
46
65
  * @param archivePath - Path to zip file
47
66
  * @param outputDir - Directory to extract to
48
67
  * @param options - Extraction options
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * await extractZip('/tmp/archive.zip', '/tmp/output')
72
+ * await extractZip('/tmp/archive.zip', '/tmp/output', { strip: 1 })
73
+ * ```
49
74
  */
50
75
  export declare function extractZip(archivePath: string, outputDir: string, options?: ExtractOptions): Promise<void>;
51
76
  /**
@@ -56,5 +81,11 @@ export declare function extractZip(archivePath: string, outputDir: string, optio
56
81
  * @param outputDir - Directory to extract to
57
82
  * @param options - Extraction options
58
83
  * @throws Error if archive format is not supported
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * await extractArchive('/tmp/package.tar.gz', '/tmp/output')
88
+ * await extractArchive('/tmp/release.zip', '/tmp/output', { strip: 1 })
89
+ * ```
59
90
  */
60
91
  export declare function extractArchive(archivePath: string, outputDir: string, options?: ExtractOptions): Promise<void>;
@@ -26,77 +26,168 @@ export type FlagInput = FlagValues | string[] | readonly string[] | undefined;
26
26
  * Get the appropriate log level based on flags.
27
27
  * Returns 'silent', 'error', 'warn', 'info', 'verbose', or 'debug'.
28
28
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * getLogLevel() // 'info' (default)
33
+ * getLogLevel({ quiet: true }) // 'silent'
34
+ * getLogLevel(['--debug']) // 'debug'
35
+ * ```
29
36
  */
30
37
  export declare function getLogLevel(input?: FlagInput): string;
31
38
  /**
32
39
  * Check if all flag is set.
33
40
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * isAll({ all: true }) // true
45
+ * isAll(['--all']) // true
46
+ * ```
34
47
  */
35
48
  export declare function isAll(input?: FlagInput): boolean;
36
49
  /**
37
50
  * Check if changed files mode is enabled.
38
51
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * isChanged({ changed: true }) // true
56
+ * isChanged(['--changed']) // true
57
+ * ```
39
58
  */
40
59
  export declare function isChanged(input?: FlagInput): boolean;
41
60
  /**
42
61
  * Check if coverage mode is enabled.
43
62
  * Checks both 'coverage' and 'cover' flags.
44
63
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * isCoverage({ coverage: true }) // true
68
+ * isCoverage(['--cover']) // true
69
+ * ```
45
70
  */
46
71
  export declare function isCoverage(input?: FlagInput): boolean;
47
72
  /**
48
73
  * Check if debug mode is enabled.
49
74
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * isDebug({ debug: true }) // true
79
+ * isDebug(['--debug']) // true
80
+ * ```
50
81
  */
51
82
  export declare function isDebug(input?: FlagInput): boolean;
52
83
  /**
53
84
  * Check if dry-run mode is enabled.
54
85
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * isDryRun({ 'dry-run': true }) // true
90
+ * isDryRun(['--dry-run']) // true
91
+ * ```
55
92
  */
56
93
  export declare function isDryRun(input?: FlagInput): boolean;
57
94
  /**
58
95
  * Check if fix/autofix mode is enabled.
59
96
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * isFix({ fix: true }) // true
101
+ * isFix(['--fix']) // true
102
+ * ```
60
103
  */
61
104
  export declare function isFix(input?: FlagInput): boolean;
62
105
  /**
63
106
  * Check if force mode is enabled.
64
107
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * isForce({ force: true }) // true
112
+ * isForce(['--force']) // true
113
+ * ```
65
114
  */
66
115
  export declare function isForce(input?: FlagInput): boolean;
67
116
  /**
68
117
  * Check if help flag is set.
69
118
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * isHelp({ help: true }) // true
123
+ * isHelp(['-h']) // true
124
+ * ```
70
125
  */
71
126
  export declare function isHelp(input?: FlagInput): boolean;
72
127
  /**
73
128
  * Check if JSON output is requested.
74
129
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * isJson({ json: true }) // true
134
+ * isJson(['--json']) // true
135
+ * ```
75
136
  */
76
137
  export declare function isJson(input?: FlagInput): boolean;
77
138
  /**
78
139
  * Check if quiet/silent mode is enabled.
79
140
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * isQuiet({ quiet: true }) // true
145
+ * isQuiet(['--silent']) // true
146
+ * ```
80
147
  */
81
148
  export declare function isQuiet(input?: FlagInput): boolean;
82
149
  /**
83
150
  * Check if staged files mode is enabled.
84
151
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * isStaged({ staged: true }) // true
156
+ * isStaged(['--staged']) // true
157
+ * ```
85
158
  */
86
159
  export declare function isStaged(input?: FlagInput): boolean;
87
160
  /**
88
161
  * Check if update mode is enabled (for snapshots, dependencies, etc).
89
162
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * isUpdate({ update: true }) // true
167
+ * isUpdate(['-u']) // true
168
+ * ```
90
169
  */
91
170
  export declare function isUpdate(input?: FlagInput): boolean;
92
171
  /**
93
172
  * Check if verbose mode is enabled.
94
173
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * isVerbose({ verbose: true }) // true
178
+ * isVerbose(['--verbose']) // true
179
+ * ```
95
180
  */
96
181
  export declare function isVerbose(input?: FlagInput): boolean;
97
182
  /**
98
183
  * Check if watch mode is enabled.
99
184
  * Accepts FlagValues object, process.argv array, or undefined (uses process.argv).
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * isWatch({ watch: true }) // true
189
+ * isWatch(['-w']) // true
190
+ * ```
100
191
  */
101
192
  export declare function isWatch(input?: FlagInput): boolean;
102
193
  /**
@@ -53,11 +53,30 @@ export interface ParsedArgs<T = Record<string, unknown>> {
53
53
  /**
54
54
  * Parse command-line arguments with a Node.js parseArgs-compatible API.
55
55
  * Uses yargs-parser internally for robust argument parsing.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const { values, positionals } = parseArgs({
60
+ * args: ['--force', '--quiet', 'file.ts'],
61
+ * options: {
62
+ * force: { type: 'boolean' },
63
+ * quiet: { type: 'boolean', short: 'q' },
64
+ * },
65
+ * })
66
+ * ```
56
67
  */
57
68
  export declare function parseArgs<T = Record<string, unknown>>(config?: ParseArgsConfig): ParsedArgs<T>;
58
69
  /**
59
70
  * Parse command-line arguments with Socket defaults.
60
71
  * Provides sensible defaults for Socket CLI applications.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const { values, positionals } = parseArgsWithDefaults({
76
+ * args: ['--force', 'file.ts'],
77
+ * options: { force: { type: 'boolean' } },
78
+ * })
79
+ * ```
61
80
  */
62
81
  export declare function parseArgsWithDefaults<T = Record<string, unknown>>(config?: ParseArgsConfig): ParsedArgs<T>;
63
82
  /**
@@ -67,10 +86,22 @@ export declare const commonParseArgsConfig: ParseArgsConfig;
67
86
  /**
68
87
  * Extract positional arguments from process.argv.
69
88
  * Useful for commands that accept file paths or other positional parameters.
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * // process.argv = ["node", "script.js", "src", "lib", "--verbose"]
93
+ * getPositionalArgs() // ["src", "lib"]
94
+ * ```
70
95
  */
71
96
  export declare function getPositionalArgs(startIndex?: number): string[];
72
97
  /**
73
98
  * Check if a specific flag is present in argv.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * hasFlag('verbose') // true if --verbose is in process.argv
103
+ * hasFlag('force', ['--force', '--quiet']) // true
104
+ * ```
74
105
  */
75
106
  export declare function hasFlag(flag: string, argv?: string[]): boolean;
76
107
  export {};
package/dist/bin.d.ts CHANGED
@@ -17,6 +17,12 @@ export interface WhichOptions {
17
17
  }
18
18
  /**
19
19
  * Execute a binary with the given arguments.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * await execBin('pnpm', ['install'])
24
+ * await execBin('/usr/local/bin/node', ['script.js'], { cwd: '/tmp' })
25
+ * ```
20
26
  */
21
27
  /*@__NO_SIDE_EFFECTS__*/
22
28
  export declare function execBin(binPath: string, args?: string[], options?: import('./spawn').SpawnOptions): Promise<{
@@ -29,28 +35,64 @@ export declare function execBin(binPath: string, args?: string[], options?: impo
29
35
  }>;
30
36
  /**
31
37
  * Find the real executable for a binary, bypassing shadow bins.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const npmPath = findRealBin('npm', ['/usr/local/bin/npm'])
42
+ * const gitPath = findRealBin('git')
43
+ * ```
32
44
  */
33
45
  export declare function findRealBin(binName: string, commonPaths?: string[]): string | undefined;
34
46
  /**
35
47
  * Find the real npm executable, bypassing any aliases and shadow bins.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const npmPath = findRealNpm()
52
+ * // e.g. '/usr/local/bin/npm'
53
+ * ```
36
54
  */
37
55
  export declare function findRealNpm(): string;
38
56
  /**
39
57
  * Find the real pnpm executable, bypassing any aliases and shadow bins.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const pnpmPath = findRealPnpm()
62
+ * // e.g. '/usr/local/bin/pnpm'
63
+ * ```
40
64
  */
41
65
  export declare function findRealPnpm(): string;
42
66
  /**
43
67
  * Find the real yarn executable, bypassing any aliases and shadow bins.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const yarnPath = findRealYarn()
72
+ * // e.g. '/usr/local/bin/yarn'
73
+ * ```
44
74
  */
45
75
  export declare function findRealYarn(): string;
46
76
  /**
47
77
  * Check if a directory path contains any shadow bin patterns.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * isShadowBinPath('/tmp/project/node_modules/.bin') // true
82
+ * isShadowBinPath('/usr/local/bin') // false
83
+ * ```
48
84
  */
49
85
  export declare function isShadowBinPath(dirPath: string | undefined): boolean;
50
86
  /*@__NO_SIDE_EFFECTS__*/
51
87
  /**
52
88
  * Resolve a binary path to the real underlying script file.
53
89
  * Handles Windows .cmd wrappers and Unix shell scripts, resolving them to the actual .js files they execute.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const realPath = resolveRealBinSync('/usr/local/bin/npm')
94
+ * // e.g. '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
95
+ * ```
54
96
  */
55
97
  export declare function resolveRealBinSync(binPath: string): string;
56
98
  /**
@@ -86,12 +128,24 @@ export declare function which(binName: string, options?: WhichOptions): Promise<
86
128
  * Find a binary in the system PATH and resolve to the real underlying script asynchronously.
87
129
  * Resolves wrapper scripts (.cmd, .ps1, shell scripts) to the actual .js files they execute.
88
130
  * @throws {Error} If the binary is not found and nothrow is false.
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const npmPath = await whichReal('npm')
135
+ * // e.g. '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
136
+ * ```
89
137
  */
90
138
  export declare function whichReal(binName: string, options?: WhichOptions): Promise<string | string[] | undefined>;
91
139
  /**
92
140
  * Find a binary in the system PATH and resolve to the real underlying script synchronously.
93
141
  * Resolves wrapper scripts (.cmd, .ps1, shell scripts) to the actual .js files they execute.
94
142
  * @throws {Error} If the binary is not found and nothrow is false.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const npmPath = whichRealSync('npm')
147
+ * // e.g. '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
148
+ * ```
95
149
  */
96
150
  export declare function whichRealSync(binName: string, options?: WhichOptions): string | string[] | undefined;
97
151
  /**