npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

guarded-array

v1.0.0

Published

Bounds checked array

Downloads

187

Readme

guarded-array

A slow bounds checked array to help with debugging.

Example

var guard = require('guarded-array')

//First create any old array
var array = [ 0, 1, 2, 3, 4, 5 ]

//Then we protect it using guard!
var guardedArray = guard(array)

//The guarded array works just like a normal array:
console.log(guardedArray.length, guardedArray.slice())

//Accessing elements in the middle of array is ok
guardedArray[3] = 100

//Writes propagate to underlying array
console.log(array)

//But reading out of bounds throws an exception
try {
  console.log(guardedArray[-1])
} catch(e) {
  console.log(e)
}

try {
  console.log(guardedArray[10])
} catch(e) {
  console.log(e)
}

//You can also create guarded arrays for subarrays of arrays
var subGuard = guard(array, 1, 3)

//Now you can only access elements in the range 1-3 of array safely
console.log(subGuard[1], subGuard[2])

//Writing/reading out of bounds throws an exception
console.log(subGuard[3])

//Use this module in your unit tests to help track down
//pesky off-by-one errors

Output:

6 [ 0, 1, 2, 3, 4, 5 ]
[ 0, 1, 2, 100, 4, 5 ]
[Error: read out of bounds: -1]
[Error: read out of bounds: 10]
1 2

Error: read out of bounds: 3
    at Array.get [as 3] (/Users/mikolalysenko/GitHub/guarded-array/guarded-array.js:39:15)
    at Object.<anonymous> (/Users/mikolalysenko/GitHub/guarded-array/example/example.js:38:21)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

Install

npm install guarded-array

API

require('guarded-array')(array[,lo, hi])

Creates a guarded view of array. Attempting to access outside of the bounds [lo,hi) or changing the length of the array will result in an exception.

  • array is an ordinary JavaScript array
  • lo is an optional lower bound (default 0)
  • hi is an optional upper bound (default array.length)

Returns A guarded view of the array object. Writes to the guarded array propagate down to the underlying array object. Out of bounds access will trigger an exception.

Notes/Warnings

Array.isArray doesn't work on guarded-array. I'm open to suggestions on how to get this to work.

Credits

(c) 2014 Mikola Lysenko. MIT License