Skip to content

Internet Functions

CIDRBlock

returns the CIDR block string of an IPv4 with the given number of bits

Syntax:

CIDRBlock(ip: string, bits: int) -> string?

Examples:

CIDRBlock("192.168.42.1", 16) = "192.168.0.0/16"
CIDRBlock("10.72.244.8", 8) = "10.0.0.0/8"

EmailDomain

extracts the domain portion of the given email address

Syntax:

EmailDomain(email: string) -> string?

Examples:

EmailDomain("hello@scowl.dev") = "scowl.dev"
EmailDomain("not-an-email") is null

EmailHandle

extracts the handle portion of the given email address

Syntax:

EmailHandle(email: string) -> string?

Examples:

EmailHandle("hello@scowl.dev") = "hello"
EmailHandle("not-an-email") is null

IPCBlock

extracts the A-C portions of an IPv4 address: A.B.C.D -> A.B.C

Syntax:

IPCBlock(ip: string) -> string?

Examples:

IPCBlock("192.168.0.1") = "192.168.0"
IPCBlock("not-an-ip") is null

NormalizeEmail

normalizes an email address by removing portions that do not impact delivery. This includes removing dots from gmail addresses and + suffixes from all emails.

Syntax:

NormalizeEmail(email: string) -> string?

Examples:

NormalizeEmail("scowl.user@gmail.com") = "scowluser@gmail.com"
NormalizeEmail("hide.me+scowl@yahoo.com") = "hide.me@yahoo.com"
NormalizeEmail("h.e.l.l.o+suffix@gmail.com") = "hello@gmail.com"

ParseUrl

converts a URL string into a map of URL components. The query string is parsed into a map of parameters. All values are URL-decoded. Parsed components are returned as a struct. Missing components are nulls.

Syntax:

ParseUrl(text: string) -> {scheme: string?, username: string?, password: string?, host: string?, port: int?, path: string?, fragment: string?, raw_query: string?, query: map{string: [string]}?}

Examples:

ParseUrl("postgres://user:pass@host.com:5432/path?k=v#f") = {scheme: "postgres", username: "user", password: "pass", host: "host.com", port: 5432, path: "/path", fragment: "f", raw_query: "k=v", query: map{"k": ["v"]}}
ParseUrl("postgres://user:pass@host.com:5432/path?k=v#f").host = "host.com"

ParseUrlQuery

converts a URL query string into a map of parameters. Keys and values are URL-decoded.

Syntax:

ParseUrlQuery(text: string) -> map{string: [string]}?

Examples:

ParseUrlQuery("x=1&y=2&y=3") = map{"x": ["1"], "y": ["2", "3"]}
ParseUrlQuery("?n%20ame=v%20alue") = map{"n ame": ["v alue"]}

ParseUserAgent

converts a user agent string into a map of structured components.

Syntax:

ParseUserAgent(text: string) -> {browser_version: string?, browser: string?, os: string?, os_version: string?, device: string?, device_type: string?, bot: bool?}

Examples:

ParseUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8") = {browser_version: "10.1.2", browser: "Safari", os: "macOS", os_version: "10.12.6", device: null, device_type: "desktop", bot: false}
ParseUserAgent("Mozilla/5.0 (Android 4.3; Mobile; rv:54.0) Gecko/54.0 Firefox/54.0") = {browser_version: "54.0", browser: "Firefox", os: "Android", os_version: "4.3", device: null, device_type: "mobile", bot: false}
ParseUserAgent("Opera/9.80 (Android; Opera Mini/28.0.2254/66.318; U; en) Presto/2.12.423 Version/12.16") = {browser_version: "28.0.2254/66.318", browser: "Opera Mini", os: "Android", os_version: null, device: null, device_type: "mobile", bot: false}

SourceIP

returns the source IP address of the request

Syntax:

SourceIP() -> string?

Examples:

SourceIP() = "192.168.42.1"