GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Kuiper, cosmos and drawing engines / stars / library

Standalone (part 17)

A JavaScript module in the library folder of Stars that maps Renewable Energy Planning Database (REPD) master and heavy emitters UK, using SHA-256, and uses data from the GridAtlas repository.

700 lines of JavaScript from stars, in 1 file. Topic: Kuiper, cosmos and drawing engines. Section 1579 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Standalone geodesy · stars / library/standalone.mjs lines 11740–12439

Standalone

A JavaScript module in the library folder of Stars that maps Renewable Energy Planning Database (REPD) master and heavy emitters UK, using SHA-256, and uses data from the GridAtlas repository.

Set aside from the main view: A comment at the top of the file says a tool wrote it. (noise-generated, proposed by noise.py). All set-aside files, with reasons. Nothing was deleted.

Evidence
  • line 2 comment: // Generated by the modular star 2026-12-05T23:26:43.596Z. Each export is one family's earliest-seen copy, unchanged; the comment links its source.

geodesystars / library/standalone.mjs · lines 11740–12439 of 12585 (continued from section 1562) · Entry point · pattern segmentConductors (shared by 2 files)

What it does
It maps REPD master, heavy emitters UK, notice and substations. Defines 1111 functions or classes, including f1586_invariant, f8767_representativePoint, f8768_voltagesKv, f8772_voltageOf, f8773_ratingsOf. Side effects: changes the web page (DOM); reads or writes files; makes network requests; uses storage (browser storage, DuckDB or Parquet).
Why it exists in the grid workflow
Domain terms in the code: substations, 750kV, 400kV, 275kV, 132kV, 66kV.
Inputs & outputs
In: data source: gridatlas data; JSON file repd_master.json; JSON file heavy_emitters_uk.json; JSON file notice.json; form fields (user input). Out: canvas drawing. Coordinate systems named: OSGB36 / EPSG:27700 (British National Grid), WGS84 / EPSG:4326. Voltage levels named: 750kV, 400kV, 275kV, 132kV, 66kV, 33kV, 1.5kV, 1500V.
Downstream impact
Used directly by 4 files: Code (stars, https://ventusltd.github.io/stars/code.html); Proof (stars); Modular Star Workflow (stars); Testcode — Code Record Page (globalgrid2050, https://globalgrid2050.com/testcode/202609141754/code-record/). Reached from 383 other entry points, including Code Generator — Index Page (code-generator, https://ventusltd.github.io/code-generator/); Generate (code-generator, https://ventusltd.github.io/code-generator/); 404 (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/404.html).
What it achieves
It snaps coordinate (`snapCoordinate`), paints cursor (`paintCursor`) and sets plan (`setPlan`). Compiled library of self-contained JavaScript functions that appear in two or more places across Ventusltd code. Its code works with 33 kV, 132 kV and 275 kV. It responds to abort events.
Why it matters
Loaded by the Code page at https://ventusltd.github.io/stars/code.html and 1 other page. Run by Proof and Modular Star Workflow.
Application
stars · library · JavaScript module
VEDIC
MEASURE (GG2050-VEDIC-000001): GridAtlas / Geodesy · Mathematics / Spherical geometry. coordinate_pair, coordinate_pair → distance_km
VEDIC
REPRESENT (GG2050-VEDIC-000002): GridAtlas / Geodesy · Computer science / Geometry processing. geojson_geometry → coordinate_pair_or_null
VEDIC
VOLTAGE (GG2050-VEDIC-000003): GridAtlas / Geodesy · Computer science / Data normalisation. voltage_properties → kilovolt_list
Uses
GlobalGrid2050 — Renewable Energy Planning Database (REPD) Grid Atlas v8 Page (estate URL), Declared Connections (estate URL)
Used by
named by URL in Code (estate URL), run by Proof (script call), run by Modular Star Workflow (workflow run), named by URL in Testcode — Code Record Page (estate URL)
Produces
f1586_invariant, f8767_representativePoint, f8768_voltagesKv, f8772_voltageOf, f8773_ratingsOf, f8775_parametersOf, f5168_escapeHTML, f8321_suppliedArrivalFields, f8850__anonymous_, f8786_crossing, f8788_legality, f8789_startNodes
Defines here
f152322_merc, f146597_flat, f146600_countAt, f146657_libRefusal, f146658_importText, f146687_clearanceWords, f146715_nearest, f146717_heightGrid, f146719_browserDecode, f146795_densify, f146802_daylight, f146803_polyArea, f146809_gridIntegrate, f146811_stripVolume, bis, f146939_summarise, stat, f147010_buildPyramid, f147011_basis, f147012_sunVector, f177207_formatCapacity, f177208_formatCount, f146481_modulesPerString, f177656_add, f177657_buildInterconnectorCapacityReport, empty, add, f47832_createArrivalGate, f70289__anonymous_, f70341_normalizeSearchText
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
stars@030ebc202d35959fecd162327892f671d1d9a0cc library/standalone.mjs:11740-12439 · blob fc3d8c8b93e14d4a56b8a26da47071d60bc5bc4d · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, filesystem, network, storage · domain stage: unknown · users: none · canonical: unknown
// Family #152322 · element #152322 · 9 places in 1 repositories · https://github.com/Ventusltd/kuiper-belt/blob/5f49da3d53de024852bbe60993add7a0c4cd5812/learn-the-kuiper/202610050144/modules/descent.js#L55-L59
export const f152322_merc = function merc(lon, lat, out, i) {
    var la = Math.max(-85.05, Math.min(85.05, lat)) * Math.PI / 180;
    out[2 * i] = (lon + 180) / 360;
    out[2 * i + 1] = (1 - Math.log(Math.tan(Math.PI / 4 + la / 2)) / Math.PI) / 2;
  };

// Family #146597 · element #146597 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/block-gpu.mjs#L59-L64
export const f146597_flat = function flat(g) {
  if (g.type === 'Point') return [g.coordinates];
  if (g.type === 'MultiPoint' || g.type === 'LineString') return g.coordinates;
  if (g.type === 'Polygon' || g.type === 'MultiLineString') return g.coordinates.flat();
  return [];
};

// Family #146600 · element #146600 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/block-gpu.mjs#L99-L103
export const f146600_countAt = function countAt(G, h) {
  let n = 0;
  for (let i = 0; i < G.ends.length && G.ends[i] <= h + 1e-9; i++) n = G.marks[i];
  return n;
};

// Family #146657 · element #146657 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/layers.mjs#L59-L63
export const f146657_libRefusal = function libRefusal(want, lib, why) {
  if (want === undefined || want === null) return null;
  if (!lib) return `refused: it needs lib version ${want} and the lib was refused (${why})`;
  return want === lib.version ? null : `refused: it declares lib version ${want}, the substrate serves ${lib.version}`;
};

// Family #146658 · element #146658 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/layers.mjs#L65-L68
export const f146658_importText = async function importText(text) {
  const blob = URL.createObjectURL(new Blob([text], { type: 'text/javascript' }));
  try { return await import(blob); } finally { URL.revokeObjectURL(blob); }
};

// Family #146687 · element #146687 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/layers/construction.mjs#L43-L45
export const f146687_clearanceWords = function clearanceWords(m) {
  return Number.isFinite(m) ? `illustrative ground clearance ${m.toFixed(1)} m at an assumed sag` : 'no illustrative clearance worked out';
};

// Family #146715 · element #146715 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/layers/imagery.mjs#L74-L78
export const f146715_nearest = function nearest(C, r, g, b) {
  let best = 0, bd = Infinity;
  for (let i = 0; i < C.length; i++) { const q = C[i], e = (q[0] - r) ** 2 + (q[1] - g) ** 2 + (q[2] - b) ** 2; if (e < bd) { bd = e; best = i; } }
  return best;
};

// Family #146717 · element #146717 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/layers/imagery.mjs#L91-L101
export const f146717_heightGrid = function heightGrid(w, h, box, heightAt, known = null) {
  const px = box.size / w, py = box.size / h, H = new Float32Array((w + 1) * (h + 1));
  for (let j = 0; j <= h; j++) {
    const y = box.y0 + box.size - j * py;
    for (let i = 0; i <= w; i++) {
      const x = box.x0 + i * px, z = known && !known(x, y) ? NaN : heightAt(x, y);
      H[j * (w + 1) + i] = Number.isFinite(z) ? z : known ? NaN : 0;
    }
  }
  return H;
};

// Family #146719 · element #146719 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/layers/imagery.mjs#L131-L138
export const f146719_browserDecode = async function browserDecode(bytes) {
  const bmp = await createImageBitmap(new Blob([bytes]));
  const c = new OffscreenCanvas(bmp.width, bmp.height), g = c.getContext('2d');
  g.drawImage(bmp, 0, 0);
  const im = g.getImageData(0, 0, bmp.width, bmp.height);
  bmp.close?.();
  return { width: im.width, height: im.height, data: im.data };
};

// Family #146795 · element #146795 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/lib/drape.mjs#L10-L18
export const f146795_densify = function densify(pts, step) {
  if (pts.length < 2) return pts.map(p => [p[0], p[1]]);
  const out = [[pts[0][0], pts[0][1]]];
  for (let i = 1; i < pts.length; i++) {
    const [ax, ay] = pts[i - 1], [bx, by] = pts[i], n = Math.max(1, Math.ceil(Math.hypot(bx - ax, by - ay) / step));
    for (let k = 1; k <= n; k++) out.push([ax + (bx - ax) * k / n, ay + (by - ay) * k / n]);
  }
  return out;
};

// Family #146802 · element #146802 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/lib/earthworks.mjs#L21-L27
export const f146802_daylight = function daylight(met, step, limit, { strict = false } = {}) {
  let a = 0, b = step;
  if (strict) { while (!met(b)) { a = b; b += step; if (b > limit) return null; } }
  else while (b < limit && !met(b)) { a = b; b += step; }
  for (let k = 0; k < 30; k++) { const m = (a + b) / 2; if (met(m)) b = m; else a = m; }
  return b;
};

// Family #146803 · element #146803 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/lib/earthworks.mjs#L31-L35
export const f146803_polyArea = pts => {
  let a = 0;
  for (let i = 0; i < pts.length; i++) { const p = pts[i], q = pts[(i + 1) % pts.length]; a += p[0] * q[1] - q[0] * p[1]; }
  return Math.abs(a) / 2;
};

// Family #146809 · element #146809 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/lib/earthworks.mjs#L114-L121
export const f146809_gridIntegrate = function gridIntegrate({ x0, y0, nx, ny, cell, sub = 8, split, visit }) {
  const h = cell / sub, w = 1 / (sub * sub);
  for (let j = 0; j < ny; j++) for (let i = 0; i < nx; i++) {
    const x = x0 + (i + 0.5) * cell, y = y0 + (j + 0.5) * cell;
    if (!split(x, y, i, j)) { visit(x, y, 1); continue; }
    for (let b = 0; b < sub; b++) for (let a = 0; a < sub; a++) visit(x - cell / 2 + (a + 0.5) * h, y - cell / 2 + (b + 0.5) * h, w);
  }
};

// Family #146811 · element #146811 · 8 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270330-site-world-v3/world/lib/earthworks.mjs#L127-L154
export const f146811_stripVolume = function stripVolume(path, width, depth, g, { nt = 6, du = 0.25 } = {}) {
  const p = [];
  for (const q of path) { const l = p[p.length - 1]; if (!l || Math.hypot(q[0] - l[0], q[1] - l[1]) > 1e-6) p.push([+q[0], +q[1]]); }
  const segs = [];
  for (let i = 0; i < p.length - 1; i++) {
    const len = Math.hypot(p[i + 1][0] - p[i][0], p[i + 1][1] - p[i][1]);
    segs.push({ a: p[i], dx: (p[i + 1][0] - p[i][0]) / len, dy: (p[i + 1][1] - p[i][1]) / len, len });
  }
  const bis = (s, t) => { const x = s.dx + t.dx, y = s.dy + t.dy, l = Math.hypot(x, y); return l < 1e-6 ? [s.dx, s.dy] : [x / l, y / l]; };
  let vol = 0;
  segs.forEach((s, i) => {
    const nx = -s.dy, ny = s.dx;
    const mS = i === 0 ? null : bis(segs[i - 1], s), mE = i === segs.length - 1 ? null : bis(s, segs[i + 1]);
    for (let k = 0; k < nt; k++) {
      const t = ((k + 0.5) / nt - 0.5) * width;
      const u0 = mS ? -t * (nx * mS[0] + ny * mS[1]) / (s.dx * mS[0] + s.dy * mS[1]) : 0;
      const u1 = mE ? s.len - t * (nx * mE[0] + ny * mE[1]) / (s.dx * mE[0] + s.dy * mE[1]) : s.len;
      const m = Math.max(1, Math.ceil((u1 - u0) / du)), h = (u1 - u0) / m;
      for (let j = 0; j < m; j++) {
        const u = u0 + (j + 0.5) * h, uc = Math.min(Math.max(u, 0), s.len);
        const x = s.a[0] + s.dx * u + nx * t, y = s.a[1] + s.dy * u + ny * t;
        const floor = g(s.a[0] + s.dx * uc, s.a[1] + s.dy * uc) - depth;
        vol += Math.max(0, g(x, y) - floor) * h;
      }
    }
  });
  return vol * width / nt;
};

// Family #146939 · element #146939 · 7 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270402-site-world-v3/world/cable-checks.mjs#L94-L101
export const f146939_summarise = function summarise(circuits) {
  const stat = k => {
    const v = circuits.map(c => c[k]).filter(Number.isFinite).sort((x, y) => x - y);
    return v.length ? { min: v[0], median: v[Math.floor(v.length / 2)], max: v[v.length - 1] } : null;
  };
  return { count: circuits.length, vd_pct: stat('vd_pct'), loading_pct: stat('loading_pct'),
    above100: circuits.filter(c => c.loading_pct > 100).length };
};

// Family #147010 · element #147010 · 7 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270402-site-world-v3/world/raycast.mjs#L22-L36
export const f147010_buildPyramid = function buildPyramid(h, n) {
  const c = n - 1;
  if (c & (c - 1)) throw Error('buildPyramid needs 2^k + 1 nodes a side');
  let lv = new Float32Array(c * c);
  for (let j = 0; j < c; j++) for (let i = 0; i < c; i++)
    lv[j * c + i] = Math.max(h[j * n + i], h[j * n + i + 1], h[(j + 1) * n + i], h[(j + 1) * n + i + 1]);
  const levels = [lv];
  for (let m = c / 2; m >= 1; m /= 2) {
    const p = levels[levels.length - 1], w = m * 2, nx = new Float32Array(m * m);
    for (let j = 0; j < m; j++) for (let i = 0; i < m; i++)
      nx[j * m + i] = Math.max(p[2 * j * w + 2 * i], p[2 * j * w + 2 * i + 1], p[(2 * j + 1) * w + 2 * i], p[(2 * j + 1) * w + 2 * i + 1]);
    levels.push(nx);
  }
  return levels;
};

// Family #147011 · element #147011 · 7 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270402-site-world-v3/world/raycast.mjs#L39-L42
export const f147011_basis = function basis(yaw, pitch) {
  const c = Math.cos(pitch), f = [Math.sin(yaw) * c, Math.cos(yaw) * c, Math.sin(pitch)], r = [Math.cos(yaw), -Math.sin(yaw), 0];
  return { f, r, u: [r[1] * f[2] - r[2] * f[1], r[2] * f[0] - r[0] * f[2], r[0] * f[1] - r[1] * f[0]] };
};

// Family #147012 · element #147012 · 7 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270402-site-world-v3/world/raycast.mjs#L45-L48
export const f147012_sunVector = function sunVector({ azimuth, elevation }) {
  const a = azimuth * Math.PI / 180, e = elevation * Math.PI / 180;
  return [Math.sin(a) * Math.cos(e), Math.cos(a) * Math.cos(e), Math.sin(e)];
};

// Family #177207 · element #177207 · 7 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/repd_reporting/v2/repd-reports-integrated.mjs#L117-L119
export const f177207_formatCapacity = function formatCapacity(n) {
  return Number(n || 0).toLocaleString("en-GB", { maximumFractionDigits: 2 });
};

// Family #177208 · element #177208 · 7 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/repd_reporting/v2/repd-reports-integrated.mjs#L120-L122
export const f177208_formatCount = function formatCount(n) {
  return Number(n || 0).toLocaleString("en-GB");
};

// Family #146481 · element #146481 · 6 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/solar-design-studio/202609270220-site-world-v3/world/plant-template.mjs#L37-L40
export const f146481_modulesPerString = function modulesPerString(p) {
  const vCold = p.moduleVoc * (1 + p.vocCoeffPerK * (p.minCellC - 25));
  return Math.floor(p.systemV / vCold);
};

// Family #177656 · element #177656 · 6 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/repd_reporting/v2/repd-reports-integrated.mjs#L97-L102
export const f177656_add = (target, project) => {
    target.count++;
    const capacity = project.capacity_mw;
    if (typeof capacity !== "number" || !Number.isFinite(capacity) || capacity < 0) target.missingCapacity++;
    else { target.recordedCapacity+=capacity;target.otherMw+=capacity; }
  };

// Family #177657 · element #177657 · 6 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/repd_reporting/v2/repd-reports-integrated.mjs#L92-L116
export const f177657_buildInterconnectorCapacityReport = function buildInterconnectorCapacityReport(projects, dimension) {
  // Separate, explicitly labelled interconnector inventory; no REPD ID dedupe or mixing.
  const empty = () => ({count:0, recordedCapacity:0, solarMwp:0, otherMw:0, missingCapacity:0});
  const total = empty(), groups = new Map();
  const seen = new Set();
  const add = (target, project) => {
    target.count++;
    const capacity = project.capacity_mw;
    if (typeof capacity !== "number" || !Number.isFinite(capacity) || capacity < 0) target.missingCapacity++;
    else { target.recordedCapacity+=capacity;target.otherMw+=capacity; }
  };
  for (const project of projects) {
    const ref = String(project.asset_id ?? project.gg_project_id ?? project.bmrs_code ?? "").trim();
    if (!ref || seen.has(ref)) throw new Error("Missing/duplicate interconnector ID: " + ref);
    seen.add(ref);
    const name = String(project[dimension] || "Not reported").trim() || "Not reported";
    let group = groups.get(name);
    if (!group) { group = {name, ...empty(), projects:[], statuses:new Map()};groups.set(name,group); }
    const status = String(project.status || "Not reported").trim() || "Not reported";
    if (!group.statuses.has(status)) group.statuses.set(status,empty());
    add(group.statuses.get(status),project);add(group,project);add(total,project);
    group.projects.push(project);
  }
  return {dimension,total,groups:[...groups.values()].sort((a,b)=>b.recordedCapacity-a.recordedCapacity || b.count-a.count || a.name.localeCompare(b.name,"en-GB")), uniqueRefs:seen.size};
};

// Family #47832 · element #47832 · 4 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atlas/cartridges/202609040058-sld-sandbox-v9-8.js#L3165-L3178
export const f47832_createArrivalGate = function createArrivalGate() {
    let epoch = 0;
    const invalidations = [];
    return Object.freeze({
      begin() { epoch += 1; return epoch; },
      invalidate(reason) {
        epoch += 1;
        invalidations.push({ epoch, reason: String(reason || 'unspecified') });
        return epoch;
      },
      isCurrent(candidate) { return candidate === epoch; },
      snapshot() { return Object.freeze({ epoch, invalidations: [...invalidations] }); }
    });
  };

// Family #70289 · element #70289 · 4 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atlas/releases/202608291237-atlas-v9/assets/atlas-v9.mjs#L102-L107
export const f70289__anonymous_ = record => ({
      type: "Feature",
      id: Number(record.repd_ref) || undefined,
      properties: { repd_ref: String(record.repd_ref), technology: record.technology, status: record.status },
      geometry: { type: "Point", coordinates: [record.longitude, record.latitude] }
    });

// Family #70341 · element #70341 · 4 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atlas/releases/202608291237-atlas-v9/cartridges/202608290716-repd-address-flyto.mjs#L15-L17
export const f70341_normalizeSearchText = function normalizeSearchText(value) {
  return String(value || "").normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/&/g, " and ").replace(/[^a-z0-9/]+/g, " ").trim();
};

