README.md

# glip

[![Package Version](https://img.shields.io/hexpm/v/glip)](https://hex.pm/packages/glip)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/glip/)

```sh
gleam add glip@1
```

Glip provides a standard representation for IP addresses
on Gleam for Erlang and node/bun on JavaScript.
The intent is to have a minimal representation in memory,
and avoid unnecessary conversions for common operations.
Glip is designed for server-oriented usage,
which is why it doesn't have a browser-compatible implementation,
and only wraps functionality in the runtimes.
(Feel free to open an issue if you have a valid browser use case).

```gleam
import gleam/bool
import gleam/io
import glip.{type ExternalIpAddress}

pub fn main() {
  let assert Ok(ip) = glip.parse_ip("127.0.0.1")
  let result = is_ipv4(glip.to_external_ip(ip))
  io.println(glip.ip_to_string(ip) <> " is IPv4: " <> bool.to_string(result))
}

/// Glip is designed to be FFI friendly and efficient!
@external(erlang, "inet", "is_ipv4_address")
@external(javascript, "node:net", "isIPv4")
fn is_ipv4(ip: ExternalIpAddress) -> Bool
```

Further documentation can be found at <https://hexdocs.pm/glip>.


## Development

Both of the following work also with the `--target javascript` option!

```sh
gleam test  # Run the tests
gleam dev   # Run the example code
```