Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vasuadari/constant
A package to create constants in elixir modules.
https://github.com/vasuadari/constant
constants elixir elixir-library
Last synced: 28 days ago
JSON representation
A package to create constants in elixir modules.
- Host: GitHub
- URL: https://github.com/vasuadari/constant
- Owner: vasuadari
- License: mit
- Created: 2019-09-23T17:35:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-25T13:51:57.000Z (6 months ago)
- Last Synced: 2024-10-09T13:02:45.859Z (3 months ago)
- Topics: constants, elixir, elixir-library
- Language: Elixir
- Size: 23.4 KB
- Stars: 6
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Constant
[![Build Status](https://travis-ci.org/vasuadari/constant.svg?branch=master)](https://travis-ci.org/vasuadari/constant)
[![Hex.pm version](https://img.shields.io/hexpm/v/constant.svg)](https://hex.pm/packages/constant)A package to define constants in your module.
## Installation
The package can be installed by adding `constant` to your list of dependencies
in `mix.exs`:```elixir
def deps do
[
{:constant, "~> 0.0.1"}
]
end
```## Usage
```elixir
defmodule HTTPStatusCode do
import Constantdefconst ok: 200, created: 201
endiex> HTTPStatusCode.ok()
200
iex> HTTPStatusCode.created()
201defmodule ColorCode do
import Constantdefconst [black: "FFFFFF", white: "000000"], atomize: true
endiex> ColorCode.black()
"FFFFFF"
iex> ColorCode.black_atom()
:FFFFFF
```The constant can be used in the format `const_` after requiring the module, and which enables the constant to be directly used in argument pattern matches and guards.
```elixir
defmodule ColorCodeMatcher do
require ColorCodedef is_black(_color = ColorCode.const_black()), do: true
def is_black(_), do: false
end
```## License
Constant source code is licensed under the [MIT License](LICENSE).