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

array-trails

v1.0.1

Published

Traverse arrays in interesting ways

Downloads

3

Readme

array-trails

Traverse arrays in interesting ways.

Installation

npm install --save array-trails

Usage

import { cycle, scan, bounce } from 'array-trails'

cycle

Iterate through any flat array in a loop that begins again at the startingIndex once an end is reached. cycle accepts the following arguments, all arguments are optional.

  • arr
    • this is a flat array to cycle through
  • dir
    • f (forwards or right) or r (reverse or left)
    • the default is f
  • startingIndex
    • where in the array to begin the cycle
    • the default is 0

Once your cycle generator is instantiated you can retrieve the next element in the cycle by calling: [generator].next().value which will return an object containing {el: the element, col: index of the element}

const cycler = cycle([0, 1, 2, 3])
cycler.next().value.el // 0
cycler.next().value.el // 1
cycler.next().value.el // 2
cycler.next().value.el // 3
cycler.next().value.el // 0
cycler.next().value.el // 1
cycler.next().value.el // 2
cycler.next().value.el // 3
// ... and so on forever.

scan

Iterate through any flat array in a loop that reverses direction once an end is reached. scan accepts the following arguments, all arguments are optional.

  • arr
    • this is a flat array to scan through
  • dir
    • f (forwards or right) or r (reverse or left)
    • the default is f
  • startingIndex
    • where in the array to begin the scan
    • the default is 0

Once your scan generator is instantiated you can retrieve the next element in the scan by calling: [generator].next().value which will return an object containing {el: the element, col: index of the element}

const scanner = scan(arr, [dir = 'f', startingIndex = 0])
const firstElement = scanner.next().value.el
const secondElement = scanner.next().value.el
const thirdElement = scanner.next().value.el
// ... and so on forever.
let scanner = scan([0, 1, 2, 3])
scanner.next().value.el // 0
scanner.next().value.el // 1
scanner.next().value.el // 2
scanner.next().value.el // 3
scanner.next().value.el // 2
scanner.next().value.el // 1
scanner.next().value.el // 0
scanner.next().value.el // 1
// ... and so on forever.

bounce

Iterate through any two-dimensional array in a loop that creates a bouncing pattern once an end is reached. bounce always starts moving down and to the right.

bounce accepts the following arguments, all arguments are optional.

  • arr
    • this is a two-dimensional array to bounce through
  • sx
    • starting x or col index
    • the default is 0
  • sy
    • starting y or row index
    • the default is 0

Once your bounce generator is instantiated you can retrieve the next element in the scan by calling: [generator].next().value which will return an object containing {el: the element, row: index of the element's array, col: element index}

const bouncer = bounce([
  ['A', 'B', 'C', 'D'],
  ['E', 'F', 'G', 'H'],
  ['I', 'J', 'K', 'L']
])
bouncer.next().value.el // 'A'
bouncer.next().value.el // 'F'
bouncer.next().value.el // 'K'
bouncer.next().value.el // 'H'
bouncer.next().value.el // 'C'
bouncer.next().value.el // 'F'
bouncer.next().value.el // 'I'
bouncer.next().value.el // 'F'
// ... and so on forever.