🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

listcontrol

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

listcontrol

A simple JavaScript tool as internal pointer in lists.

latest
Source
npmnpm
Version
1.0.6
Version published
Weekly downloads
3
-70%
Maintainers
1
Weekly downloads
 
Created
Source

ListControl.js

Overview

Unlike some other programming languages (like PHP), JavaScript does not have an internal pointer for iterable objects. Though it is not a necessacity, it is a nice-to-have functionality is some situations.

ListControl.js aims to provide that functionality. It is extended from the native Array prototype, so you can use it like a normal Array with the internal pointer functionality attached.

Installation

npm install listcontrol

Usage

const ListControl = require('listcontrol');

const list = new ListControl('a', 'b', 'c');

OR with HTML:

<script src="path/to/listcontrol.min.js"></script>
<script>
const list = new ListControl('a', 'b', 'c');
</script>

Property

.index

The property is the main pointer. Though it is writable, you are highly discouraged from replacing the value of this property under most circumstances.

list.index
// -> 0

Methods

.current()

Returns the current item of the instance.

list.current()
// -> 'a'

.next()

Increments the pointer index by 1 if there is a next item in the instance. Returns the next item if there is a next item or undefined otherwise.

list.next()
// -> 'b'

list.index
// -> 1

list.next()
// -> 'c'

list.index
// -> 2

list.next()
// -> undefined

list.index
// -> 2

.previous

Increments the pointer index by 1 if there is a previous item in the instance. Returns the previous item if there is a previous item or undefined otherwise.

list.previous()
// -> 'b'

list.index
// -> 1

list.previous()
// -> 'a'

list.index
// -> 0

list.previous()
// -> undefined

list.index
// -> 0

.last()

Moves the pointer index to the last and returns the last item in the instance.

list.last()
// -> 'c'

list.index
// -> 2

.first()

Moves the pointer index to the start and returns the first item in the instance.

list.first()
// -> 'a'

list.index
// -> 0

Keywords

internal

FAQs

Package last updated on 24 Feb 2024

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