uri-utils
v1.0.4
Published
Utility for URI encoding based on RFC 3986.
Downloads
5
Maintainers
Readme
URI Utilities
Utility for URI encoding based on RFC 3986.
Getting Started
Install
$ npm install --save uri-utils
Usage Example
import { encode, encodePath } from 'uri-utils';
// or
import * as utils from 'uri-utils';
API Reference
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 urienum 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 defaultTYPE.URI
likeencodeURIComponent
)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 queryencodeQueryParam(str: String)
: encode query paramencodeFragment(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
License
uri-utils is available under the terms of the MIT License.