@wireapp/commons
Version:
Collection of common components that are used across Wire web applications.
52 lines (51 loc) • 1.79 kB
JavaScript
;
/*
* Wire
* Copyright (C) 2018 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.flatten = void 0;
exports.chunk = chunk;
exports.getDeduplicatedUnion = getDeduplicatedUnion;
exports.getDifference = getDifference;
exports.getIntersection = getIntersection;
exports.removeDuplicates = removeDuplicates;
exports.filterFalsy = filterFalsy;
function chunk(array, chunkSize) {
const chunks = [];
for (let index = 0, length = array.length; index < length; index += chunkSize) {
chunks.push(array.slice(index, index + chunkSize));
}
return chunks;
}
function getDeduplicatedUnion(array1, array2) {
return removeDuplicates(array1.concat(array2));
}
function getDifference(array1, array2) {
return array1.filter(value => !array2.includes(value));
}
function getIntersection(array1, array2) {
return array1.filter(value => array2.includes(value));
}
function removeDuplicates(array) {
return Array.from(new Set(array));
}
const flatten = (arrays) => [].concat(...arrays);
exports.flatten = flatten;
function filterFalsy(value) {
return Boolean(value);
}