// Family #129773 · element #129773 · 3 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/testcode/202609141350/v02-radial-sunburst/index.html#L19-L23
export const f129773_arc = function arc(r0, r1, a0, a1) {
  const p = (r, a) => [r * Math.cos(a - Math.PI / 2), r * Math.sin(a - Math.PI / 2)];
  const big = a1 - a0 > Math.PI ? 1 : 0; const [x0, y0] = p(r1, a0), [x1, y1] = p(r1, a1), [x2, y2] = p(r0, a1), [x3, y3] = p(r0, a0);
  return `M${x0},${y0}A${r1},${r1} 0 ${big} 1 ${x1},${y1}L${x2},${y2}A${r0},${r0} 0 ${big} 0 ${x3},${y3}Z`;
};

// Family #129792 · element #129792 · 3 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/testcode/202609141350/v06-treemap-lines/index.html#L18-L30
export const f129792_squarify = function squarify(items, x, y, w, h) {
  const out = []; items = items.filter(i => i.w > 0).sort((a, b) => b.w - a.w); const total = items.reduce((s, i) => s + i.w, 0) || 1;
  let rest = items.map(i => ({ ...i, a: (i.w / total) * w * h }));
  while (rest.length) {
    const short = Math.min(w, h); let row = [], worst = Infinity;
    for (const it of rest) { const r = [...row, it]; const s = r.reduce((q, z) => q + z.a, 0); const wr = Math.max(...r.map(z => Math.max((short * short * z.a) / (s * s), (s * s) / (short * short * z.a)))); if (wr > worst && row.length) break; row = r; worst = wr; }
    const s = row.reduce((q, z) => q + z.a, 0); const thick = s / short; let off = 0;
    for (const z of row) { const len = z.a / thick; out.push(w >= h ? { ...z, x, y: y + off, w: thick, h: len } : { ...z, x: x + off, y, w: len, h: thick }); off += len; }
    if (w >= h) { x += thick; w -= thick; } else { y += thick; h -= thick; }
    rest = rest.slice(row.length);
  }
  return out;
};

