fast-uri 3.0.6 → 3.1.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.
@@ -4,7 +4,6 @@ on:
4
4
  push:
5
5
  branches:
6
6
  - main
7
- - master
8
7
  - next
9
8
  - 'v*'
10
9
  paths-ignore:
@@ -15,16 +14,26 @@ on:
15
14
  - 'docs/**'
16
15
  - '*.md'
17
16
 
17
+ # This allows a subsequently queued workflow run to interrupt previous runs
18
+ concurrency:
19
+ group: "${{ github.workflow }}-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
20
+ cancel-in-progress: true
21
+
22
+ permissions:
23
+ contents: read
24
+
18
25
  jobs:
19
26
  test-regression-check-node10:
20
27
  name: Test compatibility with Node.js 10
21
28
  runs-on: ubuntu-latest
29
+ permissions:
30
+ contents: read
22
31
  steps:
23
- - uses: actions/checkout@v4
32
+ - uses: actions/checkout@v6
24
33
  with:
25
34
  persist-credentials: false
26
35
 
27
- - uses: actions/setup-node@v4
36
+ - uses: actions/setup-node@v6
28
37
  with:
29
38
  node-version: '10'
30
39
  cache: 'npm'
@@ -48,11 +57,50 @@ jobs:
48
57
  env:
49
58
  NODE_OPTIONS: no-network-family-autoselection
50
59
 
60
+ test-browser:
61
+ name: Test browser compatibility
62
+ runs-on: ${{ matrix.os }}
63
+ strategy:
64
+ fail-fast: false
65
+ matrix:
66
+ os: ['ubuntu-latest', 'windows-latest', 'macos-latest']
67
+ browser: ['chromium', 'firefox', 'webkit']
68
+ exclude:
69
+ - os: ubuntu-latest
70
+ browser: webkit
71
+ permissions:
72
+ contents: read
73
+ steps:
74
+ - uses: actions/checkout@v6
75
+ with:
76
+ persist-credentials: false
77
+
78
+ - uses: actions/setup-node@v6
79
+ with:
80
+ node-version: '24'
81
+ cache: 'npm'
82
+ cache-dependency-path: package.json
83
+ check-latest: true
84
+
85
+ - name: Install dependencies
86
+ run: |
87
+ npm install --ignore-scripts
88
+
89
+ - if: ${{ matrix.os == 'windows-latest' }}
90
+ run: npx playwright install winldd
91
+
92
+ - name: Run browser tests
93
+ run: |
94
+ npm run test:browser:${{ matrix.browser }}
95
+
51
96
  test:
52
97
  needs:
53
98
  - test-regression-check-node10
54
- uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
99
+ permissions:
100
+ contents: write
101
+ pull-requests: write
102
+ uses: fastify/workflows/.github/workflows/plugins-ci.yml@v6
55
103
  with:
56
104
  license-check: true
57
105
  lint: true
58
- node-versions: '["16", "18", "20", "22"]'
106
+ node-versions: '["16", "18", "20", "22", "24"]'
@@ -0,0 +1,19 @@
1
+ name: Lock Threads
2
+
3
+ on:
4
+ schedule:
5
+ - cron: '0 0 1 * *'
6
+ workflow_dispatch:
7
+
8
+ concurrency:
9
+ group: lock
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ lock-threads:
16
+ permissions:
17
+ issues: write
18
+ pull-requests: write
19
+ uses: fastify/workflows/.github/workflows/lock-threads.yml@v6
@@ -4,7 +4,6 @@ on:
4
4
  push:
5
5
  branches:
6
6
  - main
7
- - master
8
7
  - next
9
8
  - 'v*'
10
9
  paths-ignore:
@@ -15,6 +14,11 @@ on:
15
14
  - 'docs/**'
16
15
  - '*.md'
17
16
 
17
+ permissions:
18
+ contents: read
19
+
18
20
  jobs:
19
21
  test:
