diff --git a/src/_h5ai/public/js/lib/core/format.js b/src/_h5ai/public/js/lib/core/format.js index 1bb52f69..85901f3a 100644 --- a/src/_h5ai/public/js/lib/core/format.js +++ b/src/_h5ai/public/js/lib/core/format.js @@ -1,4 +1,4 @@ -const {lo} = require('../globals'); +const isNum = x => typeof x === 'number'; const decimalMetric = { t: 1000.0, @@ -30,14 +30,14 @@ const datePatterns = [ let defaultDateFormat = 'YYYY-MM-DD HH:mm'; -function setDefaultMetric(useBinaryMetric) { +const setDefaultMetric = useBinaryMetric => { defaultMetric = useBinaryMetric ? binaryMetric : decimalMetric; -} +}; -function formatSize(size, metric) { +const formatSize = (size, metric) => { metric = metric || defaultMetric; - if (!lo.isNumber(size) || size < 0) { + if (!isNum(size) || size < 0) { return ''; } @@ -49,22 +49,22 @@ function formatSize(size, metric) { i += 1; } return (i <= 1 ? Math.round(size) : size.toFixed(1)).toString() + ' ' + metric.u[i]; -} +}; -function setDefaultDateFormat(dateFormat) { +const setDefaultDateFormat = dateFormat => { defaultDateFormat = dateFormat; -} +}; -function formatNumber(number, padding) { +const formatNumber = (number, padding) => { let str = String(number); if (padding) { str = ('000' + str).substr(-padding); } return str; -} +}; -function formatDate(millis, format) { - if (!millis || !lo.isNumber(millis)) { +const formatDate = (millis, format) => { + if (!millis || !isNum(millis)) { return ''; } @@ -85,7 +85,7 @@ function formatDate(millis, format) { }); return format; -} +}; module.exports = { diff --git a/src/_h5ai/public/js/lib/core/location.js b/src/_h5ai/public/js/lib/core/location.js index 79bb5d8a..8e073194 100644 --- a/src/_h5ai/public/js/lib/core/location.js +++ b/src/_h5ai/public/js/lib/core/location.js @@ -6,7 +6,7 @@ const event = require('./event'); const notification = require('../view/notification'); const doc = win.document; -const settings = lo.extend({ +const settings = Object.assign({ fastBrowsing: true, unmanagedInNewWindow: true }, allsettings.view); diff --git a/src/_h5ai/public/js/lib/core/resource.js b/src/_h5ai/public/js/lib/core/resource.js index 6b9fda7f..85de53f3 100644 --- a/src/_h5ai/public/js/lib/core/resource.js +++ b/src/_h5ai/public/js/lib/core/resource.js @@ -1,7 +1,8 @@ -const {lo} = require('../globals'); const config = require('../config'); const settings = require('./settings'); +const includes = (arr, x) => arr.indexOf(x) >= 0; + const imagesHref = settings.publicHref + 'images/'; const uiHref = imagesHref + 'ui/'; const themesHref = imagesHref + 'themes/'; @@ -21,11 +22,11 @@ function icon(id) { return themesHref + href; } - if (lo.includes(defaultIcons, id)) { + if (includes(defaultIcons, id)) { return defaultThemeHref + id + '.svg'; } - if (lo.includes(defaultIcons, baseId)) { + if (includes(defaultIcons, baseId)) { return defaultThemeHref + baseId + '.svg'; } diff --git a/src/_h5ai/public/js/lib/core/store.js b/src/_h5ai/public/js/lib/core/store.js index eae92a12..59e414af 100644 --- a/src/_h5ai/public/js/lib/core/store.js +++ b/src/_h5ai/public/js/lib/core/store.js @@ -4,26 +4,26 @@ const store = win.localStorage; const storekey = '_h5ai'; -function load() { +const load = () => { try { return JSON.parse(store[storekey]); } catch (e) {/* skip */} return {}; -} +}; -function save(obj) { +const save = obj => { store[storekey] = JSON.stringify(obj); -} +}; -function put(key, value) { +const put = (key, value) => { const obj = load(); obj[key] = value; save(obj); -} +}; -function get(key) { +const get = key => { return load()[key]; -} +}; module.exports = { diff --git a/src/_h5ai/public/js/lib/core/types.js b/src/_h5ai/public/js/lib/core/types.js index ca1a9fe1..256324ee 100644 --- a/src/_h5ai/public/js/lib/core/types.js +++ b/src/_h5ai/public/js/lib/core/types.js @@ -1,23 +1,25 @@ -const {lo} = require('../globals'); const config = require('../config'); +const each = (obj, fn) => Object.keys(obj).forEach(key => fn(obj[key], key)); +const map = (arr, fn) => Array.from(arr, fn); + const reEndsWithSlash = /\/$/; const regexps = {}; -function escapeRegExp(sequence) { +const escapeRegExp = sequence => { return sequence.replace(/[\-\[\]\/\{\}\(\)\+\?\.\\\^\$]/g, '\\$&'); // return sequence.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); -} +}; -function parse(types) { - lo.each(types, (patterns, type) => { - const pattern = '^(' + lo.map(patterns, p => '(' + escapeRegExp(p).replace(/\*/g, '.*') + ')').join('|') + ')$'; +const parse = types => { + each(types, (patterns, type) => { + const pattern = '^(' + map(patterns, p => '(' + escapeRegExp(p).replace(/\*/g, '.*') + ')').join('|') + ')$'; regexps[type] = new RegExp(pattern, 'i'); }); -} +}; -function getType(sequence) { +const getType = sequence => { if (reEndsWithSlash.test(sequence)) { return 'folder'; } @@ -26,15 +28,14 @@ function getType(sequence) { const name = slashidx >= 0 ? sequence.substr(slashidx + 1) : sequence; let result; - lo.each(regexps, (regexp, type) => { // eslint-disable-line consistent-return + each(regexps, (regexp, type) => { if (regexps[type].test(name)) { result = type; - return false; } }); return result ? result : 'file'; -} +}; parse(Object.assign({}, config.types)); diff --git a/src/_h5ai/public/js/lib/core/util.js b/src/_h5ai/public/js/lib/core/util.js index 4161a564..56ef64c2 100644 --- a/src/_h5ai/public/js/lib/core/util.js +++ b/src/_h5ai/public/js/lib/core/util.js @@ -1,6 +1,4 @@ -const {lo} = require('../globals'); - -function regularCmpFn(val1, val2) { +const regularCmpFn = (val1, val2) => { if (val1 < val2) { return -1; } @@ -8,13 +6,13 @@ function regularCmpFn(val1, val2) { return 1; } return 0; -} +}; // Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license // Author: Jim Palmer (based on chunking idea from Dave Koelle) // // Modified to make it work with h5ai -function naturalCmpFn(val1, val2) { +const naturalCmpFn = (val1, val2) => { const re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi; const sre = /(^[ ]*|[ ]*$)/g; const dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/; @@ -60,13 +58,13 @@ function naturalCmpFn(val1, val2) { } } return 0; -} +}; -function escapePattern(sequence) { +const escapePattern = sequence => { return sequence.replace(/[\-\[\]{}()*+?.,\\$\^|#\s]/g, '\\$&'); -} +}; -function parsePattern(sequence, advanced) { +const parsePattern = (sequence, advanced) => { if (!advanced) { return escapePattern(sequence); } @@ -75,14 +73,10 @@ function parsePattern(sequence, advanced) { return sequence.substr(3); } - sequence = lo.map(lo.trim(sequence).split(/\s+/), part => { - return lo.map(part.split(''), character => { - return escapePattern(character); - }).join('.*?'); + return sequence.trim().split(/\s+/).map(part => { + return part.split('').map(char => escapePattern(char)).join('.*?'); }).join('|'); - - return sequence; -} +}; module.exports = {