listing.js

3.3.0 • Public • Published

listing.js

A JavaScript library for working with comma separated lists.

NPM

Tests Linter

Introduction

listing.js is a library that simplifies the work with comma separated lists in JavaScript. Most of the features are similar to those of array methods. Besides commas, other delimiters are supported as well.

💻 Installation

Install via npm or yarn:

npm i --save listing.js

🔨 Usage

// ES6: import Listing from 'listing.js';
const Listing = require('listing.js');

const list = new Listing('1,2,3,4');
list.prepend(0);
list.append(5);

// 0 1 2 3 4 5
for (const item of list) console.log(item);

The list items are accessible via the .list property:

const myList = new Listing('1,2,3');
console.log(myList.list); // 1,2,3

You can also use strings instead of numbers as items:

const list = new Listing('hello,I,am,John');

listing.js supports the following delimiters. In this case, each number is a single list item:

const list1 = new Listing('1,2,3'); // ,
const list2 = new Listing('1;2;3'); // ;
const list3 = new Listing('1:2:3'); // :
const list4 = new Listing('1-2-3'); // -
const list5 = new Listing('1_2_3'); // _
const list6 = new Listing('1.2.3'); // .
const list7 = new Listing('1|2|3'); // |

The delimiter can be changed later on:

const myList = new Listing('1,2,3');
myList.setDelimiter(':');
console.log(myList.list); // 1:2:3

📚 Documentation

You can find the complete documentation including all available methods here.

:octocat: Contributing

See CONTRIBUTING.md

🔓 License

MIT

Readme

Keywords

Package Sidebar

Install

npm i listing.js

Weekly Downloads

0

Version

3.3.0

License

MIT

Unpacked Size

15.9 kB

Total Files

8

Last publish

Collaborators

  • larswaechter