1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00
denoland-deno/ext/url/urlpattern.rs
Leo Kettmeir ea30e188a8
refactor: update deno_core for error refactor (#26867)
Closes #26171

---------

Co-authored-by: David Sherret <dsherret@gmail.com>
2025-01-08 14:52:32 -08:00

40 lines
1.1 KiB
Rust

// Copyright 2018-2025 the Deno authors. MIT license.
use deno_core::op2;
use urlpattern::quirks;
use urlpattern::quirks::MatchInput;
use urlpattern::quirks::StringOrInit;
use urlpattern::quirks::UrlPattern;
deno_error::js_error_wrapper!(urlpattern::Error, UrlPatternError, "TypeError");
#[op2]
#[serde]
pub fn op_urlpattern_parse(
#[serde] input: StringOrInit,
#[string] base_url: Option<String>,
#[serde] options: urlpattern::UrlPatternOptions,
) -> Result<UrlPattern, UrlPatternError> {
let init =
quirks::process_construct_pattern_input(input, base_url.as_deref())?;
let pattern = quirks::parse_pattern(init, options)?;
Ok(pattern)
}
#[op2]
#[serde]
pub fn op_urlpattern_process_match_input(
#[serde] input: StringOrInit,
#[string] base_url: Option<String>,
) -> Result<Option<(MatchInput, quirks::Inputs)>, UrlPatternError> {
let res = quirks::process_match_input(input, base_url.as_deref())?;
let (input, inputs) = match res {
Some((input, inputs)) => (input, inputs),
None => return Ok(None),
};
Ok(quirks::parse_match_input(input).map(|input| (input, inputs)))
}