UNPKG

dtable-utils

Version:

dtable common utils

63 lines (58 loc) 1.87 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var geolocation = require('../../cell-value-get/geolocation.js'); var filterPredicate = require('../../constants/filter/filter-predicate.js'); /** * Filter geolocation * @param {object} location e.g. { province, ... } * @param {string} filter_predicate * @param {string} filter_term * @param {object} column e.g. { type, data: { geo_format, ... }, ... } * @returns bool */ var geolocationFilter = function geolocationFilter(location, _ref) { var filter_predicate = _ref.filter_predicate, filter_term = _ref.filter_term, column = _ref.column; var geolocation$1 = geolocation.getGeolocationDisplayString(location, column.data); switch (filter_predicate) { case filterPredicate.FILTER_PREDICATE_TYPE.CONTAINS: { if (!filter_term) { return true; } if (!geolocation$1) { return false; } return geolocation$1.toString().toLowerCase().indexOf(filter_term.toLowerCase()) > -1; } case filterPredicate.FILTER_PREDICATE_TYPE.NOT_CONTAIN: { if (!filter_term || !geolocation$1) { return true; } return geolocation$1.toString().toLowerCase().indexOf(filter_term.toLowerCase()) < 0; } case filterPredicate.FILTER_PREDICATE_TYPE.IS: { return !filter_term || geolocation$1 === filter_term; } case filterPredicate.FILTER_PREDICATE_TYPE.IS_NOT: { return !filter_term || geolocation$1 !== filter_term; } case filterPredicate.FILTER_PREDICATE_TYPE.EMPTY: { return !geolocation$1; } case filterPredicate.FILTER_PREDICATE_TYPE.NOT_EMPTY: { return !!geolocation$1; } default: { return false; } } }; exports.geolocationFilter = geolocationFilter;