// Family #1397 · element #1397 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/grid_engine/202609060238-site-geometry/index.html#L171-L175
export const f1397__anonymous_ = pair => {
    const [a, b] = pair.split(',').map(Number);
    if (!Number.isFinite(a) || !Number.isFinite(b)) throw new Error('cannot read point "' + pair + '"');
    return [a, b];
  };

// Family #1398 · element #1398 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/grid_engine/202609060238-site-geometry/index.html#L170-L176
export const f1398_parsePoly = function parsePoly(raw) {
  return raw.split(';').map(s => s.trim()).filter(Boolean).map(pair => {
    const [a, b] = pair.split(',').map(Number);
    if (!Number.isFinite(a) || !Number.isFinite(b)) throw new Error('cannot read point "' + pair + '"');
    return [a, b];
  });
};

// Family #1466 · element #1466 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/homepage_versions/homepage_v095.html#L455-L471
export const f1466_flatten = function flatten(children){
  // No sub-nests: a nested entry contributes itself and everything under it,
  // then the whole category is re-sorted so the flat list stays newest-first.
  const out = [];
  for (const c of children) {
    out.push({ name: c.name, url: c.url });
    if (c.children) out.push(...flatten(c.children));
  }
  const stamp = r => (r.name.match(/^(\d{12})/) || [null, ""])[1];
  return out.sort((x, y) => {
    const a = stamp(x), b = stamp(y);
    if (a && b) return b.localeCompare(a);
    if (a) return -1;
    if (b) return 1;
    return 0;
  });
};

