Browse Source

Replace depricated Lodash function contains with includes

See https://github.com/lodash/lodash/wiki/Changelog#jan-12-2016--diff--docs
pull/405/head
Julian Simioni 9 years ago
parent
commit
f4a5dd812b
  1. 2
      helper/adminFields.js
  2. 10
      helper/geojsonify.js
  3. 2
      helper/labelGenerator.js
  4. 2
      sanitiser/_details.js
  5. 2
      sanitiser/_flag_bool.js
  6. 4
      sanitiser/_groups.js
  7. 6
      sanitiser/_ids.js
  8. 2
      sanitiser/_source.js

2
helper/adminFields.js

@ -32,7 +32,7 @@ function getAvailableAdminFields(schema, expectedFields, logger) {
// check if expected fields are actually in current schema
var available = expectedFields.filter(function (field) {
return _.contains( actualFields, field );
return _.includes( actualFields, field );
});
if (available.length === 0) {

10
helper/geojsonify.js

@ -35,10 +35,10 @@ function lookupSource(src) {
*/
function lookupLayer(src) {
if (src._type === 'geoname') {
if (_.contains(src.category, 'admin')) {
if (_.contains(src.category, 'admin:city')) { return 'locality'; }
if (_.contains(src.category, 'admin:admin1')) { return 'region'; }
if (_.contains(src.category, 'admin:admin2')) { return 'county'; }
if (_.includes(src.category, 'admin')) {
if (_.includes(src.category, 'admin:city')) { return 'locality'; }
if (_.includes(src.category, 'admin:admin1')) { return 'region'; }
if (_.includes(src.category, 'admin:admin2')) { return 'county'; }
return 'neighbourhood'; // this could also be 'local_admin'
}
@ -46,7 +46,7 @@ function lookupLayer(src) {
if (src.address) { return 'address'; }
}
if (_.contains(type_mapping.types, src._type)) {
if (_.includes(type_mapping.types, src._type)) {
return type_mapping.type_to_layer[src._type];
}

2
helper/labelGenerator.js

@ -16,7 +16,7 @@ module.exports = function( record ){
var buildOutput = function(parts, schemaArr, record) {
for (var i=0; i<schemaArr.length; i++) {
var fieldValue = record[schemaArr[i]];
if (check.unemptyString(fieldValue) && !_.contains(parts, fieldValue)) {
if (check.unemptyString(fieldValue) && !_.includes(parts, fieldValue)) {
parts.push( fieldValue );
return parts;
}

2
sanitiser/_details.js

@ -22,7 +22,7 @@ function sanitize( raw, clean ){
// be lenient with 'truthy' values
function isTruthy(val) {
if( check.string( val ) ){
return _.contains( ['true', '1'], val );
return _.includes( ['true', '1'], val );
}
return val === 1 || val === true;

2
sanitiser/_flag_bool.js

@ -44,7 +44,7 @@ function sanitize( raw, clean, opts ){
* @returns {boolean}
*/
function isTruthy(val) {
return _.contains( ['true', '1', 1, true], val );
return _.includes( ['true', '1', 1, true], val );
}
module.exports = setup;

4
sanitiser/_groups.js

@ -10,7 +10,7 @@ var _ = require('lodash');
* returns true if all are present, false if none are present, throws an exception otherwise
*/
function optional_group(object, keys) {
var contained_in_object = _.contains.bind(null, Object.keys(object));
var contained_in_object = _.includes.bind(null, Object.keys(object));
if (keys.every(contained_in_object)) {
return true;
@ -26,7 +26,7 @@ function optional_group(object, keys) {
* An error will be thrown if any of the keys are missing from the object
*/
function required_group(object, keys) {
var contained_in_object = _.contains.bind(null, Object.keys(object));
var contained_in_object = _.includes.bind(null, Object.keys(object));
if (keys.every(contained_in_object)) {
return true;

6
sanitiser/_ids.js

@ -30,17 +30,17 @@ function sanitizeId(rawId, messages) {
var id = parts.slice(2).join(ID_DELIM);
// check if any parts of the gid are empty
if (_.contains([source, layer, id], '')) {
if (_.includes([source, layer, id], '')) {
messages.errors.push( formatError(rawId) );
return;
}
if (!_.contains(type_mapping.sources, source)) {
if (!_.includes(type_mapping.sources, source)) {
messages.errors.push( targetError(source, type_mapping.sources) );
return;
}
if (!_.contains(type_mapping.layers, layer)) {
if (!_.includes(type_mapping.layers, layer)) {
messages.errors.push( targetError(layer, type_mapping.layers) );
return;
}

2
sanitiser/_source.js

@ -21,7 +21,7 @@ function sanitize( raw, clean ) {
var sources = raw.source.split(',');
var invalid_sources = sources.filter(function(source) {
return !_.contains( ALL_SOURCES, source );
return !_.includes( ALL_SOURCES, source );
});
if( invalid_sources.length > 0 ){

Loading…
Cancel
Save