Skip to content

Commit 393ef18

Browse files
committed
chore: add jsdoc comments
1 parent 9639347 commit 393ef18

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/util.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { input as inputCharsets, output as outputCharsets } from './charsets.ts'
77

88
const REGEX_HEX_NUMBER = /^[0-9a-fA-F]+$/;
99

10+
/**
11+
* Detects the output file from the NSIS output.
12+
* @param str - The string to search for the output file.
13+
* @returns The detected output file path or null if not found.
14+
*/
1015
function detectOutfile(str: string): null | string {
1116
if (str.includes('Output: "')) {
1217
const regex = /Output: "(.*.exe)"/g;
@@ -24,6 +29,13 @@ function detectOutfile(str: string): null | string {
2429
return null;
2530
}
2631

32+
/**
33+
* Normalizes the output of the `makensis` command.
34+
* @param stream - The stream options containing stdout and stderr.
35+
* @param args - The arguments passed to the `makensis` command.
36+
* @param opts - The compiler options used for the makensis functions.
37+
* @returns normalized output with stdout and stderr or JSON.
38+
*/
2739
function formatOutput(
2840
stream: Makensis.StreamOptions,
2941
args: Array<string>,
@@ -63,6 +75,10 @@ function formatOutput(
6375
return output;
6476
}
6577

78+
/**
79+
* Filters environment variables that start with `NSIS_APP_` prefix.
80+
* @returns An object containing the filtered environment variables.
81+
*/
6682
function getMagicEnvVars(): Makensis.EnvironmentVariables {
6783
const definitions: Makensis.EnvironmentVariables = {};
6884
const prefix = 'NSIS_APP_';
@@ -77,6 +93,11 @@ function getMagicEnvVars(): Makensis.EnvironmentVariables {
7793
return definitions;
7894
}
7995

96+
/**
97+
* Checks the output for common NodeJS errors.
98+
* @param input - The input string to check for error codes.
99+
* @returns true if the input contains an error code, false otherwise.
100+
*/
80101
function hasErrorCode(input: string) {
81102
if (input?.includes('ENOENT') && input.match(/\bENOENT\b/)) {
82103
return true;
@@ -94,6 +115,11 @@ function hasErrorCode(input: string) {
94115
return false;
95116
}
96117

118+
/**
119+
* Checks if the given line contains warnings and returns the count.
120+
* @param line - The line to check for warnings.
121+
* @returns The number of warnings found in the line.
122+
*/
97123
function hasWarnings(line: string): number {
98124
const match = line.match(/(\d+) warnings?:/);
99125

@@ -104,19 +130,39 @@ function hasWarnings(line: string): number {
104130
return 0;
105131
}
106132

133+
/**
134+
* Checks if the given value is a hexadecimal number string.
135+
* @param x - The value to check if it is a hexadecimal number.
136+
* @returns true if the value is a hexadecimal number, false otherwise.
137+
*/
107138
function isHex(x: number | string): boolean {
108139
return REGEX_HEX_NUMBER.test(String(x));
109140
}
110141

142+
/**
143+
* Helper function to check if a number is numeric.
144+
* @param x - The number to check.
145+
* @returns true if the number is numeric, false otherwise.
146+
*/
111147
function isNumeric(x: number): boolean {
112148
return !Number.isNaN(x);
113149
}
114150

151+
/**
152+
* Checks if a value is within a specified range.
153+
* @param value - The value to check.
154+
* @param min - The minimum value of the range.
155+
* @param max - The maximum value of the range.
156+
* @returns true if the value is within the range, false otherwise.
157+
*/
115158
function inRange(value: number, min: number, max: number): boolean {
116159
return value >= min && value <= max;
117160
}
118161

119162
/**
163+
* Maps argument options to flags to be passed to `makensis` command.
164+
* @param args - The arguments to be passed to `makensis`.
165+
* @param options - The compiler options to be used.
120166
* @private
121167
*/
122168
export function mapArguments(args: string[], options: Makensis.CompilerOptions): Makensis.MapArguments {
@@ -467,6 +513,12 @@ export function splitCommands(data: string | string[]): string[] {
467513
return args;
468514
}
469515

516+
/**
517+
* Splits the input string into lines based on the platform-specific line break.
518+
* @param input - The input string to split into lines.
519+
* @param opts - Compiler options that may affect line splitting (e.g., wine).
520+
* @returns An array of strings, each representing a line from the input.
521+
*/
470522
function splitLines(input: string, opts: Makensis.CompilerOptions = {}): string[] {
471523
const lineBreak = platform() === 'win32' || opts.wine === true ? '\r\n' : '\n';
472524
const output = input.split(lineBreak);

0 commit comments

Comments
 (0)