D
Deno

help

Parsing Hostname for TLD, domain name, and SLD

Yybabts7/7/2023
does anyone know of any packages to parse a URL's hostname for the top level domain, domain name, and sublevel domains? I found one, but it actually just doesn't work. It just errors saying the label is too short for everything I give it. https://github.com/lupomontero/psl
GitHub
GitHub - lupomontero/psl: JavaScript domain name parser based on th...
JavaScript domain name parser based on the Public Suffix List - GitHub - lupomontero/psl: JavaScript domain name parser based on the Public Suffix List
Yybabts7/7/2023
I'm suprised this isn't already in the URL object for Javascript
UUUnknown User7/7/2023
Message Not Public
Sign In & Join Server To View
Yybabts7/7/2023
no I need the sub level domain of the url, which comes from the URL.hostname
// Sub level domain is "api"
// Domain Name is "geeksforgeeks"
// Top level domain is "org"
const url = new URL("https://api.geeksforgeeks.org:3000/pathname/?search=query");
// api.geeksforgeeks.org
console.log(url.hostname)
// Sub level domain is "api"
// Domain Name is "geeksforgeeks"
// Top level domain is "org"
const url = new URL("https://api.geeksforgeeks.org:3000/pathname/?search=query");
// api.geeksforgeeks.org
console.log(url.hostname)
NNeTT7/7/2023
why not use some regex for that
const parseHostname = /(?:([a-z0-9]+)\.)?([a-z0-9]+)\.(?:([a-z]+)\.)?([a-z]+)/

const url = new URL("https://api.geeksforgeeks.org:3000/pathname/?search=query");

parseHostname.exec(url.hostname)
/*
[
"api.geeksforgeeks.org", // hostname
"api", // subdomain
"geeksforgeeks", // domain name
undefined, // sld
"org", // tld
index: 0,
input: "api.geeksforgeeks.org",
groups: undefined
]
*/
const parseHostname = /(?:([a-z0-9]+)\.)?([a-z0-9]+)\.(?:([a-z]+)\.)?([a-z]+)/

const url = new URL("https://api.geeksforgeeks.org:3000/pathname/?search=query");

parseHostname.exec(url.hostname)
/*
[
"api.geeksforgeeks.org", // hostname
"api", // subdomain
"geeksforgeeks", // domain name
undefined, // sld
"org", // tld
index: 0,
input: "api.geeksforgeeks.org",
groups: undefined
]
*/
I just woke up, there may be better ways to do it
UUUnknown User7/7/2023
2 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!

Recommended Posts
Migrating large Node project to DenoIs there any reliable way to migrate a Node project to Deno? Currently working on a large project thWhy does Deno.serve not return a promise anymore?Doesn't this cause problems for error handling?Changing GitHub username โ€“ what about deno.land/x?If I change my GitHub username and I have a couple of modules on deno.land/x, what will happen to thAbsolute Imports with OakI would like to have absolute imports in my Oak-API ... ๐Ÿ˜‰Passing initial data to WorkerDetault `Worker` doesnt seem to support `WorkerData` as params. Although using `node:worker_threads`Adding npm specifiers to deno.jsonHow do i add a specific version of an npm module to the cache?How do I enqueue_microtask from other threadso `Isolate.enqueue_microtask` is obviously not send/sync so I think the only option is to use` std:how to import svg in vite without type errors?Can't connect to http server on official alpine deno with std serve.I'm using the official alpine docker container to run deno, listening on port 8080, but a simple curcalling a javascript function and waiting for the promise with `rusty_v8````rust let result = function.call(scope, recv, &[]).expect("couldnt run"); /*i got this result whicDeno KV: subtract with `sum` operation?If I do `.sum([key], 1n)` the value is increased by 1. How can I decrease it? I tried `.sum([key], Proxying a Rust API using FFI?I have a rust application that serves a rest api that runs in a container. I also have a deno cli thHow to use declarations from `vite/client`?There are declarations: https://esm.sh/v126/vite@4.3.9/client.d.ts According to documentation, I neegetting errno with ffiI am using ffi to call `execv` and need to get the value of `errno` for failures, but canโ€™t see how Purging Kv keysI have a logger which write logs to a kv store with dual keys, something like ```ts kv.set(["logs_bWhat is the right way to bundle native modules?If I'm not able to import a native module with the built-in "import" keyword, what is the ideal way HandleScope in async opIs there a way to get v8::HandleScope inside async op if I add it as ``` scope: &mut v8::HandleScopDeno LSP randomly breaks until a restart (unable to send result to client)This wasnt an issue until recently. In vscode randomly the lsp stops working. Trying to use the auto