// Family #31619 · element #31619 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/uk_energy_tracking_v4/live-helpers.js#L4-L9
export const f31619_arcPath = function arcPath(cx,cy,r,start,end){
    var s=(start-90)*Math.PI/180, e=(end-90)*Math.PI/180;
    var x1=cx+r*Math.cos(s), y1=cy+r*Math.sin(s), x2=cx+r*Math.cos(e), y2=cy+r*Math.sin(e);
    var large=end-start<=180?0:1;
    return "M "+x1+" "+y1+" A "+r+" "+r+" 0 "+large+" 1 "+x2+" "+y2;
  };

// Family #31620 · element #31620 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/uk_energy_tracking_v4/live-oil-chart.js#L3-L16
export const f31620_rangeCutoff = function rangeCutoff(range){
    if(range === "all") return null;
    var d = new Date();
    if(range === "7d") d.setDate(d.getDate()-7);
    else if(range === "1m") d.setMonth(d.getMonth()-1);
    else if(range === "3m") d.setMonth(d.getMonth()-3);
    else if(range === "6m") d.setMonth(d.getMonth()-6);
    else if(range === "9m") d.setMonth(d.getMonth()-9);
    else if(range === "1y") d.setFullYear(d.getFullYear()-1);
    else if(range === "5y") d.setFullYear(d.getFullYear()-5);
    else if(range === "10y") d.setFullYear(d.getFullYear()-10);
    else if(range === "25y") d.setFullYear(d.getFullYear()-25);
    return d;
  };

