Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/truncated-list
Create a list of items with truncating lines to the specified maximum number
https://github.com/shinnn/truncated-list
Last synced: 27 days ago
JSON representation
Create a list of items with truncating lines to the specified maximum number
- Host: GitHub
- URL: https://github.com/shinnn/truncated-list
- Owner: shinnn
- License: isc
- Created: 2017-07-28T11:14:47.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-14T06:57:42.000Z (over 5 years ago)
- Last Synced: 2024-09-26T05:58:29.339Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://npm.runkit.com/truncated-list
- Size: 93.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# truncated-list
[![npm version](https://img.shields.io/npm/v/truncated-list.svg)](https://www.npmjs.com/package/truncated-list)
[![Github Actions](https://action-badges.now.sh/shinnn/truncated-list)](https://wdp9fww0r9.execute-api.us-west-2.amazonaws.com/production/results/shinnn/truncated-list)
[![codecov](https://codecov.io/gh/shinnn/truncated-list/branch/master/graph/badge.svg)](https://codecov.io/gh/shinnn/truncated-list)Create a list of items with truncating lines to the specified maximum number
```javascript
const truncatedList = require('truncated-list');console.log(truncatedList([
'Apple',
'Orange',
'Strawberry',
'Grape',
'Lemon',
'Kiwi'
], 4));
``````
* Apple
* Orange
* Strawberry
* Grape
... and 2 more
```## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).
```
npm install truncated-list
```## API
```javascript
const truncatedList = require('truncated-list');
```### truncatedList(*items*, *max*)
*items*: `Iterable` (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.
```javascript
truncatedList(new Set(['a', 'b']), 2);
//=> '* a\n* b'truncatedList(new Set(['a', 'b']), 1);
//=> '* a\n ... and 1 more'
```## License
[ISC License](./LICENSE) © 2018 - 2019 Watanabe Shinnosuke