UNPKG

kepler.gl

Version:

kepler.gl is a webgl based application to visualize large scale location data in the browser

81 lines (75 loc) 8.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.containValidTime = containValidTime; exports.isHexWkb = isHexWkb; exports.notNullorUndefined = notNullorUndefined; exports.toArray = toArray; var _typeAnalyzer = require("type-analyzer"); // SPDX-License-Identifier: MIT // Copyright contributors to the kepler.gl project function notNullorUndefined(d) { return d !== undefined && d !== null; } /** * Check if string is a valid Well-known binary (WKB) in HEX format * https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry * * @param str input string * @returns true if string is a valid WKB in HEX format */ function isHexWkb(str) { if (!str) return false; // check if the length of the string is even and is at least 10 characters long if (str.length < 10 || str.length % 2 !== 0) { return false; } // check if first two characters are 00 or 01 if (!str.startsWith('00') && !str.startsWith('01')) { return false; } // check if the rest of the string is a valid hex return /^[0-9a-fA-F]+$/.test(str.slice(2)); } /** * Converts non-arrays to arrays. Leaves arrays alone. Converts * undefined values to empty arrays ([] instead of [undefined]). * Otherwise, just returns [item] for non-array items. * * @param {*} item * @returns {array} boom! much array. very indexed. so useful. */ function toArray(item) { if (Array.isArray(item)) { return item; } if (typeof item === 'undefined' || item === null) { return []; } return [item]; } /** * Check whether geojson linestring's 4th coordinate is 1) not timestamp 2) unix time stamp 3) real date time * @param timestamps array to be tested if its elements are timestamp * @returns the type of timestamp: unix/datetime/invalid(not timestamp) */ function containValidTime(timestamps) { var formattedTimeStamps = timestamps.map(function (ts) { return { ts: ts }; }); var ignoredDataTypes = Object.keys(_typeAnalyzer.DATA_TYPES).filter(function (type) { return ![_typeAnalyzer.DATA_TYPES.TIME, _typeAnalyzer.DATA_TYPES.DATETIME, _typeAnalyzer.DATA_TYPES.DATE].includes(type); }); // ignore all types but TIME to improve performance var analyzedType = _typeAnalyzer.Analyzer.computeColMeta(formattedTimeStamps, [], { ignoredDataTypes: ignoredDataTypes })[0]; if (!analyzedType || analyzedType.category !== 'TIME') { return null; } return analyzedType; }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