-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 603362d
Showing
6 changed files
with
528 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/target | ||
Cargo.lock | ||
.DS_Store | ||
._* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
max_width = 120 |
Oops, something went wrong.