Skip to content

truncate

truncate(code, to): Postcode

Shortens a postcode to a less precise segment, for example from a building to its area.

Postcode

A parsed postcode.

Precision

The precision to keep. It must not be more precise than the code.

Postcode

The shorter postcode.

RangeError when to is more precise than the code, or is not a precision.

const building = parse('EK-01-A03-FK-01');
if (building.ok) {
truncate(building.value, 'district').canonical; // 'EK-01-A03'
}

Unofficial. Not made or endorsed by NIPOST.