Comparing version 1.0.1 to 1.1.0
53
index.js
@@ -13,2 +13,3 @@ /*! | ||
var repeat = require('repeat-string'); | ||
var extend = require('extend-shallow'); | ||
@@ -38,7 +39,8 @@ /** | ||
* | ||
* @param {String} `options` | ||
* @option {Boolean} [options] `nobullet` Pass true if you only want the list iten and identation, but no bullets. | ||
* @option {String} [options] `indent` The amount of leading indentation to use. default is ` `. | ||
* @option {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]. | ||
* @param {Object} `options` pass options to customize list item characters, indentation, etc. | ||
* @param {Boolean} `options.nobullet` Pass true if you only want the list iten and identation, but no bullets. | ||
* @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). | ||
* @return {String} returns a formatted list item | ||
* @api public | ||
@@ -54,11 +56,12 @@ */ | ||
opts = opts || {}; | ||
var chars = character(opts, fn); | ||
var ch = character(opts, fn); | ||
return function(lvl, str, sublvl) { | ||
return function(lvl, str) { | ||
if (!isNumber(lvl)) { | ||
throw new Error('[listitem]: invalid arguments.'); | ||
throw new Error('expected level to be a number'); | ||
} | ||
lvl = isNumber(lvl) ? +lvl : 0; | ||
var ch = chars(sublvl); | ||
// cast to integer | ||
lvl = +lvl; | ||
var bullet = ch ? ch[lvl % ch.length] : ''; | ||
@@ -89,5 +92,3 @@ var indent = typeof opts.indent !== 'string' | ||
* | ||
* TODO: split this out into simpler functions. | ||
* | ||
* @param {Object} `opts` Options to pass to [expand-range] | ||
* @param {Object} `opts` Options to pass to [expand-range][] | ||
* @param {Function} `fn` | ||
@@ -98,27 +99,13 @@ * @return {Array} | ||
function character(opts, fn) { | ||
opts = extend({}, opts); | ||
var chars = opts.chars || ['-', '*', '+']; | ||
if (typeof chars === 'string') { | ||
opts = Object.create(opts || {}); | ||
return function (sublvl) { | ||
return expand(chars, opts, function(ch) { | ||
return fn ? fn(ch, sublvl) : ch; | ||
}); | ||
}; | ||
return expand(chars, opts, fn); | ||
} | ||
if (typeof fn === 'function') { | ||
return wrap(fn, chars); | ||
return chars.map(fn); | ||
} | ||
return function () { | ||
return chars; | ||
}; | ||
return chars; | ||
} | ||
function wrap (fn, chars) { | ||
return function (/*sublvl*/) { | ||
var args = [].slice.call(arguments); | ||
return chars.map(function (/*ch*/) { | ||
var ctx = args.concat.apply([], arguments); | ||
return fn.apply(fn, ctx); | ||
}); | ||
}; | ||
} |
{ | ||
"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.0.1", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/jonschlinkert/list-item", | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"maintainers": [ | ||
"Anders D. Johnson (https://github.com/adjohnson916)", | ||
"Jon Schlinkert (https://github.com/jonschlinkert)" | ||
], | ||
"repository": "jonschlinkert/list-item", | ||
@@ -11,6 +15,2 @@ "bugs": { | ||
}, | ||
"maintainers": [ | ||
"Anders D. Johnson (https://github.com/adjohnson916)", | ||
"Jon Schlinkert (https://github.com/jonschlinkert)" | ||
], | ||
"license": "MIT", | ||
@@ -29,3 +29,4 @@ "files": [ | ||
"expand-range": "^1.8.1", | ||
"is-number": "^2.0.2", | ||
"extend-shallow": "^2.0.1", | ||
"is-number": "^2.1.0", | ||
"repeat-string": "^1.5.2" | ||
@@ -36,4 +37,3 @@ }, | ||
"romanize": "^0.1.0", | ||
"should": "*", | ||
"verb": "git://github.com/verbose/verb" | ||
"should": "*" | ||
}, | ||
@@ -57,11 +57,20 @@ "keywords": [ | ||
"list": [ | ||
"deromanize", | ||
"expand-range", | ||
"fill-range", | ||
"expand-range", | ||
"to-regex-range", | ||
"randomatic", | ||
"romanize", | ||
"deromanize" | ||
"to-regex-range" | ||
] | ||
} | ||
}, | ||
"plugins": [ | ||
"gulp-format-md" | ||
], | ||
"reflinks": [ | ||
"expand-range", | ||
"randomatic", | ||
"romanize" | ||
], | ||
"layout": "default" | ||
} | ||
} |
@@ -1,5 +0,17 @@ | ||
# list-item [![NPM version](https://badge.fury.io/js/list-item.svg)](http://badge.fury.io/js/list-item) | ||
# 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) | ||
> 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) | ||
_(TOC generated by [verb](https://github.com/verbose/verb))_ | ||
## Install | ||
@@ -77,3 +89,3 @@ | ||
### [listitem](index.js#L45) | ||
### [listitem](index.js#L47) | ||
@@ -84,12 +96,9 @@ Returns a function to generate a plain-text/markdown list-item, allowing options to be cached for subsequent calls. | ||
* | ||
`options` **{String}** | ||
* `options` **{Object}**: pass options to customize list item characters, indentation, etc. | ||
* `options.nobullet` **{Boolean}**: Pass true if you only want the list iten and identation, but no bullets. | ||
* `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). | ||
* `returns` **{String}**: returns a formatted list item | ||
- `nobullet` **{Boolean}**: Pass true if you only want the list iten and identation, but no bullets. | ||
- `indent` **{String}**: The amount of leading indentation to use. default is ``. | ||
- `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]. | ||
**Example** | ||
@@ -111,9 +120,10 @@ | ||
## Related projects | ||
* [deromanize](https://github.com/jonschlinkert/deromanize): Convert roman numerals to arabic numbers (useful for books, outlines, documentation, slide decks, etc) | ||
* [expand-range](https://github.com/jonschlinkert/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See… [more](https://github.com/jonschlinkert/expand-range) | ||
* [fill-range](https://github.com/jonschlinkert/fill-range): Fill in a range of numbers or letters, optionally passing an increment or multiplier to… [more](https://github.com/jonschlinkert/fill-range) | ||
* [randomatic](https://github.com/jonschlinkert/randomatic): Generate randomized strings of a specified length, fast. Only the length is necessary, but you… [more](https://github.com/jonschlinkert/randomatic) | ||
* [romanize](https://github.com/jonschlinkert/romanize): Convert numbers to roman numerals (useful for books, outlines, documentation, slide decks, etc) | ||
* [to-regex-range](https://github.com/jonschlinkert/to-regex-range): Returns a regex-compatible range from two numbers, min and max. Useful for creating regular expressions… [more](https://github.com/jonschlinkert/to-regex-range) | ||
* [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) | ||
## Running tests | ||
@@ -135,8 +145,8 @@ | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright © 2015 Jon Schlinkert | ||
Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert) | ||
Released under the MIT license. | ||
@@ -146,2 +156,2 @@ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 07, 2015._ | ||
_This file was generated by [verb](https://github.com/verbose/verb) on December 20, 2015._ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10595
3
152
0
4
90
+ Addedextend-shallow@^2.0.1
+ Addedextend-shallow@2.0.1(transitive)
+ Addedis-extendable@0.1.1(transitive)
Updatedis-number@^2.1.0