Light Dark

Functions

from-ext core

fn (ext: Str): Str?

Get MIME type from file extension.

Arguments

  • ext - File extension (with or without leading dot)

Returns MIME type string or null if unknown.

Examples

from-ext("png")   // "image/png"
from-ext(".jpg")  // "image/jpeg"
from-ext("mp4")   // "video/mp4"
from-ext("xyz")   // null

from-path core

fn (path: Str): Str?

Get MIME type from file path.

Arguments

  • path - File path

Returns MIME type string or null if unknown.

Examples

from-path("photo.png")       // "image/png"
from-path("/dir/video.mp4")  // "video/mp4"
from-path("document.pdf")    // "application/pdf"

is-application core

fn (mime: Str): Bool

Check if MIME type is an application type.

Examples

is-application("application/json")  // true
is-application("application/pdf")   // true
is-application("text/plain")        // false

is-audio core

fn (mime: Str): Bool

Check if MIME type is an audio type.

Examples

is-audio("audio/mpeg")  // true
is-audio("audio/wav")   // true
is-audio("video/mp4")   // false

is-image core

fn (mime: Str): Bool

Check if MIME type is an image type.

Examples

is-image("image/png")   // true
is-image("image/jpeg")  // true
is-image("video/mp4")   // false

is-text core

fn (mime: Str): Bool

Check if MIME type is a text type.

Examples

is-text("text/plain")  // true
is-text("text/html")   // true
is-text("image/png")   // false

is-video core

fn (mime: Str): Bool

Check if MIME type is a video type.

Examples

is-video("video/mp4")   // true
is-video("video/webm")  // true
is-video("audio/mpeg")  // false

major-type core

fn (mime: Str): Str?

Get the major type (first part) of a MIME type.

Examples

major-type("image/png")        // "image"
major-type("video/mp4")        // "video"
major-type("application/json") // "application"

minor-type core

fn (mime: Str): Str?

Get the minor type (second part) of a MIME type.

Examples

minor-type("image/png")                   // "png"
minor-type("video/mp4")                   // "mp4"
minor-type("text/plain; charset=utf-8")   // "plain"

to-ext core

fn (mime: Str): Str?

Get file extension from MIME type.

Arguments

  • mime - MIME type string

Returns File extension (without dot) or null if unknown.

Examples

to-ext("image/png")   // "png"
to-ext("video/mp4")   // "mp4"
to-ext("text/plain")  // "txt"

to-exts core

fn (mime: Str): Vec

Get all file extensions for a MIME type.

Arguments

  • mime - MIME type string

Returns Vector of file extensions (without dots) or empty vector if unknown.

Examples

to-exts("image/jpeg")  // ["jpeg", "jpg", "jpe"]
to-exts("text/plain")  // ["txt", "text", "conf", ...]

is-media

fn (mime: Str): Bool

Check if MIME type is a media type (image, audio, or video).

Examples

is-media("image/png")   // true
is-media("audio/mpeg")  // true
is-media("video/mp4")   // true
is-media("text/plain")  // false