@lanka-data-layer/electoral
v0.1.0
Published
Offline Sri Lankan election results — 2024 parliamentary and 2015/2019/2024 presidential, by district, polling division, and postal vote. Zero dependencies.
Maintainers
Readme
@lanka-data-layer/electoral
Offline Sri Lankan election results — 2024 parliamentary and the 2015, 2019, and 2024 presidential elections, broken down by electoral district, polling division, and postal vote, plus the national total. The dataset ships inside the package: no network calls, no filesystem reads, nothing to configure. Works in Node 18+, browsers, and edge runtimes (Workers, Deno, Bun) alike — it's just data and pure functions.
Install
npm install @lanka-data-layer/electoralQuick start
import {
listElections,
getElection,
listEntities,
getEntity,
listParties,
getResult,
resultsForElection,
resultsForEntity,
} from "@lanka-data-layer/electoral";
listElections();
// [{ id: "parl-2024", type: "parliamentary", year: 2024, date: "2024-11-14", label: "2024 Parliamentary" }, ...]
getElection("pres-2024");
// { id: "pres-2024", type: "presidential", year: 2024, date: "2024-09-21", label: "2024 Presidential" }
listEntities().length; // 205 — electoral districts, polling divisions, postal-vote entities, and "LK" (national)
getEntity("EC-01");
// { id: "EC-01", kind: "ED", name: "Colombo", edId: "EC-01" }
listParties().find((p) => p.electionId === "parl-2024" && p.code === "NPP");
// { electionId: "parl-2024", code: "NPP", candidate: "...", name: "National People's Power", color: "#dc2626" }
getResult("parl-2024", "EC-01");
// {
// electors: 1765351, polled: 1211738, valid: 1149125, rejected: 62613,
// turnout: 0.6864,
// winner: { party: "NPP", votes: 788636, share: 0.6863 },
// parties: [{ party: "NPP", votes: 788636, share: 0.6863 }, ...]
// }
resultsForElection("parl-2024"); // every entity's result for one election, each tagged with entityId
resultsForEntity("EC-01"); // one entity's result across every election it appears in, tagged with electionIdgetResult, resultsForElection, and resultsForEntity all return null
(or an empty array, for the list forms) when given an id this dataset
doesn't cover — there's no need to wrap calls in try/catch.
Data model
- Election —
{ id, type, year, date, label }. Four elections total:parl-2024,pres-2015,pres-2019,pres-2024. - ElectoralEntity —
{ id, kind, name, edId }, wherekindis one of"ED"(electoral district),"PD"(polling division),"POSTAL"(a district's postal-vote entity), or"NATIONAL"(the country total, id"LK").edIdis the parent electoral district's id, ornullfor the national entity. - Party —
{ electionId, code, candidate, name, color }, one row per party per election it contested (a party's candidate, display name, and color can differ between elections). This list covers the notable contesting parties, not every candidate —Result.partiesbelow is the exhaustive one. - Result —
{ electors, polled, valid, rejected, turnout, winner, parties }.turnoutispolled / electorsto four decimal places (nullifelectorsis 0).winneris{ party, votes, share }withshareas a fraction ofvalidvotes, ornullif the source recorded no winner.partiesis every party code the source recorded for that result, descending by votes, each with its ownshareofvalid.
All types are exported — Election, ElectoralEntity, ElectoralEntityKind,
Party, Result, PartyResult, Winner, ResultForElection,
ResultForEntity, SourceAttribution.
Data provenance
| Source | License | |---|---| | Election Commission of Sri Lanka, via nuuuwan/lk_elections | Open |
The same attribution is exported at runtime as SOURCES: SourceAttribution[].
Versioning and freshness
DATA_VERSION (format YYYYMMDD.N) is exported alongside the data and
tracks the build that produced it — compare it against a previously cached
value to detect a stale copy. This package is a point-in-time snapshot
generated by the Lanka Data Layer
monorepo's foundry ETL pipeline; a new release is cut whenever the
underlying election data changes. If you need results for an election this
snapshot doesn't cover yet, check the hosted API
or open an issue.
Part of Lanka Data Layer
This package is one piece of Lanka Data Layer,
an open geo-data platform for Sri Lanka — reverse geocoding, universal
search, postal codes, population, and election results for every GN
division, DS division, district, and province on the island. If you'd
rather query this data over HTTP instead of bundling it, the same results
are served at lanka-data-layer.prabhavalabs.com
(GET /v1/elections, GET /v1/elections/:id/results/:entity). See also
@lanka-data-layer/census
for population and demographic indicators.
License
MIT — see LICENSE. Election data remains under the source's own terms (see Data provenance above); please preserve attribution to the Election Commission of Sri Lanka in anything you build with it.
