Skip to content

Presence is very small library for Elixir projects that checks if a value is blank.

License

Notifications You must be signed in to change notification settings

wnuqui/presence

Repository files navigation

Presence Build Status Coverage Status Inline docs Release Hex Version Ebert

Presence is very small library for Elixir projects that needs to check if a value is blank. A value is blank if it's nil, false, empty, or a whitespace string.

The complete documentation for Presence is located here.

Getting Started

Some examples can be found below, but I highly recommend you review the API docs here. There are examples for Atom, BitString, Float, Integer, List, Map and Tuple.

Adding Presence To Your Project

To use Presence with your projects, edit your mix.exs file and add it as a dependency:

defp deps do
  [{:presence, "~> 0.9.1"}]
end

Examples

To use Presence, I recommend you add

import Presence

to the top of the module where you will be working with Presence module. We import to easily access functions from modules implementing Presence protocol without using the fully-qualified name.

These functions are is_blank/1, is_present/1, presence/1

Few examples below:

iex> is_blank(nil)
true
iex> is_blank([])
true
iex> is_blank(%{})
true
iex> is_present({:ok, %{data: [1, 2, 3]}})
true
iex> is_present({})
false
iex> presence("    ")
nil

Current Implementation

Presence is a Protocol that is currently implemented by the following:

  • Atom
  • BitString
  • Float
  • Integer
  • List
  • Map
  • Tuple

Other modules can implement the Protocol by defining these functions:

  • is_blank/1
  • is_present/1
  • presence/1

Inspiration

Many thanks to Rails for the inspiration.

License

This software is licensed under the MIT license.

About

Presence is very small library for Elixir projects that checks if a value is blank.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages