# `Tarams.Utils`
[🔗](https://github.com/bluzky/tarams/blob/main/lib/utils.ex#L1)

# `clean_nil`

```elixir
@spec clean_nil(any()) :: any()
```

Clean all nil field from params, support nested map and list.

**Example**

    params = %{"keyword" => nil, "email" => nil, "type" => "customer"}
    Tarams.clean_nil(params)
    # => %{"type" => "customer"}

    params = %{user_ids: [1, 2, nil]}
    Tarams.clean_nil(params)
    # => %{user_ids: [1, 2]}

# `plug_scrub`

A plug which do srubbing params

**Use in Router**

    defmodule MyApp.Router do
      ...
      plug Tarams.plug_scrub
      ...
    end

**Use in controller**

    plug Tarams.plug_scrub when action in [:index, :show]
    # or specify which field to scrub
    plug Tarams.plug_scrub, ["id", "keyword"] when action in [:index, :show]

# `scrub_param`

Convert all parameter which value is empty string or string with all whitespace to nil. It works with nested map and list too.

**Example**

    params = %{"keyword" => "   ", "email" => "", "type" => "customer"}
    Tarams.scrub_param(params)
    # => %{"keyword" => nil, "email" => nil, "type" => "customer"}

    params = %{user_ids: [1, 2, "", "  "]}
    Tarams.scrub_param(params)
    # => %{user_ids: [1, 2, nil, nil]}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
