mirror of
https://github.com/certd/certd.git
synced 2026-04-14 20:40:53 +08:00
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
|
|
import { domainUtils } from './util.domain.js';
|
||
|
|
|
||
|
|
function groupByDomain(options: any[], inDomains: string[]) {
|
||
|
|
const matched = [];
|
||
|
|
const notMatched = [];
|
||
|
|
for (const item of options) {
|
||
|
|
if (domainUtils.match(item.domain, inDomains)) {
|
||
|
|
matched.push(item);
|
||
|
|
} else {
|
||
|
|
notMatched.push(item);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return {
|
||
|
|
matched,
|
||
|
|
notMatched,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
function buildGroupOptions(options: any[], inDomains: string[]) {
|
||
|
|
const grouped = groupByDomain(options, inDomains);
|
||
|
|
const groupOptions = [];
|
||
|
|
groupOptions.push({ value: '', disabled: true, label: '----已匹配----' });
|
||
|
|
if (grouped.matched.length === 0) {
|
||
|
|
options.push({ value: '', disabled: true, label: '没有可以匹配的域名' });
|
||
|
|
} else {
|
||
|
|
for (const matched of grouped.matched) {
|
||
|
|
groupOptions.push(matched);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (grouped.notMatched.length > 0) {
|
||
|
|
groupOptions.push({ value: '', disabled: true, label: '----未匹配----' });
|
||
|
|
for (const notMatched of grouped.notMatched) {
|
||
|
|
groupOptions.push(notMatched);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return groupOptions;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const optionsUtils = {
|
||
|
|
groupByDomain,
|
||
|
|
buildGroupOptions,
|
||
|
|
};
|