Skip to content

Instantly share code, notes, and snippets.

class Enumerable {
constructor(collection, operations) {
this.collection = collection;
this.operations = operations || [];
}
build(fn) {
return new Enumerable(this.collection.slice(), this.operations.concat(fn));
}
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 [];
};
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) => {
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;
};
const getAttr = (attrib) => {
if (attrib.length === 0) {
return [];
}
const keys = Object.keys(attrib);
return keys.map(element => ` ${element}="${attrib[element]}"`).join('');
};
const makeObj = {
tag: [],
const propertyActions = [
{
name: 'body',
check: arg => typeof arg === 'string',
},
{
name: 'children',
check: arg => arg instanceof Array,
},
{
const noop = () => {};
const once = (fn) => {
let called = false;
return (...args) => {
if (called) return;
called = true;
fn(...args);
};
const noop = () => {};
const once = (fn) => {
let called = false;
return (...args) => {
if (called) return;
called = true;
fn(...args);
};
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: {
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 => {