Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

sibs

jackall3n16ISC1.1.0TypeScript support: included

A small utility to easily access array siblings

sibs, siblings, array

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;
}