This repository was archived by the owner on Oct 4, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ "use strict" ;
3
+
4
+ // module DOM.XHR.FormData
5
+
6
+ exports . newFormData = function ( ) {
7
+ return new FormData ( ) ;
8
+ } ;
9
+
10
+ exports . appendString = function ( form ) {
11
+ return function ( key ) {
12
+ return function ( val ) {
13
+ form . append ( key , val ) ;
14
+ return { } ;
15
+ } ;
16
+ } ;
17
+ } ;
18
+
19
+ exports . appendWithName = function ( form ) {
20
+ return function ( key ) {
21
+ return function ( val ) {
22
+ return function ( name ) {
23
+ form . append ( key , val , name ) ;
24
+ return { } ;
25
+ } ;
26
+ } ;
27
+ } ;
28
+ } ;
29
+
Original file line number Diff line number Diff line change
1
+ module DOM.XHR.FormData (FormDataValue (..), toFormData ) where
2
+
3
+ import Data.Foldable
4
+ import Data.Tuple
5
+ import DOM.File.Types
6
+ import DOM.XHR.Types
7
+ import Prelude
8
+
9
+ -- | Possible values of a `FormData`.
10
+ data FormDataValue =
11
+ FormDataString String
12
+ | FormDataFile String File -- ^ File name and `File` object.
13
+ | FormDataBlob String Blob -- ^ Blob name and `Blob` object.
14
+
15
+ -- | Convert an associated array of keys and values to a `FormData`.
16
+ toFormData :: forall f . (Foldable f ) => f (Tuple String FormDataValue ) -> FormData
17
+ toFormData dat =
18
+ let form = newFormData unit in
19
+ let _unit = foldMap (appendData form) dat in
20
+ form
21
+
22
+ where
23
+ appendData form (Tuple key (FormDataString val)) = appendString form key val
24
+ appendData form (Tuple key (FormDataFile name val)) = appendWithName form key val name
25
+ appendData form (Tuple key (FormDataBlob name val)) = appendWithName form key val name
26
+
27
+ foreign import newFormData :: Unit -> FormData
28
+
29
+ foreign import appendString :: FormData -> String -> String -> Unit
30
+ foreign import appendWithName :: forall a . FormData -> String -> a -> String -> Unit
You can’t perform that action at this time.
0 commit comments