summaryrefslogtreecommitdiff
path: root/ext/node/idna.rs
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2023-02-20 18:47:42 +0100
committerGitHub <noreply@github.com>2023-02-20 18:47:42 +0100
commit88f6fc6a1684326ae1f947ea8ec24ad0bff0f449 (patch)
tree0fa821ef0ff1ff5120ce43bf0d6052767d1f792b /ext/node/idna.rs
parentea7ca00c895c401af57a7201f3c41524333e7939 (diff)
refactor: use ops for idna & punycode (#17817)
Towards https://github.com/denoland/deno/issues/17809
Diffstat (limited to 'ext/node/idna.rs')
-rw-r--r--ext/node/idna.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/ext/node/idna.rs b/ext/node/idna.rs
new file mode 100644
index 000000000..8f7cfe34a
--- /dev/null
+++ b/ext/node/idna.rs
@@ -0,0 +1,26 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+use deno_core::error::AnyError;
+use deno_core::op;
+
+#[op]
+pub fn op_node_idna_domain_to_ascii(
+ domain: String,
+) -> Result<String, AnyError> {
+ Ok(idna::domain_to_ascii(&domain)?)
+}
+
+#[op]
+pub fn op_node_idna_domain_to_unicode(domain: String) -> String {
+ idna::domain_to_unicode(&domain).0
+}
+
+#[op]
+pub fn op_node_idna_punycode_decode(domain: String) -> String {
+ idna::punycode::decode_to_string(&domain).unwrap_or_default()
+}
+
+#[op]
+pub fn op_node_idna_punycode_encode(domain: String) -> String {
+ idna::punycode::encode_str(&domain).unwrap_or_default()
+}