@socketsecurity/lib 1.0.4 → 1.1.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 (80) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/abort.js.map +2 -2
  3. package/dist/argv/parse.js.map +2 -2
  4. package/dist/arrays.d.ts +143 -0
  5. package/dist/arrays.js.map +2 -2
  6. package/dist/bin.js +1 -4
  7. package/dist/bin.js.map +2 -2
  8. package/dist/cacache.d.ts +0 -2
  9. package/dist/cacache.js +0 -1
  10. package/dist/cacache.js.map +2 -2
  11. package/dist/cache-with-ttl.js.map +2 -2
  12. package/dist/dlx.js.map +2 -2
  13. package/dist/external/@yarnpkg/extensions.d.ts +0 -1
  14. package/dist/external/cacache.d.ts +0 -7
  15. package/dist/external/debug.d.ts +0 -3
  16. package/dist/external/fast-sort.d.ts +0 -1
  17. package/dist/external/libnpmpack.d.ts +0 -1
  18. package/dist/external/make-fetch-happen.d.ts +0 -1
  19. package/dist/external/pacote.d.ts +0 -5
  20. package/dist/external/semver.d.ts +0 -1
  21. package/dist/external/validate-npm-package-name.js +1 -1
  22. package/dist/external/yargs-parser.d.ts +0 -1
  23. package/dist/external/yoctocolors-cjs.js +1 -1
  24. package/dist/external/zod.js +9 -9
  25. package/dist/fs.d.ts +595 -23
  26. package/dist/fs.js.map +2 -2
  27. package/dist/git.d.ts +488 -41
  28. package/dist/git.js.map +2 -2
  29. package/dist/github.d.ts +361 -12
  30. package/dist/github.js.map +2 -2
  31. package/dist/http-request.d.ts +463 -4
  32. package/dist/http-request.js.map +2 -2
  33. package/dist/json.d.ts +177 -4
  34. package/dist/json.js.map +2 -2
  35. package/dist/logger.d.ts +823 -70
  36. package/dist/logger.js +654 -51
  37. package/dist/logger.js.map +2 -2
  38. package/dist/objects.d.ts +386 -10
  39. package/dist/objects.js.map +2 -2
  40. package/dist/path.d.ts +270 -6
  41. package/dist/path.js.map +2 -2
  42. package/dist/promises.d.ts +432 -27
  43. package/dist/promises.js +3 -0
  44. package/dist/promises.js.map +2 -2
  45. package/dist/signal-exit.js.map +2 -2
  46. package/dist/sorts.js.map +2 -2
  47. package/dist/spawn.d.ts +242 -33
  48. package/dist/spawn.js.map +2 -2
  49. package/dist/spinner.d.ts +260 -20
  50. package/dist/spinner.js +201 -63
  51. package/dist/spinner.js.map +2 -2
  52. package/dist/stdio/clear.d.ts +130 -9
  53. package/dist/stdio/clear.js.map +2 -2
  54. package/dist/stdio/divider.d.ts +106 -10
  55. package/dist/stdio/divider.js +10 -0
  56. package/dist/stdio/divider.js.map +2 -2
  57. package/dist/stdio/footer.d.ts +70 -3
  58. package/dist/stdio/footer.js.map +2 -2
  59. package/dist/stdio/header.d.ts +93 -12
  60. package/dist/stdio/header.js.map +2 -2
  61. package/dist/stdio/mask.d.ts +82 -14
  62. package/dist/stdio/mask.js +25 -4
  63. package/dist/stdio/mask.js.map +2 -2
  64. package/dist/stdio/progress.d.ts +112 -15
  65. package/dist/stdio/progress.js +43 -3
  66. package/dist/stdio/progress.js.map +2 -2
  67. package/dist/stdio/prompts.d.ts +95 -5
  68. package/dist/stdio/prompts.js.map +2 -2
  69. package/dist/stdio/stderr.d.ts +114 -11
  70. package/dist/stdio/stderr.js.map +2 -2
  71. package/dist/stdio/stdout.d.ts +107 -11
  72. package/dist/stdio/stdout.js.map +2 -2
  73. package/dist/strings.d.ts +357 -28
  74. package/dist/strings.js.map +2 -2
  75. package/dist/suppress-warnings.js.map +2 -2
  76. package/dist/validation/json-parser.d.ts +226 -7
  77. package/dist/validation/json-parser.js.map +2 -2
  78. package/dist/validation/types.d.ts +114 -12
  79. package/dist/validation/types.js.map +1 -1
  80. package/package.json +5 -3
@@ -1,47 +1,143 @@
1
1
  // Get the actual stdout stream
2
2
  declare const stdout: NodeJS.WriteStream;
3
3
  /**
4
- * Write a line to stdout.
4
+ * Write a line to stdout with trailing newline.
5
+ *
6
+ * @param text - Text to write
7
+ * @default text ''
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * writeLine('Hello, world!')
12
+ * writeLine() // Write empty line
13
+ * ```
5
14
  */
6
15
  export declare function writeLine(text?: string): void;