// Family #31637 · element #31637 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/uk_energy_tracking_v5/frequency-history-ui.js#L52-L58
export const f31637__anonymous_ = function(line){
      var p=line.split(",");
      if(p.length<2) return null;
      var hz=parseFloat(p[1]);
      if(!isFinite(hz)) return null;
      return {t:p[0], hz:hz};
    };

// Family #31638 · element #31638 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/uk_energy_tracking_v5/frequency-history-ui.js#L49-L59
export const f31638_parseCsv = function parseCsv(text){
    text=(text||"").trim();
    if(!text) return [];
    return text.split(/\r?\n/).slice(1).map(function(line){
      var p=line.split(",");
      if(p.length<2) return null;
      var hz=parseFloat(p[1]);
      if(!isFinite(hz)) return null;
      return {t:p[0], hz:hz};
    }).filter(Boolean);
  };

// Family #31639 · element #31639 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/uk_energy_tracking_v5/frequency-history-ui.js#L60-L65
export const f31639_timeLabel = function timeLabel(iso){
    if(!iso) return "—";
    var d=new Date(iso);
    if(isNaN(d.getTime())) return iso;
    return d.toLocaleString("en-GB",{day:"2-digit",month:"short",hour:"2-digit",minute:"2-digit",second:"2-digit"});
  };

// Family #31640 · element #31640 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/uk_energy_tracking_v5/frequency-history-ui.js#L66-L71
export const f31640_weekLabel = function weekLabel(iso){
    if(!iso) return "—";
    var d=new Date(iso);
    if(isNaN(d.getTime())) return iso;
    return d.toLocaleDateString("en-GB",{day:"2-digit",month:"short"});
  };

// Family #32834 · element #32834 · 2 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/202608310050-gridatlas-next-version-builders/tools/202608310050-select-build-plan.mjs#L32-L39
export const f32834_londonGeneration = function londonGeneration(date = new Date()) {
  const parts = new Intl.DateTimeFormat('en-GB', {
    timeZone: 'Europe/London', year: 'numeric', month: '2-digit', day: '2-digit',
    hour: '2-digit', minute: '2-digit', hourCycle: 'h23'
  }).formatToParts(date);
  const pick = type => parts.find(part => part.type === type)?.value;
  return `${pick('year')}${pick('month')}${pick('day')}${pick('hour')}${pick('minute')}`;
};

// Family #70924 · element #70924 · 2 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atman/202608291758-v8-product-parity.mjs#L8-L10
export const f70924_requireCondition = function requireCondition(condition, message) {
  if (!condition) throw new Error(message);
};

// Family #70934 · element #70934 · 2 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atman/202608291818-prove-v8-product-mirror.mjs#L64-L68
export const f70934_ready = async function ready(page) {
  await page.waitForSelector('.dashboard', { timeout:45000 });
  await page.waitForSelector('#scada-ui-container .key-item', { timeout:45000 });
  await page.waitForSelector('#map canvas', { timeout:45000 });
};

// Family #70960 · element #70960 · 2 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/atman/202608292126-layer-performance-comparator.mjs#L25-L32
export const f70960_replaceExactlyOnce = function replaceExactlyOnce(source, before, after, label) {
  const first = source.indexOf(before);
  if (first < 0) throw new Error(`missing comparator repair anchor: ${label}`);
  if (source.indexOf(before, first + before.length) >= 0) {
    throw new Error(`ambiguous comparator repair anchor: ${label}`);
  }
  return source.slice(0, first) + after + source.slice(first + before.length);
};

// Family #71450 · element #71450 · 2 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/tools/proofs/202609041250-menu-bar-instrument-panel.browser.mjs#L76-L78
export const f71450__anonymous_ = (id) => `
  <label class="key-item"><input type="checkbox" data-layer-id="${id}">
    <span data-base-label="${id === 'dlr' ? 'DLR' : id}">${id}</span></label>`;

// Family #71744 · element #71744 · 2 places in 1 repositories · https://github.com/Ventusltd/gridatlas/blob/f944f8dcbc09cd09c0895f0126682ec241cd576f/tools/proofs/modules/202609012345-planned-change.proof.mjs#L107-L109
export const f71744_fakeProduct = function fakeProduct({ nodes = [], sites = [], circuits = [], transformers = [], planned_changes = [] }) {
  return { schema: 'data-grid-gb.transmission-network.v1', nodes, sites, circuits, transformers, planned_changes };
};

// Family #72299 · element #72299 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/archive/202608261547-pipelinenews/objects/modules/sha256/ae4bb559312e84d7cdcb69dfee444644b328c370e198d5939ff8abeca92d6235.js#L31-L33
export const f72299_invariant = function invariant(condition, message) {
  if (!condition) throw new Error(`Release contract failed: ${message}`);
};

