fast-uri 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ # Number of days of inactivity before an issue becomes stale
2
+ daysUntilStale: 15
3
+ # Number of days of inactivity before a stale issue is closed
4
+ daysUntilClose: 7
5
+ # Issues with these labels will never be considered stale
6
+ exemptLabels:
7
+ - "discussion"
8
+ - "feature request"
9
+ - "bug"
10
+ - "help wanted"
11
+ - "plugin suggestion"
12
+ - "good first issue"
13
+ # Label to use when marking an issue as stale
14
+ staleLabel: stale
15
+ # Comment to post when marking an issue as stale. Set to `false` to disable
16
+ markComment: >
17
+ This issue has been automatically marked as stale because it has not had
18
+ recent activity. It will be closed if no further activity occurs. Thank you
19
+ for your contributions.
20
+ # Comment to post when closing a stale issue. Set to `false` to disable
21
+ closeComment: false
@@ -0,0 +1,16 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: github-actions
4
+ directory: '/'
5
+ ignore:
6
+ - dependency-name: "actions/*"
7
+ update-types:
8
+ ["version-update:semver-minor", "version-update:semver-patch"]
9
+ schedule:
10
+ interval: daily
11
+ open-pull-requests-limit: 10
12
+ - package-ecosystem: npm
13
+ directory: '/'
14
+ schedule:
15
+ interval: daily
16
+ open-pull-requests-limit: 10
@@ -0,0 +1,8 @@
1
+ comment: |
2
+ Hello! Thank you for contributing!
3
+ It appears that you have changed the code, but the tests that verify your change are missing. Could you please add them?
4
+ fileExtensions:
5
+ - '.ts'
6
+ - '.js'
7
+
8
+ testDir: 'test'
@@ -0,0 +1,84 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ paths-ignore:
6
+ - 'docs/**'
7
+ - '*.md'
8
+ pull_request:
9
+ paths-ignore:
10
+ - 'docs/**'
11
+ - '*.md'
12
+
13
+ env:
14
+ CI: true
15
+ COVERALLS: 0
16
+
17
+ jobs:
18
+ test:
19
+ runs-on: ${{ matrix.os }}
20
+ strategy:
21
+ matrix:
22
+ # Maintenance and active LTS
23
+ node-version: [10, 12, 14, 16]
24
+ os: [ubuntu-latest, windows-latest, macOS-latest]
25
+ name: Node ${{ matrix.node-version }}
26
+
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+
30
+ - name: Use Node.js
31
+ id: setup_node
32
+ uses: actions/setup-node@v2
33
+ with:
34
+ node-version: ${{ matrix.node-version }}
35
+
36
+ - name: Install Dependencies
37
+ id: install
38
+ run: npm install --ignore-scripts
39
+
40
+ - name: Check licenses
41
+ id: license_check
42
+ run: |
43
+ npm run license-checker --if-present
44
+
45
+ # Unit and lint tests
46
+ - name: Tests
47
+ id: test
48
+ run: npm run test:ci
49
+
50
+ - name: Coveralls Parallel
51
+ id: coveralls-parallel
52
+ continue-on-error: true
53
+ uses: coverallsapp/github-action@master
54
+ with:
55
+ github-token: ${{ secrets.github_token }}
56
+ parallel: true
57
+ flag-name: run-${{ matrix.node-version }}-${{ matrix.os }}
58
+
59
+ - name: Should Trigger coverallsapp/github-action@master
60
+ id: coveralls-trigger
61
+ # https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#steps-context
62
+ # when continue-on-error failed, outcome is failure and conclusion is success
63
+ if: steps.coveralls-parallel.conclusion == 'success' && steps.coveralls-parallel.outcome != 'success'
64
+ run: |
65
+ echo "::set-output name=COVERALLS_TRIGGER::failure"
66
+
67
+ coverage:
68
+ needs: test
69
+ runs-on: ubuntu-latest
70
+ if: needs.test.outputs.COVERALLS != 'failure'
71
+ steps:
72
+ - name: Coveralls Finished
73
+ uses: coverallsapp/github-action@master
74
+ with:
75
+ github-token: ${{ secrets.GITHUB_TOKEN }}
76
+ parallel-finished: true
77
+
78
+ automerge:
79
+ needs: test
80
+ runs-on: ubuntu-latest
81
+ steps:
82
+ - uses: fastify/github-action-merge-dependabot@v2.7.1
83
+ with:
84
+ github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,65 @@
1
+ name: package-manager-ci
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ pnpm:
10
+ runs-on: ${{ matrix.os }}
11
+
12
+ strategy:
13
+ matrix:
14
+ # Maintenance and active LTS
15
+ node-version: [10, 12, 14, 16]
16
+ os: [ubuntu-latest]
17
+
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+
21
+ - name: Use Node.js
22
+ uses: actions/setup-node@v2
23
+ id: setup_node
24
+ with:
25
+ node-version: ${{ matrix.node-version }}
26
+
27
+ - name: Install with pnpm
28
+ id: install_package_manager
29
+ run: |
30
+ curl -L https://unpkg.com/@pnpm/self-installer | node
31
+ pnpm install
32
+
33
+ - name: Run tests
34
+ id: test
35
+ run: |
36
+ pnpm run test
37
+
38
+ yarn:
39
+ runs-on: ${{ matrix.os }}
40
+
41
+ strategy:
42
+ matrix:
43
+ # Maintenance and active LTS
44
+ node-version: [10, 12, 14, 16]
45
+ os: [ubuntu-latest]
46
+
47
+ steps:
48
+ - uses: actions/checkout@v2
49
+
50
+ - name: Use Node.js
51
+ id: setup_node
52
+ uses: actions/setup-node@v2
53
+ with:
54
+ node-version: ${{ matrix.node-version }}
55
+
56
+ - name: Install with yarn
57
+ id: install_package_manager
58
+ run: |
59
+ curl -o- -L https://yarnpkg.com/install.sh | bash
60
+ yarn install --ignore-engines
61
+
62
+ - name: Run tests
63
+ id: test
64
+ run: |
65
+ yarn run test
package/LICENSE ADDED
@@ -0,0 +1,30 @@
1
+ Copyright (c) 2021 The Fastify Team
2
+ Copyright (c) 2011-2021, Gary Court until https://github.com/garycourt/uri-js/commit/a1acf730b4bba3f1097c9f52e7d9d3aba8cdcaae
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+ * The names of any contributors may not be used to endorse or promote
13
+ products derived from this software without specific prior written
14
+ permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ * * *
28
+
29
+ The complete list of contributors can be found at:
30
+ - https://github.com/garycourt/uri-js/graphs/contributors
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # fast-uri
2
+
3
+ <div align="center">
4
+
5
+ [![CI](https://github.com/fastify/fastify/workflows/ci/badge.svg)](https://github.com/fastify/fast-uri/actions/workflows/ci.yml)
6
+ [![Coverage Status](https://coveralls.io/repos/github/fastify/fast-uri/badge.svg?branch=add_coveralls)](https://coveralls.io/github/fastify/fast-uri?branch=main)
7
+ [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
8
+
9
+ </div>
10
+
11
+ Dependency free RFC 3986 URI toolbox.
12
+
13
+ ## Usage
14
+
15
+ ## Options
16
+
17
+ All of the above functions can accept an additional options argument that is an object that can contain one or more of the following properties:
18
+
19
+ * `scheme` (string)
20
+ Indicates the scheme that the URI should be treated as, overriding the URI's normal scheme parsing behavior.
21
+
22
+ * `reference` (string)
23
+ If set to `"suffix"`, it indicates that the URI is in the suffix format and the parser will use the option's `scheme` property to determine the URI's scheme.
24
+
25
+ * `tolerant` (boolean, false)
26
+ If set to `true`, the parser will relax URI resolving rules.
27
+
28
+ * `absolutePath` (boolean, false)
29
+ If set to `true`, the serializer will not resolve a relative `path` component.
30
+
31
+ * `unicodeSupport` (boolean, false)
32
+ If set to `true`, the parser will unescape non-ASCII characters in the parsed output as per [RFC 3987](http://www.ietf.org/rfc/rfc3987.txt).
33
+
34
+ * `domainHost` (boolean, false)
35
+ If set to `true`, the library will treat the `host` component as a domain name, and convert IDNs (International Domain Names) as per [RFC 5891](http://www.ietf.org/rfc/rfc5891.txt).
36
+
37
+ ### Parse
38
+
39
+ ```js
40
+ const uri = require('fast-uri')
41
+ uri.parse('uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body')
42
+ // Output
43
+ {
44
+ scheme : "uri",
45
+ userinfo : "user:pass",
46
+ host : "example.com",
47
+ port : 123,
48
+ path : "/one/two.three",
49
+ query : "q1=a1&q2=a2",
50
+ fragment : "body"
51
+ }
52
+ ```
53
+
54
+ ### Serialize
55
+
56
+ ```js
57
+ const uri = require('fast-uri')
58
+ uri.serialize({scheme : "http", host : "example.com", fragment : "footer"})
59
+ // Output
60
+ "http://example.com/#footer"
61
+
62
+ ```
63
+
64
+ ### Resolve
65
+
66
+ ```js
67
+ const uri = require('fast-uri')
68
+ uri.resolve("uri://a/b/c/d?q", "../../g")
69
+ // Output
70
+ "uri://a/g"
71
+ ```
72
+
73
+ ### Equal
74
+
75
+ ```js
76
+ const uri = require('fast-uri')
77
+ uri.equal("example://a/b/c/%7Bfoo%7D", "eXAMPLE://a/./b/../b/%63/%7bfoo%7d")
78
+ // Output
79
+ true
80
+ ```
81
+
82
+ ## Scheme supports
83
+
84
+ fast-uri supports inserting custom [scheme](http://en.wikipedia.org/wiki/URI_scheme) dependent processing rules. Currently, fast-uri has built in support for the following schemes:
85
+
86
+ * http \[[RFC 2616](http://www.ietf.org/rfc/rfc2616.txt)\]
87
+ * https \[[RFC 2818](http://www.ietf.org/rfc/rfc2818.txt)\]
88
+ * ws \[[RFC 6455](http://www.ietf.org/rfc/rfc6455.txt)\]
89
+ * wss \[[RFC 6455](http://www.ietf.org/rfc/rfc6455.txt)\]
90
+ * urn \[[RFC 2141](http://www.ietf.org/rfc/rfc2141.txt)\]
91
+ * urn:uuid \[[RFC 4122](http://www.ietf.org/rfc/rfc4122.txt)\]
92
+
93
+
94
+ ## Benchmarks
95
+
96
+ ```
97
+ fast-uri: parse domain x 1,344,963 ops/sec ±0.31% (99 runs sampled)
98
+ urijs: parse domain x 485,273 ops/sec ±0.20% (98 runs sampled)
99
+ fast-uri: parse IPv4 x 2,429,284 ops/sec ±0.18% (98 runs sampled)
100
+ urijs: parse IPv4 x 391,142 ops/sec ±0.11% (99 runs sampled)
101
+ fast-uri: parse IPv6 x 948,434 ops/sec ±0.35% (100 runs sampled)
102
+ urijs: parse IPv6 x 293,538 ops/sec ±0.09% (97 runs sampled)
103
+ fast-uri: parse URN x 2,639,216 ops/sec ±0.10% (99 runs sampled)
104
+ urijs: parse URN x 1,175,357 ops/sec ±0.36% (95 runs sampled)
105
+ fast-uri: parse URN uuid x 1,654,986 ops/sec ±0.15% (97 runs sampled)
106
+ urijs: parse URN uuid x 870,033 ops/sec ±0.43% (96 runs sampled)
107
+ fast-uri: serialize uri x 1,804,227 ops/sec ±0.26% (100 runs sampled)
108
+ urijs: serialize uri x 394,736 ops/sec ±0.21% (99 runs sampled)
109
+ fast-uri: serialize IPv6 x 451,489 ops/sec ±0.11% (100 runs sampled)
110
+ urijs: serialize IPv6 x 263,908 ops/sec ±0.13% (99 runs sampled)
111
+ fast-uri: serialize ws x 1,412,927 ops/sec ±0.49% (96 runs sampled)
112
+ urijs: serialize ws x 353,774 ops/sec ±0.17% (99 runs sampled)
113
+ fast-uri: resolve x 350,311 ops/sec ±0.96% (97 runs sampled)
114
+ urijs: resolve x 228,281 ops/sec ±0.18% (100 runs sampled)
115
+ ```
116
+
117
+ ## TODO
118
+
119
+ - [ ] Support MailTo
120
+ - [ ] Be 100% iso compatible with uri-js
121
+ - [ ] Add browser test stack
package/benchmark.js ADDED
@@ -0,0 +1,88 @@
1
+ const benchmark = require('benchmark')
2
+ const suite = new benchmark.Suite()
3
+ const fasturi = require('./')
4
+ const urijs = require('uri-js')
5
+
6
+ const base = 'uri://a/b/c/d;p?q'
7
+ // Initialization as there is a lot to parse at first
8
+ // eg: regexes
9
+ fasturi.parse('https://example.com')
10
+ urijs.parse('https://example.com')
11
+
12
+ suite.add('fast-uri: parse domain', function () {
13
+ fasturi.parse('https://example.com')
14
+ })
15
+ suite.add('urijs: parse domain', function () {
16
+ urijs.parse('https://example.com')
17
+ })
18
+ suite.add('fast-uri: parse IPv4', function () {
19
+ fasturi.parse('//10.10.10.10')
20
+ })
21
+ suite.add('urijs: parse IPv4', function () {
22
+ urijs.parse('//10.10.10.10')
23
+ })
24
+ suite.add('fast-uri: parse IPv6', function () {
25
+ fasturi.parse('//[2001:db8::7]')
26
+ })
27
+ suite.add('urijs: parse IPv6', function () {
28
+ urijs.parse('//[2001:db8::7]')
29
+ })
30
+ suite.add('fast-uri: parse URN', function () {
31
+ fasturi.parse('urn:foo:a123,456')
32
+ })
33
+ suite.add('urijs: parse URN', function () {
34
+ urijs.parse('urn:foo:a123,456')
35
+ })
36
+ suite.add('fast-uri: parse URN uuid', function () {
37
+ fasturi.parse('urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')
38
+ })
39
+ suite.add('urijs: parse URN uuid', function () {
40
+ urijs.parse('urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')
41
+ })
42
+ suite.add('fast-uri: serialize uri', function () {
43
+ fasturi.serialize({
44
+ scheme: 'uri',
45
+ userinfo: 'foo:bar',
46
+ host: 'example.com',
47
+ port: 1,
48
+ path: 'path',
49
+ query: 'query',
50
+ fragment: 'fragment'
51
+ })
52
+ })
53
+ suite.add('urijs: serialize uri', function () {
54
+ urijs.serialize({
55
+ scheme: 'uri',
56
+ userinfo: 'foo:bar',
57
+ host: 'example.com',
58
+ port: 1,
59
+ path: 'path',
60
+ query: 'query',
61
+ fragment: 'fragment'
62
+ })
63
+ })
64
+ suite.add('fast-uri: serialize IPv6', function () {
65
+ fasturi.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
66
+ })
67
+ suite.add('urijs: serialize IPv6', function () {
68
+ urijs.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
69
+ })
70
+ suite.add('fast-uri: serialize ws', function () {
71
+ fasturi.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
72
+ })
73
+ suite.add('urijs: serialize ws', function () {
74
+ urijs.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
75
+ })
76
+ suite.add('fast-uri: resolve', function () {
77
+ fasturi.resolve(base, '../../../g')
78
+ })
79
+ suite.add('urijs: resolve', function () {
80
+ urijs.resolve(base, '../../../g')
81
+ })
82
+ suite.on('cycle', cycle)
83
+
84
+ suite.run()
85
+
86
+ function cycle (e) {
87
+ console.log(e.target.toString())
88
+ }
package/index.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ export interface URIComponents {
2
+ scheme?: string;
3
+ userinfo?: string;
4
+ host?: string;
5
+ port?: number | string;
6
+ path?: string;
7
+ query?: string;
8
+ fragment?: string;
9
+ reference?: string;
10
+ error?: string;
11
+ }
12
+ export interface options {
13
+ scheme?: string;
14
+ reference?: string;
15
+ unicodeSupport?: boolean;
16
+ domainHost?: boolean;
17
+ absolutePath?: boolean;
18
+ }
19
+
20
+ export function parse(uri: string, opts?: options): URIComponents;
21
+
22
+ export function serialize(component: URIComponents): string;
23
+
24
+ export function equal(uriA: string, uriB:string): boolean;
25
+
26
+ export function resolve(base:string, path:string): string;