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

array-cycle

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

array-cycle

Simple wrapper utility to navigate and cycle an array

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

array-cycle

Simple wrapper utility to navigate and cycle an array

Install

npm i array-cycle

API

constructor(array)

const Cycle = require('array-cycle')

var cycle = new Cycle(['a', 'b', 'c', 'd'])

// also allowed
var cycle = Cycle(['a', 'b', 'c', 'd'])

index

Getter/setter to navigate the array. Loop if out of range

var cycle = Cycle(['a', 'b', 'c', 'd'])

// 0
cycle.index

cycle.index = 1

// 1
cycle.index

cycle.index -= 2

// 3
cycle.index

keys

Getter. Return an object containing the current, next and previous indexes

var cycle = Cycle(['a', 'b', 'c', 'd'])

/*
{
  curr: 0,
  next: 1,
  prev: 3
}
*/
cycle.keys

values

Getter. Return an object containing the current, next and previous values

var cycle = Cycle(['a', 'b', 'c', 'd'])

/*
{
  curr: 'a',
  next: 'b',
  prev: 'd'
}
*/
cycle.values

last

Getter. Return an object containing the index and value of the last item

var cycle = Cycle(['a', 'b', 'c', 'd'])

/*
{
  key: 3,
  value: 'd'
}
*/
cycle.values

Example

const Cycle = require('array-cycle')

var cycle = Cycle(['a', 'b', 'c', 'd'])

// 0
cycle.index

/*
{
  curr: 0,
  next: 1,
  prev: 3
}
*/
cycle.keys

/*
{
  curr: 'a',
  next: 'b',
  prev: 'd'
}
*/
cycle.values

/*
{
  key: 3,
  value: 'd'
}
*/
cycle.last

// walk one step forward
cycle.index++

// 1
cycle.index

/*
{
  curr: 1,
  next: 2,
  prev: 0
}
*/
cycle.keys

// walk three steps forward (and loop to the beginning)
cycle.index += 3

/*
{
  curr: 0,
  next: 1,
  prev: 3
}
*/
cycle.keys

License

MIT

FAQs

Package last updated on 28 Jan 2016

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