// Family #72300 · element #72300 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/archive/202608261547-pipelinenews/objects/modules/sha256/ae4bb559312e84d7cdcb69dfee444644b328c370e198d5939ff8abeca92d6235.js#L36-L38
export const f72300__anonymous_ = (character) => ({
    "&": "&amp;", "<": "&lt;", ">": "&gt;", "'": "&#39;", '"': "&quot;",
  })[character];

// Family #72301 · element #72301 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/archive/202608261547-pipelinenews/objects/modules/sha256/ae4bb559312e84d7cdcb69dfee444644b328c370e198d5939ff8abeca92d6235.js#L35-L39
export const f72301_escapeHtml = function escapeHtml(value) {
  return String(value ?? "").replace(/[&<>'"]/g, (character) => ({
    "&": "&amp;", "<": "&lt;", ">": "&gt;", "'": "&#39;", '"': "&quot;",
  })[character]);
};

// Family #72302 · element #72302 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/archive/202608261547-pipelinenews/objects/modules/sha256/ae4bb559312e84d7cdcb69dfee444644b328c370e198d5939ff8abeca92d6235.js#L41-L48
export const f72302_safeHttpUrl = function safeHttpUrl(value) {
  try {
    const url = new URL(String(value || ""));
    return ["http:", "https:"].includes(url.protocol) ? `${url.origin}/` : "";
  } catch {
    return "";
  }
};

// Family #72305 · element #72305 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/archive/202608261547-pipelinenews/objects/modules/sha256/ae4bb559312e84d7cdcb69dfee444644b328c370e198d5939ff8abeca92d6235.js#L72-L74
export const f72305_technologyLabel = function technologyLabel(value) {
  return ({ solar: "Solar", bess: "Battery storage", wind_onshore: "Onshore wind", wind_offshore: "Offshore wind" })[value] || value;
};

// Family #72306 · element #72306 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/archive/202608261547-pipelinenews/objects/modules/sha256/ae4bb559312e84d7cdcb69dfee444644b328c370e198d5939ff8abeca92d6235.js#L76-L78
export const f72306_unitFor = function unitFor(value) {
  return value === "solar" ? "MWp" : "MW";
};

// Family #72307 · element #72307 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/archive/202608261547-pipelinenews/objects/modules/sha256/ae4bb559312e84d7cdcb69dfee444644b328c370e198d5939ff8abeca92d6235.js#L80-L82
export const f72307_formatNumber = function formatNumber(value, maximumFractionDigits = 2) {
  return Number(value || 0).toLocaleString("en-GB", { maximumFractionDigits });
};

// Family #72308 · element #72308 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/archive/202608261547-pipelinenews/objects/modules/sha256/ae4bb559312e84d7cdcb69dfee444644b328c370e198d5939ff8abeca92d6235.js#L84-L88
export const f72308_displayDate = function displayDate(value) {
  if (!value) return "NOT SUPPLIED";
  const parts = String(value).split("-");
  return parts.length === 3 ? `${parts[2]}/${parts[1]}/${parts[0]}` : String(value);
};

// Family #72322 · element #72322 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/archive/202608261547-pipelinenews/objects/modules/sha256/ae4bb559312e84d7cdcb69dfee444644b328c370e198d5939ff8abeca92d6235.js#L229-L233
export const f72322_csvCell = function csvCell(value) {
  let text = String(value ?? "");
  if (/^[=+\-@]/u.test(text)) text = `'${text}`;
  return `"${text.replaceAll('"', '""')}"`;
};

// Family #72369 · element #72369 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/archive/202608261547-pipelinenews/tooling/check-repd-source-v2.mjs#L24-L43
export const f72369_parseCsv = function parseCsv(source) {
  const rows = [];
  let row = [];
  let field = "";
  let quoted = false;
  for (let index = 0; index < source.length; index += 1) {
    const char = source[index];
    if (quoted) {
      if (char === '"' && source[index + 1] === '"') { field += '"'; index += 1; }
      else if (char === '"') quoted = false;
      else field += char;
    } else if (char === '"') quoted = true;
    else if (char === ",") { row.push(field); field = ""; }
    else if (char === "\n") { row.push(field.replace(/\r$/, "")); rows.push(row); row = []; field = ""; }
    else field += char;
  }
  if (field || row.length) { row.push(field.replace(/\r$/, "")); rows.push(row); }
  const headers = rows.shift().map((header, index) => (index === 0 ? header.replace(/^\uFEFF/, "") : header).trim());
  return rows.filter((values) => values.some(Boolean)).map((values) => Object.fromEntries(headers.map((header, index) => [header, values[index] ?? ""])));
};

// Family #73336 · element #73336 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/atman/202608290020-verify-v9-6-2-complete-equivalence.mjs#L6-L8
export const f73336__anonymous_ = (pairs, value, index, values) => value.startsWith("--")
    ? [...pairs, [value.slice(2), values[index + 1]]]
    : pairs;

// Family #73338 · element #73338 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/atman/202608290020-verify-v9-6-2-complete-equivalence.mjs#L29-L32
export const f73338_rangeTotal = function rangeTotal(text) {
  const match = String(text).replaceAll(",", "").match(/\bof\s+(\d+)\b/u);
  return match ? Number(match[1]) : Number.NaN;
};

// Family #73555 · element #73555 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/discovery/javascript/202608270844-bbc-enrichment.mjs#L25-L29
export const f73555_isPlainObject = function isPlainObject(value) {
  if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
  const prototype = Object.getPrototypeOf(value);
  return prototype === Object.prototype || prototype === null;
};

// Family #73556 · element #73556 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/discovery/javascript/202608270844-bbc-enrichment.mjs#L31-L33
export const f73556_compactText = function compactText(value) {
  return String(value ?? '').replace(/\s+/g, ' ').trim();
};

// Family #73559 · element #73559 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/discovery/javascript/202608270844-bbc-enrichment.mjs#L69-L71
export const f73559_escapeRegExp = function escapeRegExp(value) {
  return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
};

