@ceeblue/web-utils
    Preparing search index...

    Class NetAddress

    Help class to manipulate and parse a net address. The Address can be only the domain field, or a URL format with protocol and path part (http://)domain(:port/path)

    const address = new Address('nl-ams-42.live.ceeblue.tv:80');
    console.log(address.domain) // 'nl-ams-42.live.ceeblue.tv'
    console.log(address.port) // '80'
    console.log(address) // 'nl-ams-42.live.ceeblue.tv:80'
    Index

    Constructors

    Accessors

    Methods

    Constructors

    • Build a NetAddress object and parse address

      Parameters

      • address: string

        string address to parse, accept an url format with protocol and path (http://)domain(:port/path)

      • OptionaldefaultPort: number

        set a default port to use if there is no port in the string address parsed

      Returns NetAddress

    Accessors

    • get domain(): string

      The domain part from address (http://)domain(:port/path)

      Returns string

    • get host(): string

      The host part from address (http://)domain:port/path)

      Returns string

    • get port(): number | undefined

      The port part from address (http://)domain(:port/path), or defaultPort if passed in NetAddress constructor

      Returns number | undefined

    Methods

    • Returns string

      the string address as passed in the constructor

    • Static help function to build an end point from an address (proto://)domain(:port/path)

      Mainly it fix the protocol, in addition if:

      • the address passed is securized (TLS) and protocol is not => it tries to fix protocol to get its securize version
      • the address passed is non securized and protocol is (TLS) => it tries to fix protocol to get its unsecurized version

      Parameters

      • protocol: string

        protocol to set in the end point returned

      • address: string

        string address to fix with protocol as indicated

      Returns string

      the end point built

      console.log(NetAddress.fixProtocol('ws','http://domain/path')) // 'ws://domain/path'
      console.log(NetAddress.fixProtocol('ws','https://domain/path')) // 'wss://domain/path'
      console.log(NetAddress.fixProtocol('wss','http://domain/path')) // 'ws://domain/path'