mirror of
https://github.com/bellingcat/ukraine-timemap.git
synced 2026-06-12 21:38:35 +03:00
Add linting and cleaned up obvious suggestions
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
/* global d3 */
|
||||
/**
|
||||
* Get URI params to start with predefined set of
|
||||
* https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
|
||||
* @param {string} name: name of paramater to search
|
||||
* @param {string} url: url passed as variable, defaults to window.location.href
|
||||
*/
|
||||
export function getParameterByName(name, url) {
|
||||
if (!url) url = window.location.href;
|
||||
name = name.replace(/[\[\]]/g, `\\$&`);
|
||||
export function getParameterByName (name, url) {
|
||||
if (!url) url = window.location.href
|
||||
name = name.replace(/[[\]]/g, `\\$&`)
|
||||
|
||||
const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
|
||||
const results = regex.exec(url);
|
||||
const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`)
|
||||
const results = regex.exec(url)
|
||||
|
||||
if (!results) return null;
|
||||
if (!results[2]) return '';
|
||||
if (!results) return null
|
||||
if (!results[2]) return ''
|
||||
|
||||
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
||||
return decodeURIComponent(results[2].replace(/\+/g, ' '))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,61 +23,61 @@ export function getParameterByName(name, url) {
|
||||
* @param {array} arr1: array of numbers
|
||||
* @param {array} arr2: array of numbers
|
||||
*/
|
||||
export function areEqual(arr1, arr2) {
|
||||
return ((arr1.length === arr2.length) && arr1.every((element, index) => {
|
||||
return element === arr2[index];
|
||||
}));
|
||||
export function areEqual (arr1, arr2) {
|
||||
return ((arr1.length === arr2.length) && arr1.every((element, index) => {
|
||||
return element === arr2[index]
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the variable is neither null nor undefined
|
||||
* @param {object} variable
|
||||
*/
|
||||
export function isNotNullNorUndefined(variable) {
|
||||
return (typeof variable !== 'undefined' && variable !== null);
|
||||
export function isNotNullNorUndefined (variable) {
|
||||
return (typeof variable !== 'undefined' && variable !== null)
|
||||
}
|
||||
|
||||
/*
|
||||
* Capitalizes _only_ the first letter of a string
|
||||
* Taken from: https://stackoverflow.com/questions/1026069/how-do-i-make-the-first-letter-of-a-string-uppercase-in-javascript
|
||||
*/
|
||||
export function capitalizeFirstLetter(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
export function capitalizeFirstLetter (string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||
}
|
||||
|
||||
export function trimAndEllipse(string, stringNum) {
|
||||
export function trimAndEllipse (string, stringNum) {
|
||||
if (string.length > stringNum) {
|
||||
return string.substring(0, 120) + '...'
|
||||
}
|
||||
return string;
|
||||
return string
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Date object given a datetime string of the format: "2016-09-10T07:00:00"
|
||||
* @param {string} datetime
|
||||
*/
|
||||
export function parseDate(datetime) {
|
||||
export function parseDate (datetime) {
|
||||
return new Date(datetime.slice(0, 4),
|
||||
datetime.slice(5, 7) - 1,
|
||||
datetime.slice(8, 10),
|
||||
datetime.slice(11, 13),
|
||||
datetime.slice(14, 16),
|
||||
datetime.slice(17, 19)
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
export function formatterWithYear(datetime) {
|
||||
return d3.timeFormat("%d %b %Y, %H:%M")(datetime);
|
||||
export function formatterWithYear (datetime) {
|
||||
return d3.timeFormat('%d %b %Y, %H:%M')(datetime)
|
||||
}
|
||||
|
||||
export function formatter(datetime) {
|
||||
return d3.timeFormat("%d %b, %H:%M")(datetime);
|
||||
export function formatter (datetime) {
|
||||
return d3.timeFormat('%d %b, %H:%M')(datetime)
|
||||
}
|
||||
|
||||
export const parseTimestamp = ts => d3.timeParse("%Y-%m-%dT%H:%M:%S")(ts);
|
||||
export const parseTimestamp = ts => d3.timeParse('%Y-%m-%dT%H:%M:%S')(ts)
|
||||
|
||||
export function compareTimestamp (a, b) {
|
||||
return (parseTimestamp(a.timestamp) > parseTimestamp(b.timestamp));
|
||||
return (parseTimestamp(a.timestamp) > parseTimestamp(b.timestamp))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +86,7 @@ export function compareTimestamp (a, b) {
|
||||
* source, call with two sets of parentheses:
|
||||
* const src = insetSourceFrom(sources)(anEvent)
|
||||
*/
|
||||
export function insetSourceFrom(allSources) {
|
||||
export function insetSourceFrom (allSources) {
|
||||
return (event) => {
|
||||
let sources
|
||||
if (!event.sources) {
|
||||
@@ -100,14 +101,13 @@ export function insetSourceFrom(allSources) {
|
||||
sources
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Debugging function: put in place of a mapStateToProps function to
|
||||
* view that source modal by default
|
||||
*/
|
||||
export function injectSource(id) {
|
||||
export function injectSource (id) {
|
||||
return state => {
|
||||
return {
|
||||
...state,
|
||||
@@ -119,7 +119,7 @@ export function injectSource(id) {
|
||||
}
|
||||
}
|
||||
|
||||
export function urlFromEnv(ext) {
|
||||
export function urlFromEnv (ext) {
|
||||
if (process.env[ext]) {
|
||||
return `${process.env.SERVER_ROOT}${process.env[ext]}`
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user