elm/libraries/JavaScript.elm

74 lines
1.9 KiB
Elm
Raw Normal View History

module JavaScript where
2013-09-10 13:46:26 +00:00
{-|This library does basic conversions between Elm and JS values. This allows
the internal data structures of Elm to change and improve with no impact on JS
integration.
It is intended to be imported as `import JavaScript as JS`. That way functions
like `JS.toInt` convert JavaScript *to* Elm integers and functions like
`JS.fromString` gets JavaScript *from* Elm strings.
2013-09-10 13:46:26 +00:00
# Javascript to Elm
@docs toString, toInt, toFloat, toBool, toList
# JavaScript from Elm
2013-10-22 08:09:22 +00:00
@docs fromString, fromInt, fromFloat, fromBool, fromList
-}
{-
2013-09-10 13:46:26 +00:00
# DOM Nodes and Elements
@docs toElement, fromElement
-}
import Native.JavaScript
2013-07-26 09:42:00 +00:00
data JSNumber = JSNumber
data JSBool = JSBool
data JSString = JSString
data JSArray a = JSArray a
data JSDomNode = JSDomNode
2013-07-26 14:38:11 +00:00
data JSObject = JSObject
2013-09-11 01:21:30 +00:00
{-| Requires that the input array be uniform (all members have the same type) -}
2013-03-10 08:54:37 +00:00
toList : JSArray a -> [a]
toList = Native.JavaScript.toList
2013-07-26 09:42:00 +00:00
toInt : JSNumber -> Int
toInt = Native.JavaScript.toInt
2013-07-26 09:42:00 +00:00
toFloat : JSNumber -> Float
toFloat = Native.JavaScript.toFloat
2013-07-26 09:42:00 +00:00
toBool : JSBool -> Bool
toBool = Native.JavaScript.toBool
2013-07-26 09:42:00 +00:00
toString : JSString -> String
toString = Native.JavaScript.toString
2013-09-11 01:21:30 +00:00
{-| Produces a uniform JavaScript array with all members of the same type. -}
2013-03-10 08:54:37 +00:00
fromList : [a] -> JSArray a
fromList = Native.JavaScript.fromList
2013-07-26 09:42:00 +00:00
fromInt : Int -> JSNumber
fromInt = Native.JavaScript.fromInt
2013-07-26 09:42:00 +00:00
fromFloat : Float -> JSNumber
fromFloat = Native.JavaScript.fromFloat
2013-07-26 09:42:00 +00:00
fromBool : Bool -> JSBool
fromBool = Native.JavaScript.fromBool
2013-07-26 09:42:00 +00:00
fromString : String -> JSString
fromString = Native.JavaScript.fromString
{-
2013-09-10 13:46:26 +00:00
{-| Turn an `Element` into a DOM node. -}
fromElement : Element -> JSDomNode
fromElement = Native.JavaScript.fromElement
2013-09-10 13:46:26 +00:00
{-| Turn a DOM node into an `Element`. You can resize the node
using the normal `width` and `height` functions. -}
toElement : Int -> Int -> JSDomNode -> Element
toElement = Native.JavaScript.toElement
-}