@js-ninja/list
TypeScript icon, indicating that this package has built-in type declarations

1.0.18 • Public • Published

List Library

The List Library provides a class for managing an array or a DOM collection.

README.md

Installation

You can install the List Library using npm or yarn by executing the following command:

npm install @js-ninja/list

or

yarn add @js-ninja/list

Usage

To use the library, you need to import the List class. Here's an example import statement:

import List from "list-library";

The each method

The each method allows you to efficiently iterate over an array or a DOM collection. It takes the following parameters:

  • arr - an array, NodeList, or HTMLCollection to iterate over.
  • cb - a function that is called for each element. It takes the following parameters:
    • item - the list item.
    • index - the index of the item.
    • arr - the list.
  • breakOn (optional) - the index at which the function will stop execution.

Example usage of the each method:

const arr = [1, 2, 3, 4, 5];

List.each(arr, (item, index) => {
    console.log(item); // Outputs each element of the array
});

The filter method

The filter method allows you to efficiently filter an array or a DOM collection. It takes the following parameters:

  • arr - an array, NodeList, or HTMLCollection to filter.
  • cb - a function that is called for each element. It takes the following parameters:
    • item - the list item.
    • index - the index of the item.
    • arr - the list.
  • Returns the filtered array.

Example usage of the filter method:

const arr = [1, 2, 3, 4, 5];

const filtered = List.filter(arr, (item) => item % 2 === 0);

console.log(filtered); // Outputs [2, 4]

The map method

The map method allows you to efficiently transform an array or a DOM collection. It takes the following parameters:

  • arr - an array, NodeList, or HTMLCollection to transform.
  • cb - a transformation function for each element. It takes the following parameters:
    • item - the item from the original list.
    • index - the index of the item.
    • array - the original list.
  • Returns the resulting array.

Example usage of the map method:

const arr = [1, 2, 3, 4, 5];

const doubled = List.map(arr, (item) => item * 2);

console.log(doubled); // Outputs [2, 4, 6, 8, 10]

License

The List Library is distributed under the MIT License.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.181latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.181
1.0.170
1.0.160
1.0.150
1.0.140
1.0.130
1.0.120
1.0.110
1.0.100
1.0.90
1.0.80
1.0.60
1.0.51
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i @js-ninja/list

Weekly Downloads

2

Version

1.0.18

License

MIT

Unpacked Size

13.3 kB

Total Files

8

Last publish

Collaborators

  • radislav