Reference · Flags a page registers itself
registerFlagsfunction
Registers a set of flags a page brings: the source is checked at once (a TypeError for an empty credit, no licence, a bad id, a set id already registered, or a source that is not a records source), its
records are read once, and each record is checked on its own. A record that is not allowed is left out and listed in rejected with the reason, never drawn part-cleaned; a source that throws, or holds more than
200,000 records, adds nothing and says so. A flag's id is custom:<slug>; one already held by another set is left out (the first keeps it), and so is any id that is not in that form, which is how a country's
code or an org: id can never be shadowed. At most 1,000 flags in all.
What an SVG may hold: svg g defs symbol path rect circle ellipse line polyline polygon use linearGradient radialGradient stop clipPath mask title desc; the usual drawing attributes (fill, stroke, d,
transform, viewBox and so on) read by a rule each; href and url() only as a #id in the same file, the id there. No scripts, styles, images, links, animation, filters, text, foreignObject, event
attributes or prefixed names; no data: or javascript:; no character references (&#…;) and no entity but & < > " ' in a title or description; a viewBox and no width or height on the
root; 64 KiB, 32 levels and 4,000 elements (each <use>, gradient href, clip-path and mask counted as what it points to) at most; xmlns exactly the SVG namespace. The SVG drawn is written again from what was read, with its ids made custom-<slug>--<id>.
Import it
import { registerFlags } from "@johnmorrisdotca/hata/custom";
Definition
function registerFlags(source: CustomFlagSource, options?: { signal?: AbortSignal; }): Promise<FlagsRegistered>
Parameters
| Name | Type | Description |
|---|---|---|
source | CustomFlagSource | The set: a records source of the data door ( |
options (optional) | { signal?: AbortSignal; } |
|
Returns
Promise<FlagsRegistered>
A promise of what was done.
Examples
import { customCreditLine, customFlag, registerFlags } from "@johnmorrisdotca/hata/custom";
const done = await registerFlags({
kind: "records",
info: {
id: "my-club",
name: { en: "My club", ja: "私のクラブ" },
credit: { en: "Harbour FC crest, drawn by the club", ja: "ハーバーFCの紋章(クラブ作成)" },
licence: { name: "Used with the club's permission", url: "https://example.org/permission" },
url: "https://example.org/club",
retrieved: "2026-11-13",
},
records: () => [{ id: "custom:harbour-fc", name: { en: "Harbour FC" }, svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><path fill="#036" d="M0 0h3v2H0z"/></svg>' }],
});
console.log(done.added, customFlag("custom:harbour-fc")?.startsWith("<svg"), customCreditLine("en"));
done.remove();[ 'custom:harbour-fc' ] true Harbour FC crest, drawn by the club (Used with the club's permission).What it prints (run when this page was built)