mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:11:25 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -6,23 +6,35 @@ type ParsedVcard = {
|
||||
const ALLOWED_VCARD_KEYS = new Set(["FN", "N", "TEL"]);
|
||||
|
||||
export function parseVcard(vcard?: string): ParsedVcard {
|
||||
if (!vcard) return { phones: [] };
|
||||
if (!vcard) {
|
||||
return { phones: [] };
|
||||
}
|
||||
const lines = vcard.split(/\r?\n/);
|
||||
let nameFromN: string | undefined;
|
||||
let nameFromFn: string | undefined;
|
||||
const phones: string[] = [];
|
||||
for (const rawLine of lines) {
|
||||
const line = rawLine.trim();
|
||||
if (!line) continue;
|
||||
if (!line) {
|
||||
continue;
|
||||
}
|
||||
const colonIndex = line.indexOf(":");
|
||||
if (colonIndex === -1) continue;
|
||||
if (colonIndex === -1) {
|
||||
continue;
|
||||
}
|
||||
const key = line.slice(0, colonIndex).toUpperCase();
|
||||
const rawValue = line.slice(colonIndex + 1).trim();
|
||||
if (!rawValue) continue;
|
||||
if (!rawValue) {
|
||||
continue;
|
||||
}
|
||||
const baseKey = normalizeVcardKey(key);
|
||||
if (!baseKey || !ALLOWED_VCARD_KEYS.has(baseKey)) continue;
|
||||
if (!baseKey || !ALLOWED_VCARD_KEYS.has(baseKey)) {
|
||||
continue;
|
||||
}
|
||||
const value = cleanVcardValue(rawValue);
|
||||
if (!value) continue;
|
||||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
if (baseKey === "FN" && !nameFromFn) {
|
||||
nameFromFn = normalizeVcardName(value);
|
||||
continue;
|
||||
@@ -33,7 +45,9 @@ export function parseVcard(vcard?: string): ParsedVcard {
|
||||
}
|
||||
if (baseKey === "TEL") {
|
||||
const phone = normalizeVcardPhone(value);
|
||||
if (phone) phones.push(phone);
|
||||
if (phone) {
|
||||
phones.push(phone);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { name: nameFromFn ?? nameFromN, phones };
|
||||
@@ -41,7 +55,9 @@ export function parseVcard(vcard?: string): ParsedVcard {
|
||||
|
||||
function normalizeVcardKey(key: string): string | undefined {
|
||||
const [primary] = key.split(";");
|
||||
if (!primary) return undefined;
|
||||
if (!primary) {
|
||||
return undefined;
|
||||
}
|
||||
const segments = primary.split(".");
|
||||
return segments[segments.length - 1] || undefined;
|
||||
}
|
||||
@@ -56,7 +72,9 @@ function normalizeVcardName(value: string): string {
|
||||
|
||||
function normalizeVcardPhone(value: string): string {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) return "";
|
||||
if (!trimmed) {
|
||||
return "";
|
||||
}
|
||||
if (trimmed.toLowerCase().startsWith("tel:")) {
|
||||
return trimmed.slice(4).trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user