Skip to content

Instantly share code, notes, and snippets.

@epequeno
Created March 13, 2019 14:20
Show Gist options
  • Save epequeno/d00f7572a03980b467221f1289cf26e0 to your computer and use it in GitHub Desktop.
Save epequeno/d00f7572a03980b467221f1289cf26e0 to your computer and use it in GitHub Desktop.
take an input (bash script ideally) and output a json string
-- Elm 0.19.0
import Browser
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Json.Encode exposing (..)
main = Browser.sandbox { init = init, view = view, update = update }
type alias Model =
String
init =
"""#!/bin/bash
set -xe
for i in {1..3}; do
echo "${i}"
done
"""
type Msg
= Stringify String
update msg model =
case msg of
Stringify newModel ->
newModel
view model =
div [] [ div [] [ text "paste script here:" ]
, br [] []
, textarea [ cols 100, rows 20, placeholder init, onInput Stringify ] []
, p [] [ text "output:" ]
, br [] []
, code [] [ text (toJSONString model)]
]
toJSONString text =
encode 0 (string text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment