UNPKG

@ariakit/core

Version:
31 lines (24 loc) 757 B
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/array.ts function toArray(arg) { if (Array.isArray(arg)) { return arg; } return typeof arg !== "undefined" ? [arg] : []; } function addItemToArray(array, item, index = -1) { if (!(index in array)) { return [...array, item]; } return [...array.slice(0, index), item, ...array.slice(index)]; } function flatten2DArray(array) { const flattened = []; for (const row of array) { flattened.push(...row); } return flattened; } function reverseArray(array) { return array.slice().reverse(); } exports.toArray = toArray; exports.addItemToArray = addItemToArray; exports.flatten2DArray = flatten2DArray; exports.reverseArray = reverseArray;