normaliseBodiesfunction
Cleans a list that came as text (the bodies attribute is JSON): an entry with no id, no place or no brightness is dropped; a missing name falls back to the other language, else the id; a bad phase counts as full;
a bad size or brightLimb is dropped; of two entries with the same id the first is kept. Anything that is not a list gives an empty one.
Import it
import { normaliseBodies } from "@johnmorrisdotca/hoshi-stars/chart";
Definition
function normaliseBodies(value: unknown): SkyBody[]
Parameters
| Name | Type | Description |
|---|---|---|
value | unknown | The parsed JSON, or anything. |
Returns
SkyBody[]
The bodies that can be drawn.
Examples
import { normaliseBodies } from "@johnmorrisdotca/hoshi-stars/chart";
const list = normaliseBodies([{ id: "mars", names: { en: "Mars" }, ra: 10, dec: -5, magnitude: 1.1, phase: 0.9 }, { id: "bad" }]);
console.log(list.length, list[0]?.names.ja);
// 1 Mars1 MarsWhat it prints (run when this page was built)