qs

Types

pub type Config {
  Config(fail_on_invalid: Bool)
}

Constructors

  • Config(fail_on_invalid: Bool)
pub type Query(v) =
  Dict(String, v)
pub type QueryBasic =
  Query(List(String))

Functions

pub fn default_config() -> Config
pub fn default_parse(
  qs: String,
) -> Result(Dict(String, List(String)), String)

Parse a query string. Values that cannot be parsed are ignored.

Example

"?color=red&tags=large&tags=wool"
|> qs.default_parse

==

Ok(
  dict.from_list(
    [ #("color", ["red"]), #("tags", ["large", "wool"]) ]
  )
)
pub fn default_serialize(
  query: Dict(String, List(String)),
) -> String

Serialize a query

Example

[ #("color", ["red"]), #("tag", ["large", "wool"]) ]
|> qs.default_serialize

==

"?color=red&tag=large&tag=wool"
pub fn delete(
  query: Dict(String, a),
  key: String,
) -> Dict(String, a)

Delete a key from the query

pub fn empty() -> Dict(String, a)

Make an empty Query

pub fn get(
  query: Dict(String, a),
  key: String,
) -> Result(a, String)

Get values from the query

pub fn has_key(query: Dict(String, a), key: String) -> Bool

Tell if the query has the given key

pub fn insert(
  query: Dict(String, a),
  key: String,
  value: a,
) -> Dict(String, a)

Insert a value in the query Replaces existing values

pub fn merge(
  a: Dict(String, a),
  b: Dict(String, a),
) -> Dict(String, a)

Merge two Querys. Second query takes precedence.

pub fn parse(
  input: String,
  config: Config,
) -> Result(Dict(String, List(String)), String)
pub fn with_fail_on_invalid(
  config: Config,
  value: Bool,
) -> Config
Search Document