Dala.Ui.Scan (dala v0.3.2)

Copy Markdown View Source

Parsers for common NFC tag payloads and QR/barcode content.

Takes a raw string from an NFC tag read or barcode scan and returns a structured map with :type and :value fields.

Supported formats

TypeExample raw input:value shape
:urlhttps://example.comString.t()
:wifiWIFI:T:WPA;S:MyNet;P:pass;H:true;;%{ssid, password, security, hidden}
:emailmailto:user@example.com%{email, subject, body}
:phonetel:+1234567890%{number}
:smssmsto:+1234567890:hello%{number, message}
:geogeo:37.78,-122.40?q=Golden+Gate%{lat, lon, query, altitude}
:vcardBEGIN:VCARD...END:VCARD%{name, phone, email, org, title, url, address}
:veventBEGIN:VEVENT...END:VEVENT%{summary, start, end, location, description}
:textHello worldString.t()

Usage

# Parse an NFC tag payload
Dala.Ui.Scan.parse("WIFI:T:WPA;S:MyNet;P:secret;;")
# => %{type: :wifi, value: %{ssid: "MyNet", password: "secret", security: :wpa, hidden: false}}

# Parse a QR code value
Dala.Ui.Scan.parse("https://example.com")
# => %{type: :url, value: "https://example.com"}

# Parse a vCard
Dala.Ui.Scan.parse("BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nTEL:+1234567890\nEND:VCARD")
# => %{type: :vcard, value: %{name: "John Doe", phone: "+1234567890", ...}}

Summary

Functions

Parse a raw NFC/barcode string into a structured format.

Types

parsed()

@type parsed() :: %{
  type: :url | :wifi | :email | :phone | :sms | :geo | :vcard | :vevent | :text,
  value: term()
}

Functions

parse(raw)

@spec parse(String.t()) :: parsed()

Parse a raw NFC/barcode string into a structured format.

Returns %{type: atom, value: term()} or %{type: :text, value: raw} as fallback.