truncated-list

1.0.1 • Public • Published

truncated-list

npm version Build Status Coverage Status

Create a list of items with truncating lines to the specified maximum number

const truncatedList = require('truncated-list');
 
console.log(truncatedList([
  'Apple',
  'Orange',
  'Strawberry',
  'Grape',
  'Lemon',
  'Kiwi'
], 4));
* Apple
* Orange
* Strawberry
* Grape
  ... and 2 more

Installation

Use npm.

npm install truncated-list

API

const truncatedList = require('truncated-list');

truncatedList(items, max)

items: Iterable<string> (list items)
max: integer (maximum number of items)
Return: string

It joins items into a list each of lines begins with *.

If the number of items exceeds max, it truncates the surplus and append ... and X more to the result.

truncatedList(new Set(['a', 'b']), 2);
//=> '* a\n* b'
 
truncatedList(new Set(['a', 'b']), 1);
//=> '* a\n  ... and 1 more'

License

ISC License © 2018 Shinnosuke Watanabe

Package Sidebar

Install

npm i truncated-list

Weekly Downloads

4

Version

1.0.1

License

ISC

Unpacked Size

5.02 kB

Total Files

4

Last publish

Collaborators

  • shinnn