// Family #75391 · element #75391 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/releases/javascript/202609010200-sector-intelligence.js#L84-L89
export const f75391_validateAsset = function validateAsset(asset) {
  if (!asset || typeof asset !== "object") throw new Error("sector payload asset is missing");
  if (!/^data\/202609010200-sector-intelligence\.json$/u.test(asset.url)) throw new Error("sector payload URL changed");
  if (!Number.isSafeInteger(asset.bytes) || asset.bytes <= 0) throw new Error("sector payload byte count is invalid");
  if (!/^[a-f0-9]{64}$/u.test(asset.sha256)) throw new Error("sector payload digest is invalid");
};

// Family #75481 · element #75481 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/releases/javascript/202609010719-sector-intelligence.js#L84-L89
export const f75481_validateAsset = function validateAsset(asset) {
  if (!asset || typeof asset !== "object") throw new Error("sector payload asset is missing");
  if (!/^data\/202609010719-sector-intelligence\.json$/u.test(asset.url)) throw new Error("sector payload URL changed");
  if (!Number.isSafeInteger(asset.bytes) || asset.bytes <= 0) throw new Error("sector payload byte count is invalid");
  if (!/^[a-f0-9]{64}$/u.test(asset.sha256)) throw new Error("sector payload digest is invalid");
};

// Family #75612 · element #75612 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/releases/javascript/202609010836-projects-v9-5-1.js#L30-L37
export const f75612_gridAnalyticsEngineV1 = function gridAnalyticsEngineV1(project) {
  const explicit = String(project?.grid_engine || "").trim();
  if (explicit) return explicit;
  const technology = String(project?.technology || "").trim().toLowerCase();
  if (technology === "wind_offshore") return "VENTUS OFFSHORE DETERMINISTIC";
  if (technology === "interconnector") return "VENTUS INTERCONNECTOR";
  return "VENTUS ONSHORE";
};

// Family #75819 · element #75819 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/tools/intelligence/cartridges/map-corpus-contract/proof.mjs#L82-L85
export const f75819__anonymous_ = (row) => ({ lane: "wider", project: {
    repd_ref: row.ref || "", name: row.n, technology: row.t, capacity_mw: row.c,
    longitude: row.ll?.[0], latitude: row.ll?.[1], geometry_status: "valid",
  } });

// Family #76216 · element #76216 · 2 places in 1 repositories · https://github.com/Ventusltd/pipelinenews/blob/45c944c8640a9d7ae65edb51d66032ba204f3f46/ui/javascript/202608270055-v8-fast-runtime.js#L292-L300
export const f76216_atlasUrl = function atlasUrl(item) {
  if (item.geometry_status !== "valid") return "";
  const url = new URL("https://ventusltd.github.io/gridatlas/202608300453-atlas-v9/");
  url.searchParams.set("repd_ref", item.repd_ref);
  url.searchParams.set("technology", item.technology);
  url.searchParams.set("longitude", item.longitude);
  url.searchParams.set("latitude", item.latitude);
  return url.href;
};

// Family #77453 · element #77453 · 2 places in 1 repositories · https://github.com/Ventusltd/solar-electrical-topology-analysis-engine-text-based/blob/d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9/tests/v8-model.test.js#L7-L9
export const f77453_close = function close(actual, expected, tolerance = 1e-9) {
  return Math.abs(actual - expected) <= tolerance;
};

// Family #77454 · element #77454 · 2 places in 1 repositories · https://github.com/Ventusltd/solar-electrical-topology-analysis-engine-text-based/blob/d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9/v10-development/authority/authority-evidence.js#L3-L8
export const f77454_requireObject = function requireObject(value, name) {
  if (value === null || typeof value !== 'object' || Array.isArray(value)) {
    throw new TypeError(`${name} must be an object`);
  }
  return value;
};

// Family #77455 · element #77455 · 2 places in 1 repositories · https://github.com/Ventusltd/solar-electrical-topology-analysis-engine-text-based/blob/d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9/v10-development/authority/authority-evidence.js#L10-L13
export const f77455_requireArray = function requireArray(value, name) {
  if (!Array.isArray(value)) throw new TypeError(`${name} must be an array`);
  return value;
};

// Family #77456 · element #77456 · 2 places in 1 repositories · https://github.com/Ventusltd/solar-electrical-topology-analysis-engine-text-based/blob/d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9/v10-development/authority/authority-evidence.js#L15-L18
export const f77456_requireValue = function requireValue(value, name) {
  if (value === undefined) throw new TypeError(`${name} is required`);
  return value;
};

// Family #77606 · element #77606 · 2 places in 1 repositories · https://github.com/Ventusltd/solar-electrical-topology-analysis-engine-text-based/blob/d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9/v8-leapfrog/authority-reconciliation.js#L81-L83
export const f77606_nearlyEqual = function nearlyEqual(actual, expected, tolerance = 1e-9) {
      return Math.abs(actual - expected) <= tolerance;
    };

// Family #77776 · element #77776 · 2 places in 1 repositories · https://github.com/Ventusltd/spiders/blob/e391092b836c2bdd1420b4470e06a107be622524/species/genome-spider/lib/edges.mjs#L17-L21
export const f77776_lineOf = function lineOf(text, index) {
  let line = 1;
  for (let i = 0; i < index && i < text.length; i++) if (text[i] === '\n') line++;
  return line;
};

// Family #78252 · element #78252 · 2 places in 1 repositories · https://github.com/Ventusltd/teleprinter/blob/e45bfe38c3040b0f36f7df94ce262b63db8d0b60/source.js#L24-L28
export const f78252_stamp = () => {
  const d = new Date();
  const p = (n) => String(n).padStart(2, '0');
  return `${d.getUTCFullYear()}${p(d.getUTCMonth() + 1)}${p(d.getUTCDate())}${p(d.getUTCHours())}${p(d.getUTCMinutes())}`;
};

// Family #80357 · element #80357 · 2 places in 1 repositories · https://github.com/Ventusltd/ventus-grid-engine/blob/ad566356a44e006682e956483d569f31ddbb9630/engine/current-from-power.js#L92-L97
export const f80357_phasesOf = function phasesOf(phases) {
    if (phases !== 'three' && phases !== 'single') {
        throw new RangeError(`phases must be "three" or "single", received ${JSON.stringify(phases)}`);
    }
    return phases;
};

