Socket
Socket
Sign inDemoInstall

list-item

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

list-item - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

77

index.js
/*!
* list-item <https://github.com/jonschlinkert/list-item>
*
* Copyright (c) 2015, Jon Schlinkert.
* Copyright (c) 2015-present, Jon Schlinkert.
* Licensed under the MIT License.

@@ -10,14 +10,6 @@ */

var isNumber = require('is-number');
var expand = require('expand-range');
var repeat = require('repeat-string');
var extend = require('extend-shallow');
const isNumber = require('is-number');
const fill = require('fill-range');
/**
* Expose `listitem`
*/
module.exports = listitem;
/**
* Returns a function to generate a plain-text/markdown list-item,

@@ -27,3 +19,3 @@ * allowing options to be cached for subsequent calls.

* ```js
* var li = listitem(options);
* const li = listitem(options);
*

@@ -43,4 +35,4 @@ * li(0, 'Level 0 list item');

* @param {String} `options.indent` The amount of leading indentation to use. default is ` `.
* @param {String|Array} `options.chars` If a string is passed, [expand-range][] will be used to generate an array of bullets (visit [expand-range][] to see all options.) Or directly pass an array of bullets, numbers, letters or other characters to use for each list item. Default `['-', '*', '+']`
* @param {Function} `fn` pass a function [expand-range][] to modify the bullet for an item as it's generated. See the [examples](#examples).
* @param {String|Array} `options.chars` If a string is passed, [fill-range][] will be used to generate an array of bullets (visit [fill-range][] to see all options.) Or directly pass an array of bullets, numbers, letters or other characters to use for each list item. Default `['-', '*', '+']`
* @param {Function} `fn` pass a function [fill-range][] to modify the bullet for an item as it's generated. See the [examples](#examples).
* @return {String} returns a formatted list item

@@ -50,12 +42,12 @@ * @api public

function listitem(opts, fn) {
if (typeof opts === 'function') {
fn = opts;
opts = {};
function listitem(options = {}, fn) {
if (typeof options === 'function') {
fn = options;
options = {};
}
opts = opts || {};
var ch = character(opts, fn);
let chars = character(options);
let index = 0;
return function(lvl, str) {
return (lvl, suffix) => {
if (!isNumber(lvl)) {

@@ -65,18 +57,23 @@ throw new Error('expected level to be a number');

// cast to integer
// cast to number
lvl = +lvl;
index++;
var bullet = ch ? ch[lvl % ch.length] : '';
var indent = typeof opts.indent !== 'string'
let bullet = chars ? chars[lvl % chars.length] : '';
let indent = typeof options.indent !== 'string'
? (lvl > 0 ? ' ' : '')
: opts.indent;
: options.indent;
var prefix = !opts.nobullet
let prefix = !options.nobullet
? bullet + ' '
: '';
var res = '';
res += repeat(indent, lvl);
if (typeof fn === 'function') {
return fn(indent.repeat(lvl), bullet, index);
}
let res = '';
res += indent.repeat(lvl);
res += prefix;
res += str;
res += suffix;
return res;

@@ -87,4 +84,3 @@ };

/**
* Generate and cache the array of characters to use as
* bullets.
* Create the array of characters to use as bullets.
*

@@ -95,19 +91,20 @@ * - http://spec.commonmark.org/0.19/#list-items

*
* @param {Object} `opts` Options to pass to [expand-range][]
* @param {Function} `fn`
* @param {Object} `opts` Options to pass to [fill-range][]
* @return {Array}
*/
function character(opts, fn) {
opts = extend({}, opts);
var chars = opts.chars || ['-', '*', '+'];
function character(options = {}) {
let chars = options.chars || ['-', '*', '+'];
if (typeof chars === 'string') {
return expand(chars, opts, fn);
return fill(...chars.split('..'), options);
}
if (typeof fn === 'function') {
return chars.map(fn);
}
return chars;
}
/**
* Expose `listitem`
*/
module.exports = listitem;
{
"name": "list-item",
"description": "Generate a single formatted list item, allowing you to easily generate lists with proper indentation, bullets, numbers or other leading characters.",
"version": "1.1.1",
"version": "2.0.0",
"homepage": "https://github.com/jonschlinkert/list-item",

@@ -24,3 +24,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},

@@ -31,11 +31,9 @@ "scripts": {

"dependencies": {
"expand-range": "^1.8.1",
"extend-shallow": "^2.0.1",
"is-number": "^2.1.0",
"repeat-string": "^1.5.2"
"fill-range": "^6.0.0",
"is-number": "^7.0.0"
},
"devDependencies": {
"mocha": "*",
"romanize": "^0.1.0",
"should": "*"
"gulp-format-md": "^1.0.0",
"mocha": "^5.2.0",
"romanize": "^1.1.1"
},

@@ -57,6 +55,13 @@ "keywords": [

"verb": {
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"related": {
"list": [
"deromanize",
"expand-range",
"fill-range",

@@ -68,12 +73,11 @@ "randomatic",

},
"plugins": [
"gulp-format-md"
],
"reflinks": [
"expand-range",
"fill-range",
"randomatic",
"romanize"
],
"layout": "default"
"lint": {
"reflinks": true
}
}
}

@@ -1,23 +0,13 @@

# list-item [![NPM version](https://img.shields.io/npm/v/list-item.svg)](https://www.npmjs.com/package/list-item) [![Build Status](https://img.shields.io/travis/jonschlinkert/list-item.svg)](https://travis-ci.org/jonschlinkert/list-item)
# list-item [![NPM version](https://img.shields.io/npm/v/list-item.svg?style=flat)](https://www.npmjs.com/package/list-item) [![NPM monthly downloads](https://img.shields.io/npm/dm/list-item.svg?style=flat)](https://npmjs.org/package/list-item) [![NPM total downloads](https://img.shields.io/npm/dt/list-item.svg?style=flat)](https://npmjs.org/package/list-item) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/list-item.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/list-item)
> Generate a single formatted list item, allowing you to easily generate lists with proper indentation, bullets, numbers or other leading characters.
- [Install](#install)
- [Usage](#usage)
- [Examples](#examples)
- [API](#api)
- [Related projects](#related-projects)
- [Running tests](#running-tests)
- [Contributing](#contributing)
- [Author](#author)
- [License](#license)
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
_(TOC generated by [verb](https://github.com/verbose/verb))_
## Install
Install with [npm](https://www.npmjs.com/)
Install with [npm](https://www.npmjs.com/):
```sh
$ npm i list-item --save
$ npm install --save list-item
```

@@ -28,3 +18,3 @@

```js
var listitem = require('list-item');
const listitem = require('list-item');
```

@@ -39,9 +29,7 @@

```js
var listitem = require('list-item');
var li = listitem();
var res = '';
const listitem = require('list-item');
const li = listitem();
['a', 'b', 'c', 'd', 'e'].forEach(function (ele, i) {
res += li(i, ele) + '\n';
});
let list = ['a', 'b', 'c', 'd', 'e'].map((ele, i) => li(i, ele));
console.log(list.join('\n'));
```

@@ -64,15 +52,14 @@

```js
var listitem = require('list-item');
var romanize = require('romanize');
const listitem = require('list-item');
const romanize = require('romanize');
// specify `chars` to be passed to expand-range (lib),
// and use the callback to modify generated numerals
var li = listitem({chars: '1..100..10'}, function (ch) {
return romanize(ch) + '.';
// specify `chars` to pass to fill-range, and use the callback
// to modify generated numerals
const li = listitem({ chars: '1..100..10' }, (indent, ch) => {
return indent + romanize(ch) + '.';
});
// generate a formatted list!
['a', 'b', 'c', 'd', 'e'].forEach(function (ele, i) {
res += li(i, ele) + '\n';
});
let list = ['a', 'b', 'c', 'd', 'e'].map((ele, i) => li(i, ele));
console.log(list.join('\n'));
```

@@ -92,3 +79,3 @@

### [listitem](index.js#L47)
### [listitem](index.js#L39)

@@ -102,4 +89,4 @@ Returns a function to generate a plain-text/markdown list-item, allowing options to be cached for subsequent calls.

* `options.indent` **{String}**: The amount of leading indentation to use. default is ``.
* `options.chars` **{String|Array}**: If a string is passed, [expand-range](https://github.com/jonschlinkert/expand-range) will be used to generate an array of bullets (visit [expand-range](https://github.com/jonschlinkert/expand-range) to see all options.) Or directly pass an array of bullets, numbers, letters or other characters to use for each list item. Default `['-', '*', '+']`
* `fn` **{Function}**: pass a function [expand-range](https://github.com/jonschlinkert/expand-range) to modify the bullet for an item as it's generated. See the [examples](#examples).
* `options.chars` **{String|Array}**: If a string is passed, [fill-range](https://github.com/jonschlinkert/fill-range) will be used to generate an array of bullets (visit [fill-range](https://github.com/jonschlinkert/fill-range) to see all options.) Or directly pass an array of bullets, numbers, letters or other characters to use for each list item. Default `['-', '*', '+']`
* `fn` **{Function}**: pass a function [fill-range](https://github.com/jonschlinkert/fill-range) to modify the bullet for an item as it's generated. See the [examples](#examples).
* `returns` **{String}**: returns a formatted list item

@@ -110,3 +97,3 @@

```js
var li = listitem(options);
const li = listitem(options);

@@ -123,37 +110,75 @@ li(0, 'Level 0 list item');

## Related projects
## Release History
* [deromanize](https://www.npmjs.com/package/deromanize): Convert roman numerals to arabic numbers (useful for books, outlines, documentation, slide decks, etc) | [homepage](https://github.com/jonschlinkert/deromanize)
* [expand-range](https://www.npmjs.com/package/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See… [more](https://www.npmjs.com/package/expand-range) | [homepage](https://github.com/jonschlinkert/expand-range)
* [fill-range](https://www.npmjs.com/package/fill-range): Fill in a range of numbers or letters, optionally passing an increment or multiplier to… [more](https://www.npmjs.com/package/fill-range) | [homepage](https://github.com/jonschlinkert/fill-range)
* [randomatic](https://www.npmjs.com/package/randomatic): Generate randomized strings of a specified length, fast. Only the length is necessary, but you… [more](https://www.npmjs.com/package/randomatic) | [homepage](https://github.com/jonschlinkert/randomatic)
* [romanize](https://www.npmjs.com/package/romanize): Convert numbers to roman numerals (useful for books, outlines, documentation, slide decks, etc) | [homepage](https://github.com/jonschlinkert/romanize)
* [to-regex-range](https://www.npmjs.com/package/to-regex-range): Returns a regex-compatible range from two numbers, min and max. Useful for creating regular expressions… [more](https://www.npmjs.com/package/to-regex-range) | [homepage](https://github.com/jonschlinkert/to-regex-range)
### 2.0.0 - July 5, 2018
## Running tests
**Breaking changes**
Install dev dependencies:
* The callback signature has changed to `(indent, char, level)`.
## About
<details>
<summary><strong>Contributing</strong></summary>
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
</details>
<details>
<summary><strong>Running Tests</strong></summary>
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm i -d && npm test
$ npm install && npm test
```
## Contributing
</details>
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/list-item/issues/new).
<details>
<summary><strong>Building docs</strong></summary>
## Author
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
</details>
### Related projects
You might also be interested in these projects:
* [deromanize](https://www.npmjs.com/package/deromanize): Convert roman numerals to arabic numbers (useful for books, outlines, documentation, slide decks, etc) | [homepage](https://github.com/jonschlinkert/deromanize "Convert roman numerals to arabic numbers (useful for books, outlines, documentation, slide decks, etc)")
* [fill-range](https://www.npmjs.com/package/fill-range): Fill in a range of numbers or letters, optionally passing an increment or `step` to… [more](https://github.com/jonschlinkert/fill-range) | [homepage](https://github.com/jonschlinkert/fill-range "Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`")
* [randomatic](https://www.npmjs.com/package/randomatic): Generate randomized strings of a specified length using simple character sequences. The original generate-password. | [homepage](https://github.com/jonschlinkert/randomatic "Generate randomized strings of a specified length using simple character sequences. The original generate-password.")
* [romanize](https://www.npmjs.com/package/romanize): Convert numbers to roman numerals (useful for books, outlines, documentation, slide decks, etc) | [homepage](https://github.com/jonschlinkert/romanize "Convert numbers to roman numerals (useful for books, outlines, documentation, slide decks, etc)")
* [to-regex-range](https://www.npmjs.com/package/to-regex-range): Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than… [more](https://github.com/micromatch/to-regex-range) | [homepage](https://github.com/micromatch/to-regex-range "Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than 2.78 million test assertions.")
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 18 | [jonschlinkert](https://github.com/jonschlinkert) |
| 7 | [adjohnson916](https://github.com/adjohnson916) |
### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
## License
### License
Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert)
Released under the MIT license.
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb](https://github.com/verbose/verb) on December 20, 2015._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 05, 2018._

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc