Socket
Socket
Sign inDemoInstall

array-sorting-utilities

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    array-sorting-utilities

Dependency-free utility functions for efficiently managing sorted arrays


Version published
Weekly downloads
1.2K
decreased by-34.62%
Maintainers
1
Install size
26.6 kB
Created
Weekly downloads
 

Readme

Source

array-sorting-utilities

Dependency-free utility functions for efficiently managing sorted arrays.

This package exists primarily in support of the suspense package, though it may be useful in other contexts.

Installation

# NPM
npm install array-sorting-utilities

# Yarn
yarn add array-sorting-utilities

Configuration

Configure the utility to compare values of a specific type. For example...

To compare values with numeric ids/keys:

import { configure } from "point-utilities";

const utils = configure<number>((a: Object, b: Object) => a.key - b.key);

To compare values with string ids/keys:

import { configure } from "point-utilities";

const utils = configure<number>((a: Object, b: Object) => a.key.localeCompare(b));

API

find(sortedItems: Value[], targetItem: Value): Value | null

If an item matching the one specified can be found the array, this value will return it. Else it will return null.

findIndex(sortedItems: Value[], targetItem: Value, exactMatch?: boolean): number

Returns the index of an item matching the one specified (or -1 if no match is found).

By default, exactMatch is true. Setting this parameter to false will return the index of the closest match.

findInsertIndex(sortedItems: Value[], item: Value): number

Returns the insertion index for the specified value.

insert(sortedItems: Value[], item: Value): Value[]

Inserts a value.

FAQs

Last updated on 25 Apr 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc