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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bracketing

v1.0.2

Published

Function to efficiently traverse large strings or arrays and run a predicate on adjacent values.

Downloads

7

Readme

Bracketing

bracketing is a small utility function to effeciantly walk and compare consecutive elements in an array or string and extract the longest sub array that fulfills this predicate. It is essentially two managed array pointers to traverse an array with the bare minimum number of comparisons. It will return the longest sequence that satisfies the supplied predicate function.

Current Version Build Status

Useage

These following examples demonstrate some basic usage and should give you a better idea what bracketing is all about

const bracketing = require('bracketing');

let result;

result = bracketing((left, right) => right > left, [1, 2, 3, 0, 5, 6, 7, 8, 100]);
// result equals [0, 5, 6, 7, 8, 100] because it is the longest sub array where the right value is greater than the left
result = bracketing((left, right) => left === right, 'aaaaaabbbbbccdeeeeeeeeeee');
// result equals "eeeeeeeeeee" because it is the longest substring where each character equals the one to the right

API

bracketing(predicate, sequence)

Returns the result of running the predicate against sequence. The result is either a string or array, matching the type of sequence.

  • predicate - a function to run against the elements of sequence. It must return a boolean value indicating pass or fail of the two elements. Has the following signature
    • left - the left value
    • right - the right value
  • sequence - a string or array to traverse.

Browser Usage

There is a UMD build provided in the "dist" folder. bracketing should have no issues working in a browser context. The only potential "got ya" is that accessing a string using bracket notation, which this module does, will not work in Internet Explorer 7.