slate/common/arrays.js

42 lines
964 B
JavaScript
Raw Normal View History

2021-07-07 23:50:57 +03:00
import * as Validations from "~/common/validations";
export const filterPublic = (arr = []) => {
return arr.filter((item) => item.isPublic);
};
export const filterPrivate = (arr = []) => {
return arr.filter((item) => !item.isPublic);
};
export const mapToIds = (arr = []) => {
return arr.map((item) => item.id);
};
2021-07-07 23:50:57 +03:00
export const mapToCids = (arr = []) => {
return arr.map((item) => item.cid);
};
export const countPublic = (arr = []) => {
const reducer = (count, item) => {
if (item.isPublic) return count + 1;
else return count;
};
return arr.reduce(reducer, 0);
};
export const countPrivate = (arr = []) => {
const reducer = (count, item) => {
if (!item.isPublic) return count + 1;
else return count;
};
return arr.reduce(reducer, 0);
};
2021-07-07 23:50:57 +03:00
export const filterLinks = (arr = []) => {
return arr.filter((item) => item.isLink);
};
export const filterFiles = (arr = []) => {
return arr.filter((item) => !item.isLink);
};