all da files
This commit is contained in:
		
							
								
								
									
										149
									
								
								node_modules/cheerio/lib/api/attributes.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										149
									
								
								node_modules/cheerio/lib/api/attributes.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,149 @@
 | 
			
		||||
var _ = require('underscore'),
 | 
			
		||||
    utils = require('../utils'),
 | 
			
		||||
    isTag = utils.isTag,
 | 
			
		||||
    decode = utils.decode,
 | 
			
		||||
    encode = utils.encode,
 | 
			
		||||
    rspace = /\s+/,
 | 
			
		||||
 | 
			
		||||
    // Attributes that are booleans
 | 
			
		||||
    rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
var setAttr = function(el, name, value) {
 | 
			
		||||
  if (typeof name === 'object') return _.extend(el.attribs, name);
 | 
			
		||||
 | 
			
		||||
  if (value === null) {
 | 
			
		||||
    removeAttribute(el, name);
 | 
			
		||||
  } else {
 | 
			
		||||
    el.attribs[name] = encode(value);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return el.attribs;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var attr = exports.attr = function(name, value) {
 | 
			
		||||
  var elem = this[0];
 | 
			
		||||
 | 
			
		||||
  if (!elem || !isTag(elem))
 | 
			
		||||
    return undefined;
 | 
			
		||||
 | 
			
		||||
  if (!elem.attribs) {
 | 
			
		||||
    elem.attribs = {};
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Return the entire attribs object if no attribute specified
 | 
			
		||||
  if (!name) {
 | 
			
		||||
    for (var a in elem.attribs) {
 | 
			
		||||
      elem.attribs[a] = decode(elem.attribs[a]);
 | 
			
		||||
    }
 | 
			
		||||
    return elem.attribs;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Set the value (with attr map support)
 | 
			
		||||
  if (typeof name === 'object' || value !== undefined) {
 | 
			
		||||
    this.each(function(i, el) {
 | 
			
		||||
      el.attribs = setAttr(el, name, value);
 | 
			
		||||
    });
 | 
			
		||||
    return this;
 | 
			
		||||
  } else if (Object.hasOwnProperty.call(elem.attribs, name)) {
 | 
			
		||||
    // Get the (decoded) attribute
 | 
			
		||||
    return decode(elem.attribs[name]);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Remove an attribute
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
var removeAttribute = function(elem, name) {
 | 
			
		||||
 if (!isTag(elem.type) || !elem.attribs || !Object.hasOwnProperty.call(elem.attribs, name))
 | 
			
		||||
   return;
 | 
			
		||||
 | 
			
		||||
 if (rboolean.test(elem.attribs[name]))
 | 
			
		||||
   elem.attribs[name] = false;
 | 
			
		||||
 else
 | 
			
		||||
   delete elem.attribs[name];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
var removeAttr = exports.removeAttr = function(name) {
 | 
			
		||||
  this.each(function(i, elem) {
 | 
			
		||||
    removeAttribute(elem, name);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var hasClass = exports.hasClass = function(className) {
 | 
			
		||||
  return _.any(this, function(elem) {
 | 
			
		||||
    var attrs = elem.attribs;
 | 
			
		||||
    return attrs && _.contains((attrs['class'] || '').split(rspace), className);
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var addClass = exports.addClass = function(value) {
 | 
			
		||||
  // Support functions
 | 
			
		||||
  if (_.isFunction(value)) {
 | 
			
		||||
    this.each(function(i) {
 | 
			
		||||
      var className = this.attr('class') || '';
 | 
			
		||||
      this.addClass(value.call(this, i, className));
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Return if no value or not a string or function
 | 
			
		||||
  if (!value || !_.isString(value)) return this;
 | 
			
		||||
 | 
			
		||||
  var classNames = value.split(rspace),
 | 
			
		||||
      numElements = this.length,
 | 
			
		||||
      numClasses,
 | 
			
		||||
      setClass,
 | 
			
		||||
      $elem;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  for (var i = 0; i < numElements; i++) {
 | 
			
		||||
    $elem = this.make(this[i]);
 | 
			
		||||
    // If selected element isnt a tag, move on
 | 
			
		||||
    if (!isTag(this[i])) continue;
 | 
			
		||||
 | 
			
		||||
    // If we don't already have classes
 | 
			
		||||
    if (!$elem.attr('class')) {
 | 
			
		||||
      $elem.attr('class', classNames.join(' ').trim());
 | 
			
		||||
    } else {
 | 
			
		||||
      setClass = ' ' + $elem.attr('class') + ' ';
 | 
			
		||||
      numClasses = classNames.length;
 | 
			
		||||
 | 
			
		||||
      // Check if class already exists
 | 
			
		||||
      for (var j = 0; j < numClasses; j++) {
 | 
			
		||||
        if (!~setClass.indexOf(' ' + classNames[j] + ' '))
 | 
			
		||||
          setClass += classNames[j] + ' ';
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      $elem.attr('class', setClass.trim());
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var removeClass = exports.removeClass = function(value) {
 | 
			
		||||
  var split = function(className) {
 | 
			
		||||
    return className ? className.trim().split(rspace) : [];
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  var classes = split(value);
 | 
			
		||||
 | 
			
		||||
  // Handle if value is a function
 | 
			
		||||
  if (_.isFunction(value)) {
 | 
			
		||||
    return this.each(function(i, el) {
 | 
			
		||||
      this.removeClass(value.call(this, i, el.attribs['class'] || ''));
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return this.each(function(i, el) {
 | 
			
		||||
    if (!isTag(el)) return;
 | 
			
		||||
    el.attribs['class'] = (!value) ? '' : _.reject(
 | 
			
		||||
      split(el.attribs['class']),
 | 
			
		||||
      function(name) { return _.contains(classes, name); }
 | 
			
		||||
    ).join(' ');
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										192
									
								
								node_modules/cheerio/lib/api/manipulation.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										192
									
								
								node_modules/cheerio/lib/api/manipulation.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,192 @@
 | 
			
		||||
var _ = require('underscore'),
 | 
			
		||||
    parse = require('../parse'),
 | 
			
		||||
    $ = require('../static'),
 | 
			
		||||
    updateDOM = parse.update,
 | 
			
		||||
    evaluate = parse.evaluate,
 | 
			
		||||
    encode = require('../utils').encode,
 | 
			
		||||
    slice = Array.prototype.slice;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
  Creates an array of cheerio objects,
 | 
			
		||||
  parsing strings if necessary
 | 
			
		||||
*/
 | 
			
		||||
var makeCheerioArray = function(elems) {
 | 
			
		||||
  return _.reduce(elems, function(dom, elem) {
 | 
			
		||||
    return dom.concat(elem.cheerio ? elem.toArray() : evaluate(elem));
 | 
			
		||||
  }, []);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var _insert = function(concatenator) {
 | 
			
		||||
  return function() {
 | 
			
		||||
    var elems = slice.call(arguments),
 | 
			
		||||
        dom = makeCheerioArray(elems);
 | 
			
		||||
 | 
			
		||||
    return this.each(function(i, el) {
 | 
			
		||||
      if (_.isFunction(elems[0])) return el; // not yet supported
 | 
			
		||||
      updateDOM(concatenator(dom, el.children || (el.children = [])), el);
 | 
			
		||||
    });
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var append = exports.append = _insert(function(dom, children) {
 | 
			
		||||
  return children.concat(dom);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
var prepend = exports.prepend = _insert(function(dom, children) {
 | 
			
		||||
  return dom.concat(children);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
var after = exports.after = function() {
 | 
			
		||||
  var elems = slice.call(arguments),
 | 
			
		||||
      dom = makeCheerioArray(elems);
 | 
			
		||||
 | 
			
		||||
  this.each(function(i, el) {
 | 
			
		||||
    var siblings = el.parent.children,
 | 
			
		||||
        index = siblings.indexOf(el);
 | 
			
		||||
 | 
			
		||||
    // If not found, move on
 | 
			
		||||
    if (!~index) return;
 | 
			
		||||
 | 
			
		||||
    // Add element after `this` element
 | 
			
		||||
    siblings.splice.apply(siblings, [++index, 0].concat(dom));
 | 
			
		||||
 | 
			
		||||
    // Update next, prev, and parent pointers
 | 
			
		||||
    updateDOM(siblings, el.parent);
 | 
			
		||||
    el.parent.children = siblings;
 | 
			
		||||
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var before = exports.before = function() {
 | 
			
		||||
  var elems = slice.call(arguments),
 | 
			
		||||
      dom = makeCheerioArray(elems);
 | 
			
		||||
 | 
			
		||||
  this.each(function(i, el) {
 | 
			
		||||
    var siblings = el.parent.children,
 | 
			
		||||
        index = siblings.indexOf(el);
 | 
			
		||||
 | 
			
		||||
    // If not found, move on
 | 
			
		||||
    if (!~index) return;
 | 
			
		||||
 | 
			
		||||
    // Add element before `el` element
 | 
			
		||||
    siblings.splice.apply(siblings, [index, 0].concat(dom));
 | 
			
		||||
 | 
			
		||||
    // Update next, prev, and parent pointers
 | 
			
		||||
    updateDOM(siblings, el.parent);
 | 
			
		||||
    el.parent.children = siblings;
 | 
			
		||||
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
  remove([selector])
 | 
			
		||||
*/
 | 
			
		||||
var remove = exports.remove = function(selector) {
 | 
			
		||||
  var elems = this;
 | 
			
		||||
 | 
			
		||||
  // Filter if we have selector
 | 
			
		||||
  if (selector)
 | 
			
		||||
    elems = elems.filter(selector);
 | 
			
		||||
 | 
			
		||||
  elems.each(function(i, el) {
 | 
			
		||||
    var siblings = el.parent.children,
 | 
			
		||||
        index = siblings.indexOf(el);
 | 
			
		||||
 | 
			
		||||
    if (!~index) return;
 | 
			
		||||
 | 
			
		||||
    siblings.splice(index, 1);
 | 
			
		||||
 | 
			
		||||
    // Update next, prev, and parent pointers
 | 
			
		||||
    updateDOM(siblings, el.parent);
 | 
			
		||||
    el.parent.children = siblings;
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var replaceWith = exports.replaceWith = function(content) {
 | 
			
		||||
  content = content.cheerio ? content.toArray() : evaluate(content);
 | 
			
		||||
 | 
			
		||||
  this.each(function(i, el) {
 | 
			
		||||
    var siblings = el.parent.children,
 | 
			
		||||
        index = siblings.indexOf(el);
 | 
			
		||||
 | 
			
		||||
    if (!~index) return;
 | 
			
		||||
 | 
			
		||||
    siblings.splice.apply(siblings, [index, 1].concat(content));
 | 
			
		||||
 | 
			
		||||
    updateDOM(siblings, el.parent);
 | 
			
		||||
    el.parent.children = siblings;
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var empty = exports.empty = function() {
 | 
			
		||||
  this.each(function(i, el) {
 | 
			
		||||
    el.children = [];
 | 
			
		||||
  });
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Set/Get the HTML
 | 
			
		||||
 */
 | 
			
		||||
var html = exports.html = function(str) {
 | 
			
		||||
  if (str === undefined) {
 | 
			
		||||
    if (!this[0] || !this[0].children) return null;
 | 
			
		||||
    return $.html(this[0].children);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  str = str.cheerio ? str.toArray() : evaluate(str);
 | 
			
		||||
 | 
			
		||||
  this.each(function(i, el) {
 | 
			
		||||
    el.children = str;
 | 
			
		||||
    updateDOM(el.children, el);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var toString = exports.toString = function() {
 | 
			
		||||
  return $.html(this);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var text = exports.text = function(str) {
 | 
			
		||||
  // If `str` blank or an object
 | 
			
		||||
  if (!str || typeof str === 'object') {
 | 
			
		||||
    return $.text(this);
 | 
			
		||||
  } else if (_.isFunction(str)) {
 | 
			
		||||
    // Function support
 | 
			
		||||
    return this.each(function(i, el) {
 | 
			
		||||
      return this.text(str.call(el, i, this.text()));
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  var elem = {
 | 
			
		||||
    data: encode(str),
 | 
			
		||||
    type: 'text',
 | 
			
		||||
    parent: null,
 | 
			
		||||
    prev: null,
 | 
			
		||||
    next: null,
 | 
			
		||||
    children: []
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  // Append text node to each selected elements
 | 
			
		||||
  this.each(function(i, el) {
 | 
			
		||||
    el.children = elem;
 | 
			
		||||
    updateDOM(el.children, el);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var clone = exports.clone = function() {
 | 
			
		||||
  // Turn it into HTML, then recreate it,
 | 
			
		||||
  // Seems to be the easiest way to reconnect everything correctly
 | 
			
		||||
  return this.constructor($.html(this));
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										116
									
								
								node_modules/cheerio/lib/api/traversing.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								node_modules/cheerio/lib/api/traversing.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,116 @@
 | 
			
		||||
var _ = require('underscore'),
 | 
			
		||||
    select = require('cheerio-select'),
 | 
			
		||||
    utils = require('../utils'),
 | 
			
		||||
    isTag = utils.isTag;
 | 
			
		||||
 | 
			
		||||
var find = exports.find = function(selector) {
 | 
			
		||||
  if (!selector) return this;
 | 
			
		||||
  try {
 | 
			
		||||
    var elem = select(selector, [].slice.call(this.children()));
 | 
			
		||||
    return this.make(elem);
 | 
			
		||||
  } catch(e) {
 | 
			
		||||
    return this.make([]);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var parent = exports.parent = function(elem) {
 | 
			
		||||
  if (this[0] && this[0].parent)
 | 
			
		||||
    return this.make(this[0].parent);
 | 
			
		||||
  else
 | 
			
		||||
    return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var next = exports.next = function(elem) {
 | 
			
		||||
  if (!this[0]) return this;
 | 
			
		||||
 | 
			
		||||
  var nextSibling = this[0].next;
 | 
			
		||||
  while (nextSibling) {
 | 
			
		||||
    if (isTag(nextSibling)) return this.make(nextSibling);
 | 
			
		||||
    nextSibling = nextSibling.next;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var prev = exports.prev = function(elem) {
 | 
			
		||||
  if (!this[0]) return this;
 | 
			
		||||
 | 
			
		||||
  var prevSibling = this[0].prev;
 | 
			
		||||
  while (prevSibling) {
 | 
			
		||||
    if (isTag(prevSibling)) return this.make(prevSibling);
 | 
			
		||||
    prevSibling = prevSibling.prev;
 | 
			
		||||
  }
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var siblings = exports.siblings = function(elem) {
 | 
			
		||||
  if (!this[0]) return this;
 | 
			
		||||
  var self = this,
 | 
			
		||||
      siblings = (this.parent()) ? this.parent().children()
 | 
			
		||||
                                 : this.siblingsAndMe();
 | 
			
		||||
 | 
			
		||||
  siblings = _.filter(siblings, function(elem) {
 | 
			
		||||
    return (elem !== self[0] && isTag(elem));
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return this.make(siblings);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var children = exports.children = function(selector) {
 | 
			
		||||
 | 
			
		||||
  var elems = _.reduce(this, function(memo, elem) {
 | 
			
		||||
    return memo.concat(_.filter(elem.children, isTag));
 | 
			
		||||
  }, []);
 | 
			
		||||
 | 
			
		||||
  if (selector === undefined) return this.make(elems);
 | 
			
		||||
  else if (_.isNumber(selector)) return this.make(elems[selector]);
 | 
			
		||||
 | 
			
		||||
  return this.make(elems).filter(selector);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var each = exports.each = function(fn) {
 | 
			
		||||
  var length = this.length,
 | 
			
		||||
      el, i;
 | 
			
		||||
 | 
			
		||||
  for (i = 0; i < length; ++i) {
 | 
			
		||||
    el = this[i];
 | 
			
		||||
    if (fn.call(this.make(el), i, el) === false) {
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var map = exports.map = function(fn) {
 | 
			
		||||
  return _.map(this, function(el, i) {
 | 
			
		||||
    return fn.call(this.make(el), i, el);
 | 
			
		||||
  }, this);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var filter = exports.filter = function(match) {
 | 
			
		||||
  var make = _.bind(this.make, this);
 | 
			
		||||
  return make(_.filter(this, _.isString(match) ?
 | 
			
		||||
    function(el) { return select(match, el)[0] === el; }
 | 
			
		||||
  : function(el, i) { return match.call(make(el), i, el); }
 | 
			
		||||
  ));
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var first = exports.first = function() {
 | 
			
		||||
  return this[0] ? this.make(this[0]) : this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var last = exports.last = function() {
 | 
			
		||||
  return this[0] ? this.make(this[this.length - 1]) : this;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Reduce the set of matched elements to the one at the specified index.
 | 
			
		||||
var eq = exports.eq = function(i) {
 | 
			
		||||
  i = +i;
 | 
			
		||||
  if (i < 0) i = this.length + i;
 | 
			
		||||
  return this[i] ? this.make(this[i]) : this.make([]);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var slice = exports.slice = function() {
 | 
			
		||||
  return this.make([].slice.apply(this, arguments));
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user