@lanka-data-layer/census
v0.1.0
Published
Offline Sri Lankan census indicators — 2024 population, age structure, ethnicity, and religion for the country, every district, and every DS division, with a 2012-census comparison. Zero dependencies.
Downloads
87
Maintainers
Readme
@lanka-data-layer/census
Offline Sri Lankan census indicators — 2024 population, age structure, ethnicity, and religion for the country, all 25 districts, and all 339 DS divisions (365 p-coded units in total), plus a 2012-vs-2024 comparison for the 25 districts. 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/censusQuick start
import { CENSUS_YEAR, coveredPcodes, population, ethnicity, religion, demographics } from "@lanka-data-layer/census";
CENSUS_YEAR; // 2024
coveredPcodes().length; // 365 — country ("LK") + 25 districts + 339 DS divisions
population("LK11");
// { total: 2375415, male: 1154799, female: 1220616,
// ages: { "0-14": 392721, "15-59": 1525340, "60-64": 136268, "65+": 321086 } }
ethnicity("LK11");
// [{ key: "sinhala", count: 1807945, share: 0.7611 }, { key: "moor", count: 285346, share: 0.1201 }, ...]
religion("LK11");
// [{ key: "buddhist", count: 1682524, share: 0.7083 }, ...]
demographics("LK11");
// {
// pcode: "LK11", censusYear: 2024,
// population: { total: 2375415, male: 1154799, female: 1220616, sexRatio: 94.6, femaleShare: 0.5139 },
// age: {
// buckets: [{ bucket: "0-14", count: 392721, share: 0.1653 }, ...],
// dependencyRatio: 43, workingAgeShare: 0.6995, childShare: 0.1653, elderlyShare: 0.1352,
// },
// ethnicity: [...], religion: [...],
// change2012: {
// ethnicity: [{ key: "sinhala", share2012: 0.7454, share2024: 0.7611, delta: 0.0157 }, ...],
// religion: [...],
// },
// }Every function returns null for a p-code this dataset doesn't cover —
there's no need to wrap calls in try/catch. population, ethnicity,
and religion cover all 365 p-codes; GN divisions (level 4) are outside
2024 census coverage and always resolve to null.
Data model
population(pcode)— raw 2024 counts:{ total, male, female, ages }, whereagesis keyed by the census's four coarse buckets ("0-14","15-59","60-64","65+"— the published tables carry no finer breakdown and no sex-by-age cross-tabulation).ethnicity(pcode)/religion(pcode)—{ key, count, share }[], descending by count.shareis a fraction of the group's own total (all ethnicity counts, or all religion counts), four decimal places.demographics(pcode)— the full derived profile, matching the indicators served by the hosted API's/v1/demographicsendpoint: population withsexRatio(males per 100 females) andfemaleShare; age with per-bucket shares plusdependencyRatio((0-14 + 65+) / (15-59 + 60-64) * 100),workingAgeShare,childShare, andelderlyShare;ethnicityandreligionbreakdowns; andchange2012, a 2012-vs-2024 comparison restricted to keys present in both census years,nullfor any p-code outside the 25 districts the 2012 census covered.coveredPcodes()— every p-code with 2024 census data, for iterating the full dataset or checking coverage up front.
All types are exported — Population, StatEntry, AgeBucket,
AgeBucketShare, ChangeEntry, Demographics, SourceAttribution.
Data provenance
| Source | License | |---|---| | Department of Census and Statistics, Sri Lanka | Not stated (government statistical publication) |
The same attribution is exported at runtime as SOURCES: SourceAttribution[].
The Department of Census and Statistics publishes the 2024 Census of
Population and Housing tables without explicit license terms on the source
pages; this package reproduces them as a public government statistical
publication, with full attribution.
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 census data changes. If you need indicators this snapshot
doesn't cover, 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
indicators are served at lanka-data-layer.prabhavalabs.com
(GET /v1/demographics/:pcode). See also
@lanka-data-layer/electoral
for election results.
License
MIT — see LICENSE. Census data remains under the source's own terms (see Data provenance above); please preserve attribution to the Department of Census and Statistics, Sri Lanka in anything you build with it.
