module

Ktistec::Util

Constants

SAFE_IRI_SCHEMES = ["http", "https"] of ::String
SAFE_URL_SCHEMES = ["http", "https", "mailto", "tel", "xmpp", "matrix", "magnet", "ws", "wss", "at", "did"] of ::String
SLUG_LIMIT = 64

The maximum length of a slug, in codepoints.

Instance methods

absolute_uri?(value : String) : Bool
Source
distance_of_time_in_words(from_time : Time, to_time : Time = Time.utc)

Transforms the span of time between two different times into words.

Source
distance_of_time_in_words(distance : Time::Span)

Transforms the span of time between two different times into words.

Source
duration_in_words(span : Time::Span)

Transforms a duration into words, adapting the unit (minutes, hours, or days) to the magnitude of the duration.

Source
generate_summary(content : String | Nil, *, threshold = LONG_CONTENT_THRESHOLD, length = GENERATED_SUMMARY_LENGTH, ellipsis = "…") : String | Nil

Generates a summary from long content.

Whitespace is collapsed and the result is a single line.

Source
id

Generates a random, URL-safe identifier.

64 bits should ensure it takes about 5 billion attempts to generate a collision.

Source
origin?(uri : String | Nil) : String | Nil

Returns the origin of the given URI.

An origin is the scheme, host and port, as defined by RFC 6454 and required by FEP-fe34.

Returns nil if the URI cannot be parsed, if it does not specify both a scheme and a host, or if the scheme is not one an IRI may use.

Source
pluralize(noun)

Pluralizes a singular noun.

Source
quote_inline_href?(content : String | Nil) : String | Nil

Returns the link to the quoted post that servers include for clients that don't render quotes.

Source
render_as_text(content)

Renders content as simple text.

Source
render_as_text_and_truncate(content : String, length : Int, *, ellipsis = "…")

Renders content as simple text and truncates to the given length.

Source
safe_iri?(value : String) : Bool
Source
safe_url?(value : String) : Bool
Source
same_origin?(uri : String | Nil, other : String | Nil) : Bool

Returns true if both URIs have the same, non-nil origin.

See origin?.

Source
sanitize(content : String | Nil) : Ktistec::SafeHTML

Cleans up the content we receive from others.

Source
slugify(name : String) : String

Generates a slug from a name.

An all-digit slug is prefixed, so that it can never be mistaken for a database id.

Source
to_sentence(array, *, words_connector = ", ", last_word_connector = " and ")

Converts the array of words to comma-separated sentence form where the last word is joined by a connector word (by default "and").

Source
url_scheme(value : String) : String | Nil
Source

Nested types