mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-14 02:00:37 +08:00
Refactor: drop punycode.js
This commit is contained in:
parent
c848f9c5b6
commit
02a2302210
@ -8,7 +8,7 @@ import { noop } from 'foxts/noop';
|
|||||||
import { fastStringArrayJoin } from 'foxts/fast-string-array-join';
|
import { fastStringArrayJoin } from 'foxts/fast-string-array-join';
|
||||||
|
|
||||||
import { deleteBit, getBit, missingBit, setBit } from 'foxts/bitwise';
|
import { deleteBit, getBit, missingBit, setBit } from 'foxts/bitwise';
|
||||||
import { toASCII } from 'punycode/';
|
import { domainToASCII } from 'node:url';
|
||||||
|
|
||||||
const START = 1 << 1;
|
const START = 1 << 1;
|
||||||
const INCLUDE_ALL_SUBDOMAIN = 1 << 2;
|
const INCLUDE_ALL_SUBDOMAIN = 1 << 2;
|
||||||
@ -320,13 +320,13 @@ abstract class Triebase<Meta = unknown> {
|
|||||||
|
|
||||||
const onMatches = subdomainOnly
|
const onMatches = subdomainOnly
|
||||||
? (suffix: string[], subdomain: boolean) => { // fast path (default option)
|
? (suffix: string[], subdomain: boolean) => { // fast path (default option)
|
||||||
const d = toASCII(fastStringArrayJoin(suffix, '.'));
|
const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
|
||||||
if (!subdomain && subStringEqual(inputSuffix, d, 1)) return;
|
if (!subdomain && subStringEqual(inputSuffix, d, 1)) return;
|
||||||
|
|
||||||
results.push(subdomain ? '.' + d : d);
|
results.push(subdomain ? '.' + d : d);
|
||||||
}
|
}
|
||||||
: (suffix: string[], subdomain: boolean) => { // fast path (default option)
|
: (suffix: string[], subdomain: boolean) => { // fast path (default option)
|
||||||
const d = toASCII(fastStringArrayJoin(suffix, '.'));
|
const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
|
||||||
results.push(subdomain ? '.' + d : d);
|
results.push(subdomain ? '.' + d : d);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -380,7 +380,7 @@ abstract class Triebase<Meta = unknown> {
|
|||||||
|
|
||||||
public dumpWithoutDot(onSuffix: (suffix: string, subdomain: boolean) => void, withSort = false) {
|
public dumpWithoutDot(onSuffix: (suffix: string, subdomain: boolean) => void, withSort = false) {
|
||||||
const handleSuffix = (suffix: string[], subdomain: boolean) => {
|
const handleSuffix = (suffix: string[], subdomain: boolean) => {
|
||||||
onSuffix(toASCII(fastStringArrayJoin(suffix, '.')), subdomain);
|
onSuffix(domainToASCII(fastStringArrayJoin(suffix, '.')), subdomain);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.walk(handleSuffix, withSort);
|
this.walk(handleSuffix, withSort);
|
||||||
@ -393,11 +393,11 @@ abstract class Triebase<Meta = unknown> {
|
|||||||
|
|
||||||
const handleSuffix = onSuffix
|
const handleSuffix = onSuffix
|
||||||
? (suffix: string[], subdomain: boolean) => {
|
? (suffix: string[], subdomain: boolean) => {
|
||||||
const d = toASCII(fastStringArrayJoin(suffix, '.'));
|
const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
|
||||||
onSuffix(subdomain ? '.' + d : d);
|
onSuffix(subdomain ? '.' + d : d);
|
||||||
}
|
}
|
||||||
: (suffix: string[], subdomain: boolean) => {
|
: (suffix: string[], subdomain: boolean) => {
|
||||||
const d = toASCII(fastStringArrayJoin(suffix, '.'));
|
const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
|
||||||
results.push(subdomain ? '.' + d : d);
|
results.push(subdomain ? '.' + d : d);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -427,11 +427,11 @@ abstract class Triebase<Meta = unknown> {
|
|||||||
|
|
||||||
const handleSuffix = onSuffix
|
const handleSuffix = onSuffix
|
||||||
? (suffix: string[], subdomain: boolean, meta: Meta | undefined) => {
|
? (suffix: string[], subdomain: boolean, meta: Meta | undefined) => {
|
||||||
const d = toASCII(fastStringArrayJoin(suffix, '.'));
|
const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
|
||||||
return onSuffix(subdomain ? '.' + d : d, meta);
|
return onSuffix(subdomain ? '.' + d : d, meta);
|
||||||
}
|
}
|
||||||
: (suffix: string[], subdomain: boolean, meta: Meta | undefined) => {
|
: (suffix: string[], subdomain: boolean, meta: Meta | undefined) => {
|
||||||
const d = toASCII(fastStringArrayJoin(suffix, '.'));
|
const d = domainToASCII(fastStringArrayJoin(suffix, '.'));
|
||||||
results.push([subdomain ? '.' + d : d, meta]);
|
results.push([subdomain ? '.' + d : d, meta]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,6 @@
|
|||||||
"json-stringify-pretty-compact": "3.0.0",
|
"json-stringify-pretty-compact": "3.0.0",
|
||||||
"null-prototype-object": "^1.2.3",
|
"null-prototype-object": "^1.2.3",
|
||||||
"picocolors": "^1.1.1",
|
"picocolors": "^1.1.1",
|
||||||
"punycode": "^2.3.1",
|
|
||||||
"tar-fs": "^3.1.1",
|
"tar-fs": "^3.1.1",
|
||||||
"telegram": "^2.26.22",
|
"telegram": "^2.26.22",
|
||||||
"tldts": "^7.0.17",
|
"tldts": "^7.0.17",
|
||||||
@ -58,7 +57,6 @@
|
|||||||
"@types/dns2": "^2.0.10",
|
"@types/dns2": "^2.0.10",
|
||||||
"@types/mocha": "^10.0.10",
|
"@types/mocha": "^10.0.10",
|
||||||
"@types/node": "^24.7.1",
|
"@types/node": "^24.7.1",
|
||||||
"@types/punycode": "^2.1.4",
|
|
||||||
"@types/tar-fs": "^2.0.4",
|
"@types/tar-fs": "^2.0.4",
|
||||||
"@types/yauzl-promise": "^4.0.1",
|
"@types/yauzl-promise": "^4.0.1",
|
||||||
"eslint": "^9.37.0",
|
"eslint": "^9.37.0",
|
||||||
|
|||||||
11
pnpm-lock.yaml
generated
11
pnpm-lock.yaml
generated
@ -65,9 +65,6 @@ importers:
|
|||||||
picocolors:
|
picocolors:
|
||||||
specifier: ^1.1.1
|
specifier: ^1.1.1
|
||||||
version: 1.1.1
|
version: 1.1.1
|
||||||
punycode:
|
|
||||||
specifier: ^2.3.1
|
|
||||||
version: 2.3.1
|
|
||||||
tar-fs:
|
tar-fs:
|
||||||
specifier: ^3.1.1
|
specifier: ^3.1.1
|
||||||
version: 3.1.1
|
version: 3.1.1
|
||||||
@ -126,9 +123,6 @@ importers:
|
|||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^24.7.1
|
specifier: ^24.7.1
|
||||||
version: 24.7.1
|
version: 24.7.1
|
||||||
'@types/punycode':
|
|
||||||
specifier: ^2.1.4
|
|
||||||
version: 2.1.4
|
|
||||||
'@types/tar-fs':
|
'@types/tar-fs':
|
||||||
specifier: ^2.0.4
|
specifier: ^2.0.4
|
||||||
version: 2.0.4
|
version: 2.0.4
|
||||||
@ -678,9 +672,6 @@ packages:
|
|||||||
'@types/node@24.7.1':
|
'@types/node@24.7.1':
|
||||||
resolution: {integrity: sha512-CmyhGZanP88uuC5GpWU9q+fI61j2SkhO3UGMUdfYRE6Bcy0ccyzn1Rqj9YAB/ZY4kOXmNf0ocah5GtphmLMP6Q==}
|
resolution: {integrity: sha512-CmyhGZanP88uuC5GpWU9q+fI61j2SkhO3UGMUdfYRE6Bcy0ccyzn1Rqj9YAB/ZY4kOXmNf0ocah5GtphmLMP6Q==}
|
||||||
|
|
||||||
'@types/punycode@2.1.4':
|
|
||||||
resolution: {integrity: sha512-trzh6NzBnq8yw5e35f8xe8VTYjqM3NE7bohBtvDVf/dtUer3zYTLK1Ka3DG3p7bdtoaOHZucma6FfVKlQ134pQ==}
|
|
||||||
|
|
||||||
'@types/stack-utils@2.0.3':
|
'@types/stack-utils@2.0.3':
|
||||||
resolution: {integrity: sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==}
|
resolution: {integrity: sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==}
|
||||||
|
|
||||||
@ -2674,8 +2665,6 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
undici-types: 7.14.0
|
undici-types: 7.14.0
|
||||||
|
|
||||||
'@types/punycode@2.1.4': {}
|
|
||||||
|
|
||||||
'@types/stack-utils@2.0.3': {}
|
'@types/stack-utils@2.0.3': {}
|
||||||
|
|
||||||
'@types/tar-fs@2.0.4':
|
'@types/tar-fs@2.0.4':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user