on 4ca3dba help sign in
elk/libraries/JavaScript.elm
68 lines 1.7 kB history raw
2module JavaScript where
4{-|This library does basic conversions between Elm and JS values. This allows
5the internal data structures of Elm to change and improve with no impact on JS
6integration.
8# Javascript to Elm
9@docs toString, toInt, toFloat, toBool, toList
11# JavaScript from Elm
12@docs fromString, fromInt, fromFloat, fromBool fromList
14# DOM Nodes and Elements
15@docs toElement, fromElement
16-}
18import Native.JavaScript
19import open Basics
21data JSNumber = JSNumber
22data JSBool = JSBool
23data JSString = JSString
24data JSArray a = JSArray a
25data JSDomNode = JSDomNode
26data JSObject = JSObject
28{-| Requires that the input array be uniform (all members have the same type) -}
29toList : JSArray a -> [a]
30toList = Native.JavaScript.toList
32toInt : JSNumber -> Int
33toInt = Native.JavaScript.toInt
35toFloat : JSNumber -> Float
36toFloat = Native.JavaScript.toFloat
38toBool : JSBool -> Bool
39toBool = Native.JavaScript.toBool
41toString : JSString -> String
42toString = Native.JavaScript.toString
45{-| Produces a uniform JavaScript array with all members of the same type. -}
46fromList : [a] -> JSArray a
47fromList = Native.JavaScript.fromList
49fromInt : Int -> JSNumber
50fromInt = Native.JavaScript.fromInt
52fromFloat : Float -> JSNumber
53fromFloat = Native.JavaScript.fromFloat
55fromBool : Bool -> JSBool
56fromBool = Native.JavaScript.fromBool
58fromString : String -> JSString
59fromString = Native.JavaScript.fromString
61{-| Turn an `Element` into a DOM node. -}
62fromElement : Element -> JSDomNode
63fromElement = Native.JavaScript.fromElement
65{-| Turn a DOM node into an `Element`. You can resize the node
66using the normal `width` and `height` functions. -}
67toElement : Int -> Int -> JSDomNode -> Element
68toElement = Native.JavaScript.toElement