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

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsmale90 authored Feb 2, 2023
1 parent 667e567 commit 640472d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/packages/cli/src/detach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ If there is a single instance with an exact prefix match, it is returned as the
are similar to `instanceName` are returned as `suggestions`. Names with an exact
prefix match are prioritized, followed by increasing Levenshtein distance, up to
a maximum distance of `MAX_LEVENSHTEIN_DISTANCE`.
@param {string} instanceName the name for which similarly named instance will be searched
@returns {{ match: string } | { suggestions: string[] }} either a single exact `match` or a number of `suggestions`
*/
async function getSimilarInstanceNames(
instanceName: string
Expand Down Expand Up @@ -429,6 +431,16 @@ export function formatUptime(ms: number) {
return isFuture ? `In ${duration}` : duration;
}

/**
* This function calculates the Levenshtein distance between two strings.
* Levenshtein distance is a measure of the difference between two strings,
* defined as the minimum number of edits (insertions, deletions or substitutions)
* required to transform one string into another.
*
* @param {string} a - The first string to compare.
* @param {string} b - The second string to compare.
* @return {number} The Levenshtein distance between the two strings.
*/
export function levenshteinDistance(a: string, b: string): number {
if (a.length === 0) return b.length;
if (b.length === 0) return a.length;
Expand Down

0 comments on commit 640472d

Please sign in to comment.