This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Enumerable { | |
constructor(collection, operations) { | |
this.collection = collection; | |
this.operations = operations || []; | |
} | |
build(fn) { | |
return new Enumerable(this.collection.slice(), this.operations.concat(fn)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const findFile = (node, fn, pathToFile) => { | |
const pathElement = node.name; | |
if (node.type === 'directory') { | |
return node.children.reduce((res, element) => [...res, ...findFile(element, fn, path.join(pathToFile, pathElement))], []); | |
} | |
if (fn(node)) { | |
return [path.join(pathToFile, node.name)]; | |
} | |
return []; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const countSize = (node) => { | |
return reduce((size, element) => { | |
if (element.type === 'file') { | |
return (size + element.meta.size); | |
} | |
return size; | |
}, node, 0); | |
}; | |
export const sortDu = (array) => array.sort((prev, next) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const sortDeps = (keys, packetList) => { | |
const keyRed = keys.reduce((acc, element) => { | |
if (packetList[element] instanceof Array && packetList[element].length === 0 || !packetList[element]) { | |
return [...acc, element]; | |
} | |
return [...acc, ...sortDeps(packetList[element], packetList), element]; | |
}, []); | |
return keyRed; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getAttr = (attrib) => { | |
if (attrib.length === 0) { | |
return []; | |
} | |
const keys = Object.keys(attrib); | |
return keys.map(element => ` ${element}="${attrib[element]}"`).join(''); | |
}; | |
const makeObj = { | |
tag: [], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const propertyActions = [ | |
{ | |
name: 'body', | |
check: arg => typeof arg === 'string', | |
}, | |
{ | |
name: 'children', | |
check: arg => arg instanceof Array, | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const noop = () => {}; | |
const once = (fn) => { | |
let called = false; | |
return (...args) => { | |
if (called) return; | |
called = true; | |
fn(...args); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const noop = () => {}; | |
const once = (fn) => { | |
let called = false; | |
return (...args) => { | |
if (called) return; | |
called = true; | |
fn(...args); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (queryPar) => { | |
const postData = querystring.stringify(queryPar.data); | |
const { protocol, hostname, pathname, port, query } = url.parse(queryPar.url, true); | |
const options = { | |
protocol, | |
host: hostname, | |
path: `${pathname}${getSearch(query, queryPar.params)}`, | |
port, | |
method: queryPar.method, | |
headers: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (backendUrl, currentUrl) => { | |
return new Promise((resolve, reject) => { | |
get(backendUrl) | |
.then(response => { | |
if (response.status !== 200) { | |
reject(new Error(response.status)); | |
return; | |
} | |
const parseJs = JSON.parse(response.data); | |
Promise.all(parseJs.map(element => { |
OlderNewer