PageSourceSearch

https://smartcone.ai/src/projects/idRegistry.js

js smartcone.ai collected 2026-10-05 15:06:55 UTC 1,009 bytes, 36 lines download raw bytes

1// /src/projects/idRegistry.js
2// Stable IDs for project/layout names using timestamp-based ids.
3
4import { newId } from "../lib/idFactory.js";
5
6const PKEY = "repo.projectIds";
7const LKEY = (p) => `repo.layoutIds:${p}`;
8
9function readMap(key) {
10  try { return JSON.parse(localStorage.getItem(key) || "{}"); } catch { return {}; }
11}
12function writeMap(key, obj) {
13  try { localStorage.setItem(key, JSON.stringify(obj)); } catch {}
14}
15
16export function getOrCreateProjectId(projectName) {
17  const name = (projectName || "").trim() || "MainProject";
18  const map = readMap(PKEY);
19  if (map[name]) return map[name];
20  const id = newId();
21  map[name] = id;
22  writeMap(PKEY, map);
23  return id;
24}
25
26export function getOrCreateLayoutId(projectName, layoutName) {
27  const p = (projectName || "").trim() || "MainProject";
28  const l = (layoutName  || "").trim() || "Main";
29  const key = LKEY(p);
30  const map = readMap(key);
31  if (map[l]) return map[l];
32  const id = newId();
33  map[l] = id;
34  writeMap(key, map);
35  return id;
36}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.