7
16
  /**
8
- * Write text to stdout without newline.
17
+ * Write text to stdout without adding a newline.
18
+ *
19
+ * @param text - Text to write
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * write('Loading...')
24
+ * // Later: clear and update
25
+ * ```
9
26
  */
10
27
  export declare function write(text: string): void;
11
28
  /**
12
29
  * Clear the current line on stdout.
30
+ * Only works in TTY environments.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * write('Processing...')
35
+ * clearLine()
36
+ * write('Done!')
37
+ * ```
13
38
  */
14
39
  export declare function clearLine(): void;
15
40
  /**
16
- * Move cursor to position on stdout.
41
+ * Move cursor to specific position on stdout.
42
+ * Only works in TTY environments.
43
+ *
44
+ * @param x - Column position (0-based)
45
+ * @param y - Row position (0-based, optional)
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * cursorTo(0) // Move to start of line
50
+ * cursorTo(10, 5) // Move to column 10, row 5
51
+ * ```
17
52
  */
18
- export declare function cursorTo(x: number, y?: number): void;
53
+ export declare function cursorTo(x: number, y?: number | undefined): void;
19
54
  /**
20
- * Clear screen from cursor down.
55
+ * Clear screen from cursor position down to bottom.
56
+ * Only works in TTY environments.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * cursorTo(0, 5)
61
+ * clearScreenDown() // Clear from row 5 to bottom
62
+ * ```
21
63
  */
22
64
  export declare function clearScreenDown(): void;
23
65
  /**
24
- * Check if stdout is a TTY.
66
+ * Check if stdout is connected to a TTY (terminal).
67
+ *
68
+ * @returns `true` if stdout is a TTY, `false` if piped/redirected
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * if (isTTY()) {
73
+ * // Show interactive UI
74
+ * } else {
75
+ * // Use simple text output
76
+ * }
77
+ * ```
25
78
  */
26
79
  export declare function isTTY(): boolean;
27
80
  /**
28
- * Get terminal columns for stdout.
81
+ * Get the number of columns (width) in the terminal.
82
+ *
83
+ * @returns Terminal width in characters
84
+ * @default 80
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const width = getColumns()
89
+ * console.log(`Terminal is ${width} characters wide`)
90
+ * ```
29
91
  */
30
92
  export declare function getColumns(): number;
31
93
  /**
32
- * Get terminal rows for stdout.
94
+ * Get the number of rows (height) in the terminal.
95
+ *
96
+ * @returns Terminal height in lines
97
+ * @default 24
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * const height = getRows()
102
+ * console.log(`Terminal is ${height} lines tall`)
103
+ * ```
33
104
  */
34
105
  export declare function getRows(): number;
35
106
  /**
36
- * Hide cursor on stdout.
107
+ * Hide the cursor on stdout.
108
+ * Useful for cleaner output during animations.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * hideCursor()
113
+ * // Show animation
114
+ * showCursor()
115
+ * ```
37
116
  */
38
117
  export declare function hideCursor(): void;
39
118
  /**
40
- * Show cursor on stdout.
119
+ * Show the cursor on stdout.
120
+ * Should be called after `hideCursor()`.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * hideCursor()
125
+ * // Show animation
126
+ * showCursor()
127
+ * ```
41
128
  */
42
129
  export declare function showCursor(): void;
43
130
  /**
44
- * Ensure cursor is shown on exit.
131
+ * Register handlers to ensure cursor is shown on process exit.
132
+ * Prevents hidden cursor after abnormal termination.
133
+ * Handles SIGINT (Ctrl+C) and SIGTERM signals.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * ensureCursorOnExit()
138
+ * hideCursor()
139
+ * // Even if process crashes, cursor will be restored
140
+ * ```
45
141
  */
46
142
  export declare function ensureCursorOnExit(): void;
