pablohirafuji/elm-qrcode/2.2.0

NOTE: this package is not compatible with Elm 0.19.1

QRCode

QR Code encoding and rendering.

type QRCode

QRCode type.

Encoding

encode : String -> Result Error QRCode

Transform a string into a result Error or a QRCode using ECLevel.Q (25% of codewords can be restored).

encodeWithECLevel : String -> ECLevel -> Result Error QRCode

Transform a string with a given EClevel into a result Error or a QRCode.

Rendering

toCanvas : QRCode -> Html msg

Transform a QRCode into a canvas element. The default module size is 5px.

qrCodeView : String -> Html msg
qrCodeView message =
    QRCode.encode message
        |> Result.map QRCode.toCanvas
        |> Result.withDefault
            (Html.text "Error while encoding to QRCode.")
toCanvasWithModuleSize : Int -> QRCode -> Html msg

Transform a QRCode into a canvas element with a given module size in pixels.

toCanvasWithAbsoluteSize : Int -> QRCode -> Html msg

Transform a QRCode into a canvas element with a given canvas size in pixels.

toSvg : QRCode -> Html msg

Transform a QRCode into a svg element.

qrCodeView : String -> Html msg
qrCodeView message =
    QRCode.encode message
        |> Result.map QRCode.toSvg
        |> Result.withDefault
            (Html.text "Error while encoding to QRCode.")

Tip: You can determine the size of the generated svg setting width and height styles.

toString : QRCode -> String

Transform a QRCode into a string.

"Hello World!"
    |> QRCode.encode
    |> Result.map QRCode.toString
    |> Result.withDefault "Error while encoding to QRCode."

Returns:

■■■■■■■ ■■■■  ■■■■■■■
■     ■ ■■■■  ■     ■
■ ■■■ ■ ■■■■■ ■ ■■■ ■
■ ■■■ ■ ■   ■ ■ ■■■ ■
■ ■■■ ■ ■■■■  ■ ■■■ ■
■     ■    ■  ■     ■
■■■■■■■ ■ ■ ■ ■■■■■■■
        ■ ■■
 ■■ ■ ■■  ■   ■ ■■■■■
■■ ■■■   ■■■■ ■■■  ■■
 ■ ■■ ■■ ■■■■■ ■■■■■■
 ■■      ■■■■   ■  ■
■  ■ ■■■  ■■■■ ■■
        ■■ ■■■    ■■
■■■■■■■ ■ ■    ■■ ■■■
■     ■  ■  ■  ■    ■
■ ■■■ ■ ■■■     ■
■ ■■■ ■   ■■  ■■■ ■■
■ ■■■ ■ ■ ■ ■ ■ ■ ■ ■
■     ■ ■  ■    ■  ■
■■■■■■■   ■■■  ■   ■■

Utilities

toBoolList : QRCode -> List (List Bool)

Transform a QRCode into a list of list of bools. The list of bools are the rows. True represents a dark module, False a light one.

fromBoolList : List (List Bool) -> QRCode

Transform a list of list of bools into a QRCode.