Add new version in repository
This commit is contained in:
21
build/js/include/core/helpers.js
Normal file
21
build/js/include/core/helpers.js
Normal file
@@ -0,0 +1,21 @@
|
||||
// Array Helpers
|
||||
const countOccurrences = arr => arr.reduce((prev, curr) => (prev[curr] = ++prev[curr] || 1, prev), {});
|
||||
const isEmpty = arr => !(Array.isArray(arr) && arr.length > 0 && arr.filter(el => el === undefined).length > 0)
|
||||
const isEqual = (a, b) => JSON.stringify(a.sort()) === JSON.stringify(b.sort());
|
||||
const countBy = (arr, prop) => arr.reduce((prev, curr) => (prev[curr[prop]] = ++prev[curr[prop]] || 1, prev), {});
|
||||
const transpose = matrix => matrix[0].map((col, i) => matrix.map(row => row[i]));
|
||||
|
||||
// Dom Helpers
|
||||
const insertAfter = (ele, anotherEle) => anotherEle.parentNode.insertBefore(ele, anotherEle.nextSibling);
|
||||
const insertBefore = (ele, anotherEle) => anotherEle.parentNode.insertBefore(ele, anotherEle);
|
||||
const insertHtmlAfter = (html, ele) => ele.insertAdjacentHTML('afterend', html);
|
||||
const insertHtmlBefore = (html, ele) => ele.insertAdjacentHTML('beforebegin', html);
|
||||
|
||||
const goTo = url => location.href = url;
|
||||
const replace = (ele, newEle) => ele.parentNode.replaceChild(newEle, ele);
|
||||
const toNumbers = arr => arr.map(Number);
|
||||
const wait = async (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
|
||||
|
||||
const capitalize = str => `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
|
||||
const slugify = string => string.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]+/g, '');
|
||||
const isNumeric = str => !/[^0-9]/.test(str);
|
||||
Reference in New Issue
Block a user