parse-fetch-command ( string -- request )


Vocabulary
chrome-tools

Inputs
stringan object


Outputs
requestan object


Definition


: parse-fetch-command ( string -- request )
[ blank? ] trim "fetch(" ?head drop ", " split1
[ <request> swap trim-dquotes >url >>url ] dip
");" ?tail drop json> [
swap {
{ "method" [ [ >>method ] curry ] }
{
"headers"
[
[
swap dup "if-modified-since" =
~quotation~ ~quotation~ if
] { } assoc>map [ ] concat-as
]
}
{
"body"
[
[
dup json-null =
~quotation~ ~quotation~ if
] curry
]
}
[ 2drop f ]
} case
] { } assoc>map [ ] concat-as curry
( -- request ) call-effect ;