sibs
v1.1.0
Published
A small utility to easily access array siblings
Downloads
16
Readme
Sibs 👧🏻👦🏽
A small utility function used to loop through an array and easily access the previous and next sibling of the current item
Installation
pnpm add sibs
npm install sibs
yarn add sibs
Usage
import sibs from 'sibs';
const array = [{}, {}, {}];
for (const [previous, current, next] of sibs(array)) {
}
Index
import sibs from 'sibs';
const array = [{}, {}, {}];
for (const [previous, current, next, index] of sibs(array)) {
}
Typed
import sibs from 'sibs';
interface Item {
id: string;
}
const array: Item[] = [...];
for (const item of sibs(array)) {
const [
previous, // Item | undefined
current, // Item
next, // Item | undefined
index, // number
] = item;
}