2023-01-13 02:51:32 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2021-09-08 05:14:29 -04:00
|
|
|
use deno_core::error::type_error;
|
|
|
|
use deno_core::error::AnyError;
|
2022-03-14 13:44:15 -04:00
|
|
|
use deno_core::op;
|
2021-09-08 05:14:29 -04:00
|
|
|
|
|
|
|
use urlpattern::quirks;
|
|
|
|
use urlpattern::quirks::MatchInput;
|
|
|
|
use urlpattern::quirks::StringOrInit;
|
|
|
|
use urlpattern::quirks::UrlPattern;
|
|
|
|
|
2022-03-14 13:44:15 -04:00
|
|
|
#[op]
|
2021-09-08 05:14:29 -04:00
|
|
|
pub fn op_urlpattern_parse(
|
|
|
|
input: StringOrInit,
|
|
|
|
base_url: Option<String>,
|
|
|
|
) -> Result<UrlPattern, AnyError> {
|
|
|
|
let init = urlpattern::quirks::process_construct_pattern_input(
|
|
|
|
input,
|
|
|
|
base_url.as_deref(),
|
|
|
|
)
|
|
|
|
.map_err(|e| type_error(e.to_string()))?;
|
|
|
|
|
|
|
|
let pattern = urlpattern::quirks::parse_pattern(init)
|
|
|
|
.map_err(|e| type_error(e.to_string()))?;
|
|
|
|
|
|
|
|
Ok(pattern)
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:44:15 -04:00
|
|
|
#[op]
|
2021-09-08 05:14:29 -04:00
|
|
|
pub fn op_urlpattern_process_match_input(
|
|
|
|
input: StringOrInit,
|
|
|
|
base_url: Option<String>,
|
|
|
|
) -> Result<Option<(MatchInput, quirks::Inputs)>, AnyError> {
|
|
|
|
let res = urlpattern::quirks::process_match_input(input, base_url.as_deref())
|
|
|
|
.map_err(|e| type_error(e.to_string()))?;
|
|
|
|
|
|
|
|
let (input, inputs) = match res {
|
|
|
|
Some((input, inputs)) => (input, inputs),
|
|
|
|
None => return Ok(None),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(urlpattern::quirks::parse_match_input(input).map(|input| (input, inputs)))
|
|
|
|
}
|