This file contains hidden or 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
/** | |
* Description | |
* @param {Date} date | |
* @param {number} offset | |
* @returns {Date} | |
*/ | |
export const getOffsetDate = (date, offset) => { | |
return new Date(date.setDate(date.getDate() - offset * 7)) | |
} |
This file contains hidden or 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
/** | |
* Description | |
* @param {Date} {date | |
* @param {number} offset=0 | |
* @param {'nice|short|iso|none':string} format='nice'} | |
* @returns {Date} | |
*/ | |
export const niceDate = ({ date, offset = 0, format = 'nice' }) => { | |
const offsetDate = getOffsetDate(date, offset) | |
switch (format) { |
This file contains hidden or 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
/** | |
* <input type=week genererar en sträng typ '2022-W12' som vi vill ha omvandlad till två datum | |
* @param {string} weekString:'2021-W01' | |
* @returns {object} {from: date, to: date} | |
*/ | |
export const datesFromWeek = (weekString) => { | |
let [y, w] = weekString.split('-') | |
w = w.replace('W', '') | |
const offsetDate = new Date(y, 0, w * 7) | |
return { |
This file contains hidden or 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 async function blockUntilEvent(page: Page, callback: (frame: Frame, resolve: any, reject: any) => Promise<void>) { | |
return await new Promise((resolve, reject) => | |
page.on('framenavigated', async (frame) => { | |
try { | |
await callback(frame, resolve, reject); | |
} catch (err) { | |
reject(err); | |
} | |
}) | |
); |
This file contains hidden or 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
type GroupByMulti = (list: any[], paths: { [key: string]: string }) => any | |
export const groupByMulti: GroupByMulti = (list, paths) => { | |
return ( | |
list?.reduce((acc: { [key: string]: any }, row: any) => { | |
Object.keys(paths).forEach((key) => { | |
const path = paths[key] | |
if (getVal(row, path)) { | |
;(acc[key] = acc[key] || {})[getVal(row, path)] = (acc[key] = acc[key] || {})[getVal(row, path)] || [] | |
acc[key][getVal(row, path)].push(row) | |
} |
This file contains hidden or 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
function svgColorSwatches(colors, size = 64, vertical = false) { | |
let svg = vertical | |
? `<svg width="${size}" height="${colors.length * size}" viewBox="0 0 ${size} ${colors.length * size}" fill="none" xmlns="http://www.w3.org/2000/svg">` | |
: `<svg width="${colors.length * size}" height="${size}" viewBox="0 0 ${colors.length * size} ${size}" fill="none" xmlns="http://www.w3.org/2000/svg">`; | |
let x = 0, y = 0; | |
for (let shade of colors) { | |
svg += ` | |
<rect width="${size}" height="${size}" fill="${shade}" x="${x}" y="${y}"/>`; | |
x += vertical ? 0 : size; | |
y += vertical ? size : 0; |
This file contains hidden or 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
!function () { function e(e) { var t = { height: e.offsetHeight, width: e.offsetWidth }; return t.height > r && t.height < s && t.width > i && t.width < d; } function t() { for (var e = document.getElementsByClassName(m), t = RegExp("\\b" + m + "\\b"); 0 < e.length;)e[0].className = e[0].className.replace(t, ""); } for (var n, o, a, r = 30, i = 30, s = 350, d = 350, m = "mw-harlem_shake_me", l = ["im_drunk", "im_baked", "im_trippin", "im_blown"], u = "mw_added_css", c = (n = document.documentElement, window.innerWidth ? window.innerHeight : n && !isNaN(n.clientHeight) ? n.clientHeight : 0), h = window.pageYOffset ? window.pageYOffset : Math.max(document.documentElement.scrollTop, document.body.scrollTop), f = document.getElementsByTagName("*"), p = null, g = 0; g < f.length; g++) { var b = f[g]; if (e(b) && function (e) { var t = function (e) { for (var t = e, n = 0; t;)n += t.offsetTop, t = t.offsetParent; return n; }(e); return t >= h && t <= c + h; }(b)) { p = b; break; } } if (null === b) { console.warn(" |
This file contains hidden or 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
[ | |
{ | |
"id": 1, | |
"name": "Darla", | |
"url": "https://www.viralcats.net/media/thumbs/embedded/174.jpg" | |
}, | |
{ | |
"id": 2, | |
"name": "Fluffykins", | |
"url": "https://i.pinimg.com/originals/11/ae/2f/11ae2f50407d4be73cb3e561f2e65e5f.jpg" |
This file contains hidden or 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
/* eslint-disable */ | |
import { useEffect, useRef } from 'react' | |
import _ from 'lodash' | |
function getObjectDiff([obj1, obj2]: [{ [key: string]: any }, { [key: string]: any }]) { | |
const diff = Object.keys(obj1).reduce((result, key) => { | |
if (!obj2.hasOwnProperty(key)) { | |
result.push(key) | |
} else if (_.isEqual(obj1[key], obj2[key])) { | |
const resultKeyIndex = result.indexOf(key) | |
result.splice(resultKeyIndex, 1) |