Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

order-with-group

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

order-with-group

A lightweight, zero-dependency TypeScript utility library for managing hierarchical ordered items with grouping support.

latest
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

order-with-group

A lightweight, zero-dependency TypeScript utility library for managing hierarchical ordered items with grouping support.

Features

  • Zero dependencies – Lightweight and efficient.
  • Simple API – Easy-to-use functions for managing ordered items.
  • Grouping support – Handle hierarchical structures effortlessly.
  • TypeScript-ready – Full type safety with generics.

Installation

npm install order-with-group

or

yarn add order-with-group

Usage

Importing

import { getItem, getSiblings, getNextItem, isFirst, isLast } from 'order-with-group';
import { OWG_Item } from 'order-with-group/types';

Data Structure

The library operates on items structured as follows:

type OWG_Item<T> = {
  id: T;
  order: number;
  title?: string;
  parentId?: T | null;
};

API Reference

getItem<T>(items: OWG_Item<T>[], id: T): OWG_Item<T> | undefined

Finds and returns an item by its id.

getSiblings<T>(items: OWG_Item<T>[], currentId: T): OWG_Item<T>[]

Retrieves all sibling items of the given currentId, sorted by order.

getNextItem<T>(items: OWG_Item<T>[], currentId: T): OWG_Item<T> | undefined

Finds the next item in the hierarchy based on order.

isFirst<T>(items: OWG_Item<T>[], currentId: T): boolean

Checks if the given item is the first among its siblings.

isLast<T>(items: OWG_Item<T>[], currentId: T): boolean

Checks if the given item is the last among its siblings.

hasAncestor<T>(items: OWG_Item<T>[], descendantId: T, ancestorId: T): boolean

Checks if the given item is descendant of.

License

MIT

FAQs

Package last updated on 03 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts