on 284438d help sign in
elk/libraries/JavaScript.elm
74 lines 1.9 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.
8It is intended to be imported as `import JavaScript as JS`. That way functions
9like `JS.toInt` convert JavaScript *to* Elm integers and functions like
10`JS.fromString` gets JavaScript *from* Elm strings.
12# Javascript to Elm
13@docs toString, toInt, toFloat, toBool, toList
15# JavaScript from Elm
16@docs fromString, fromInt, fromFloat, fromBool, fromList
17-}
18{-
19# DOM Nodes and Elements
20@docs toElement, fromElement
21-}
23import Native.JavaScript
25data JSNumber = JSNumber
26data JSBool = JSBool
27data JSString = JSString
28data JSArray a = JSArray a
29data JSDomNode = JSDomNode
30data JSObject = JSObject
32{-| Requires that the input array be uniform (all members have the same type) -}
33toList : JSArray a -> [a]
34toList = Native.JavaScript.toList
36toInt : JSNumber -> Int
37toInt = Native.JavaScript.toInt
39toFloat : JSNumber -> Float
40toFloat = Native.JavaScript.toFloat
42toBool : JSBool -> Bool
43toBool = Native.JavaScript.toBool
45toString : JSString -> String
46toString = Native.JavaScript.toString
49{-| Produces a uniform JavaScript array with all members of the same type. -}
50fromList : [a] -> JSArray a
51fromList = Native.JavaScript.fromList
53fromInt : Int -> JSNumber
54fromInt = Native.JavaScript.fromInt
56fromFloat : Float -> JSNumber
57fromFloat = Native.JavaScript.fromFloat
59fromBool : Bool -> JSBool
60fromBool = Native.JavaScript.fromBool
62fromString : String -> JSString
63fromString = Native.JavaScript.fromString
65{-
66{-| Turn an `Element` into a DOM node. -}
67fromElement : Element -> JSDomNode
68fromElement = Native.JavaScript.fromElement
70{-| Turn a DOM node into an `Element`. You can resize the node
71using the normal `width` and `height` functions. -}
72toElement : Int -> Int -> JSDomNode -> Element
73toElement = Native.JavaScript.toElement
74-}