@ariakit/core
Version:
Ariakit core
33 lines (30 loc) • 622 B
JavaScript
"use client";
// 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();
}
export {
toArray,
addItemToArray,
flatten2DArray,
reverseArray
};