Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

keydir

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keydir - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

39

keydir.js

@@ -44,12 +44,37 @@ var ltgt = require('ltgt')

Keydir.prototype.range = function (opts) {
opts = opts || {}
var keys = this._keys.filter(ltgt.filter(opts))
Keydir.prototype.range = function (options) {
options = options || {}
if (opts.reverse)
keys.reverse()
var lowerBound = ltgt.lowerBound(options)
, fromIdx = lowerBound ?
this._sortedIndexOf(lowerBound) : 0
, upperBound = ltgt.upperBound(options)
// toIdx - the id to slice to (exclusive)
, toIdx = upperBound ?
this._sortedIndexOf(upperBound) + 1 : this._keys.length
, keys
if (opts.limit && opts.limit !== -1)
keys = keys.slice(0, opts.limit)
if (ltgt.lowerBoundExclusive(options) && this._keys[fromIdx] === lowerBound)
fromIdx++
// behave correcly when the upperBound is between two keys
if (upperBound && this._keys[toIdx - 1] > upperBound)
toIdx--
if (ltgt.upperBoundExclusive(options) && this._keys[toIdx - 1] === upperBound)
toIdx--
if (options.limit && options.limit !== -1) {
if (options.reverse) {
fromIdx = Math.max(toIdx - options.limit, fromIdx)
} else {
toIdx = Math.min(fromIdx + options.limit, toIdx)
}
}
keys = this._keys.slice(fromIdx, toIdx)
if (options.reverse)
keys = keys.reverse()
return keys

@@ -56,0 +81,0 @@ }

2

package.json
{
"name": "keydir",
"version": "1.0.0",
"version": "1.0.1",
"description": "A sorted list of keys with support for level-* ranges",

@@ -5,0 +5,0 @@ "main": "keydir.js",

@@ -103,3 +103,48 @@ var test = require('tape')

t.deepEqual(
dir.range({ gt: 'foo1', limit: 3 })
, [ 'foo2', 'foo3', 'foo4' ]
)
t.deepEqual(
dir.range({ lte: 'foo4', limit: 3, reverse: true })
, [ 'foo4', 'foo3', 'foo2' ]
)
t.deepEqual(
dir.range({ lt: 'foo5', limit: 3, reverse: true })
, [ 'foo4', 'foo3', 'foo2' ]
)
t.deepEqual(
dir.range({ gt: 'foo2', lt: 'foo5', limit: 3})
, [ 'foo3', 'foo4' ]
)
t.deepEqual(
dir.range({ gt: 'foo2', lt: 'foo5', limit: 3, reverse: true})
, [ 'foo4', 'foo3' ]
)
t.deepEqual(
dir.range({ lt: 'foo1.5' })
, [ 'foo1' ]
)
t.deepEqual(
dir.range({ lte: 'foo1.5' })
, [ 'foo1' ]
)
t.deepEqual(
dir.range({ gt: 'foo4.5' })
, [ 'foo5' ]
)
t.deepEqual(
dir.range({ gte: 'foo4.5' })
, [ 'foo5' ]
)
t.end()
})
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc