New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

rangeindex

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rangeindex

Minimalistic helper for simple operation: put a bunch of [from, to] values and get any selection of them

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

RangeIndex

Minimalistic helper for simple operation: put a bunch of [from, to] values and get any selection of them

API

put(from: integer, to: integer, record: Object): RangeIndex - put record to the index

find(from: integer, to: integer, options: Object?): Array - find records in range of from-to

findOuter(innerFrom: integer, innerTo: integer, options: Object?): Array - find records which from-to range contains innerFrom-innerTo range

Note: the result of findOuter is unsorted list of records. The records in this result would be in a different order than they were put. Specify the options.sort to sort result.

options = {
    sort: function(Object.<from, to>, Object.<from, to>){} // For findOuter method only. Callback for sorting result
    filter: function(record: Object, from: number, to: number){} // Callback for filtering result
}

Example

const rangeIndex = new RangeIndex()
	, dataset = [
		{from: 0, to: 10, data: '0-10'}, {from: 0, to: 20, data: '0-20'}, {from: 0, to: 50, data: '0-50'}
		, {from: 50, to: 100, data: '50-100'}, {from: 50, to: 120, data: '50-120'}, {from: 50, to: 150, data: '50-150'}
		, {from: 150, to: 1000, data: '150-1000'}
		, {from: 250, to: 1200, data: '250-1200'}
		, {from: 350, to: 2000, data: '350-2000'}
	]
;
for ( let {from, to, data} of dataset ) {
	rangeIndex.put(from, to, data);
}
rangeIndex.find(0, 500);//["0-10", "0-20", "0-50", "50-100", "50-120", "50-150"]
rangeIndex.findOuter(300, 500);//["150-1000", "250-1200"]

Install

npm install rangeindex

License

MIT

Keywords

range

FAQs

Package last updated on 02 Apr 2014

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