cosepo/directive

Types

Use .new_directive(name: String, value: String) to construct a Directive

pub opaque type Directive

Functions

pub fn get_name(directive: Directive) -> String

Returns the name of a directive

Example

Directive("default-src", ["'none'"])
|> get_name // -> "default-src"
pub fn get_value(directive: Directive) -> List(String)

Returns the value of a directive

Example

Directive("default-src", ["'none'"])
|> get_value // -> ["'none'"]
pub fn new_directive(
  name name: String,
  value value: List(String),
) -> Result(Directive, String)

Creates a new Directive, validating the directive name and values.

Example

new_directive("default-src", ["'self'"])
// -> Ok(Directive(name: "default-src", value: ["'self'"]))

new_directive("invalid-directive", [])
// -> Error("invalid-directive is not a valid directive name")
Search Document