diff --git a/common/btoa.js b/common/btoa.js index bf26630b..6cc9fbaf 100644 --- a/common/btoa.js +++ b/common/btoa.js @@ -1,6 +1,4 @@ -'use strict'; - -module.exports = (str) => { +export default (str) => { if (typeof btoa === 'function') return btoa(str); diff --git a/common/callbackify.js b/common/callbackify.js index f661eed7..4b1cf3ed 100644 --- a/common/callbackify.js +++ b/common/callbackify.js @@ -1,8 +1,6 @@ -'use strict'; - const success = (f) => (data) => f(null, data); -module.exports = (promise) => { +export default (promise) => { return (...a) => { const fn = a.pop(); diff --git a/common/callbackify.spec.js b/common/callbackify.spec.js index 0b7f6d8c..f8ec81ff 100644 --- a/common/callbackify.spec.js +++ b/common/callbackify.spec.js @@ -1,7 +1,5 @@ -'use strict'; - -const test = require('supertape'); -const callbackify = require('./callbackify'); +import test from 'supertape'; +import callbackify from './callbackify.js'; test('cloudcmd: common: callbackify: error', (t) => { const promise = async () => { diff --git a/common/cloudfunc.js b/common/cloudfunc.js index 81124e2a..4d357ddc 100644 --- a/common/cloudfunc.js +++ b/common/cloudfunc.js @@ -1,30 +1,22 @@ -'use strict'; - -const rendy = require('rendy'); -const currify = require('currify'); -const store = require('fullstore'); -const {encode} = require('./entity'); -const btoa = require('./btoa'); - -const getHeaderField = currify(_getHeaderField); +import rendy from 'rendy'; +import currify from 'currify'; +import store from 'fullstore'; +import {encode} from './entity.js'; +import btoa from './btoa.js'; /* КОНСТАНТЫ (общие для клиента и сервера)*/ /* название программы */ const NAME = 'Cloud Commander'; -const FS = '/fs'; +export const FS = '/fs'; const Path = store(); Path('/'); -module.exports.FS = FS; -module.exports.apiURL = '/api/v1'; -module.exports.MAX_FILE_SIZE = 500 * 1024; -module.exports.getHeaderField = getHeaderField; -module.exports.getPathLink = getPathLink; -module.exports.getDotDot = getDotDot; +export const apiURL = '/api/v1'; +export const MAX_FILE_SIZE = 500 * 1024; -module.exports.formatMsg = (msg, name, status) => { +export const formatMsg = (msg, name, status) => { status = status || 'ok'; name = name || ''; @@ -38,7 +30,7 @@ module.exports.formatMsg = (msg, name, status) => { * Функция возвращает заголовок веб страницы * @path */ -module.exports.getTitle = (options) => { +export const getTitle = (options) => { options = options || {}; const { @@ -60,6 +52,10 @@ module.exports.getTitle = (options) => { * возвращаеться массив каталогов * @param url - адрес каталога */ +export /** Функция получает адреса каждого каталога в пути + * возвращаеться массив каталогов + * @param url - адрес каталога + */ function getPathLink(url, prefix, template) { if (!url) throw Error('url could not be empty!'); @@ -108,7 +104,7 @@ const getDataName = (name) => { * @param params - информация о файлах * */ -module.exports.buildFromJSON = (params) => { +export const buildFromJSON = (params) => { const { prefix, template, @@ -248,7 +244,7 @@ function getAttribute(type) { return 'target="_blank" '; } -module.exports._getSize = getSize; +export const _getSize = getSize; function getSize(file) { const { size, @@ -264,7 +260,7 @@ function getSize(file) { return size; } -function _getHeaderField(sort, order, name) { +export const getHeaderField = currify((sort, order, name) => { const arrow = order === 'asc' ? '↑' : '↓'; if (sort !== name) @@ -274,9 +270,9 @@ function _getHeaderField(sort, order, name) { return name; return `${name}${arrow}`; -} +}); -function getDotDot(path) { +export function getDotDot(path) { // убираем последний слеш и каталог в котором мы сейчас находимся const lastSlash = path.substr(path, path.lastIndexOf('/')); const dotDot = lastSlash.substr(lastSlash, lastSlash.lastIndexOf('/')); diff --git a/common/cloudfunc.spec.js b/common/cloudfunc.spec.js index 217d9ca5..45f48c02 100644 --- a/common/cloudfunc.spec.js +++ b/common/cloudfunc.spec.js @@ -1,7 +1,5 @@ -'use strict'; - -const test = require('supertape'); -const {_getSize} = require('./cloudfunc'); +import test from 'supertape'; +import {_getSize} from './cloudfunc.js'; test('cloudfunc: getSize: dir', (t) => { const type = 'directory'; diff --git a/common/datetime.js b/common/datetime.js index 131c27fb..d7982ab4 100644 --- a/common/datetime.js +++ b/common/datetime.js @@ -1,8 +1,6 @@ -'use strict'; +import shortdate from 'shortdate'; -const shortdate = require('shortdate'); - -module.exports = (date) => { +export default (date) => { date = date || new Date(); check(date); diff --git a/common/datetime.spec.js b/common/datetime.spec.js index cc2aed16..2bfecefa 100644 --- a/common/datetime.spec.js +++ b/common/datetime.spec.js @@ -1,9 +1,7 @@ -'use strict'; +import test from 'supertape'; +import tryCatch from 'try-catch'; -const test = require('supertape'); -const tryCatch = require('try-catch'); - -const datetime = require('./datetime'); +import datetime from './datetime.js'; test('common: datetime', (t) => { const dateStr = 'Fri, 17 Aug 2018 10:56:48'; diff --git a/common/entity.js b/common/entity.js index bad8ef77..ba8de2af 100644 --- a/common/entity.js +++ b/common/entity.js @@ -1,5 +1,3 @@ -'use strict'; - const Entities = { ' ': ' ', '<': '<', @@ -9,7 +7,7 @@ const Entities = { const keys = Object.keys(Entities); -module.exports.encode = (str) => { +export const encode = (str) => { for (const code of keys) { const char = Entities[code]; const reg = RegExp(char, 'g'); @@ -20,7 +18,7 @@ module.exports.encode = (str) => { return str; }; -module.exports.decode = (str) => { +export const decode = (str) => { for (const code of keys) { const char = Entities[code]; const reg = RegExp(code, 'g'); diff --git a/common/try-to-promise-all.js b/common/try-to-promise-all.js index c8a54eab..7c5328df 100644 --- a/common/try-to-promise-all.js +++ b/common/try-to-promise-all.js @@ -1,9 +1,7 @@ -'use strict'; - -const tryToCatch = require('try-to-catch'); +import tryToCatch from 'try-to-catch'; const all = Promise.all.bind(Promise); -module.exports = async (a) => { +export default async (a) => { const [e, result = []] = await tryToCatch(all, a); return [ diff --git a/common/try-to-promise-all.spec.js b/common/try-to-promise-all.spec.js index 628bc931..bf35b3c0 100644 --- a/common/try-to-promise-all.spec.js +++ b/common/try-to-promise-all.spec.js @@ -1,7 +1,5 @@ -'use strict'; - -const test = require('supertape'); -const tryToPromiseAll = require('./try-to-promise-all'); +import test from 'supertape'; +import tryToPromiseAll from './try-to-promise-all.js'; const resolve = Promise.resolve.bind(Promise); const reject = Promise.reject.bind(Promise); diff --git a/common/util.js b/common/util.js index 8551b1ef..35cff594 100644 --- a/common/util.js +++ b/common/util.js @@ -1,8 +1,10 @@ -'use strict'; +import exec from 'execon'; -const exec = require('execon'); +export { + exec, +}; -module.exports.escapeRegExp = (str) => { +export const escapeRegExp = (str) => { const isStr = typeof str === 'string'; if (isStr) @@ -14,7 +16,7 @@ module.exports.escapeRegExp = (str) => { /** * get regexp from wild card */ -module.exports.getRegExp = (wildcard) => { +export const getRegExp = (wildcard) => { const escaped = '^' + wildcard // search from start of line .replace(/\./g, '\\.') .replace(/\*/g, '.*') @@ -23,15 +25,13 @@ module.exports.getRegExp = (wildcard) => { return RegExp(escaped); }; -module.exports.exec = exec; - /** * function gets file extension * * @param name * @return ext */ -module.exports.getExt = (name) => { +export const getExt = (name) => { const isStr = typeof name === 'string'; if (!isStr) @@ -51,7 +51,7 @@ module.exports.getExt = (name) => { * @param array * @param name */ -module.exports.findObjByNameInArr = (array, name) => { +export const findObjByNameInArr = (array, name) => { let ret; if (!Array.isArray(array)) @@ -89,7 +89,7 @@ module.exports.findObjByNameInArr = (array, name) => { * start timer * @param name */ -module.exports.time = (name) => { +export const time = (name) => { exec.ifExist(console, 'time', [name]); }; @@ -97,7 +97,7 @@ module.exports.time = (name) => { * stop timer * @param name */ -module.exports.timeEnd = (name) => { +export const timeEnd = (name) => { exec.ifExist(console, 'timeEnd', [name]); }; diff --git a/common/util.spec.js b/common/util.spec.js index cb84f18d..4f7cea11 100644 --- a/common/util.spec.js +++ b/common/util.spec.js @@ -1,9 +1,6 @@ -'use strict'; - -const test = require('supertape'); -const {reRequire} = require('mock-require'); -const tryCatch = require('try-catch'); -const Util = require('./util'); +import test from 'supertape'; +import tryCatch from 'try-catch'; +import * as Util from './util.js'; const { findObjByNameInArr, @@ -122,15 +119,3 @@ test('util: escapeRegExp', (t) => { t.end(); }); -test('util: scope', (t) => { - global.window = {}; - - reRequire('./util'); - - t.pass('should set window in scope'); - - delete global.window; - - t.end(); -}); -