Clean code.
This commit is contained in:
parent
95c473a7c7
commit
9234e3f287
6 changed files with 22 additions and 51 deletions
|
@ -71,18 +71,9 @@ const encodedHref = href => {
|
|||
return forceEncoding(location);
|
||||
};
|
||||
|
||||
const getDomain = () => {
|
||||
return doc.domain;
|
||||
};
|
||||
|
||||
const getAbsHref = () => {
|
||||
return absHref;
|
||||
};
|
||||
|
||||
const getItem = () => {
|
||||
const Item = require('../model/item');
|
||||
return Item.get(absHref);
|
||||
};
|
||||
const getDomain = () => doc.domain;
|
||||
const getAbsHref = () => absHref;
|
||||
const getItem = () => require('../model/item').get(absHref);
|
||||
|
||||
const load = callback => {
|
||||
request({action: 'get', items: {href: absHref, what: 1}}).then(json => {
|
||||
|
|
|
@ -9,9 +9,7 @@ const defaultThemeHref = themesHref + 'default/';
|
|||
const defaultIcons = ['file', 'folder', 'folder-page', 'folder-parent', 'ar', 'aud', 'bin', 'img', 'txt', 'vid', 'x'];
|
||||
|
||||
|
||||
const image = id => {
|
||||
return uiHref + id + '.svg';
|
||||
};
|
||||
const image = id => uiHref + id + '.svg';
|
||||
|
||||
const icon = id => {
|
||||
const baseId = (id || '').split('-')[0];
|
||||
|
|
|
@ -21,9 +21,7 @@ const put = (key, value) => {
|
|||
save(obj);
|
||||
};
|
||||
|
||||
const get = key => {
|
||||
return load()[key];
|
||||
};
|
||||
const get = key => load()[key];
|
||||
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -1,12 +1,4 @@
|
|||
const regularCmpFn = (val1, val2) => {
|
||||
if (val1 < val2) {
|
||||
return -1;
|
||||
}
|
||||
if (val1 > val2) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
const regularCmpFn = (x, y) => x < y ? -1 : x > y ? 1 : 0;
|
||||
|
||||
// Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
|
||||
// Author: Jim Palmer (based on chunking idea from Dave Koelle)
|
||||
|
|
|
@ -25,13 +25,10 @@ const intersection = (obj1, obj2) => {
|
|||
obj2 = values(obj2);
|
||||
return filter(obj1, x => obj2.indexOf(x) >= 0);
|
||||
};
|
||||
const cmp = (x, y) => x < y ? -1 : x > y ? 1 : 0;
|
||||
const sortBy = (obj, sel) => {
|
||||
const selFn = isFn(sel) ? sel : x => x[sel];
|
||||
const cmpFn = (x, y) => {
|
||||
x = selFn(x);
|
||||
y = selFn(y);
|
||||
return x < y ? -1 : x > y ? 1 : 0;
|
||||
};
|
||||
const cmpFn = (x, y) => cmp(selFn(x), selFn(y));
|
||||
return values(obj).sort(cmpFn);
|
||||
};
|
||||
const debounce = (fn, delay) => {
|
||||
|
|
|
@ -4,19 +4,12 @@ const location = require('../core/location');
|
|||
const settings = require('../core/settings');
|
||||
const types = require('../core/types');
|
||||
|
||||
|
||||
const reEndsWithSlash = /\/$/;
|
||||
const reSplitPath = /^(.*\/)([^\/]+\/?)$/;
|
||||
const cache = {};
|
||||
|
||||
|
||||
const startsWith = (sequence, part) => {
|
||||
if (!sequence || !sequence.indexOf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return sequence.indexOf(part) === 0;
|
||||
};
|
||||
const startsWith = (sequence, part) => isStr(sequence) && sequence.startsWith(part);
|
||||
|
||||
const createLabel = sequence => {
|
||||
sequence = sequence.replace(reEndsWithSlash, '');
|
||||
|
@ -26,7 +19,7 @@ const createLabel = sequence => {
|
|||
return sequence;
|
||||
};
|
||||
|
||||
const splitPath = sequence => { // eslint-disable-line consistent-return
|
||||
const splitPath = sequence => {
|
||||
if (sequence === '/') {
|
||||
return {
|
||||
parent: null,
|
||||
|
@ -35,17 +28,19 @@ const splitPath = sequence => { // eslint-disable-line consistent-return
|
|||
}
|
||||
|
||||
const match = reSplitPath.exec(sequence);
|
||||
if (match) {
|
||||
const split = {
|
||||
parent: match[1],
|
||||
name: match[2]
|
||||
};
|
||||
|
||||
if (split.parent && !startsWith(split.parent, settings.rootHref)) {
|
||||
split.parent = null;
|
||||
}
|
||||
return split;
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const split = {
|
||||
parent: match[1],
|
||||
name: match[2]
|
||||
};
|
||||
|
||||
if (split.parent && !startsWith(split.parent, settings.rootHref)) {
|
||||
split.parent = null;
|
||||
}
|
||||
return split;
|
||||
};
|
||||
|
||||
const getItem = options => {
|
||||
|
|
Loading…
Add table
Reference in a new issue