/*!
 * bullets <https://github.com/jonschlinkert/bullets>
 *
 * Copyright (c) 2015, Jon Schlinkert.
 * Licensed under the MIT License.
 */

'use strict';

var pad = require('pad-left');
var expand = require('expand-range');
var listitem = require('list-item');

/**
 * Expose `bullets`
 */

module.exports = bullets;

/**
 * Pass an array of list-item objects to generate a formatted list
 * or table of contents. Uses [list-item] for generating the actual
 * items.
 *
 *
 * ```js
 * var list = [
 *   {text: 'This is item 1', lvl: 0},
 *   {text: 'This is item 2', lvl: 0},
 *   {text: 'This is item 3', lvl: 0},
 *   {text: 'This is sub-item A', lvl: 2},
 *   {text: 'This is sub-item B', lvl: 2},
 *   {text: 'This is sub-item C', lvl: 2},
 * ];
 * bullets([{text: 'This is a list item', lvl: 0}]);
 *
 * // Results in
 * // '- This is item 1'
 * // '- This is item 2'
 * // '- This is item 3'
 * // '  * This is sub-item A'
 * // '  * This is sub-item B'
 * // '  * This is sub-item C'
 * ```
 *
 * @name list
 * @param {Array} `list` Array of item objects with `text` and `lvl` properties
 *   @property {String} `text` [list] The text for the list item.
 *   @property {Number} `lvl` [list] The level of the list item to be used for indenting the list.
 * @param {Object} `opts` Options to pass to [list-item].
 * @param {Function} `fn` pass a function [expand-range] to modify the bullet for an item as it's generated.
 * @api public
 */

function bullets(list, opts, fn) {
  if (typeof opts === 'function') {
    fn = opts; opts = {};
  }

  var len = list.length, i = 0;
  var li = listitem(opts, fn);
  var res = '';

  var sublvl = {};

  while (len--) {
    var item = list[i++];
    var lvl = item.lvl;

    sublvl[lvl] = sublvl[lvl] || 0;
    sublvl[lvl]++;

    var str = item.text;

    res += li(lvl, str, sublvl);
    res += '\n';
  }
  return res;
};

bullets.flat = function (list, opts, fn) {
  if (typeof opts === 'function') {
    fn = opts; opts = {};
  }

  var len = list.length, i = 0;
  var lvl = opts && opts.lvl || 0;
  var li = listitem(opts, fn);
  var res = '';

  while (len--) {
    var item = list[i++];

    res += li(lvl, item);
    res += '\n';
  }
  return res;
};

@@ -1003,20 +1003,23 @@
 * @name 
-list
+bullets
 %0A * @par
@@ -1094,27 +1094,22 @@
 ties%0A * 
-  @property
+@param
  %7BString
@@ -1159,19 +1159,14 @@
 %0A * 
-  @property
+@param
  %7BNu
@@ -1619,28 +1619,8 @@
 ';%0A%0A
-  var sublvl = %7B%7D;%0A%0A
   wh
@@ -1687,65 +1687,8 @@
 vl;%0A
-%0A    sublvl%5Blvl%5D = sublvl%5Blvl%5D %7C%7C 0;%0A    sublvl%5Blvl%5D++;%0A%0A
     
@@ -1735,16 +1735,8 @@
  str
-, sublvl
 );%0A 
@@ -2042,17 +2042,16 @@
 t%5Bi++%5D;%0A
-%0A
     res 

clean up unused code and comments