Files
console-dev/app/lib/os-name.js
T
2026-11-06 00:04:38 +08:00

79 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var e = {
debian: `Debian`,
ubuntu: `Ubuntu`,
centos: `CentOS`,
windows: `Windows`,
rocky: `Rocky`,
"rocky linux": `Rocky Linux`,
almalinux: `AlmaLinux`,
fedora: `Fedora`,
openeuler: `openEuler`,
freebsd: `FreeBSD`,
tencentos: `TencentOS`,
alpine: `Alpine`,
"alpine linux": `Alpine Linux`,
},
t = {
server: `Server`,
stream: `Stream`,
datacenter: `Datacenter`,
standard: `Standard`,
enterprise: `Enterprise`,
professional: `Professional`,
essentials: `Essentials`,
education: `Education`,
desktop: `Desktop`,
minimal: `Minimal`,
core: `Core`,
pro: `Pro`,
home: `Home`,
lts: `LTS`,
uefi: `UEFI`,
bios: `BIOS`,
gpt: `GPT`,
bt: `BT`,
};
function n(n) {
let r = n.match(
/^(Debian|Ubuntu|CentOS|Windows|Rocky(?:[ _-]+Linux)?|AlmaLinux|Fedora|openEuler|FreeBSD|TencentOS|Alpine(?:[ _-]+Linux)?)(?=$|[\d\s_-])/i,
);
if (!r) return n;
let i = n.slice(r[0].length),
a = !1,
o = [e[r[0].replace(/[ _-]+/g, ` `).toLowerCase()]],
s =
/^[\s_-]*(x86[_-]64|64[ _-]?(?:bits?|位)|32[ _-]?(?:bits?|位)|\d+(?:\.\d+)*(?:R2)?|Server|Stream|Datacenter|Standard|Enterprise|Professional|Essentials|Education|Desktop|Minimal|Core|Pro|Home|R2|LTS|SP\d+|UEFI|BIOS|GPT|BT|ARM64|aarch64|x64|amd64|x86|x32|i386|i686|ARM|cn|en|zh(?:[ _-](?:CN|TW))?|专业版|标准版|数据中心版|企业版|家庭版|教育版|中文版|英文版)(?=$|[\s_()()\[\]【】-])/i;
for (let e = i.match(s); e; e = i.match(s)) {
let n = t[e[1].toLowerCase()] ?? e[1];
(/^\d+(?:\.\d+)*(?:R2)?$/i.test(n) &&
(o[0] === `CentOS` &&
!a &&
(n = n.replace(/^(\d+\.\d+)(?:\.\d+)+$/, `$1`)),
(n = n.replace(/^(\d+(?:\.\d+)*)R2$/i, `$1 R2`)),
(a = !0)),
o.push(n),
(i = i.slice(e[0].length)));
}
return o.join(` `) + i;
}
function r(e) {
if (typeof e != `string`) return ``;
let t = e.trim();
if (!t) return ``;
let r = `(?:x86[_-]64|x64|amd64|64[ _-]?(?:bit|bits|位))`;
return (
n(t.replace(/\.(?:iso|qcow2?|img|raw|vhdx?|vmdk)$/i, ``))
.replace(
/[\s_-]*(?:[((【\[]\s*)?纯净优化版(?:\s*[))】\]])?(?=$|[\s_-])/g,
``,
)
.replace(RegExp(`[((\\[【]\\s*${r}\\s*[))\\]】]`, `gi`), ` `)
.replace(RegExp(`(^|[\\s_])${r}(?=$|[\\s_])`, `gi`), `$1`)
.replace(RegExp(`-${r}$`, `i`), ``)
.replace(/_+/g, ` `)
.replace(/\s+/g, ` `)
.trim() || (t.includes(`纯净优化版`) ? `默认镜像` : t)
);
}
export { r as t };