Overview
The encoder module provides functions to transform structured QR data objects into properly formatted strings ready for QR code generation. Each QR type has its own encoding logic to produce the appropriate output format.Main Encoder
encodeQrData
Main encoding function that routes to the appropriate encoder based on QR type.The QR code type identifier (PlainText, Url, Wifi, VCard, Payment, or Event)
The data object corresponding to the specified type
Encoded string ready for QR code generation. Returns empty string if type is invalid
Example
Type-Specific Encoders
encodeText
Encodes plain text data by trimming whitespace.Text data object containing the text to encode
Trimmed text string
Example
encodeUrl
Encodes URL data, automatically adding https:// protocol if missing.URL data object containing the URL to encode
Fully qualified URL with protocol
Behavior
- Trims whitespace from the URL
- If URL doesn’t start with
http://orhttps://, prependshttps:// - Preserves existing protocol if present
Example
encodeWifi
Encodes WiFi network data in the standard WiFi QR code format.WiFi data object containing network credentials
WiFi QR code string in format:
WIFI:T:security;S:ssid;P:password;;Behavior
- Formats data according to WiFi QR code specification
- Omits password for
nopasssecurity type - Trims SSID and password values
Example
encodeVCard
Encodes contact data in vCard 3.0 format.vCard data object containing contact information
Multi-line vCard 3.0 formatted string
Behavior
- Generates vCard 3.0 format
- Combines firstName and lastName into FN (full name) field
- Only includes optional fields if they contain non-empty values
- Automatically adds
https://protocol to website if missing - Phone marked as TYPE=VOICE, mobile as TYPE=CELL
Example
encodePayment
Encodes payment data in either cryptocurrency or bank transfer format.Payment data object containing payment details
Payment string formatted according to payment method
Behavior
- For
method === "crypto": Returns{account}?amount={amount} - For other methods: Returns URL-encoded parameters joined with
& - Includes reference field only if provided
Example
encodeEvent
Encodes calendar event data in iCalendar (vCalendar) format.Event data object containing event details
Multi-line vCalendar formatted string
Behavior
- Generates vCalendar 2.0 format
- Converts datetime strings to iCalendar format (removes
-,:, replaces space withT) - Only includes description if provided
- Required fields: title, location, start, end
Example
Format Specifications
WiFi Format
Follows the standard WiFi QR code format:vCard Format
vCard 3.0 specification with standard fields:FN: Full nameN: Structured name (Last;First;;;)TEL: Phone numbers with TYPE parameterEMAIL: Email addressORG: OrganizationTITLE: Job titleURL: WebsiteADR: Address (;;street;;;)NOTE: Notes
vCalendar Format
vCalendar 2.0 (iCalendar) specification with:SUMMARY: Event titleDESCRIPTION: Event descriptionLOCATION: Event locationDTSTART: Start datetimeDTEND: End datetime