Browse Source

Replace _.includes with ES6 Array.prototype.includes

es6-include
Julian Simioni 8 years ago
parent
commit
402971528f
No known key found for this signature in database
GPG Key ID: 6DAD08919FDBF563
  1. 2
      middleware/localNamingConventions.js
  2. 2
      sanitizer/_deprecate_quattroshapes.js
  3. 6
      sanitizer/_details.js
  4. 2
      sanitizer/_flag_bool.js
  5. 2
      sanitizer/_geo_reverse.js
  6. 12
      sanitizer/_groups.js
  7. 6
      sanitizer/_ids.js
  8. 2
      sanitizer/_sources_and_layers.js

2
middleware/localNamingConventions.js

@ -28,7 +28,7 @@ function applyLocalNamingConventions(req, res, next) {
// relevant for some countries // relevant for some countries
var flip = place.parent.country_a.some(function(country) { var flip = place.parent.country_a.some(function(country) {
return _.includes(flipNumberAndStreetCountries, country); return flipNumberAndStreetCountries.includes(country);
}); });
if (!flip){ return false; } if (!flip){ return false; }
if( !place.hasOwnProperty('address_parts') ){ return false; } if( !place.hasOwnProperty('address_parts') ){ return false; }

2
sanitizer/_deprecate_quattroshapes.js

@ -18,7 +18,7 @@ function sanitize( raw, clean, opts ) {
if( raw.hasOwnProperty('sources') ){ if( raw.hasOwnProperty('sources') ){
var sources = raw.sources.split(','); var sources = raw.sources.split(',');
if (_.includes(sources, 'quattroshapes') || _.includes(sources, 'qs')) { if (sources.includes('quattroshapes') || sources.includes('qs')) {
// emit a warning message so users can transition. // emit a warning message so users can transition.
messages.warnings.push('You are using Quattroshapes as a data source in this query. ' + messages.warnings.push('You are using Quattroshapes as a data source in this query. ' +

6
sanitizer/_details.js

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

2
sanitizer/_flag_bool.js

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

2
sanitizer/_geo_reverse.js

@ -30,7 +30,7 @@ module.exports = function sanitize( raw, clean ){
// if no radius was passed, set the default // if no radius was passed, set the default
if ( _.isUndefined( raw['boundary.circle.radius'] ) ) { if ( _.isUndefined( raw['boundary.circle.radius'] ) ) {
// the default is small unless layers other than venue or address were explicitly specified // the default is small unless layers other than venue or address were explicitly specified
if (clean.layers && clean.layers.length > 0 && !_.includes(clean.layers, 'venue') && !_.includes(clean.layers, 'address')) { if (clean.layers && clean.layers.length > 0 && !clean.layers.includes('venue') && !clean.layers.includes('address')) {
raw['boundary.circle.radius'] = defaults['boundary:circle:radius:coarse']; raw['boundary.circle.radius'] = defaults['boundary:circle:radius:coarse'];
} else { } else {
raw['boundary.circle.radius'] = defaults['boundary:circle:radius']; raw['boundary.circle.radius'] = defaults['boundary:circle:radius'];

12
sanitizer/_groups.js

@ -1,5 +1,3 @@
var _ = require('lodash');
/* /*
* Specify an object and array of keys to check. * Specify an object and array of keys to check.
* An error will be thrown if at least one, but not all of them are specified * An error will be thrown if at least one, but not all of them are specified
@ -10,7 +8,10 @@ var _ = require('lodash');
* returns true if all are present, false if none are present, throws an exception otherwise * returns true if all are present, false if none are present, throws an exception otherwise
*/ */
function optional_group(object, keys) { function optional_group(object, keys) {
var contained_in_object = _.includes.bind(null, Object.keys(object)); var object_properties = Object.keys(object);
var contained_in_object = function(key_to_check) {
return object_properties.includes(key_to_check);
};
if (keys.every(contained_in_object)) { if (keys.every(contained_in_object)) {
return true; return true;
@ -26,7 +27,10 @@ function optional_group(object, keys) {
* An error will be thrown if any of the keys are missing from the object * An error will be thrown if any of the keys are missing from the object
*/ */
function required_group(object, keys) { function required_group(object, keys) {
var contained_in_object = _.includes.bind(null, Object.keys(object)); var object_properties = Object.keys(object);
var contained_in_object = function(key_to_check) {
return object_properties.includes(key_to_check);
};
if (keys.every(contained_in_object)) { if (keys.every(contained_in_object)) {
return true; return true;

6
sanitizer/_ids.js

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

2
sanitizer/_sources_and_layers.js

@ -15,7 +15,7 @@ function sanitize( raw, clean ){
clean.sources.forEach(function(source) { clean.sources.forEach(function(source) {
var layers_for_source = type_mapping.layers_by_source[source]; var layers_for_source = type_mapping.layers_by_source[source];
clean.layers.forEach(function(layer) { clean.layers.forEach(function(layer) {
if (_.includes(layers_for_source, layer)) { if (layers_for_source.includes(layer)) {
at_least_one_valid_combination = true; at_least_one_valid_combination = true;
} else { } else {
var message = 'You have specified both the `sources` and `layers` ' + var message = 'You have specified both the `sources` and `layers` ' +

Loading…
Cancel
Save