Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 8b2c81d

Browse files
committed
Add comments
1 parent 667e567 commit 8b2c81d

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/packages/cli/src/detach.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ type InstanceOrSuggestions =
7070
*
7171
* Note: This does not guarantee that the instance actually stops.
7272
* @param {string} instanceName
73-
* @returns {InstanceOrSuggestions} either the stopped `instance`, or
74-
* `suggestions` for similar instance names
73+
* @returns {InstanceOrSuggestions} an object containing either the stopped
74+
* `instance`, or `suggestions` for similar instance names
7575
*/
7676
export async function stopDetachedInstance(
7777
instanceName: string
@@ -119,15 +119,19 @@ export async function stopDetachedInstance(
119119
}
120120
}
121121

122-
/*
123-
Find instances with names similar to `instanceName`.
124-
125-
If there is a single instance with an exact prefix match, it is returned as the
126-
`match` property in the result. Otherwise, up to `MAX_SUGGESTIONS` names that
127-
are similar to `instanceName` are returned as `suggestions`. Names with an exact
128-
prefix match are prioritized, followed by increasing Levenshtein distance, up to
129-
a maximum distance of `MAX_LEVENSHTEIN_DISTANCE`.
130-
*/
122+
/**
123+
* Find instances with names similar to `instanceName`.
124+
*
125+
* If there is a single instance with an exact prefix match, it is returned as
126+
* the `match` property in the result. Otherwise, up to `MAX_SUGGESTIONS` names
127+
* that are similar to `instanceName` are returned as `suggestions`. Names with
128+
* an exact prefix match are prioritized, followed by increasing Levenshtein
129+
* distance, up to a maximum distance of `MAX_LEVENSHTEIN_DISTANCE`.
130+
* @param {string} instanceName the name for which similarly named instance will
131+
* be searched
132+
* @returns {{ match: string } | { suggestions: string[] }} an object
133+
* containiner either a single exact `match` or a number of `suggestions`
134+
*/
131135
async function getSimilarInstanceNames(
132136
instanceName: string
133137
): Promise<{ match: string } | { suggestions: string[] }> {
@@ -429,6 +433,16 @@ export function formatUptime(ms: number) {
429433
return isFuture ? `In ${duration}` : duration;
430434
}
431435

436+
/**
437+
* This function calculates the Levenshtein distance between two strings.
438+
* Levenshtein distance is a measure of the difference between two strings,
439+
* defined as the minimum number of edits (insertions, deletions or substitutions)
440+
* required to transform one string into another.
441+
*
442+
* @param {string} a - The first string to compare.
443+
* @param {string} b - The second string to compare.
444+
* @return {number} The Levenshtein distance between the two strings.
445+
*/
432446
export function levenshteinDistance(a: string, b: string): number {
433447
if (a.length === 0) return b.length;
434448
if (b.length === 0) return a.length;

0 commit comments

Comments
 (0)