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 filterMap<T extends unknown, R extends unknown>( | |
arr: T[], | |
filterFn: (item: T, index: number) => boolean, | |
mapFn: (item: T, index: number) => R | |
) { | |
return arr.reduce((acc, item, i) => { | |
if (filterFn(item, i)) acc.push(mapFn(item, i)); | |
return acc; | |
}, [] as R[]); |
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 function update<T extends Record<K, unknown>, K extends keyof T>( | |
arr: T[], | |
predicate: (item: T, index: number, array: T[]) => boolean, | |
payload: Partial<T> | |
) { | |
const targetIndex = arr.findIndex(predicate); | |
if (targetIndex > -1) { | |
return arr.with(targetIndex, { ...arr[targetIndex], ...payload }); | |
} |
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 function isEqual(a: unknown, b: unknown): boolean { | |
if (a === b) return true; | |
if (a == null || b == null) return a === b; | |
if (typeof a !== typeof b) return false; | |
if (Array.isArray(a) && Array.isArray(b)) { | |
if (a.length !== b.length) return false; | |
return a.every((item, index) => isEqual(item, b[index])); |
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 function pick<T extends object, K extends keyof T>( | |
base: T, | |
...keys: K[] | |
): Pick<T, K> { | |
if (!keys.length) return base; | |
const entries = keys.map((key) => [key, base[key]]); | |
return Object.fromEntries(entries); | |
} |
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 function omit<T extends object, K extends keyof T>( | |
base: T, | |
...keys: K[] | |
): Omit<T, K> { | |
if (keys.length) { | |
const result = { ...base }; | |
for (const key of keys) delete result[key]; | |
return result; |
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 const onClickOutside = (element: HTMLElement, callback: Function) => { | |
const handler = ({ target }: Event) => { | |
let currentElement = target; | |
do { | |
if (currentElement === element) { | |
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
import { Component } from 'solid-js'; | |
import { HTMLElementEvent } from '../../@types/alltypes'; | |
import { throttle } from '../lib/helpers'; | |
interface Props { | |
className?: string; | |
children: any; | |
ref: (el: HTMLDivElement) => HTMLDivElement; | |
onScroll?: (e: HTMLElementEvent<HTMLDivElement>) => void; | |
onScrollEnd?: () => void; |
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
const getStartOfQuarter = date => { | |
const | |
quarters = { | |
1: 1, | |
2: 4, | |
3: 7, | |
4: 10 | |
}, | |
d = date ? new Date(date) : new Date(), | |
q = Math.ceil((d.getMonth() + 1) / 3), |
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
const out = document.querySelector('output'); | |
const plaindiv = document.querySelector('div'); | |
const absdiv = document.querySelector('div.absolute'); | |
const floatdiv = document.querySelector('div.float'); | |
const getposition = ev => { | |
let x = ev.clientX; | |
let y = ev.clientY; | |
let pos = ev.target.getBoundingClientRect(); | |
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
const stripScripts = (s) => { | |
const div = document.createElement('div'); | |
div.innerHTML = s; | |
const scripts = div.querySelectorAll('script'); | |
for (var script of scripts) { | |
script.parentNode.removeChild(script); | |
} |
NewerOlder