https://github.com/d-band/uri-utils
Utility for URI encoding based on RFC 3986.
https://github.com/d-band/uri-utils
encode-path encodeuri rfc-3986 uri
Last synced: 11 months ago
JSON representation
Utility for URI encoding based on RFC 3986.
- Host: GitHub
- URL: https://github.com/d-band/uri-utils
- Owner: d-band
- Created: 2017-12-29T10:37:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-06-01T01:00:53.000Z (about 6 years ago)
- Last Synced: 2025-06-23T02:49:02.160Z (12 months ago)
- Topics: encode-path, encodeuri, rfc-3986, uri
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
URI Utilities
=============
[](https://www.npmjs.com/package/uri-utils)
[](https://www.npmjs.com/package/uri-utils)
[](https://travis-ci.org/d-band/uri-utils)
[](https://coveralls.io/github/d-band/uri-utils?branch=master)
[](https://david-dm.org/d-band/uri-utils)
[](https://greenkeeper.io/)
> Utility for URI encoding based on RFC 3986.
## Getting Started
### Install
```bash
$ npm install --save uri-utils
```
### Usage Example
```javascript
import { encode, encodePath } from 'uri-utils';
// or
import * as utils from 'uri-utils';
```
## API Reference
```javascript
import {
TYPE,
encodeScheme,
encodeAuthority,
encodeUserInfo,
encodeHost,
encodePort,
encodePath,
encodePathSegment,
encodeQuery,
encodeQueryParam,
encodeFragment,
encode
} from 'uri-utils';
```
```
foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
| _____________________|__
/ \ / \
urn:example:animal:ferret:nose
```
- `TYPE`: encode type for uri
```
enum TYPE {
SCHEME,
AUTHORITY,
USER_INFO,
HOST_IPV4,
HOST_IPV6,
PORT,
PATH,
PATH_SEGMENT,
QUERY,
QUERY_PARAM,
FRAGMENT,
URI
}
```
- `encode(source: String, type: TYPE)`: encode with type (type default `TYPE.URI` like `encodeURIComponent`)
- `encodeScheme(str: String)`: encode scheme
- `encodeAuthority(str: String)`: encode authority
- `encodeUserInfo(str: String)`: encode user info
- `encodeHost(str: String)`: encode host
- `encodePort(str: String)`: encode port
- `encodePath(str: String)`: encode path
- `encodePathSegment(str: String)`: encode path segment
- `encodeQuery(str: String)`: encode query
- `encodeQueryParam(str: String)`: encode query param
- `encodeFragment(str: String)`: encode fragment
## Benchmark
```
node version: v4.8.7
uri-utils x 150,915 ops/sec ±1.08% (89 runs sampled)
encodeURIComponent x 112,777 ops/sec ±1.29% (73 runs sampled)
Fastest is uri-utils
node version: v6.12.3
uri-utils x 80,632 ops/sec ±0.55% (75 runs sampled)
encodeURIComponent x 73,166 ops/sec ±1.32% (77 runs sampled)
Fastest is uri-utils
node version: v8.9.4
uri-utils x 155,020 ops/sec ±5.58% (75 runs sampled)
encodeURIComponent x 612,347 ops/sec ±4.05% (83 runs sampled)
Fastest is encodeURIComponent
```
## Report a issue
* [All issues](https://github.com/d-band/uri-utils/issues)
* [New issue](https://github.com/d-band/uri-utils/issues/new)
## License
uri-utils is available under the terms of the MIT License.