sibs
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i sibs

Weekly Downloads

2

Version

1.1.0

License

ISC

Unpacked Size

4.51 kB

Total Files

6

Last publish

Collaborators

  • jackall3n