URL Functions¶
Functions for parsing and constructing URLs and query strings.
Summary¶
| Function | Signature | Description |
|---|---|---|
query_string_build |
object -> string |
Build a URL query string from an object |
query_string_parse |
string -> object |
Parse a URL query string into an object |
url_build |
object -> string |
Build a URL from component parts |
url_decode |
string -> string |
URL decode a string |
url_encode |
string -> string |
URL encode a string |
url_parse |
string -> object |
Parse URL into components |
Functions¶
query_string_build¶
Build a URL query string from an object
Signature: object -> string
Examples:
# Basic query string
query_string_build({foo: 'bar', baz: 'qux'}) -> "foo=bar&baz=qux"
# With special characters
query_string_build({q: 'hello world'}) -> "q=hello+world"
# Empty object
query_string_build({}) -> ""
query_string_parse¶
Parse a URL query string into an object
Signature: string -> object
Examples:
# Basic parsing
query_string_parse('foo=bar&baz=qux') -> {foo: 'bar', baz: 'qux'}
# Encoded values
query_string_parse('greeting=hello%20world') -> {greeting: 'hello world'}
# Empty string
query_string_parse('') -> {}
url_build¶
Build a URL from component parts
Signature: object -> string
Examples:
# Minimal URL
url_build({scheme: 'https', host: 'example.com'}) -> "https://example.com/"
# With port and path
url_build({scheme: 'https', host: 'example.com', port: 8080, path: '/api'}) -> full URL
# Roundtrip with url_parse
url_build(url_parse('https://example.com/path')) -> roundtrip
url_decode¶
URL decode a string
Signature: string -> string
Examples:
# Decode space
url_decode('hello%20world') -> \"hello world\"
# Decode plus sign
url_decode('a%2Bb') -> \"a+b\"
# Decode percent
url_decode('100%25') -> \"100%\"
# No encoding
url_decode('hello') -> \"hello\"
url_encode¶
URL encode a string
Signature: string -> string
Examples:
# Encode space
url_encode('hello world') -> \"hello%20world\"
# Encode plus
url_encode('a+b') -> \"a%2Bb\"
# Encode percent
url_encode('100%') -> \"100%25\"
# No special chars
url_encode('hello') -> \"hello\"
url_parse¶
Parse URL into components
Signature: string -> object
Examples: