Utility for URI encoding based on RFC 3986.
npm install uri-utilsURI Utilities
=============






> Utility for URI encoding based on RFC 3986.
``bash`
$ npm install --save uri-utils
`javascript
import { encode, encodePath } from 'uri-utils';
// or
import * as utils from 'uri-utils';
`
`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 schemeencodeAuthority(str: String)
- : encode authorityencodeUserInfo(str: String)
- : encode user infoencodeHost(str: String)
- : encode hostencodePort(str: String)
- : encode portencodePath(str: String)
- : encode pathencodePathSegment(str: String)
- : encode path segmentencodeQuery(str: String)
- : encode query encodeQueryParam(str: String)
- : encode query paramencodeFragment(str: String)
- : encode fragment
`
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
``
uri-utils is available under the terms of the MIT License.