DSH-Arch-Setup/plugins/dsh-project-tree/lib/tree-utils.js
Шурупов Илья Викторович cf9443753e Add one-command Arch DSH setup
Package the portable DSH profiles, local plugins, desktop integration, Firefox wrapper, and ownership-aware installer lifecycle. Bundle checksum-pinned OpenVSCode, editor extensions, translation assets, and cloudflared so unreliable upstream artifact downloads cannot break a clean installation.
2026-09-12 19:13:36 +03:00

31 lines
849 B
JavaScript

export const MAX_NAME_LENGTH = 80;
export function parseName(raw) {
if (typeof raw !== "string") return undefined;
const trimmed = raw.trim();
if (trimmed.length === 0 || trimmed.length > MAX_NAME_LENGTH) return undefined;
return trimmed;
}
export function hasNameConflict(records, sameParent, name, exceptId) {
const needle = name.toLowerCase();
return records.some((record) =>
sameParent(record) &&
record.id !== exceptId &&
record.name.toLowerCase() === needle
);
}
export function nextSortIndex(siblings) {
return siblings.reduce((max, record) => Math.max(max, record.sortIndex ?? 0), 0) + 1;
}
export function isExactIdSet(ids, allowed) {
if (ids.length !== allowed.size) return false;
const seen = new Set();
for (const id of ids) {
if (!allowed.has(id) || seen.has(id)) return false;
seen.add(id);
}
return true;
}