import React from "react"; export * from "css-box-model"; export * from "./array"; export * from "./assertion"; export * from "./breakpoint"; export * from "./dom"; export * from "./dom-query"; export * from "./focus"; export * from "./function"; export * from "./lazy"; export * from "./number"; export * from "./object"; export * from "./responsive"; export * from "./tabbable"; export * from "./types"; export * from "./user-agent"; export * from "./walk-object"; export function notEmpty( value: TValue | null | undefined, ): value is TValue { return value !== null && value !== undefined; } // Thank you https://stackoverflow.com/a/49725198 export type RequireOnlyOne = Pick< T, Exclude > & { [K in Keys]-?: Required> & Partial, undefined>>; }[Keys]; export const isBrowser = (): boolean => typeof window !== "undefined"; export const useFocus = (): [React.RefObject, () => void] => { const htmlElRef = React.useRef(null); const setFocus = (): void => { htmlElRef.current && htmlElRef.current.focus(); }; return [htmlElRef, setFocus]; }; // Thank you: https://github.com/jaredpalmer/the-platform/blob/e66c72d/src/utils.tsx // License MIT export function throttle void>( func: T, threshold = 250, scope?: unknown, ): T { let last: number, deferTimer: number; return function (this: any, ...args: any) { const context: unknown = scope || this; const now = Date.now(); if (last && now < last + threshold) { // hold on to it clearTimeout(deferTimer); deferTimer = window.setTimeout(function () { last = now; func.apply(context, args); }, threshold); } else { last = now; func.apply(context, args); } } as T; }