// Family #80417 · element #80417 · 2 places in 1 repositories · https://github.com/Ventusltd/ventus-grid-engine/blob/ad566356a44e006682e956483d569f31ddbb9630/proofs/electrification-demand.proof.mjs#L36-L38
export const f80417_throws = (fn, pattern) => {
    try { fn(); return false; } catch (e) { return pattern.test(e.message); }
};

// Family #131808 · element #131808 · 2 places in 1 repositories · https://github.com/Ventusltd/galaxies-wafers/blob/5814793812add74605660fa821e6a39b8de80588/app.mjs#L816-L823
export const f131808__anonymous_ = j => {
    if (!j._bySymbol) {
      const m = new Map();
      for (const b of j.blocks || []) if (!m.has(b.symbol)) m.set(b.symbol, b);
      Object.defineProperty(j, '_bySymbol', { value: m });
    }
    return j._bySymbol;
  };

// Family #131818 · element #131818 · 2 places in 1 repositories · https://github.com/Ventusltd/galaxies-wafers/blob/5814793812add74605660fa821e6a39b8de80588/app.mjs#L1092-L1094
export const f131818_who = (xs, verb) => xs?.length
    ? `${verb} ${xs.slice(0, 8).map(u => `#${u.family} ${u.name}`).join(', ')}${xs.length > 8 ? ` and ${xs.length - 8} more` : ''} (name-match inference by the modular star build: a needed name linked to the families defining it, ${[...new Set(xs.map(u => u.via || 'by name'))].join(' / ')})`
    : null;

// Family #131837 · element #131837 · 2 places in 1 repositories · https://github.com/Ventusltd/galaxies-wafers/blob/5814793812add74605660fa821e6a39b8de80588/app.mjs#L1371-L1380
export const f131837_functionBody = function functionBody(lines, fn) {
  const start = lines.findIndex(l => new RegExp(`function\\s+${fn}\\b`).test(l));
  if (start < 0) return '';
  let depth = 0, seen = false;
  for (let j = start; j < lines.length; j++) {
    for (const c of lines[j].replace(/(['"`])(?:\\.|(?!\1).)*\1/g, '')) { if (c === '{') { depth++; seen = true; } else if (c === '}') depth--; }
    if (seen && depth <= 0) return lines.slice(start, j + 1).join('\n');
  }
  return lines.slice(start).join('\n');
};

// Family #131838 · element #131838 · 2 places in 1 repositories · https://github.com/Ventusltd/galaxies-wafers/blob/5814793812add74605660fa821e6a39b8de80588/app.mjs#L1381-L1385
export const f131838_outputsOf = function outputsOf(text) {
  const out = [];
  for (const m of text.matchAll(/quantity:\s*'([^']+)'[\s\S]{0,120}?unit:\s*'([^']*)'/g)) out.push(`${m[1]} in ${m[2]}`);
  return [...new Set(out)];
};

// Family #132395 · element #132395 · 2 places in 1 repositories · https://github.com/Ventusltd/galaxies-wafers/blob/5814793812add74605660fa821e6a39b8de80588/iterations/22-fast-zoom/layers-panel.mjs#L333-L339
export const f132395_bandsInView = function bandsInView(s, v) {
  const z = v.zoom, hw = v.w / 2 / z, hh = v.h / 2 / z;
  const ax = Math.abs(v.x), ay = Math.abs(v.y);
  const r0 = Math.hypot(Math.max(ax - hw, 0), Math.max(ay - hh, 0)), r1 = Math.hypot(ax + hw, ay + hh);
  const n = s.tiles.bands.length;
  return [Math.min(n, Math.floor(r0 / s.tiles.S)), Math.min(n - 1, Math.floor(r1 / s.tiles.S))];
};

// Family #135551 · element #135551 · 2 places in 1 repositories · https://github.com/Ventusltd/faraday/blob/e439b450f37a8c124fa4a0cb38159ae0dc337062/apparatus/cells.mjs#L28-L34
export const f135551_inputOn = function inputOn(schedule, name, t) {
  const s = schedule[name];
  if (s === 0 || s === 1) return s;
  if (!s) return 0;
  for (const [from, to] of s) if (t >= from && t < to) return 1;
  return 0;
};

// Family #173532 · element #173532 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/news/context-ui/adapter.mjs#L7-L12
export const f173532_equal = function equal(a, b) {
  if (a === b) return true;
  if (!a || !b || typeof a !== 'object' || typeof b !== 'object') return false;
  const keys = Object.keys(a);
  return keys.length === Object.keys(b).length && keys.every(k => Object.hasOwn(b, k) && equal(a[k], b[k]));
};

// Family #173536 · element #173536 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/news/context-ui/adapter.mjs#L37-L43
export const f173536_scope = function scope(nativeScope, entity, family, relationship) {
  const kind = relationship === 'portfolio_storage_access' || nativeScope === 'consolidated_group'
    ? 'portfolio' : nativeScope === 'issuer' ? 'issuer'
      : ['project', 'site', 'campus', 'phase'].includes(nativeScope) ? 'project'
        : family === 'policy' ? 'policy' : 'UNKNOWN';
  return {kind, native_scope: nativeScope, entity_id: entity, canonical_project_id: null, binding: 'UNLINKED'};
};

// Family #173559 · element #173559 · 2 places in 1 repositories · https://github.com/Ventusltd/globalgrid2050/blob/32ae2ded87b626ab573efa6887547f2128c55304/automation/news/context-ui/render.mjs#L41-L45
export const f173559_node = function node(document, tag, text) {
  const result = document.createElement(tag);
  if (text !== undefined) result.textContent = text;
  return result;
};

// Family #179120 · element #179120 · 2 places in 1 repositories · https://github.com/Ventusltd/seed-data/blob/e4af7ee340a38d94f21ddbba147395b569ccce11/experiments/explain-cable-screen-change/followup/explain.mjs#L31-L39