# uri_encode
URI percent-encoding for Rust, providing functions equivalent to JavaScript's `encodeURI()` and `encodeURIComponent()`.
## Installation
```toml
[dependencies]
uri_encode = "1.0"
```
## Usage
```rust
use uri_encode::{encode_uri, encode_uri_component, encode_query_param};
// Encode a complete URL (preserves structure)
let url = encode_uri("https://example.com/path?q=hello world");
assert_eq!(url, "https://example.com/path?q=hello%20world");
// Encode a URL component (more aggressive)
let component = encode_uri_component("path/with spaces");
assert_eq!(component, "path%2fwith%20spaces");
// Encode query parameters (spaces become +)
let param = encode_query_param("hello world");
assert_eq!(param, "hello+world");
```
## Functions
### `encode_uri`
Encodes a complete URI while preserving its structure. Equivalent to JavaScript's `encodeURI()`.
Preserves: `A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; , / ? : @ & = + $ #`
```rust
encode_uri("https://example.com/hello world?name=foo bar")
// => "https://example.com/hello%20world?name=foo%20bar"
```
### `encode_uri_component`
Encodes a URI component such as a path segment or query value. Equivalent to JavaScript's `encodeURIComponent()`.
Preserves: `A-Z a-z 0-9 - _ . ! ~ * ' ( )`
```rust
encode_uri_component("hello world&foo=bar")
// => "hello%20world%26foo%3dbar"
```
### `encode_query_param`
Encodes a query parameter using `application/x-www-form-urlencoded` format. Spaces become `+`.
```rust
encode_query_param("John Doe")
// => "John+Doe"
```
## Character Encoding Reference
| space | `%20` | `%20` | `+` |
| `/` | `/` | `%2f` | `/` |
| `?` | `?` | `%3f` | `?` |
| `&` | `&` | `%26` | `&` |
| `=` | `=` | `%3d` | `=` |
| `#` | `#` | `%23` | `#` |
## Features
- Zero dependencies
- No unsafe code (`#![forbid(unsafe_code)]`)
- Works with `&str`, `String`, or any type implementing `AsRef<str>`
## License
ISC