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