Giter Club home page Giter Club logo

Comments (5)

manpreet-compro avatar manpreet-compro commented on July 24, 2024 1

I further spent some time checking the RFC specification (https://datatracker.ietf.org/doc/html/rfc3986#autoid-21), As per the specifications, a valid hostname could be

from zod.

m10rten avatar m10rten commented on July 24, 2024

Hi, first of all: I think this idea has potential in being implemented and used widely.

However this can be widely interpreted, hi.how.are.you.google.com is a valid domain, but should it be a valid hostname? Or should only google.com or example.com be valid.

Lets look at mozilla's definition on hostname:

https://hello.world.example.com/ -> url.hostname = hello.world.example.com

But should www also be part of it?

from zod.

manpreet-compro avatar manpreet-compro commented on July 24, 2024

@m10rten Thanks for following up.

I believe the value returned from URL.hostname should be considered a valid hostname. It may or may not include www, depending on the domain, Ref: https://developer.mozilla.org/en-US/docs/Web/API/URL/hostname

const url1 = new URL(
  "https://developer.mozilla.org/en-US/docs/Web/API/URL/hostname"
);
console.log(url1.hostname);  // developer.mozilla.org

const url2 = new URL("https://hello.world.example.com/");
console.log(url2.hostname);  // hello.world.example.com

const url3 = new URL("https://www.google.com/");
console.log(url3.hostname);  // www.google.com

from zod.

m10rten avatar m10rten commented on July 24, 2024

Thanks for clearing that up!

Maybe we can work with that, how do you see using it? And what would the result look like?

Or exact like a new URL().hostname?

from zod.

manpreet-compro avatar manpreet-compro commented on July 24, 2024

I think it should be used similarly to existing zod string validations, such as email or uuid.
So this will be z.string().hostname().

As for the implementation options:

  • Adding a regex is one option.
  • Another option is to check if a URL can be successfully constructed from the hostname string without throwing any errors. (I haven't tried this yet, so I'm not sure of the correctness of this option but can explore.)

from zod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.