{"id":13508528,"url":"https://github.com/DevL/guardsafe","last_synced_at":"2025-03-30T11:32:08.480Z","repository":{"id":27543594,"uuid":"31025114","full_name":"DevL/guardsafe","owner":"DevL","description":"Macros expanding into code that can be safely used in guard clauses.","archived":true,"fork":false,"pushed_at":"2025-03-10T12:34:41.000Z","size":23,"stargazers_count":26,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-10T13:34:37.394Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DevL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-19T16:41:22.000Z","updated_at":"2025-03-10T12:34:53.000Z","dependencies_parsed_at":"2022-09-02T11:10:49.037Z","dependency_job_id":null,"html_url":"https://github.com/DevL/guardsafe","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevL%2Fguardsafe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevL%2Fguardsafe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevL%2Fguardsafe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevL%2Fguardsafe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevL","download_url":"https://codeload.github.com/DevL/guardsafe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246314011,"owners_count":20757450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:54.395Z","updated_at":"2025-03-30T11:32:03.459Z","avatar_url":"https://github.com/DevL.png","language":"Elixir","funding_links":[],"categories":["Macros"],"sub_categories":[],"readme":"# Guardsafe\n\n[![Build Status](https://travis-ci.org/DevL/guardsafe.svg?branch=master)](https://travis-ci.org/DevL/guardsafe)\n[![Inline docs](http://inch-ci.org/github/DevL/guardsafe.svg?branch=master)](http://inch-ci.org/github/DevL/guardsafe)\n[![Hex.pm](https://img.shields.io/hexpm/v/guardsafe.svg)](https://hex.pm/packages/guardsafe)\n[![Documentation](https://img.shields.io/badge/Documentation-online-c800c8.svg)](http://hexdocs.pm/guardsafe)\n\nMacros expanding into code that can be safely used in guard clauses.\n\n## Usage\n\nUpdate your `mix.exs` file and run `mix deps.get`.\n```elixir\ndefp deps do\n  [{:guardsafe, \"~\u003e 0.5.0\"}]\nend\n```\n\nImport all the macros...\n```elixir\ndefmodule MyModule do\n  import Guardsafe\n```\n\n...or just the ones you need.\n```elixir\ndefmodule MyOtherModule do\n  import Guardsafe, only: [divisible_by?: 2, integer?: 1]\n```\n\nNow go forth and make your guard clauses more readable!\n```elixir\ndef leap_year?(year) when not integer?(year), do: raise \"That's not a proper year!\"\ndef leap_year?(year) when divisible_by?(year, 400), do: true\ndef leap_year?(year) when divisible_by?(year, 100), do: false\ndef leap_year?(year), do: divisible_by?(year, 4)\n```\n\nDocumentation for each macro is of course available in `iex`.\n```\niex(1)\u003e h Guardsafe.divisible_by?\n\n                    defmacro divisible_by?(number, divisor)\n\nExpands divisible_by?(number, divisor) into rem(number, divisor) == 0\n```\n\n## Available macros\n\n**NB:** If a macro is translated into a function residing in another module\nthan `Kernel` you need to require it before use, e.g. `require Integer`.\n\n#### Macros for checking types\n* `atom?/1` - translates into `Kernel.is_atom/1`\n* `binary?/1` - translates into `Kernel.is_binary/1`\n* `bitstring?/1` - translates into `Kernel.is_bitstring/1`\n* `boolean?/1` - translates into `Kernel.is_boolean/1`\n* `float?/1` - translates into `Kernel.is_float/1`\n* `function?/1` - translates into `Kernel.is_function/1`\n* `function?/2` - translates into `Kernel.is_function/2`\n* `integer?/1` - translates into `Kernel.is_integer/1`\n* `list?/1` - translates into `Kernel.is_list/1`\n* `map?/1` - translates into `Kernel.is_map/1`\n* `nil?/1` - translates into `Kernel.is_nil/1`\n* `number?/1` - translates into `Kernel.is_number/1`\n* `pid?/1` - translates into `Kernel.is_pid/1`\n* `port?/1` - translates into `Kernel.is_port/1`\n* `reference?/1` - translates into `Kernel.is_reference/1`\n* `tuple?/1` - translates into `Kernel.is_tuple/1`\n\n#### Macros for checking values\n* `divisible_by?/2` - checks whether two integers are evenly divisible.\n* `even?/1` - returns true for even integers.\n* `odd?/1` - returns true for odd integers.\n* `within?/3` - checks whether a value is in the range of the last two arguments.\n\n#### Macros for dates and times\n* `date?/1` - checks if the term is an Erlang-style date tuple.\n* `datetime?/1` - checks if the term is an Erlang-style datetime tuple.\n* `time?/1` - checks if the term is an Erlang-style time tuple.\n\n_These can come in handy when working with a library such as [GoodTimes](https://github.com/DevL/good_times)._\n\n### Why nil? and float? instead of is_nil and is_float\n\nWhile the Elixir core team thinks that `nil?` compared to `is_nil` is [an inconcistency](https://groups.google.com/forum/#!topic/elixir-lang-core/FaKJstePFV0), others, especially Rubyists, might be more comfortable with the `nil?` notation. Honestly though, this is mostly intended as a display of how Elixir's metaprogramming capabilities can be used to shape the look and feel of the language itself.\n\n## Online documentation\n\nFor more information, see [the full documentation](http://hexdocs.pm/guardsafe).\n\n## Contributing\n\n1. Fork this repository\n2. Create your feature branch (`git checkout -b quis-custodiet-ipsos-custodes`)\n3. Commit your changes (`git commit -am 'Guards! Guards!'`)\n4. Push to the branch (`git push origin quis-custodiet-ipsos-custodes`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDevL%2Fguardsafe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDevL%2Fguardsafe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDevL%2Fguardsafe/lists"}