2023-02-20 12:47:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
use deno_core::error::AnyError;
|
2023-09-14 02:29:44 -04:00
|
|
|
use deno_core::op2;
|
2023-02-20 12:47:42 -05:00
|
|
|
|
2023-09-14 02:29:44 -04:00
|
|
|
#[op2]
|
|
|
|
#[string]
|
2023-02-20 12:47:42 -05:00
|
|
|
pub fn op_node_idna_domain_to_ascii(
|
2023-09-14 02:29:44 -04:00
|
|
|
#[string] domain: String,
|
2023-02-20 12:47:42 -05:00
|
|
|
) -> Result<String, AnyError> {
|
|
|
|
Ok(idna::domain_to_ascii(&domain)?)
|
|
|
|
}
|
|
|
|
|
2023-09-14 02:29:44 -04:00
|
|
|
#[op2]
|
|
|
|
#[string]
|
|
|
|
pub fn op_node_idna_domain_to_unicode(#[string] domain: String) -> String {
|
2023-02-20 12:47:42 -05:00
|
|
|
idna::domain_to_unicode(&domain).0
|
|
|
|
}
|
|
|
|
|
2023-09-14 02:29:44 -04:00
|
|
|
#[op2]
|
|
|
|
#[string]
|
|
|
|
pub fn op_node_idna_punycode_decode(#[string] domain: String) -> String {
|
2023-02-20 12:47:42 -05:00
|
|
|
idna::punycode::decode_to_string(&domain).unwrap_or_default()
|
|
|
|
}
|
|
|
|
|
2023-09-14 02:29:44 -04:00
|
|
|
#[op2]
|
|
|
|
#[string]
|
|
|
|
pub fn op_node_idna_punycode_encode(#[string] domain: String) -> String {
|
2023-02-20 12:47:42 -05:00
|
|
|
idna::punycode::encode_str(&domain).unwrap_or_default()
|
|
|
|
}
|