@std/data/diff.ms#
Import each required symbol with import Name from "@std/data/diff.ms".
CloseMatchesOptions Type#
Settings for close_matches.
type CloseMatchesOptions {
limit Int = 3
cutoff Float = 0.6
}CloseMatchesOptions.cutoff#
Minimum similarity_ratio from 0.0 to 1.0; at or below 0.0 keeps every candidate
and above 1.0 keeps none.
cutoff Float = 0.6CloseMatchesOptions.limit#
Maximum candidates returned; zero or below returns none.
limit Int = 3UnifiedDiffOptions Type#
Settings for unified_diff.
type UnifiedDiffOptions {
context Int = 3
old_name String = "a"
new_name String = "b"
}UnifiedDiffOptions.context#
Unchanged lines kept around each change; below zero counts as zero.
context Int = 3UnifiedDiffOptions.new_name#
Label of the +++ header.
new_name String = "b"UnifiedDiffOptions.old_name#
Label of the --- header.
old_name String = "a"close_matches Function#
Returns up to options.limit candidates whose similarity_ratio with word is at least options.cutoff, best match first; ties keep the candidates’ order.
Example: close_matches("appel", ["ape", "apple", "peach"], CloseMatchesOptions(limit: 2)) is ["apple", "ape"].
fn close_matches(word String, candidates List[String], options CloseMatchesOptions = CloseMatchesOptions()) List[String] { ... }edit_distance Function#
Returns the number of single-scalar insertions, deletions and substitutions that turn
left into right (Levenshtein distance). Example:
edit_distance("kitten", "sitting") is 3; equal strings give 0.
fn edit_distance(left String, right String) Int { ... }similarity_ratio Function#
Returns how alike two strings are, from 0.0 (nothing shared) to 1.0 (equal): twice the length of their longest common subsequence of scalars, divided by the total length.
Two empty strings give 1.0. Use close_matches to rank a list of candidates by this score.
Example: similarity_ratio("abcd", "abd") is about 0.857.
fn similarity_ratio(left String, right String) Float { ... }unified_diff Function#
Compares two lists of lines and returns the differences in unified diff format, or an empty string when the lists are equal.
Input lines carry no trailing newline. Each output line, including the last, ends with “\n”.
Example: unified_diff(["a", "b"], ["a", "c"], UnifiedDiffOptions(context: 1)) is "--- a\n+++ b\n@@ -1,2 +1,2 @@\n a\n-b\n+c\n".
fn unified_diff(old List[String], new List[String], options UnifiedDiffOptions = UnifiedDiffOptions()) String { ... }