@eryx/encoding/url Module

JSON

URL percent-encoding utilities.

Encodes and decodes strings using percent-encoding as defined by RFC 3986. Unreserved characters (A–Z, a–z, 0–9, -, _, ., ~) are left untouched; all others are replaced with %XX hex sequences.

local url = require("@eryx/encoding/url")
print(url.encode("hello world", true))  -- "hello+world"
print(url.encode("hello world", false)) -- "hello%20world"

Summary

Functions

url.encode(str: string, spaceIsPlus: boolean)string
url.decode(str: string, plusIsSpace: boolean)string

API Reference

Functions

url.encode

Percent-encodes a string.

When spaceIsPlus is true, spaces are encoded as + (common in application/x-www-form-urlencoded form data). Otherwise spaces are encoded as %20.

url.encode(str: string, spaceIsPlus: boolean)string

Parameters

str: string

The string to encode.

spaceIsPlus: boolean

Whether to encode spaces as +.

Returns

string

The percent-encoded string.

url.decode

Decodes a percent-encoded string.

When plusIsSpace is true, + characters are decoded as spaces (matching application/x-www-form-urlencoded form data).

url.decode(str: string, plusIsSpace: boolean)string

Parameters

str: string

The percent-encoded string.

plusIsSpace: boolean

Whether to decode + as a space.

Returns

string

The decoded string.