Coder Social home page Coder Social logo

waratuman / elm-coder Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 2.0 33 KB

An encoder and decoder of Base64, Base32, and Base16 for Elm

License: BSD 3-Clause "New" or "Revised" License

Elm 100.00%
elm elm-lang encoding decoder encoder decoding base64 base32 base16 rfc4648

elm-coder's Introduction

Elm Coder

An encoder and decoder for Base64, Base32 and Base16 (Hexadecimal).

Example

import Base32 exposing (decode, encode)


encodeFooBar =
    ("foobar"
        |> String.toList
        |> List.map Char.toCode
        |> encode
    )
        == Ok "Zm9vYmFy"


decodeFooBar =
    ("Zm9vYmFy"
        |> decode
        |> Result.map (List.map Char.fromCode >> String.fromList)
    )
        == Ok "foobar"

elm-coder's People

Contributors

pravdomil avatar waratuman avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

surstrosti malax

elm-coder's Issues

Drop Result from return type for encode functions

All currently implemented schemes (base16, base32 and base64) are defined for arbitrary sequences of bytes and encoding should never fail. In contrast, all encode functions currently return a Result String String which makes working with this package more clunky than necessary.

From my understanding, the Result type is used internally in an abstraction (intToChar) that allows to generically implement different Schemes using common core code.

I understand that there is some unsafety involved since there is no Byte type that can ensure users only call encode with a list of valid bytes (integers from 0x00 to 0xFF).

There is some precedent in other packages (https://github.com/rtfeldman/elm-hex/blob/master/src/Hex.elm#L138) that provide functions prefixed with unsafe that require users to pass in only valid values in cases where Elm's type-system cannot enforce them. This allows a more pragmatic API.

Would it be possible to re-implement the public API so that encode-type functions do not return a Result String String? This might be an issue when this package supports more Schemes in the future that can fail while encoding.

I'd be happy to discuss this further! :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.