快速上手
安装
pnpm add belgicanpm install belgicayarn add belgica这个包是 ESM 格式,自带类型定义,没有运行时依赖,可以在浏览器和 Node 22.12 及以上版本中运行;在 Node 中也可以用 require() 加载。测试覆盖 Node 22.12、22、24 和 26。
只导入你需要的部分
数据被打包进 JavaScript,所以从包的根路径导入会加载所有数据集。每个数据集都有自己的 entry point, 其中法院和 canton(含其辖区的法律条文)是体积最大的两个:
import { getInterestRate } from 'belgica/interest-rates'
import { getCourt } from 'belgica/courts'
import { getCanton } from 'belgica/territory'
import { getMunicipalitiesForPostalCode } from 'belgica/postal-codes'canton 边界是个例外:它包含约一百万个几何坐标点,只在 belgica/canton-boundaries 中提供,包的根路径从不加载它。
| Entry point | 加载的 JavaScript | gzip |
|---|---|---|
belgica | 1031 KB | 110 KB |
belgica/territory | 251 KB | 33 KB |
belgica/canton-boundaries | 254 KB | 34 KB |
belgica/arrondissement-boundaries | 254 KB | 34 KB |
belgica/courts | 587 KB | 55 KB |
belgica/court-locations | 80 KB | 10 KB |
belgica/courts/format | 1 KB | 1 KB |
belgica/courts/load | 16 KB | 2 KB |
belgica/cantons | 67 KB | 8 KB |
belgica/cantons/territory | 78 KB | 17 KB |
belgica/prisons | 62 KB | 7 KB |
belgica/houses-of-justice | 27 KB | 4 KB |
belgica/interest-rates | 13 KB | 3 KB |
belgica/calendar | 8 KB | 3 KB |
belgica/postal-codes | 169 KB | 19 KB |
初步了解
import {
getCourt,
findCourts,
getCanton,
getCantonsForMunicipality,
getInterestRate,
} from 'belgica'
getCourt('justice-of-the-peace-gent-1').name.nl // 'Vredegerecht Gent 1'
findCourts({ type: 'enterprise-court', arrondissement: 'west-vlaanderen' })
getCantonsForMunicipality('44088') // [Canton merelbeke-melle]
getCantonsForMunicipality('44021') // Gent 1–5:被分割的城市,见各 canton 的 `territory`
getCanton('oudergem').seat.nl // 'Etterbeek'
getInterestRate('2024-06-15', 'legal') // { rate: 5.75, period: { from: '2024-01-01', to: '2024-12-31' } }
getInterestRate(new Date(2014, 5, 15), 'commercial', { contractAfter20130316: true }) // { rate: 8.5, … }常见任务
某个地址由哪个治安法院管辖?
在比利时,每个司法 canton(最小的司法辖区单位)设有一个 vredegerecht / justice de paix(治安法院)。 先查出市镇的 REFNIS 代码,取得它所属的 canton,再取得该 canton 的治安法院。
import { getCantonsForMunicipality, getJusticeOfThePeace } from 'belgica'
const cantons = getCantonsForMunicipality('44088')
if (cantons.length === 1) {
const court = getJusticeOfThePeace(cantons[0].id) // 每个 canton 都有自己的治安法院
}
// 以传票送达当天为准,而不是今天
getCantonsForMunicipality('44088', { on: '2025-09-15' })如果一个城市分属多个 canton(Antwerpen、Gent、Brussel、Luik……),结果会不止一个。这时由街道地址决定, 每个 canton 的 territory 字段保存了它所辖部分的法律描述。可以在 地域与 canton 页面上试一试。
如果有地址的坐标,canton 边界就能给出答案:
import { findCantonsAt } from 'belgica/canton-boundaries'
const [canton] = findCantonsAt(3.7268, 51.053) // 经度,纬度:gent-1
const court = getJusticeOfThePeace(canton.id)某个市镇由哪个法院管辖?
除治安法院外,每个法院都按法律规定列出它覆盖的 canton(cantons)。findCourtsWithJurisdiction 会在这些列表中查找 市镇所属的 canton。
import { findCourtsWithJurisdiction, getDivisions } from 'belgica'
findCourtsWithJurisdiction('23088', 'police-court') // [police-court-vilvoorde],而不是 Brussel
findCourtsWithJurisdiction('21004', 'labour-court') // 布鲁塞尔的荷兰语法院和法语法院
// 返回的是整个法院;由哪个分部审理案件,数据中还没有
const [court] = findCourtsWithJurisdiction('44021', 'enterprise-court')
getDivisions(court.id) // enterprise-court-gent-gent, enterprise-court-gent-brugge, …从邮政编码出发
地址上写的是邮政编码,而不是 REFNIS 代码。findCourtsForPostalCode 先从邮政编码找到市镇 (邮政编码),再从市镇找到治安法院和指定类型的法院。结果按市镇给出:有三个邮政编码 (1040、1050、1804)分属两个市镇,这时由街道决定。
import { findCourtsForPostalCode, getMunicipalitiesForPostalCode } from 'belgica'
const [gent] = findCourtsForPostalCode('9050', 'labour-court')
gent.municipality.name.nl // 'Gent'
gent.courts.map((c) => c.id) // ['labour-court-gent']
gent.justicesOfThePeace.map((c) => c.canton.id) // ['gent-1', …, 'gent-5']:由街道决定
findCourtsForPostalCode('1040', 'police-court').map((r) => r.municipality.name.nl) // ['Brussel', 'Etterbeek']
getMunicipalitiesForPostalCode('9050').map((m) => m.id) // ['44021']在分属多个 canton 的城市里,邮政编码只能把问题缩小到市镇;要确定 canton 仍然需要街道,而 canton 的边界目前还是 法律条文,直到 #29 把它们加为几何数据。
某一天应付的利息
import { getInterestRate, getLatestKnownRateDate } from 'belgica'
const result = getInterestRate(new Date(), 'commercial')
if (!result) {
console.warn(`No rate on file; latest known day is ${getLatestKnownRateDate('commercial')}`)
}对于没有利率记录的日期,getInterestRate 返回 null,这样你可以发出警告,而不是悄悄地按 0 % 计算。 对于格式错误的日期(例如 '2024-6-1'),它会抛出 RangeError:请传入 YYYY-MM-DD 或 Date。
其他语言的法院名称
名称按各法院自己公布的形式收录,涵盖它有页面的每种语言。弗拉芒大区的法院只用荷兰语公布;布鲁塞尔的双语法院 用荷兰语和法语;Eupen 的法院用德语和法语。
getCourt('court-of-appeal-brussel').name.fr // "Cour d'appel de Bruxelles"
getCourt('police-court-eupen-sankt-vith').name.de // 'Polizeigericht Eupen, Abteilung Sankt Vith'原始 JSON
数据文件也一并导出:
import courts from 'belgica/data/courts.json' with { type: 'json' }id 是公共 API
各项目会保存 justice-of-the-peace-gent-1 或 oost-vlaanderen 这样的 id,所以它们在同一个主版本内绝不会改变 (见标识符),版本号遵循以下规则:
| 变更 | 版本 |
|---|---|
| 新增数据 | minor |
| 修正某个值 | patch |
| 删除或重命名某个 id | major |