This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

159
node_modules/fast-uri/benchmark/benchmark.mjs generated vendored Normal file
View File

@@ -0,0 +1,159 @@
import { Bench } from 'tinybench'
import { fastUri } from '../index.js'
import { parse as uriJsParse, serialize as uriJsSerialize, resolve as uriJsResolve, equal as uriJsEqual } from 'uri-js'
const base = 'uri://a/b/c/d;p?q'
const domain = 'https://example.com/foo#bar$fiz'
const ipv4 = '//10.10.10.10'
const ipv6 = '//[2001:db8::7]'
const urn = 'urn:foo:a123,456'
const urnuuid = 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
const urnuuidComponent = {
scheme: 'urn',
nid: 'uuid',
uuid: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
}
const {
parse: fastUriParse,
serialize: fastUriSerialize,
resolve: fastUriResolve,
equal: fastUriEqual,
} = fastUri
// Initialization as there is a lot to parse at first
// eg: regexes
fastUriParse(domain)
uriJsParse(domain)
const benchFastUri = new Bench({ name: 'fast-uri benchmark' })
const benchUriJs = new Bench({ name: 'uri-js benchmark' })
const benchWHATWG = new Bench({ name: 'WHATWG URL benchmark' })
benchFastUri.add('fast-uri: parse domain', function () {
fastUriParse(domain)
})
benchUriJs.add('urijs: parse domain', function () {
uriJsParse(domain)
})
benchWHATWG.add('WHATWG URL: parse domain', function () {
// eslint-disable-next-line
new URL(domain)
})
benchFastUri.add('fast-uri: parse IPv4', function () {
fastUriParse(ipv4)
})
benchUriJs.add('urijs: parse IPv4', function () {
uriJsParse(ipv4)
})
benchFastUri.add('fast-uri: parse IPv6', function () {
fastUriParse(ipv6)
})
benchUriJs.add('urijs: parse IPv6', function () {
uriJsParse(ipv6)
})
benchFastUri.add('fast-uri: parse URN', function () {
fastUriParse(urn)
})
benchUriJs.add('urijs: parse URN', function () {
uriJsParse(urn)
})
benchWHATWG.add('WHATWG URL: parse URN', function () {
// eslint-disable-next-line
new URL(urn)
})
benchFastUri.add('fast-uri: parse URN uuid', function () {
fastUriParse(urnuuid)
})
benchUriJs.add('urijs: parse URN uuid', function () {
uriJsParse(urnuuid)
})
benchFastUri.add('fast-uri: serialize URN uuid', function () {
fastUriSerialize(urnuuidComponent)
})
benchUriJs.add('uri-js: serialize URN uuid', function () {
uriJsSerialize(urnuuidComponent)
})
benchFastUri.add('fast-uri: serialize uri', function () {
fastUriSerialize({
scheme: 'uri',
userinfo: 'foo:bar',
host: 'example.com',
port: 1,
path: 'path',
query: 'query',
fragment: 'fragment'
})
})
benchUriJs.add('urijs: serialize uri', function () {
uriJsSerialize({
scheme: 'uri',
userinfo: 'foo:bar',
host: 'example.com',
port: 1,
path: 'path',
query: 'query',
fragment: 'fragment'
})
})
benchFastUri.add('fast-uri: serialize long uri with dots', function () {
fastUriSerialize({
scheme: 'uri',
userinfo: 'foo:bar',
host: 'example.com',
port: 1,
path: './a/./b/c/../.././d/../e/f/.././/',
query: 'query',
fragment: 'fragment'
})
})
benchUriJs.add('urijs: serialize long uri with dots', function () {
uriJsSerialize({
scheme: 'uri',
userinfo: 'foo:bar',
host: 'example.com',
port: 1,
path: './a/./b/c/../.././d/../e/f/.././/',
query: 'query',
fragment: 'fragment'
})
})
benchFastUri.add('fast-uri: serialize IPv6', function () {
fastUriSerialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
})
benchUriJs.add('urijs: serialize IPv6', function () {
uriJsSerialize({ host: '2606:2800:220:1:248:1893:25c8:1946' })
})
benchFastUri.add('fast-uri: serialize ws', function () {
fastUriSerialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
})
benchUriJs.add('urijs: serialize ws', function () {
uriJsSerialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true })
})
benchFastUri.add('fast-uri: resolve', function () {
fastUriResolve(base, '../../../g')
})
benchUriJs.add('urijs: resolve', function () {
uriJsResolve(base, '../../../g')
})
benchFastUri.add('fast-uri: equal', function () {
fastUriEqual('example://a/b/c/%7Bfoo%7D', 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d')
})
benchUriJs.add('urijs: equal', function () {
uriJsEqual('example://a/b/c/%7Bfoo%7D', 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d')
})
await benchFastUri.run()
console.log(benchFastUri.name)
console.table(benchFastUri.table())
await benchUriJs.run()
console.log(benchUriJs.name)
console.table(benchUriJs.table())
await benchWHATWG.run()
console.log(benchWHATWG.name)
console.table(benchWHATWG.table())

51
node_modules/fast-uri/benchmark/equal.mjs generated vendored Normal file
View File

@@ -0,0 +1,51 @@
import { Bench } from 'tinybench'
import { fastUri } from '../index.js'
const {
equal: fastUriEqual,
parse: fastUriParse,
} = fastUri
const stringA = 'example://a/b/c/%7Bfoo%7D'
const stringB = 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d'
const componentA = fastUriParse(stringA)
const componentB = fastUriParse(stringB)
const benchFastUri = new Bench({ name: 'fast-uri equal' })
benchFastUri.add('equal string with string', function () {
fastUriEqual(stringA, stringA)
})
benchFastUri.add('equal component with component', function () {
fastUriEqual(componentA, componentA)
})
benchFastUri.add('equal component with string', function () {
fastUriEqual(componentA, stringA)
})
benchFastUri.add('equal string with component', function () {
fastUriEqual(stringA, componentA)
})
benchFastUri.add('not equal string with string', function () {
fastUriEqual(stringA, stringB)
})
benchFastUri.add('not equal component with component', function () {
fastUriEqual(componentA, componentB)
})
benchFastUri.add('not equal component with string', function () {
fastUriEqual(componentA, stringB)
})
benchFastUri.add('not equal string with component', function () {
fastUriEqual(stringA, componentB)
})
await benchFastUri.run()
console.log(benchFastUri.name)
console.table(benchFastUri.table())

22
node_modules/fast-uri/benchmark/non-simple-domain.mjs generated vendored Normal file
View File

@@ -0,0 +1,22 @@
import { Bench } from 'tinybench'
import { nonSimpleDomain } from '../lib/utils.js'
const benchNonSimpleDomain = new Bench({ name: 'nonSimpleDomain' })
const exampleCom = 'example.com'
const exaumlmpleCom = 'exämple.com'
const longDomain = 'abc'.repeat(100) + '.com'
console.assert(nonSimpleDomain(exampleCom) === false, 'example.com should be a simple domain')
console.assert(nonSimpleDomain(exaumlmpleCom) === true, 'exämple.com should not be a simple domain')
console.assert(nonSimpleDomain(longDomain) === false, `${longDomain} should be a simple domain?`)
benchNonSimpleDomain.add('nonSimpleDomain', function () {
nonSimpleDomain(exampleCom)
nonSimpleDomain(exaumlmpleCom)
nonSimpleDomain(longDomain)
})
await benchNonSimpleDomain.run()
console.log(benchNonSimpleDomain.name)
console.table(benchNonSimpleDomain.table())

17
node_modules/fast-uri/benchmark/package.json generated vendored Normal file
View File

@@ -0,0 +1,17 @@
{
"name": "benchmark",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": true,
"scripts": {
"bench": "node benchmark.mjs"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"tinybench": "^5.0.0",
"uri-js": "^4.4.1"
}
}

View File

@@ -0,0 +1,24 @@
import { Bench } from 'tinybench'
import { stringArrayToHexStripped } from '../lib/utils.js'
const benchStringArrayToHexStripped = new Bench({ name: 'stringArrayToHexStripped' })
const case1 = ['0', '0', '0', '0']
const case2 = ['0', '0', '0', '1']
const case3 = ['0', '0', '1', '0']
const case4 = ['0', '1', '0', '0']
const case5 = ['1', '0', '0', '0']
const case6 = ['1', '0', '0', '1']
benchStringArrayToHexStripped.add('stringArrayToHexStripped', function () {
stringArrayToHexStripped(case1)
stringArrayToHexStripped(case2)
stringArrayToHexStripped(case3)
stringArrayToHexStripped(case4)
stringArrayToHexStripped(case5)
stringArrayToHexStripped(case6)
})
await benchStringArrayToHexStripped.run()
console.log(benchStringArrayToHexStripped.name)
console.table(benchStringArrayToHexStripped.table())

65
node_modules/fast-uri/benchmark/ws-is-secure.mjs generated vendored Normal file
View File

@@ -0,0 +1,65 @@
import { Bench } from 'tinybench'
import { wsIsSecure } from '../lib/schemes.js'
const benchWsIsSecure = new Bench({ name: 'wsIsSecure' })
const wsComponentAttributeSecureTrue = {
scheme: 'ws',
secure: true,
}
const wsComponentAttributeSecureFalse = {
scheme: 'ws',
secure: false,
}
const wssComponent = {
scheme: 'wss',
}
const wssComponentMixedCase = {
scheme: 'Wss',
}
const wssComponentUpperCase = {
scheme: 'WSS',
}
const httpComponent = {
scheme: 'http',
}
console.assert(wsIsSecure(wsComponentAttributeSecureTrue) === true, 'wsComponentAttributeSecureTrue should be secure')
console.assert(wsIsSecure(wsComponentAttributeSecureFalse) === false, 'wsComponentAttributeSecureFalse should not be secure')
console.assert(wsIsSecure(wssComponent) === true, 'wssComponent should be secure')
console.assert(wsIsSecure(wssComponentMixedCase) === true, 'wssComponentMixedCase should be secure')
console.assert(wsIsSecure(wssComponentUpperCase) === true, 'wssComponentUpperCase should be secure')
console.assert(wsIsSecure(httpComponent) === false, 'httpComponent should not be secure')
benchWsIsSecure.add(JSON.stringify(wsComponentAttributeSecureFalse), function () {
wsIsSecure(wsComponentAttributeSecureFalse)
})
benchWsIsSecure.add(JSON.stringify(wsComponentAttributeSecureTrue), function () {
wsIsSecure(wsComponentAttributeSecureTrue)
})
benchWsIsSecure.add(JSON.stringify(wssComponent), function () {
wsIsSecure(wssComponent)
})
benchWsIsSecure.add(JSON.stringify(wssComponentMixedCase), function () {
wsIsSecure(wssComponentMixedCase)
})
benchWsIsSecure.add(JSON.stringify(wssComponentUpperCase), function () {
wsIsSecure(wssComponentUpperCase)
})
benchWsIsSecure.add(JSON.stringify(httpComponent), function () {
wsIsSecure(httpComponent)
})
await benchWsIsSecure.run()
console.log(benchWsIsSecure.name)
console.table(benchWsIsSecure.table())