PHP 8.2.30
Preview: utils.js.flow Size: 1.46 KB
/proc/thread-self/root/home/byroehnu/.trash/node_modules11/react-popper/lib/cjs/utils.js.flow

// @flow strict
import * as React from 'react';
import { type Ref } from './RefTypes';

/**
 * Takes an argument and if it's an array, returns the first item in the array,
 * otherwise returns the argument. Used for Preact compatibility.
 */
export const unwrapArray = (arg: *): * => (Array.isArray(arg) ? arg[0] : arg);

/**
 * Takes a maybe-undefined function and arbitrary args and invokes the function
 * only if it is defined.
 */
export const safeInvoke = <F: Function>(
  fn: ?F,
  ...args: Array<mixed>
): $Call<F> => {
  if (typeof fn === 'function') {
    return fn(...args);
  }
};

/**
 * Sets a ref using either a ref callback or a ref object
 */
export const setRef = (ref: ?Ref, node: ?HTMLElement): void => {
  // if its a function call it
  if (typeof ref === 'function') {
    return safeInvoke(ref, node);
  }
  // otherwise we should treat it as a ref object
  else if (ref != null) {
    ref.current = node;
  }
};

/**
 * Simple ponyfill for Object.fromEntries
 */
export const fromEntries = (
  entries: Array<[string, any]>
): { [key: string]: any } =>
  entries.reduce((acc, [key, value]) => {
    acc[key] = value;
    return acc;
  }, {});

/**
 * Small wrapper around `useLayoutEffect` to get rid of the warning on SSR envs
 */
export const useIsomorphicLayoutEffect:
  | typeof React.useEffect
  | typeof React.useLayoutEffect =
  typeof window !== 'undefined' &&
  window.document &&
  window.document.createElement
    ? React.useLayoutEffect
    : React.useEffect;

Directory Contents

Dirs: 1 × Files: 14

Name Size Perms Modified Actions
- drwxr-xr-x 2026-02-28 00:28:44
Edit Download
746 B lrw-r--r-- 2026-02-28 00:28:24
Edit Download
607 B lrw-r--r-- 2026-02-28 00:28:26
Edit Download
2.16 KB lrw-r--r-- 2026-02-28 00:27:44
Edit Download
1.03 KB lrw-r--r-- 2026-02-28 00:27:52
Edit Download
3.66 KB lrw-r--r-- 2026-02-28 00:28:00
Edit Download
3.04 KB lrw-r--r-- 2026-02-28 00:28:04
Edit Download
2.13 KB lrw-r--r-- 2026-02-28 00:28:16
Edit Download
1.12 KB lrw-r--r-- 2026-02-28 00:28:20
Edit Download
13 B lrw-r--r-- 2026-02-28 00:28:08
Edit Download
145 B lrw-r--r-- 2026-02-28 00:28:12
Edit Download
4.61 KB lrw-r--r-- 2026-02-28 00:28:28
Edit Download
3.96 KB lrw-r--r-- 2026-02-28 00:28:28
Edit Download
2.81 KB lrw-r--r-- 2026-02-28 00:28:30
Edit Download
1.46 KB lrw-r--r-- 2026-02-28 00:28:30
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).