47
143
  // Export the raw stream for advanced usage
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/stdio/stdout.ts"],
4
- "sourcesContent": ["/**\n * Standard output stream utilities.\n * Provides utilities for writing to stdout with formatting and control.\n */\n\nimport { WriteStream } from 'node:tty'\n\n// Get the actual stdout stream\nconst stdout: NodeJS.WriteStream = process.stdout\n\n/**\n * Write a line to stdout.\n */\nexport function writeLine(text: string = ''): void {\n stdout.write(`${text}\\n`)\n}\n\n/**\n * Write text to stdout without newline.\n */\nexport function write(text: string): void {\n stdout.write(text)\n}\n\n/**\n * Clear the current line on stdout.\n */\nexport function clearLine(): void {\n if (stdout.isTTY) {\n stdout.cursorTo(0)\n stdout.clearLine(0)\n }\n}\n\n/**\n * Move cursor to position on stdout.\n */\nexport function cursorTo(x: number, y?: number): void {\n if (stdout.isTTY) {\n stdout.cursorTo(x, y)\n }\n}\n\n/**\n * Clear screen from cursor down.\n */\nexport function clearScreenDown(): void {\n if (stdout.isTTY) {\n stdout.clearScreenDown()\n }\n}\n\n/**\n * Check if stdout is a TTY.\n */\nexport function isTTY(): boolean {\n return stdout.isTTY || false\n}\n\n/**\n * Get terminal columns for stdout.\n */\nexport function getColumns(): number {\n return stdout.columns || 80\n}\n\n/**\n * Get terminal rows for stdout.\n */\nexport function getRows(): number {\n return stdout.rows || 24\n}\n\n/**\n * Hide cursor on stdout.\n */\nexport function hideCursor(): void {\n if (stdout.isTTY && stdout instanceof WriteStream) {\n stdout.write('\\u001B[?25l')\n }\n}\n\n/**\n * Show cursor on stdout.\n */\nexport function showCursor(): void {\n if (stdout.isTTY && stdout instanceof WriteStream) {\n stdout.write('\\u001B[?25h')\n }\n}\n\n/**\n * Ensure cursor is shown on exit.\n */\nexport function ensureCursorOnExit(): void {\n process.on('exit', showCursor)\n process.on('SIGINT', () => {\n showCursor()\n // eslint-disable-next-line n/no-process-exit\n process.exit(130)\n })\n process.on('SIGTERM', () => {\n showCursor()\n // eslint-disable-next-line n/no-process-exit\n process.exit(143)\n })\n}\n\n// Export the raw stream for advanced usage\nexport { stdout }\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,sBAA4B;AAG5B,MAAM,SAA6B,QAAQ;AAKpC,SAAS,UAAU,OAAe,IAAU;AACjD,SAAO,MAAM,GAAG,IAAI;AAAA,CAAI;AAC1B;AAKO,SAAS,MAAM,MAAoB;AACxC,SAAO,MAAM,IAAI;AACnB;AAKO,SAAS,YAAkB;AAChC,MAAI,OAAO,OAAO;AAChB,WAAO,SAAS,CAAC;AACjB,WAAO,UAAU,CAAC;AAAA,EACpB;AACF;AAKO,SAAS,SAAS,GAAW,GAAkB;AACpD,MAAI,OAAO,OAAO;AAChB,WAAO,SAAS,GAAG,CAAC;AAAA,EACtB;AACF;AAKO,SAAS,kBAAwB;AACtC,MAAI,OAAO,OAAO;AAChB,WAAO,gBAAgB;AAAA,EACzB;AACF;AAKO,SAAS,QAAiB;AAC/B,SAAO,OAAO,SAAS;AACzB;AAKO,SAAS,aAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAKO,SAAS,UAAkB;AAChC,SAAO,OAAO,QAAQ;AACxB;AAKO,SAAS,aAAmB;AACjC,MAAI,OAAO,SAAS,kBAAkB,6BAAa;AACjD,WAAO,MAAM,WAAa;AAAA,EAC5B;AACF;AAKO,SAAS,aAAmB;AACjC,MAAI,OAAO,SAAS,kBAAkB,6BAAa;AACjD,WAAO,MAAM,WAAa;AAAA,EAC5B;AACF;AAKO,SAAS,qBAA2B;AACzC,UAAQ,GAAG,QAAQ,UAAU;AAC7B,UAAQ,GAAG,UAAU,MAAM;AACzB,eAAW;AAEX,YAAQ,KAAK,GAAG;AAAA,EAClB,CAAC;AACD,UAAQ,GAAG,WAAW,MAAM;AAC1B,eAAW;AAEX,YAAQ,KAAK,GAAG;AAAA,EAClB,CAAC;AACH;",
4
+ "sourcesContent": ["/**\n * @fileoverview Standard output stream utilities.\n * Provides utilities for writing to stdout with formatting and control.\n */\n\nimport { WriteStream } from 'node:tty'\n\n// Get the actual stdout stream\nconst stdout: NodeJS.WriteStream = process.stdout\n\n/**\n * Write a line to stdout with trailing newline.\n *\n * @param text - Text to write\n * @default text ''\n *\n * @example\n * ```ts\n * writeLine('Hello, world!')\n * writeLine() // Write empty line\n * ```\n */\nexport function writeLine(text: string = ''): void {\n stdout.write(`${text}\\n`)\n}\n\n/**\n * Write text to stdout without adding a newline.\n *\n * @param text - Text to write\n *\n * @example\n * ```ts\n * write('Loading...')\n * // Later: clear and update\n * ```\n */\nexport function write(text: string): void {\n stdout.write(text)\n}\n\n/**\n * Clear the current line on stdout.\n * Only works in TTY environments.\n *\n * @example\n * ```ts\n * write('Processing...')\n * clearLine()\n * write('Done!')\n * ```\n */\nexport function clearLine(): void {\n if (stdout.isTTY) {\n stdout.cursorTo(0)\n stdout.clearLine(0)\n }\n}\n\n/**\n * Move cursor to specific position on stdout.\n * Only works in TTY environments.\n *\n * @param x - Column position (0-based)\n * @param y - Row position (0-based, optional)\n *\n * @example\n * ```ts\n * cursorTo(0) // Move to start of line\n * cursorTo(10, 5) // Move to column 10, row 5\n * ```\n */\nexport function cursorTo(x: number, y?: number | undefined): void {\n if (stdout.isTTY) {\n stdout.cursorTo(x, y)\n }\n}\n\n/**\n * Clear screen from cursor position down to bottom.\n * Only works in TTY environments.\n *\n * @example\n * ```ts\n * cursorTo(0, 5)\n * clearScreenDown() // Clear from row 5 to bottom\n * ```\n */\nexport function clearScreenDown(): void {\n if (stdout.isTTY) {\n stdout.clearScreenDown()\n }\n}\n\n/**\n * Check if stdout is connected to a TTY (terminal).\n *\n * @returns `true` if stdout is a TTY, `false` if piped/redirected\n *\n * @example\n * ```ts\n * if (isTTY()) {\n * // Show interactive UI\n * } else {\n * // Use simple text output\n * }\n * ```\n */\nexport function isTTY(): boolean {\n return stdout.isTTY || false\n}\n\n/**\n * Get the number of columns (width) in the terminal.\n *\n * @returns Terminal width in characters\n * @default 80\n *\n * @example\n * ```ts\n * const width = getColumns()\n * console.log(`Terminal is ${width} characters wide`)\n * ```\n */\nexport function getColumns(): number {\n return stdout.columns || 80\n}\n\n/**\n * Get the number of rows (height) in the terminal.\n *\n * @returns Terminal height in lines\n * @default 24\n *\n * @example\n * ```ts\n * const height = getRows()\n * console.log(`Terminal is ${height} lines tall`)\n * ```\n */\nexport function getRows(): number {\n return stdout.rows || 24\n}\n\n/**\n * Hide the cursor on stdout.\n * Useful for cleaner output during animations.\n *\n * @example\n * ```ts\n * hideCursor()\n * // Show animation\n * showCursor()\n * ```\n */\nexport function hideCursor(): void {\n if (stdout.isTTY && stdout instanceof WriteStream) {\n stdout.write('\\u001B[?25l')\n }\n}\n\n/**\n * Show the cursor on stdout.\n * Should be called after `hideCursor()`.\n *\n * @example\n * ```ts\n * hideCursor()\n * // Show animation\n * showCursor()\n * ```\n */\nexport function showCursor(): void {\n if (stdout.isTTY && stdout instanceof WriteStream) {\n stdout.write('\\u001B[?25h')\n }\n}\n\n/**\n * Register handlers to ensure cursor is shown on process exit.\n * Prevents hidden cursor after abnormal termination.\n * Handles SIGINT (Ctrl+C) and SIGTERM signals.\n *\n * @example\n * ```ts\n * ensureCursorOnExit()\n * hideCursor()\n * // Even if process crashes, cursor will be restored\n * ```\n */\nexport function ensureCursorOnExit(): void {\n process.on('exit', showCursor)\n process.on('SIGINT', () => {\n showCursor()\n // eslint-disable-next-line n/no-process-exit\n process.exit(130)\n })\n process.on('SIGTERM', () => {\n showCursor()\n // eslint-disable-next-line n/no-process-exit\n process.exit(143)\n })\n}\n\n// Export the raw stream for advanced usage\nexport { stdout }\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,sBAA4B;AAG5B,MAAM,SAA6B,QAAQ;AAcpC,SAAS,UAAU,OAAe,IAAU;AACjD,SAAO,MAAM,GAAG,IAAI;AAAA,CAAI;AAC1B;AAaO,SAAS,MAAM,MAAoB;AACxC,SAAO,MAAM,IAAI;AACnB;AAaO,SAAS,YAAkB;AAChC,MAAI,OAAO,OAAO;AAChB,WAAO,SAAS,CAAC;AACjB,WAAO,UAAU,CAAC;AAAA,EACpB;AACF;AAeO,SAAS,SAAS,GAAW,GAA8B;AAChE,MAAI,OAAO,OAAO;AAChB,WAAO,SAAS,GAAG,CAAC;AAAA,EACtB;AACF;AAYO,SAAS,kBAAwB;AACtC,MAAI,OAAO,OAAO;AAChB,WAAO,gBAAgB;AAAA,EACzB;AACF;AAgBO,SAAS,QAAiB;AAC/B,SAAO,OAAO,SAAS;AACzB;AAcO,SAAS,aAAqB;AACnC,SAAO,OAAO,WAAW;AAC3B;AAcO,SAAS,UAAkB;AAChC,SAAO,OAAO,QAAQ;AACxB;AAaO,SAAS,aAAmB;AACjC,MAAI,OAAO,SAAS,kBAAkB,6BAAa;AACjD,WAAO,MAAM,WAAa;AAAA,EAC5B;AACF;AAaO,SAAS,aAAmB;AACjC,MAAI,OAAO,SAAS,kBAAkB,6BAAa;AACjD,WAAO,MAAM,WAAa;AAAA,EAC5B;AACF;AAcO,SAAS,qBAA2B;AACzC,UAAQ,GAAG,QAAQ,UAAU;AAC7B,UAAQ,GAAG,UAAU,MAAM;AACzB,eAAW;AAEX,YAAQ,KAAK,GAAG;AAAA,EAClB,CAAC;AACD,UAAQ,GAAG,WAAW,MAAM;AAC1B,eAAW;AAEX,YAAQ,KAAK,GAAG;AAAA,EAClB,CAAC;AACH;",
6
6
  "names": []
7
7
  }
package/dist/strings.d.ts CHANGED
@@ -23,117 +23,446 @@ export type EmptyString = string & {
23
23
  // See: https://github.com/SocketDev/socket-packageurl-js/issues/3
24
24
  export declare const fromCharCode: (...codes: number[]) => string;
25
25
  export interface ApplyLinePrefixOptions {
26
- prefix?: string;
26
+ /**
27
+ * The prefix to add to each line.
28
+ * @default ''
29
+ */
30
+ prefix?: string | undefined;
27
31
  }
28
32
  /**
29
33
  * Apply a prefix to each line of a string.
34
+ *
35
+ * Prepends the specified prefix to the beginning of each line in the input string.
36
+ * If the string contains newlines, the prefix is added after each newline as well.
37
+ * When no prefix is provided or prefix is empty, returns the original string unchanged.
38
+ *
39
+ * @param str - The string to add prefixes to
40
+ * @param options - Configuration options
41
+ * @returns The string with prefix applied to each line
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * applyLinePrefix('hello\nworld', { prefix: '> ' })
46
+ * // Returns: '> hello\n> world'
47
+ *
48
+ * applyLinePrefix('single line', { prefix: ' ' })
49
+ * // Returns: ' single line'
50
+ *
51
+ * applyLinePrefix('no prefix')
52
+ * // Returns: 'no prefix'
53
+ * ```
30
54
  */
31
55
  /*@__NO_SIDE_EFFECTS__*/
32
56
  export declare function applyLinePrefix(str: string, options?: ApplyLinePrefixOptions | undefined): string;
33
57
  /**
34
58
  * Convert a camelCase string to kebab-case.
59
+ *
60
+ * Transforms camelCase strings by converting uppercase letters to lowercase
61
+ * and inserting hyphens before uppercase sequences. Handles consecutive
62
+ * uppercase letters (like "XMLHttpRequest") by treating them as a single word.
63
+ * Returns empty string for empty input.
64
+ *
65
+ * Note: This function only handles camelCase. For mixed formats including
66
+ * snake_case, use `toKebabCase()` instead.
67
+ *
68
+ * @param str - The camelCase string to convert
69
+ * @returns The kebab-case string
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * camelToKebab('helloWorld')
74
+ * // Returns: 'hello-world'
75
+ *
76
+ * camelToKebab('XMLHttpRequest')
77
+ * // Returns: 'xmlhttprequest'
78
+ *
79
+ * camelToKebab('iOS')
80
+ * // Returns: 'ios'
81
+ *
82
+ * camelToKebab('')
83
+ * // Returns: ''
84
+ * ```
35
85
  */
36
86
  /*@__NO_SIDE_EFFECTS__*/
37
87
  export declare function camelToKebab(str: string): string;
38
88
  export interface IndentStringOptions {
39
- count?: number;
89
+ /**
90
+ * Number of spaces to indent each line.
91
+ * @default 1
92
+ */
93
+ count?: number | undefined;
40
94
  }
41
95
  /**
42
96
  * Indent each line of a string with spaces.
97
+ *
98
+ * Adds the specified number of spaces to the beginning of each non-empty line
99
+ * in the input string. Empty lines (containing only whitespace) are not indented.
100
+ * Uses a regular expression to efficiently handle multi-line strings.
101
+ *
102
+ * @param str - The string to indent
103
+ * @param options - Configuration options
104
+ * @returns The indented string
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * indentString('hello\nworld', { count: 2 })
109
+ * // Returns: ' hello\n world'
110
+ *
111
+ * indentString('line1\n\nline3', { count: 4 })
112
+ * // Returns: ' line1\n\n line3'
113
+ *
114
+ * indentString('single line')
115
+ * // Returns: ' single line' (default: 1 space)
116
+ * ```
43
117
  */
44
118
  /*@__NO_SIDE_EFFECTS__*/
45
119
  export declare function indentString(str: string, options?: IndentStringOptions | undefined): string;
46
120
  /**
47
121
  * Check if a value is a blank string (empty or only whitespace).
122
+ *
123
+ * A blank string is defined as a string that is either:
124
+ * - Completely empty (length 0)
125
+ * - Contains only whitespace characters (spaces, tabs, newlines, etc.)
126
+ *
127
+ * This is useful for validation when you need to ensure user input
128
+ * contains actual content, not just whitespace.
129
+ *
130
+ * @param value - The value to check
131
+ * @returns `true` if the value is a blank string, `false` otherwise
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * isBlankString('')
136
+ * // Returns: true
137
+ *
138
+ * isBlankString(' ')
139
+ * // Returns: true
140
+ *
141
+ * isBlankString('\n\t ')
142
+ * // Returns: true
143
+ *
144
+ * isBlankString('hello')
145
+ * // Returns: false
146
+ *
147
+ * isBlankString(null)
148
+ * // Returns: false
149
+ * ```
48
150
  */
49
151
  /*@__NO_SIDE_EFFECTS__*/
50
152
  export declare function isBlankString(value: unknown): value is BlankString;
51
153
  /**
52
154
  * Check if a value is a non-empty string.
155
+ *
156
+ * Returns `true` only if the value is a string with at least one character.
157
+ * This includes strings containing only whitespace (use `isBlankString()` if
158
+ * you want to exclude those). Type guard ensures TypeScript knows the value
159
+ * is a string after this check.
160
+ *
161
+ * @param value - The value to check
162
+ * @returns `true` if the value is a non-empty string, `false` otherwise
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * isNonEmptyString('hello')
167
+ * // Returns: true
168
+ *
169
+ * isNonEmptyString(' ')
170
+ * // Returns: true (contains whitespace)
171
+ *
172
+ * isNonEmptyString('')
173
+ * // Returns: false
174
+ *
175
+ * isNonEmptyString(null)
176
+ * // Returns: false
177
+ *
178
+ * isNonEmptyString(123)
179
+ * // Returns: false
180
+ * ```
53
181
  */
54
182
  /*@__NO_SIDE_EFFECTS__*/
55
183
  export declare function isNonEmptyString(value: unknown): value is Exclude<string, EmptyString>;
56
184
  export interface SearchOptions {
57
- fromIndex?: number;
185
+ /**
186
+ * The position in the string to begin searching from.
187
+ * Negative values count back from the end of the string.
188
+ * @default 0
189
+ */
190
+ fromIndex?: number | undefined;
58
191
  }
59
192
  /**
60
193
  * Search for a regular expression in a string starting from an index.
194
+ *
195
+ * Similar to `String.prototype.search()` but allows specifying a starting
196
+ * position. Returns the index of the first match at or after `fromIndex`,
197
+ * or -1 if no match is found. Negative `fromIndex` values count back from
198
+ * the end of the string.
199
+ *
200
+ * This is more efficient than using `str.slice(fromIndex).search()` when
201
+ * you need the absolute position in the original string, as it handles
202
+ * the offset calculation for you.
203
+ *
204
+ * @param str - The string to search in
205
+ * @param regexp - The regular expression to search for
206
+ * @param options - Configuration options
207
+ * @returns The index of the first match, or -1 if not found
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * search('hello world hello', /hello/, { fromIndex: 0 })
212
+ * // Returns: 0 (first 'hello')
213
+ *
214
+ * search('hello world hello', /hello/, { fromIndex: 6 })
215
+ * // Returns: 12 (second 'hello')
216
+ *
217
+ * search('hello world', /goodbye/, { fromIndex: 0 })
218
+ * // Returns: -1 (not found)
219
+ *
220
+ * search('hello world', /hello/, { fromIndex: -5 })
221
+ * // Returns: -1 (starts searching from 'world', no match)
222
+ * ```
61
223
  */
62
224
  /*@__NO_SIDE_EFFECTS__*/
63
225
  export declare function search(str: string, regexp: RegExp, options?: SearchOptions | undefined): number;
64
226
  /**
65
227
  * Strip the Byte Order Mark (BOM) from the beginning of a string.
228
+ *
229
+ * The BOM (U+FEFF) is a Unicode character that can appear at the start of
230
+ * a text file to indicate byte order and encoding. In UTF-16 (JavaScript's
231
+ * internal string representation), it appears as 0xFEFF. This function
232
+ * removes it if present, leaving the rest of the string unchanged.
233
+ *
234
+ * Most text processing doesn't need to handle the BOM explicitly, but it
235
+ * can cause issues when parsing JSON, CSV, or other structured data formats
236
+ * that don't expect a leading invisible character.
237
+ *
238
+ * @param str - The string to strip BOM from
239
+ * @returns The string without BOM
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * stripBom('\uFEFFhello world')
244
+ * // Returns: 'hello world'
245
+ *
246
+ * stripBom('hello world')
247
+ * // Returns: 'hello world' (no BOM to strip)
248
+ *
249
+ * stripBom('')
250
+ * // Returns: ''
251
+ * ```
66
252
  */
67
253
  /*@__NO_SIDE_EFFECTS__*/
68
254
  export declare function stripBom(str: string): string;
69
255
  /**
70
256
  * Get the visual width of a string in terminal columns.
71
- * Strips ANSI escape codes and accounts for wide characters.
72
257
  *
73
- * Based on string-width:
258
+ * Calculates how many columns a string will occupy when displayed in a terminal,
259
+ * accounting for:
260
+ * - ANSI escape codes (stripped before calculation)
261
+ * - Wide characters (CJK ideographs, fullwidth forms) that take 2 columns
262
+ * - Emoji (including complex sequences) that take 2 columns
263
+ * - Combining marks and zero-width characters (take 0 columns)
264
+ * - East Asian Width properties (Fullwidth, Wide, Halfwidth, Narrow, etc.)
265
+ *
266
+ * Based on string-width by Sindre Sorhus:
74
267
  * https://socket.dev/npm/package/string-width/overview/7.2.0
75
268
  * MIT License
76
269
  * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
77
270
  *
78
271
  * Terminal emulators display characters in a grid of cells (columns).
79
272
  * Most ASCII characters take 1 column, but some characters (especially
80
- * emoji and CJK characters) take 2 columns.
81
- *
82
- * This function calculates how many columns a string will occupy when
83
- * displayed in a terminal, which is crucial for:
84
- * - Aligning text properly
273
+ * emoji and CJK characters) take 2 columns. This function calculates
274
+ * the actual visual width, which is crucial for:
275
+ * - Aligning text properly in tables or columns
85
276
  * - Preventing text from jumping when characters change
86
- * - Calculating padding/spacing
277
+ * - Calculating padding/spacing for spinners and progress bars
278
+ * - Wrapping text at the correct column width
87
279
  *
88
- * Logic:
89
- * - Segment graphemes to match how terminals render clusters.
90
- * - Width rules:
91
- * 1. Skip non-printing clusters (Default_Ignorable, Control, pure Mark, lone Surrogates).
92
- * 2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
93
- * 3. Otherwise use East Asian Width of the cluster's first visible code point.
94
- * 4. Add widths for trailing Halfwidth/Fullwidth Forms within the same cluster.
280
+ * Algorithm Overview:
281
+ * 1. Strip ANSI escape codes (invisible in terminal)
282
+ * 2. Segment into grapheme clusters (user-perceived characters)
283
+ * 3. For each cluster:
284
+ * - Skip zero-width/non-printing clusters (width = 0)
285
+ * - RGI emoji clusters are double-width (width = 2)
286
+ * - Otherwise use East Asian Width of first visible code point
287
+ * - Add width for trailing Halfwidth/Fullwidth Forms
95
288
  *
96
- * East Asian Width categories (Unicode Standard Annex #11):
289
+ * East Asian Width Categories (Unicode Standard Annex #11):
97
290
  * - F (Fullwidth): 2 columns - e.g., fullwidth Latin letters (A, B)
98
291
  * - W (Wide): 2 columns - e.g., CJK ideographs (漢字), emoji (⚡, 😀)
99
292
  * - H (Halfwidth): 1 column - e.g., halfwidth Katakana (ア, イ)
100
293
  * - Na (Narrow): 1 column - e.g., ASCII (a-z, 0-9)
101
- * - A (Ambiguous): Context-dependent, we treat as 1 column
294
+ * - A (Ambiguous): Context-dependent, treated as 1 column by default
102
295
  * - N (Neutral): 1 column - e.g., most symbols (✦, ✧, ⋆)
103
296
  *
104
- * Why this matters for Socket spinners:
297
+ * Why This Matters for Socket:
105
298
  * - Lightning bolt (⚡) takes 2 columns
106
299
  * - Stars (✦, ✧, ⋆) take 1 column
107
- * - Without compensation, text jumps when frames change
108
- * - We use this to calculate padding for consistent alignment
300
+ * - Without proper width calculation, spinner text jumps between frames
301
+ * - This function enables consistent alignment by calculating padding
302
+ *
303
+ * @param text - The string to measure
304
+ * @returns The visual width in terminal columns
109
305
  *
110
306
  * @example
111
- * stringWidth('hello') // => 5 (5 ASCII chars = 5 columns)
112
- * stringWidth('') // => 2 (lightning bolt is wide)
113
- * stringWidth('✦') // => 1 (star is narrow)
114
- * stringWidth('\x1b[31mred\x1b[0m') // => 3 (ANSI codes stripped, 'red' = 3)
307
+ * ```ts
308
+ * stringWidth('hello')
309
+ * // Returns: 5 (5 ASCII chars = 5 columns)
310
+ *
311
+ * stringWidth('⚡')
312
+ * // Returns: 2 (lightning bolt is wide)
313
+ *
314
+ * stringWidth('✦')
315
+ * // Returns: 1 (star is narrow)
316
+ *
317
+ * stringWidth('漢字')
318
+ * // Returns: 4 (2 CJK characters × 2 columns each)
319
+ *
320
+ * stringWidth('\x1b[31mred\x1b[0m')
321
+ * // Returns: 3 (ANSI codes stripped, 'red' = 3)
322
+ *
323
+ * stringWidth('👍🏽')
324
+ * // Returns: 2 (emoji with skin tone = 1 grapheme cluster = 2 columns)
115
325
  *
116
- * @throws {TypeError} When input is not a string.
326
+ * stringWidth('é')
327
+ * // Returns: 1 (combining accent doesn't add width)
328
+ *
329
+ * stringWidth('')
330
+ * // Returns: 0
331
+ * ```
332
+ *
333
+ * @throws {TypeError} When input is not a string
117
334
  */
118
335
  /*@__NO_SIDE_EFFECTS__*/
119
336
  export declare function stringWidth(text: string): number;
120
337
  /**
121
338
  * Convert a string to kebab-case (handles camelCase and snake_case).
339
+ *
340
+ * Transforms strings from camelCase or snake_case to kebab-case by:
341
+ * - Converting uppercase letters to lowercase
342
+ * - Inserting hyphens before uppercase letters (for camelCase)
343
+ * - Replacing underscores with hyphens (for snake_case)
344
+ *
345
+ * This is more comprehensive than `camelToKebab()` as it handles mixed
346
+ * formats including snake_case. Returns empty string for empty input.
347
+ *
348
+ * @param str - The string to convert
349
+ * @returns The kebab-case string
350
+ *
351
+ * @example
352
+ * ```ts
353
+ * toKebabCase('helloWorld')
354
+ * // Returns: 'hello-world'
355
+ *
356
+ * toKebabCase('hello_world')
357
+ * // Returns: 'hello-world'
358
+ *
359
+ * toKebabCase('XMLHttpRequest')
360
+ * // Returns: 'xmlhttp-request'
361
+ *
362
+ * toKebabCase('iOS_Version')
363
+ * // Returns: 'io-s-version'
364
+ *
365
+ * toKebabCase('')
366
+ * // Returns: ''
367
+ * ```
122
368
  */
123
369
  /*@__NO_SIDE_EFFECTS__*/
124
370
  export declare function toKebabCase(str: string): string;
125
371
  /**
126
372
  * Trim newlines from the beginning and end of a string.
373
+ *
374
+ * Removes all leading and trailing newline characters (both `\n` and `\r`)
375
+ * from a string, while preserving any newlines in the middle. This is similar
376
+ * to `String.prototype.trim()` but specifically targets newlines instead of
377
+ * all whitespace.
378
+ *
379
+ * Optimized for performance by checking the first and last characters before
380
+ * doing any string manipulation. Returns the original string unchanged if no
381
+ * newlines are found at the edges.
382
+ *
383
+ * @param str - The string to trim
384
+ * @returns The string with leading and trailing newlines removed
385
+ *
386
+ * @example
387
+ * ```ts
388
+ * trimNewlines('\n\nhello\n\n')
389
+ * // Returns: 'hello'
390
+ *
391
+ * trimNewlines('\r\nworld\r\n')
392
+ * // Returns: 'world'
393
+ *
394
+ * trimNewlines('hello\nworld')
395
+ * // Returns: 'hello\nworld' (middle newline preserved)
396
+ *
397
+ * trimNewlines(' hello ')
398
+ * // Returns: ' hello ' (spaces not trimmed, only newlines)
399
+ *
400
+ * trimNewlines('hello')
401
+ * // Returns: 'hello'
402
+ * ```
127
403
  */
128
404
  /*@__NO_SIDE_EFFECTS__*/
129
405
  export declare function trimNewlines(str: string): string;
130
406
  /**
131
407
  * Repeat a string n times.
408
+ *
409
+ * Creates a new string by repeating the input string the specified number of times.
410
+ * Returns an empty string if count is zero or negative. This is a simple wrapper
411
+ * around `String.prototype.repeat()` with guard for non-positive counts.
412
+ *
413
+ * @param str - The string to repeat
414
+ * @param count - The number of times to repeat the string
415
+ * @returns The repeated string, or empty string if count <= 0
416
+ *
417
+ * @example
418
+ * ```ts
419
+ * repeatString('hello', 3)
420
+ * // Returns: 'hellohellohello'
421
+ *
422
+ * repeatString('x', 5)
423
+ * // Returns: 'xxxxx'
424
+ *
425
+ * repeatString('hello', 0)
426
+ * // Returns: ''
427
+ *
428
+ * repeatString('hello', -1)
429
+ * // Returns: ''
430
+ * ```
132
431
  */
133
432
  /*@__NO_SIDE_EFFECTS__*/
134
433
  export declare function repeatString(str: string, count: number): string;
135
434
  /**
136
435
  * Center text within a given width.
436
+ *
437
+ * Adds spaces before and after the text to center it within the specified width.
438
+ * Distributes padding evenly on both sides. When the padding is odd, the extra
439
+ * space is added to the right side. Strips ANSI codes before calculating text
440
+ * length to ensure accurate centering of colored text.
441
+ *
442
+ * If the text is already wider than or equal to the target width, returns the
443
+ * original text unchanged (no truncation occurs).
444
+ *
445
+ * @param text - The text to center (may include ANSI codes)
446
+ * @param width - The target width in columns
447
+ * @returns The centered text with padding
448
+ *
449
+ * @example
450
+ * ```ts
451
+ * centerText('hello', 11)
452
+ * // Returns: ' hello ' (3 spaces on each side)
453
+ *
454
+ * centerText('hi', 10)
455
+ * // Returns: ' hi ' (4 spaces on each side)
456
+ *
457
+ * centerText('odd', 8)
458
+ * // Returns: ' odd ' (2 left, 3 right)
459
+ *
460
+ * centerText('\x1b[31mred\x1b[0m', 7)
461
+ * // Returns: ' \x1b[31mred\x1b[0m ' (ANSI codes preserved, 'red' centered)
462
+ *
463
+ * centerText('too long text', 5)
464
+ * // Returns: 'too long text' (no truncation, returned as-is)
465
+ * ```
137
466
  */
138
467
  /*@__NO_SIDE_EFFECTS__*/
139
468
  export declare function centerText(text: string, width: number): string;