Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hiql committed Jul 19, 2024
0 parents commit 603362d
Show file tree
Hide file tree
Showing 6 changed files with 528 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target
Cargo.lock
.DS_Store
._*
16 changes: 16 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "is-ip"
version = "0.1.0"
authors = ["hiql <[email protected]>"]
categories = ["Network programming"]
description = "Check if a string is an IP address"
documentation = "https://docs.rs/is-ip"
edition = "2021"
keywords = ["ip", "network", "utilities"]
license = "MIT"
repository = "https://github.com/hiql/is-ip"
readme = "README.md"
rust-version = "1.70.0"

[dependencies]
regex = "1.10"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 HiQL

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# is-ip

Check if a string is an IP address

## Install

```toml
[dependencies]
is-ip = "0.1.0"
```

## Usage

```rust
use super::{is_ip, is_ipv4, is_ipv6}

is_ip("1:2:3:4:5:6:7:8");
//=> true

is_ip("192.168.0.1");
//=> true

is_ipv4("1:2:3:4:5:6:7:8");
//=> false
```

## API

#### is_ip(string: &str) -> bool

Check if `string` is IPv6 or IPv4.

#### is_ipv4(string: &str) -> bool

Check if `string` is IPv4.

#### is_ipv6(string: &str) -> bool

Check if `string` is IPv6.

#### ip_version(string: &str) -> Option<u8>

Returns `Some(6)` if `string` is IPv6, `Some(4)` if `string` is IPv4, or `None` if `string` is neither.

```rust
use is_ip::ip_version;

ip_version("1:2:3:4:5:6:7:8");
//=> Some(6)

ip_version("192.168.0.1");
//=> Some(4)

ip_version("abc");
//=> None
```

This lib inspired by [is-ip](https://www.npmjs.com/package/is-ip) a nodejs package!
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 120
Loading

0 comments on commit 603362d

Please sign in to comment.