@subconverter/core 0.2.1 → 0.3.0
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.
- package/dist/index.cjs +89 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -19
- package/dist/index.d.ts +48 -19
- package/dist/index.js +89 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -79,6 +79,7 @@ __export(index_exports, {
|
|
|
79
79
|
explodeVmess: () => explodeVmess,
|
|
80
80
|
explodeVmessConf: () => explodeVmessConf,
|
|
81
81
|
filterNodes: () => filterNodes,
|
|
82
|
+
filterNodesByCountry: () => filterNodesByCountry,
|
|
82
83
|
findSection: () => findSection,
|
|
83
84
|
fnv1a64: () => fnv1a64,
|
|
84
85
|
fnv1a64Hex: () => fnv1a64Hex,
|
|
@@ -113,6 +114,7 @@ __export(index_exports, {
|
|
|
113
114
|
nodeNameRegex: () => nodeNameRegex,
|
|
114
115
|
nodeNameRemove: () => nodeNameRemove,
|
|
115
116
|
nodeRename: () => nodeRename,
|
|
117
|
+
normalizeCountryCode: () => normalizeCountryCode,
|
|
116
118
|
normalizeQueryKey: () => normalizeQueryKey,
|
|
117
119
|
normalizeUserinfoProvider: () => normalizeUserinfoProvider,
|
|
118
120
|
pad2: () => pad2,
|
|
@@ -142,8 +144,6 @@ __export(index_exports, {
|
|
|
142
144
|
queryBoolFlag: () => queryBoolFlag,
|
|
143
145
|
regMatch: () => regMatch,
|
|
144
146
|
regReplace: () => regReplace,
|
|
145
|
-
regionDisplayName: () => regionDisplayName,
|
|
146
|
-
regionFlag: () => regionFlag,
|
|
147
147
|
removeEmoji: () => removeEmoji,
|
|
148
148
|
renderRawIni: () => renderRawIni,
|
|
149
149
|
renderTemplate: () => renderTemplate,
|
|
@@ -452,12 +452,15 @@ function createExtraSettings() {
|
|
|
452
452
|
clashProxiesStyle: "flow",
|
|
453
453
|
clashProxyGroupsStyle: "flow",
|
|
454
454
|
clashScript: false,
|
|
455
|
-
countryLocale: "zh-CN",
|
|
456
455
|
countryResolver: void 0,
|
|
457
456
|
dedupe: false,
|
|
458
457
|
emojiArray: [],
|
|
459
458
|
enableRuleGenerator: true,
|
|
459
|
+
excludeCountries: [],
|
|
460
|
+
excludeRemarks: [],
|
|
460
461
|
filterDeprecated: false,
|
|
462
|
+
includeCountries: [],
|
|
463
|
+
includeRemarks: [],
|
|
461
464
|
managedConfigPrefix: "",
|
|
462
465
|
nameRegexArray: [],
|
|
463
466
|
nameRemove: [],
|
|
@@ -943,8 +946,10 @@ function parseExternalConfig(content) {
|
|
|
943
946
|
baseFiles: {},
|
|
944
947
|
emoji: [],
|
|
945
948
|
enableRuleGenerator: true,
|
|
949
|
+
excludeCountries: [],
|
|
946
950
|
excludeRemarks: [],
|
|
947
951
|
groups: [],
|
|
952
|
+
includeCountries: [],
|
|
948
953
|
includeRemarks: [],
|
|
949
954
|
nameRegex: [],
|
|
950
955
|
nameRemove: [],
|
|
@@ -1013,6 +1018,22 @@ function parseExternalConfig(content) {
|
|
|
1013
1018
|
result.includeRemarks.push(value);
|
|
1014
1019
|
}
|
|
1015
1020
|
break;
|
|
1021
|
+
case "include_country":
|
|
1022
|
+
for (const fragment of value.split(",")) {
|
|
1023
|
+
const trimmed = fragment.trim().toUpperCase();
|
|
1024
|
+
if (trimmed !== "") {
|
|
1025
|
+
result.includeCountries.push(trimmed);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
break;
|
|
1029
|
+
case "exclude_country":
|
|
1030
|
+
for (const fragment of value.split(",")) {
|
|
1031
|
+
const trimmed = fragment.trim().toUpperCase();
|
|
1032
|
+
if (trimmed !== "") {
|
|
1033
|
+
result.excludeCountries.push(trimmed);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
break;
|
|
1016
1037
|
case "exclude_remarks":
|
|
1017
1038
|
case "exclude":
|
|
1018
1039
|
if (value !== "") {
|
|
@@ -1067,6 +1088,9 @@ function listArg(query, key) {
|
|
|
1067
1088
|
const value = getUrlArg(query, key);
|
|
1068
1089
|
return value === "" ? [] : value.split(",");
|
|
1069
1090
|
}
|
|
1091
|
+
function countryListArg(query, key) {
|
|
1092
|
+
return getAllUrlArgs(query, key).flatMap((raw) => raw.split(",")).map((raw) => raw.trim().toUpperCase()).filter((raw) => raw !== "");
|
|
1093
|
+
}
|
|
1070
1094
|
function resolveNewFieldName(query) {
|
|
1071
1095
|
if (boolArg(query, "legacy") || boolArg(query, "legacy_field_name") || boolArg(query, "legacy-field-name")) {
|
|
1072
1096
|
return false;
|
|
@@ -1109,9 +1133,11 @@ function createRequestSettings() {
|
|
|
1109
1133
|
classicalRuleset: false,
|
|
1110
1134
|
dedupe: false,
|
|
1111
1135
|
emoji: [],
|
|
1136
|
+
excludeCountries: [],
|
|
1112
1137
|
excludeRemarks: [],
|
|
1113
1138
|
filterDeprecated: false,
|
|
1114
1139
|
group: [],
|
|
1140
|
+
includeCountries: [],
|
|
1115
1141
|
includeRemarks: [],
|
|
1116
1142
|
insert: false,
|
|
1117
1143
|
interval: 0,
|
|
@@ -1172,6 +1198,8 @@ function parseRequestSettings(query) {
|
|
|
1172
1198
|
settings.proxyGroupsStyle = getUrlArg(query, "proxy_groups_style") || "flow";
|
|
1173
1199
|
settings.includeRemarks = listArg(query, "include");
|
|
1174
1200
|
settings.excludeRemarks = listArg(query, "exclude");
|
|
1201
|
+
settings.includeCountries = countryListArg(query, "include_country");
|
|
1202
|
+
settings.excludeCountries = countryListArg(query, "exclude_country");
|
|
1175
1203
|
settings.userinfoUrl = firstArg(query, "userinfo_url", "userinfo-url", "userinfo");
|
|
1176
1204
|
settings.userinfoProvider = firstArg(
|
|
1177
1205
|
query,
|
|
@@ -5117,7 +5145,11 @@ function normalizeRegionCode(code) {
|
|
|
5117
5145
|
const upper = code.trim().toUpperCase();
|
|
5118
5146
|
return /^[A-Z]{2}$/.test(upper) ? upper : "";
|
|
5119
5147
|
}
|
|
5120
|
-
function
|
|
5148
|
+
function normalizeCountryCode(code) {
|
|
5149
|
+
const upper = normalizeRegionCode(code);
|
|
5150
|
+
return upper !== "" && isRegionCode(upper) ? upper : void 0;
|
|
5151
|
+
}
|
|
5152
|
+
function displayName(code, locale) {
|
|
5121
5153
|
const upper = normalizeRegionCode(code);
|
|
5122
5154
|
if (upper === "") {
|
|
5123
5155
|
return code.trim();
|
|
@@ -5160,8 +5192,8 @@ function buildAliasRegex() {
|
|
|
5160
5192
|
}
|
|
5161
5193
|
};
|
|
5162
5194
|
for (const code of REGION_CODES) {
|
|
5163
|
-
add(
|
|
5164
|
-
add(
|
|
5195
|
+
add(displayName(code, "zh-CN"));
|
|
5196
|
+
add(displayName(code, "en"));
|
|
5165
5197
|
add(regionFlag(code));
|
|
5166
5198
|
}
|
|
5167
5199
|
for (const alias of EXTRA_ALIASES) {
|
|
@@ -5201,13 +5233,13 @@ function hasRegionName(remark) {
|
|
|
5201
5233
|
}
|
|
5202
5234
|
return false;
|
|
5203
5235
|
}
|
|
5204
|
-
function formatCountryRemark(remark, code
|
|
5205
|
-
const
|
|
5236
|
+
function formatCountryRemark(remark, code) {
|
|
5237
|
+
const normalized = normalizeCountryCode(code);
|
|
5206
5238
|
const trimmed = remark.trim();
|
|
5207
|
-
if (
|
|
5239
|
+
if (normalized === void 0) {
|
|
5208
5240
|
return trimmed;
|
|
5209
5241
|
}
|
|
5210
|
-
return trimmed === "" ?
|
|
5242
|
+
return trimmed === "" ? normalized : `${normalized}-${trimmed}`;
|
|
5211
5243
|
}
|
|
5212
5244
|
|
|
5213
5245
|
// src/generator/nodes.ts
|
|
@@ -5466,7 +5498,7 @@ function nodeRename(node, renameArray) {
|
|
|
5466
5498
|
node.remark = original;
|
|
5467
5499
|
}
|
|
5468
5500
|
}
|
|
5469
|
-
function addCountryPrefix(node, resolve
|
|
5501
|
+
function addCountryPrefix(node, resolve) {
|
|
5470
5502
|
const remark = node.remark.trim();
|
|
5471
5503
|
if (hasRegionName(remark)) {
|
|
5472
5504
|
return node.remark;
|
|
@@ -5475,7 +5507,31 @@ function addCountryPrefix(node, resolve, locale = "zh-CN") {
|
|
|
5475
5507
|
if (code === void 0 || code === "") {
|
|
5476
5508
|
return node.remark;
|
|
5477
5509
|
}
|
|
5478
|
-
return formatCountryRemark(remark, code
|
|
5510
|
+
return formatCountryRemark(remark, code);
|
|
5511
|
+
}
|
|
5512
|
+
function filterNodesByCountry(nodes, resolve, include, exclude) {
|
|
5513
|
+
const includeSet = new Set(
|
|
5514
|
+
include.map((code) => normalizeCountryCode(code)).filter((code) => code !== void 0)
|
|
5515
|
+
);
|
|
5516
|
+
const excludeSet = new Set(
|
|
5517
|
+
exclude.map((code) => normalizeCountryCode(code)).filter((code) => code !== void 0)
|
|
5518
|
+
);
|
|
5519
|
+
if (includeSet.size === 0 && excludeSet.size === 0) {
|
|
5520
|
+
return;
|
|
5521
|
+
}
|
|
5522
|
+
const kept = [];
|
|
5523
|
+
for (const node of nodes) {
|
|
5524
|
+
const code = resolve ? normalizeCountryCode(resolve(node) ?? "") : void 0;
|
|
5525
|
+
if (includeSet.size > 0 && (code === void 0 || !includeSet.has(code))) {
|
|
5526
|
+
continue;
|
|
5527
|
+
}
|
|
5528
|
+
if (code !== void 0 && excludeSet.has(code)) {
|
|
5529
|
+
continue;
|
|
5530
|
+
}
|
|
5531
|
+
kept.push(node);
|
|
5532
|
+
}
|
|
5533
|
+
nodes.length = 0;
|
|
5534
|
+
nodes.push(...kept);
|
|
5479
5535
|
}
|
|
5480
5536
|
function preprocessNodes(nodes, options) {
|
|
5481
5537
|
for (const node of nodes) {
|
|
@@ -5493,13 +5549,25 @@ function preprocessNodes(nodes, options) {
|
|
|
5493
5549
|
node.remark = addEmoji(node, options.emojiArray);
|
|
5494
5550
|
}
|
|
5495
5551
|
if (options.autoCountry && options.countryResolver) {
|
|
5496
|
-
node.remark = addCountryPrefix(
|
|
5497
|
-
node,
|
|
5498
|
-
options.countryResolver,
|
|
5499
|
-
options.countryLocale ?? "zh-CN"
|
|
5500
|
-
);
|
|
5552
|
+
node.remark = addCountryPrefix(node, options.countryResolver);
|
|
5501
5553
|
}
|
|
5502
5554
|
}
|
|
5555
|
+
filterNodesByCountry(
|
|
5556
|
+
nodes,
|
|
5557
|
+
options.countryResolver,
|
|
5558
|
+
options.includeCountries ?? [],
|
|
5559
|
+
options.excludeCountries ?? []
|
|
5560
|
+
);
|
|
5561
|
+
const includeRemarks = options.includeRemarks ?? [];
|
|
5562
|
+
const excludeRemarks = options.excludeRemarks ?? [];
|
|
5563
|
+
if (includeRemarks.length > 0 || excludeRemarks.length > 0) {
|
|
5564
|
+
const kept = nodes.filter((node) => !checkIgnore(node, excludeRemarks, includeRemarks));
|
|
5565
|
+
kept.forEach((node, index) => {
|
|
5566
|
+
node.id = index;
|
|
5567
|
+
});
|
|
5568
|
+
nodes.length = 0;
|
|
5569
|
+
nodes.push(...kept);
|
|
5570
|
+
}
|
|
5503
5571
|
if (options.sortFlag) {
|
|
5504
5572
|
nodes.sort((a, b) => a.remark < b.remark ? -1 : a.remark > b.remark ? 1 : 0);
|
|
5505
5573
|
}
|
|
@@ -8385,9 +8453,12 @@ function runPreprocess(nodes, settings) {
|
|
|
8385
8453
|
preprocessNodes(nodes, {
|
|
8386
8454
|
addEmoji: settings.addEmoji,
|
|
8387
8455
|
autoCountry: settings.autoCountry,
|
|
8388
|
-
countryLocale: settings.countryLocale,
|
|
8389
8456
|
countryResolver: settings.countryResolver,
|
|
8390
8457
|
emojiArray: settings.emojiArray,
|
|
8458
|
+
excludeCountries: settings.excludeCountries,
|
|
8459
|
+
excludeRemarks: settings.excludeRemarks,
|
|
8460
|
+
includeCountries: settings.includeCountries,
|
|
8461
|
+
includeRemarks: settings.includeRemarks,
|
|
8391
8462
|
nameRegexArray: settings.nameRegexArray,
|
|
8392
8463
|
nameRemove: settings.nameRemove,
|
|
8393
8464
|
removeEmoji: settings.removeEmoji,
|