Browse Source

converted labelSchema to .js with module.exports

this is in preparation to introduce functions into the schema instead of strings
pull/430/head
Stephen Hess 9 years ago committed by Julian Simioni
parent
commit
431fe44f05
  1. 5
      helper/labelGenerator.js
  2. 23
      helper/labelSchema.js
  3. 23
      helper/labelSchema.json
  4. 2
      test/unit/helper/labelSchema.js

5
helper/labelGenerator.js

@ -1,7 +1,7 @@
var _ = require('lodash'),
check = require('check-types'),
schemas = require('./labelSchema.json');
schemas = require('./labelSchema');
module.exports = function( record ){
var schema = getSchema(record.country_a);
@ -23,7 +23,6 @@ module.exports = function( record ){
labelParts = buildOutput(labelParts, schema[key], record);
}
// de-dupe, join, trim
// NOTE: while it may seem odd to call `uniq` on the list of label parts,
// the effect is quite subtle. Take, for instance, a result for "Lancaster, PA"
// the pseudo-object is:
@ -44,6 +43,8 @@ module.exports = function( record ){
// where the `name` field would contain the address or name of a point-of-interest
//
// Also see https://github.com/pelias/api/issues/429 for other ways that this is bad
//
// de-dupe, join, trim
return _.uniq( labelParts ).join(', ').trim();
};

23
helper/labelSchema.js

@ -0,0 +1,23 @@
module.exports = {
'USA': {
'local': ['localadmin', 'locality', 'neighbourhood', 'county'],
'regional': ['region_a', 'region'],
'country': ['country_a']
},
'GBR': {
'local': ['neighbourhood', 'county', 'localadmin', 'locality', 'region'],
'regional': ['county','country','region']
},
'SGP': {
'local': ['neighbourhood', 'region', 'county', 'localadmin', 'locality'],
'regional': ['county','country','region']
},
'SWE': {
'local': ['neighbourhood', 'region', 'county', 'localadmin', 'locality'],
'regional': ['country']
},
'default': {
'local': ['localadmin', 'locality', 'neighbourhood', 'county', 'region'],
'regional': ['country']
}
};

23
helper/labelSchema.json

@ -1,23 +0,0 @@
{
"USA": {
"local": ["localadmin", "locality", "neighbourhood", "county"],
"regional": ["region_a", "region"],
"country": ["country_a"]
},
"GBR": {
"local": ["neighbourhood", "county", "localadmin", "locality", "region"],
"regional": ["county","country","region"]
},
"SGP": {
"local": ["neighbourhood", "region", "county", "localadmin", "locality"],
"regional": ["county","country","region"]
},
"SWE": {
"local": ["neighbourhood", "region", "county", "localadmin", "locality"],
"regional": ["country"]
},
"default": {
"local": ["localadmin", "locality", "neighbourhood", "county", "region"],
"regional": ["country"]
}
}

2
test/unit/helper/labelSchema.js

@ -1,5 +1,5 @@
var schemas = require('../../../helper/labelSchema.json');
var schemas = require('../../../helper/labelSchema');
var alpha3 = require('../mock/alpha3.json');
module.exports.tests = {};

Loading…
Cancel
Save