# Code coverage report for cheerio/lib/utils.js

## Statements: 100% (15 / 15) Branches: 83.33% (5 / 6) Functions: 100% (5 / 5) Lines: 100% (13 / 13) Ignored: none

All files » cheerio/lib/ » utils.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52

    1

    1
    1751
    1751

    1
    5
    1

    1
    13

    1
    216
    325
    216

     /**
     * HTML Tags
     */

    var tags = { tag: true, script: true, style: true };

    /**
     * Check if the DOM element is a tag
     *
     * isTag(type) includes <script> and <style> tags
     */

    exports.isTag = function(type) {
      Eif (type.type) type = type.type;
      return tags[type] || false;
    };

    /**
     * Convert a string to camel case notation.
     * @param  {String} str String to be converted.
     * @return {String}     String in camel case notation.
     */

    exports.camelCase = function(str) {
      return str.replace(/[_.-](\w|$)/g, function(_, x) {
        return x.toUpperCase();
      });
    };

    /**
     * Convert a string from camel case to "CSS case", where word boundaries are
     * described by hyphens ("-") and all characters are lower-case.
     * @param  {String} str String to be converted.
     * @return {string}     String in "CSS case".
     */
    exports.cssCase = function(str) {
      return str.replace(/[A-Z]/g, '-$&').toLowerCase();
    };

    /**
     * Iterate over each DOM element without creating intermediary Cheerio instances.
     *
     * This is indented for use internally to avoid otherwise unnecessary memory pressure introduced
     * by _make.
     */

    exports.domEach = function(cheerio, fn) {
      var i = 0, len = cheerio.length;
      while (i < len && fn(i, cheerio[i]) !== false) ++i;
      return cheerio;
    };