Skip to content

Commit

Permalink
feat: Add the concept of a 'label builder'
Browse files Browse the repository at this point in the history
This allows us to control higher level aspects of the label, such as
whether or not administrative data comes first.

Most parts of the world would write an address with the
housenumber/street first, and admin info second, but not _all_ places do
this.

With a label builder we can support these places
  • Loading branch information
orangejulius committed Feb 18, 2022
1 parent 382276b commit 4528c45
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions labelGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,30 @@ function buildPostfixLabelParts(schema, record) {
return [record.name.default];
}

module.exports = function( record ){
const schema = getSchema(record.country_a);
const separator = _.get(schema, ['meta','separator'], ', ');
// builds a complete label by combining several components
// the parts generally follow this format
// prefix parts: the venue name or address
// admin parts: administrative information like city
// postfix part: higher level admin areas
function defaultBuilder(schema, record) {

// in virtually all cases, this will be the `name` field
const prefixParts = buildPrefixLabelParts(schema, record);
const adminParts = buildAdminLabelPart(schema, record);
const postfixParts = buildPostfixLabelParts(schema, record);

let labelParts = _.concat(prefixParts, adminParts, postfixParts);
const labelParts = _.concat(prefixParts, adminParts, postfixParts);

// retain only things that are truthy
labelParts = _.compact(labelParts);
return _.compact(labelParts);
}

module.exports = function( record ){
const schema = getSchema(record.country_a);
const separator = _.get(schema, ['meta','separator'], ', ');
const builder = _.get(schema, ['meta', 'builder'], defaultBuilder);

let labelParts = builder(schema, record);

// third, dedupe and join with a comma and return
if (isInKOR(record)) {
Expand Down

0 comments on commit 4528c45

Please sign in to comment.