20
- uses: fastify/workflows/.github/workflows/plugins-ci-package-manager.yml@v5
22
+ permissions:
23
+ contents: read
24
+ uses: fastify/workflows/.github/workflows/plugins-ci-package-manager.yml@v6
package/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
- Copyright (c) 2021 The Fastify Team
2
1
  Copyright (c) 2011-2021, Gary Court until https://github.com/garycourt/uri-js/commit/a1acf730b4bba3f1097c9f52e7d9d3aba8cdcaae
2
+ Copyright (c) 2021-present The Fastify team <https://github.com/fastify/fastify#team>
3
3
  All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
package/README.md CHANGED
@@ -1,13 +1,9 @@
1
1
  # fast-uri
2
2
 
3
- <div align="center">
4
-
5
3
  [![NPM version](https://img.shields.io/npm/v/fast-uri.svg?style=flat)](https://www.npmjs.com/package/fast-uri)
6
4
  [![CI](https://github.com/fastify/fast-uri/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fast-uri/actions/workflows/ci.yml)
7
5
  [![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
8
6
 
9
- </div>
10
-
11
7
  Dependency-free RFC 3986 URI toolbox.
12
8
 
13
9
  ## Usage
@@ -70,6 +66,17 @@ uri.resolve("uri://a/b/c/d?q", "../../g")
70
66
  "uri://a/g"
71
67
  ```
72
68
 
69
+ ### Normalize
70
+
71
+ ```js
72
+ const uri = require('fast-uri')
73
+ uri.normalize('http://example.com/a%2Fb')
74
+ // Output
75
+ "http://example.com/a%2Fb"
76
+ ```
77
+
78
+ Reserved path escapes such as `%2F` and `%2E` are preserved as path data during normalization and comparison.
79
+
73
80
  ### Equal
74
81
 
75
82
  ```js
@@ -94,36 +101,49 @@ fast-uri supports inserting custom [scheme](http://en.wikipedia.org/wiki/URI_sch
94
101
  ## Benchmarks
95
102
 
96
103
  ```
97
- fast-uri: parse domain x 1,306,864 ops/sec ±0.31% (100 runs sampled)
98
- urijs: parse domain x 483,001 ops/sec ±0.09% (99 runs sampled)
99
- WHATWG URL: parse domain x 862,461 ops/sec ±0.18% (97 runs sampled)
100
- fast-uri: parse IPv4 x 2,381,452 ops/sec ±0.26% (96 runs sampled)
101
- urijs: parse IPv4 x 384,705 ops/sec ±0.34% (99 runs sampled)
102
- WHATWG URL: parse IPv4 NOT SUPPORTED
103
- fast-uri: parse IPv6 x 923,519 ops/sec ±0.09% (100 runs sampled)
104
- urijs: parse IPv6 x 289,070 ops/sec ±0.07% (95 runs sampled)
105
- WHATWG URL: parse IPv6 NOT SUPPORTED
106
- fast-uri: parse URN x 2,596,395 ops/sec ±0.42% (98 runs sampled)
107
- urijs: parse URN x 1,152,412 ops/sec ±0.09% (97 runs sampled)
108
- WHATWG URL: parse URN x 1,183,307 ops/sec ±0.38% (100 runs sampled)
109
- fast-uri: parse URN uuid x 1,666,861 ops/sec ±0.10% (98 runs sampled)
110
- urijs: parse URN uuid x 852,724 ops/sec ±0.17% (95 runs sampled)
111
- WHATWG URL: parse URN uuid NOT SUPPORTED
112
- fast-uri: serialize uri x 1,741,499 ops/sec ±0.57% (95 runs sampled)
113
- urijs: serialize uri x 389,014 ops/sec ±0.28% (93 runs sampled)
114
- fast-uri: serialize IPv6 x 441,095 ops/sec ±0.37% (97 runs sampled)
115
- urijs: serialize IPv6 x 255,443 ops/sec ±0.58% (94 runs sampled)
116
- fast-uri: serialize ws x 1,448,667 ops/sec ±0.25% (97 runs sampled)
117
- urijs: serialize ws x 352,884 ops/sec ±0.08% (96 runs sampled)
118
- fast-uri: resolve x 340,084 ops/sec ±0.98% (98 runs sampled)
119
- urijs: resolve x 225,759 ops/sec ±0.37% (95 runs sampled)
104
+ fast-uri benchmark
105
+ ┌─────────┬──────────────────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
106
+ │ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
107
+ ├─────────┼──────────────────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
108
+ │ 0 │ 'fast-uri: parse domain' │ '951.31 ± 0.75%' │ '875.00 ± 11.00' │ '1122538 ± 0.01%' │ '1142857 ± 14550' │ 1051187 │
109
+ │ 1 │ 'fast-uri: parse IPv4' │ '443.44 ± 0.22%' │ '406.00 ± 3.00' │ '2422762 ± 0.01%' │ '2463054 ± 18335' │ 2255105 │
110
+ │ 2 │ 'fast-uri: parse IPv6' │ '1241.6 ± 1.74%' │ '1131.0 ± 30.00' │ '875177 ± 0.02%' │ '884173 ± 24092' │ 805399 │
111
+ │ 3 │ 'fast-uri: parse URN' │ '689.19 ± 4.29%' │ '618.00 ± 9.00' │ '1598373 ± 0.01%' │ '1618123 ± 23913' │ 1450972 │
112
+ │ 4 │ 'fast-uri: parse URN uuid' │ '1025.4 ± 2.02%' │ '921.00 ± 19.00' │ '1072419 ± 0.02%' │ '1085776 ± 22871' │ 975236 │
113
+ │ 5 │ 'fast-uri: serialize uri' │ '1028.5 ± 0.53%' │ '933.00 ± 43.00' │ '1063310 ± 0.02%' │ '1071811 ± 50523' │ 972249 │
114
+ │ 6 │ 'fast-uri: serialize long uri with dots' │ '1805.1 ± 0.52%' │ '1627.0 ± 17.00' │ '602620 ± 0.02%' │ '614628 ± 6490' │ 553997 │
115
+ │ 7 │ 'fast-uri: serialize IPv6' │ '2569.4 ± 2.69%' │ '2302.0 ± 21.00' │ '426080 ± 0.03%' │ '434405 ± 3999' │ 389194 │
116
+ │ 8 │ 'fast-uri: serialize ws' │ '979.39 ± 0.43%' │ '882.00 ± 8.00' │ '1111665 ± 0.02%' │ '1133787 ± 10378' │ 1021045 │
117
+ │ 9 │ 'fast-uri: resolve' │ '2208.2 ± 1.08%' │ '1980.0 ± 24.00' │ '495001 ± 0.03%' │ '505051 ± 6049' │ 452848 │
118
+ └─────────┴──────────────────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
119
+ uri-js benchmark
120
+ ┌─────────┬───────────────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
121
+ │ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
122
+ ├─────────┼───────────────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
123
+ │ 0 │ 'urijs: parse domain' │ '3618.3 ± 0.43%' │ '3314.0 ± 33.00' │ '294875 ± 0.04%' │ '301750 ± 2975' │ 276375 │
124
+ │ 1 │ 'urijs: parse IPv4' │ '4024.1 ± 0.41%' │ '3751.0 ± 25.00' │ '261981 ± 0.04%' │ '266596 ± 1789' │ 248506 │
125
+ │ 2 │ 'urijs: parse IPv6' │ '5417.2 ± 0.46%' │ '4968.0 ± 43.00' │ '196023 ± 0.05%' │ '201288 ± 1727' │ 184598 │
126
+ │ 3 │ 'urijs: parse URN' │ '1324.2 ± 0.23%' │ '1229.0 ± 17.00' │ '801535 ± 0.02%' │ '813670 ± 11413' │ 755185 │
127
+ │ 4 │ 'urijs: parse URN uuid' │ '1822.0 ± 3.08%' │ '1655.0 ± 15.00' │ '594433 ± 0.02%' │ '604230 ± 5427' │ 548843 │
128
+ │ 5 │ 'urijs: serialize uri' │ '4196.8 ± 0.36%' │ '3908.0 ± 27.00' │ '251146 ± 0.04%' │ '255885 ± 1756' │ 238276 │
129
+ │ 6 │ 'urijs: serialize long uri with dots' │ '8331.0 ± 1.30%' │ '7658.0 ± 72.00' │ '126440 ± 0.07%' │ '130582 ± 1239' │ 120034 │
130
+ │ 7 │ 'urijs: serialize IPv6' │ '5685.5 ± 0.30%' │ '5366.0 ± 33.00' │ '182632 ± 0.05%' │ '186359 ± 1153' │ 175886 │
131
+ │ 8 │ 'urijs: serialize ws' │ '4159.3 ± 0.20%' │ '3899.0 ± 28.00' │ '250459 ± 0.04%' │ '256476 ± 1855' │ 240423 │
132
+ │ 9 │ 'urijs: resolve' │ '6729.9 ± 0.39%' │ '6261.0 ± 37.00' │ '156361 ± 0.06%' │ '159719 ± 949' │ 148591 │
133
+ └─────────┴───────────────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
134
+ WHATWG URL benchmark
135
+ ┌─────────┬────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
136
+ │ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
137
+ ├─────────┼────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
138
+ │ 0 │ 'WHATWG URL: parse domain' │ '475.22 ± 0.20%' │ '444.00 ± 5.00' │ '2217599 ± 0.01%' │ '2252252 ± 25652' │ 2104289 │
139
+ │ 1 │ 'WHATWG URL: parse URN' │ '384.78 ± 0.85%' │ '350.00 ± 5.00' │ '2809071 ± 0.01%' │ '2857143 ± 41408' │ 2598885 │
140
+ └─────────┴────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
120
141
  ```
121
142
 
122
143
  ## TODO
123
144
 
124
145
  - [ ] Support MailTo
125
146
  - [ ] Be 100% iso compatible with uri-js
126
- - [ ] Add browser test stack
127
147
 
128
148
  ## License
129
149
 
@@ -0,0 +1,159 @@
1
+ import { Bench } from 'tinybench'
2
+ import { fastUri } from '../index.js'
3
+ import { parse as uriJsParse, serialize as uriJsSerialize, resolve as uriJsResolve, equal as uriJsEqual } from 'uri-js'
4
+
5
+ const base = 'uri://a/b/c/d;p?q'
6
+
7
+ const domain = 'https://example.com/foo#bar$fiz'
8
+ const ipv4 = '//10.10.10.10'
9
+ const ipv6 = '//[2001:db8::7]'
10
+ const urn = 'urn:foo:a123,456'
11
+ const urnuuid = 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
12
+
13
+ const urnuuidComponent = {
14
+ scheme: 'urn',
15
+ nid: 'uuid',
16
+ uuid: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
17
+ }
18
+
19
+ const {
20
+ parse: fastUriParse,
21
+ serialize: fastUriSerialize,
22
+ resolve: fastUriResolve,
23
+ equal: fastUriEqual,
24
+ } = fastUri
25
+
26
+ // Initialization as there is a lot to parse at first
27
+ // eg: regexes
28
+ fastUriParse(domain)
29
+ uriJsParse(domain)
30
+
31
+ const benchFastUri = new Bench({ name: 'fast-uri benchmark' })
32
+ const benchUriJs = new Bench({ name: 'uri-js benchmark' })
33
+ const benchWHATWG = new Bench({ name: 'WHATWG URL benchmark' })
34
+
35
+ benchFastUri.add('fast-uri: parse domain', function () {
36
+ fastUriParse(domain)
37
+ })
38
+ benchUriJs.add('urijs: parse domain', function () {
39
+ uriJsParse(domain)
40
+ })
41
+ benchWHATWG.add('WHATWG URL: parse domain', function () {
42
+ // eslint-disable-next-line
43
+ new URL(domain)
44
+ })
45
+ benchFastUri.add('fast-uri: parse IPv4', function () {
46
+ fastUriParse(ipv4)
47
+ })
48
+ benchUriJs.add('urijs: parse IPv4', function () {
49
+ uriJsParse(ipv4)
50
+ })
51
+ benchFastUri.add('fast-uri: parse IPv6', function () {
52
+ fastUriParse(ipv6)
53
+ })
54
+ benchUriJs.add('urijs: parse IPv6', function () {
55
+ uriJsParse(ipv6)
56
+ })
57
+ benchFastUri.add('fast-uri: parse URN', function () {
58
+ fastUriParse(urn)
59
+ })
60
+ benchUriJs.add('urijs: parse URN', function () {
61
+ uriJsParse(urn)
62
+ })
63
+ benchWHATWG.add('WHATWG URL: parse URN', function () {
64
+ // eslint-disable-next-line
65
+ new URL(urn)
66
+ })
67
+ benchFastUri.add('fast-uri: parse URN uuid', function () {
68
+ fastUriParse(urnuuid)
69
+ })
70
+ benchUriJs.add('urijs: parse URN uuid', function () {
71
+ uriJsParse(urnuuid)
72
+ })
73
+ benchFastUri.add('fast-uri: serialize URN uuid', function () {
74
+ fastUriSerialize(urnuuidComponent)
75
+ })
76
+ benchUriJs.add('uri-js: serialize URN uuid', function () {
77
+ uriJsSerialize(urnuuidComponent)
78
+ })
79
+ benchFastUri.add('fast-uri: serialize uri', function () {
80
+ fastUriSerialize({
81
+ scheme: 'uri',
82
+ userinfo: 'foo:bar',
83
+ host: 'example.com',
84
+ port: 1,
85
+ path: 'path',
86
+ query: 'query',
87
+ fragment: 'fragment'
88
+ })
89
+ })
90
+ benchUriJs.add('urijs: serialize uri', function () {
91
+ uriJsSerialize({
92
+ scheme: 'uri',
93
+ userinfo: 'foo:bar',
94
+ host: 'example.com',
95
+ port: 1,
96
+ path: 'path',
97
+ query: 'query',
98
+ fragment: 'fragment'
99
+ })
100
+ })
101
+ benchFastUri.add('fast-uri: serialize long uri with dots', function () {
102
+ fastUriSerialize({
103
+ scheme: 'uri',
104
+ userinfo: 'foo:bar',
105
+ host: 'example.com',
106
+ port: 1,
107
+ path: './a/./b/c/../.././d/../e/f/.././/',
108
+ query: 'query',
109
+ fragment: 'fragment'
110
+ })
111
+ })
112
+ benchUriJs.add('urijs: serialize long uri with dots', function () {
113
+ uriJsSerialize({
114
+ scheme: 'uri',
115
+ userinfo: 'foo:bar',
116
+ host: 'example.com',
117
+ port: 1,
118
+ path: './a/./b/c/../.././d/../e/f/.././/',
119
+ query: 'query',
120
+ fragment: 'fragment'
121
+ })
122
+ })
123
+ benchFastUri.add('fast-uri: serialize IPv6', function () {
124
+ fastUriSerialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
125
+ })
126
+ benchUriJs.add('urijs: serialize IPv6', function () {
127
+ uriJsSerialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
128
+ })
129
+ benchFastUri.add('fast-uri: serialize ws', function () {
130
+ fastUriSerialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
131
+ })
132
+ benchUriJs.add('urijs: serialize ws', function () {
133
+ uriJsSerialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
134
+ })
135
+ benchFastUri.add('fast-uri: resolve', function () {
136
+ fastUriResolve(base, '../../../g')
137
+ })
138
+ benchUriJs.add('urijs: resolve', function () {
139
+ uriJsResolve(base, '../../../g')
140
+ })
141
+
142
+ benchFastUri.add('fast-uri: equal', function () {
143
+ fastUriEqual('example://a/b/c/%7Bfoo%7D', 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d')
144
+ })
145
+ benchUriJs.add('urijs: equal', function () {
146
+ uriJsEqual('example://a/b/c/%7Bfoo%7D', 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d')
147
+ })
148
+
149
+ await benchFastUri.run()
150
+ console.log(benchFastUri.name)
151
+ console.table(benchFastUri.table())
152
+
153
+ await benchUriJs.run()
154
+ console.log(benchUriJs.name)
155
+ console.table(benchUriJs.table())
156
+
157
+ await benchWHATWG.run()
158
+ console.log(benchWHATWG.name)
159
+ console.table(benchWHATWG.table())
@@ -0,0 +1,51 @@
1
+ import { Bench } from 'tinybench'
2
+ import { fastUri } from '../index.js'
3
+
4
+ const {
5
+ equal: fastUriEqual,
6
+ parse: fastUriParse,
7
+ } = fastUri
8
+
9
+ const stringA = 'example://a/b/c/%7Bfoo%7D'
10
+ const stringB = 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d'
11
+
12
+ const componentA = fastUriParse(stringA)
13
+ const componentB = fastUriParse(stringB)
14
+
15
+ const benchFastUri = new Bench({ name: 'fast-uri equal' })
16
+
17
+ benchFastUri.add('equal string with string', function () {
18
+ fastUriEqual(stringA, stringA)
19
+ })
20
+
21
+ benchFastUri.add('equal component with component', function () {
22
+ fastUriEqual(componentA, componentA)
23
+ })
24
+
25
+ benchFastUri.add('equal component with string', function () {
26
+ fastUriEqual(componentA, stringA)
27
+ })
28
+
29
+ benchFastUri.add('equal string with component', function () {
30
+ fastUriEqual(stringA, componentA)
31
+ })
32
+
33
+ benchFastUri.add('not equal string with string', function () {
34
+ fastUriEqual(stringA, stringB)
35
+ })
36
+
37
+ benchFastUri.add('not equal component with component', function () {
38
+ fastUriEqual(componentA, componentB)
39
+ })
40
+
41
+ benchFastUri.add('not equal component with string', function () {
42
+ fastUriEqual(componentA, stringB)
43
+ })
44
+
45
+ benchFastUri.add('not equal string with component', function () {
46
+ fastUriEqual(stringA, componentB)
47
+ })
48
+
49
+ await benchFastUri.run()
50
+ console.log(benchFastUri.name)
51
+ console.table(benchFastUri.table())
@@ -0,0 +1,22 @@
1
+ import { Bench } from 'tinybench'
2
+ import { nonSimpleDomain } from '../lib/utils.js'
3
+
4
+ const benchNonSimpleDomain = new Bench({ name: 'nonSimpleDomain' })
5
+
6
+ const exampleCom = 'example.com'
7
+ const exaumlmpleCom = 'exämple.com'
8
+ const longDomain = 'abc'.repeat(100) + '.com'
9
+
10
+ console.assert(nonSimpleDomain(exampleCom) === false, 'example.com should be a simple domain')
11
+ console.assert(nonSimpleDomain(exaumlmpleCom) === true, 'exämple.com should not be a simple domain')
12
+ console.assert(nonSimpleDomain(longDomain) === false, `${longDomain} should be a simple domain?`)
13
+
14
+ benchNonSimpleDomain.add('nonSimpleDomain', function () {
15
+ nonSimpleDomain(exampleCom)
16
+ nonSimpleDomain(exaumlmpleCom)
17
+ nonSimpleDomain(longDomain)
18
+ })
19
+
20
+ await benchNonSimpleDomain.run()
21
+ console.log(benchNonSimpleDomain.name)
22
+ console.table(benchNonSimpleDomain.table())
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "benchmark",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "private": true,
7
+ "scripts": {
8
+ "bench": "node benchmark.mjs"
9
+ },
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "tinybench": "^5.0.0",
15
+ "uri-js": "^4.4.1"
16
+ }
17
+ }
@@ -0,0 +1,24 @@
1
+ import { Bench } from 'tinybench'
2
+ import { stringArrayToHexStripped } from '../lib/utils.js'
3
+
4
+ const benchStringArrayToHexStripped = new Bench({ name: 'stringArrayToHexStripped' })
5
+
6
+ const case1 = ['0', '0', '0', '0']
7
+ const case2 = ['0', '0', '0', '1']
8
+ const case3 = ['0', '0', '1', '0']
9
+ const case4 = ['0', '1', '0', '0']
10
+ const case5 = ['1', '0', '0', '0']
11
+ const case6 = ['1', '0', '0', '1']
12
+
13
+ benchStringArrayToHexStripped.add('stringArrayToHexStripped', function () {
14
+ stringArrayToHexStripped(case1)
15
+ stringArrayToHexStripped(case2)
16
+ stringArrayToHexStripped(case3)
17
+ stringArrayToHexStripped(case4)
18
+ stringArrayToHexStripped(case5)
19
+ stringArrayToHexStripped(case6)
20
+ })
21
+
22
+ await benchStringArrayToHexStripped.run()
23
+ console.log(benchStringArrayToHexStripped.name)
24
+ console.table(benchStringArrayToHexStripped.table())
@@ -0,0 +1,65 @@
1
+ import { Bench } from 'tinybench'
2
+ import { wsIsSecure } from '../lib/schemes.js'
3
+
4
+ const benchWsIsSecure = new Bench({ name: 'wsIsSecure' })
5
+
6
+ const wsComponentAttributeSecureTrue = {
7
+ scheme: 'ws',
8
+ secure: true,
9
+ }
10
+
11
+ const wsComponentAttributeSecureFalse = {
12
+ scheme: 'ws',
13
+ secure: false,
14
+ }
15
+
16
+ const wssComponent = {
17
+ scheme: 'wss',
18
+ }
19
+
20
+ const wssComponentMixedCase = {
21
+ scheme: 'Wss',
22
+ }
23
+
24
+ const wssComponentUpperCase = {
25
+ scheme: 'WSS',
26
+ }
27
+
28
+ const httpComponent = {
29
+ scheme: 'http',
30
+ }
31
+
32
+ console.assert(wsIsSecure(wsComponentAttributeSecureTrue) === true, 'wsComponentAttributeSecureTrue should be secure')
33
+ console.assert(wsIsSecure(wsComponentAttributeSecureFalse) === false, 'wsComponentAttributeSecureFalse should not be secure')
34
+ console.assert(wsIsSecure(wssComponent) === true, 'wssComponent should be secure')
35
+ console.assert(wsIsSecure(wssComponentMixedCase) === true, 'wssComponentMixedCase should be secure')
36
+ console.assert(wsIsSecure(wssComponentUpperCase) === true, 'wssComponentUpperCase should be secure')
37
+ console.assert(wsIsSecure(httpComponent) === false, 'httpComponent should not be secure')
38
+
39
+ benchWsIsSecure.add(JSON.stringify(wsComponentAttributeSecureFalse), function () {
40
+ wsIsSecure(wsComponentAttributeSecureFalse)
41
+ })
42
+
43
+ benchWsIsSecure.add(JSON.stringify(wsComponentAttributeSecureTrue), function () {
44
+ wsIsSecure(wsComponentAttributeSecureTrue)
45
+ })
46
+
47
+ benchWsIsSecure.add(JSON.stringify(wssComponent), function () {
48
+ wsIsSecure(wssComponent)
49
+ })
50
+
51
+ benchWsIsSecure.add(JSON.stringify(wssComponentMixedCase), function () {
52
+ wsIsSecure(wssComponentMixedCase)
53
+ })
54
+
55
+ benchWsIsSecure.add(JSON.stringify(wssComponentUpperCase), function () {
56
+ wsIsSecure(wssComponentUpperCase)
57
+ })
58
+
59
+ benchWsIsSecure.add(JSON.stringify(httpComponent), function () {
60
+ wsIsSecure(httpComponent)
61
+ })
62
+
63
+ await benchWsIsSecure.run()
64
+ console.log(benchWsIsSecure.name)
65
+ console.table(benchWsIsSecure.table())