gdDocumentation0.8.0

API reference

GD.text

Entry for formatting and comparing text.

Methods

closest

closest(word: String, options: PackedStringArray) -> String

Choose the candidate closest to the supplied text. This is useful for suggesting corrections to a mistyped command or option.

Parameters

NameTypeDefaultDescription
wordStringRequiredInput to compare against candidates.
optionsPackedStringArrayRequiredCandidate strings in selection order.

Return value

String

The first candidate with the smallest edit distance, or an empty string if its distance exceeds max(2, word.length() / 3) or there are no candidates.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

See also

ellipsis

ellipsis(text: String, width: int) -> String

Shorten text to fit a width and append an ellipsis.

Parameters

NameTypeDefaultDescription
textStringRequiredInput string.
widthintRequiredMaximum output length in characters.

Return value

String

The original text when it fits, otherwise a shortened form.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

size_of

size_of(bytes: int) -> String

Format a byte count with readable units.

Parameters

NameTypeDefaultDescription
bytesintRequiredByte count to format.

Return value

String

A human-readable size string.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

duration

duration(ms: float) -> String

Format milliseconds as a readable duration.

Parameters

NameTypeDefaultDescription
msfloatRequiredDuration in milliseconds.

Return value

String

A human-readable duration string.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

distance

distance(a: String, b: String) -> int

Compute the edit distance between two strings. A lower result means fewer single-character edits are needed; zero means the strings match.

Parameters

NameTypeDefaultDescription
aStringRequiredFirst string.
bStringRequiredSecond string.

Return value

int

A nonnegative edit count.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

See also

snake

snake(text: String) -> String

Convert text to snake_case.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

camel

camel(text: String) -> String

Convert text to camelCase.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

title

title(text: String) -> String

Convert text to Title Case.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

table

table(rows: Array, gap: int = 2) -> String

Format rows as an aligned text table.

Parameters

NameTypeDefaultDescription
rowsArrayRequiredRows in input order. Batch database calls use one parameter set per row.
gapint2Number of spaces between formatted table columns.

Return value

String

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

distance_async

distance_async(a: String, b: String) -> await int

Compute the edit distance between two strings. A lower result means fewer single-character edits are needed; zero means the strings match.

Parameters

NameTypeDefaultDescription
aStringRequiredFirst string.
bStringRequiredSecond string.

Return value

await int

A nonnegative edit count.

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

See also

closest_async

closest_async(word: String, options: PackedStringArray) -> await String

Choose the candidate closest to the supplied text. This is useful for suggesting corrections to a mistyped command or option.

Parameters

NameTypeDefaultDescription
wordStringRequiredInput to compare against candidates.
optionsPackedStringArrayRequiredCandidate strings in selection order.

Return value

await String

The first candidate with the smallest edit distance, or an empty string if its distance exceeds max(2, word.length() / 3) or there are no candidates.

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

See also

ellipsis_async

ellipsis_async(text: String, width: int) -> await String

Dispatch text shortening to a CPU worker.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.
widthintRequiredMaximum width in characters for the formatted text.

Return value

await String

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

snake_async

snake_async(text: String) -> await String

Dispatch snake-case conversion to a CPU worker.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.

Return value

await String

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

camel_async

camel_async(text: String) -> await String

Dispatch camel-case conversion to a CPU worker.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.

Return value

await String

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

title_async

title_async(text: String) -> await String

Dispatch title-case conversion to a CPU worker.

Parameters

NameTypeDefaultDescription
textStringRequiredText to inspect, decode or transform; the input is not modified in place.

Return value

await String

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.

table_async

table_async(rows: Array, gap: int = 2) -> await String

Dispatch text-table formatting to a CPU worker.

Parameters

NameTypeDefaultDescription
rowsArrayRequiredRows in input order. Batch database calls use one parameter set per row.
gapint2Number of spaces between formatted table columns.

Return value

await String

Returns a Signal. Use await to receive the completion value shown in the signature.

Errors

This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.