Skip to content

Commit

Permalink
add get_field helper method (#398)
Browse files Browse the repository at this point in the history
* add get field

* format
  • Loading branch information
dev-ardi authored Nov 8, 2023
1 parent 73a127c commit bb215a8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions worker/src/formdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ impl FormData {
None
}

/// Returns the first Field value associated with a given key from within a `FormData` object.
pub fn get_field(&self, name: &str) -> Option<String> {
let val = self.0.get(name);
if val.is_undefined() {
return None;
}

if val.is_instance_of::<web_sys::File>() {
return None;
}

if let Some(field) = val.as_string() {
return Some(field);
}

None
}

/// Returns a vec of all the values associated with a given key from within a `FormData` object.
pub fn get_all(&self, name: &str) -> Option<Vec<FormEntry>> {
let val = self.0.get_all(name);
Expand Down

0 comments on commit bb215a8

Please sign in to comment.