|
"use strict"; |
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
exports.isHtml = exports.cloneDom = exports.domEach = exports.cssCase = exports.camelCase = exports.isCheerio = exports.isTag = void 0; |
|
var domhandler_1 = require("domhandler"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var domhandler_2 = require("domhandler"); |
|
Object.defineProperty(exports, "isTag", { enumerable: true, get: function () { return domhandler_2.isTag; } }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isCheerio(maybeCheerio) { |
|
return maybeCheerio.cheerio != null; |
|
} |
|
exports.isCheerio = isCheerio; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function camelCase(str) { |
|
return str.replace(/[_.-](\w|$)/g, function (_, x) { return x.toUpperCase(); }); |
|
} |
|
exports.camelCase = camelCase; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function cssCase(str) { |
|
return str.replace(/[A-Z]/g, '-$&').toLowerCase(); |
|
} |
|
exports.cssCase = cssCase; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function domEach(array, fn) { |
|
var len = array.length; |
|
for (var i = 0; i < len; i++) |
|
fn(array[i], i); |
|
return array; |
|
} |
|
exports.domEach = domEach; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function cloneDom(dom) { |
|
var clone = 'length' in dom |
|
? Array.prototype.map.call(dom, function (el) { return (0, domhandler_1.cloneNode)(el, true); }) |
|
: [(0, domhandler_1.cloneNode)(dom, true)]; |
|
|
|
var root = new domhandler_1.Document(clone); |
|
clone.forEach(function (node) { |
|
node.parent = root; |
|
}); |
|
return clone; |
|
} |
|
exports.cloneDom = cloneDom; |
|
var CharacterCodes; |
|
(function (CharacterCodes) { |
|
CharacterCodes[CharacterCodes["LowerA"] = 97] = "LowerA"; |
|
CharacterCodes[CharacterCodes["LowerZ"] = 122] = "LowerZ"; |
|
CharacterCodes[CharacterCodes["UpperA"] = 65] = "UpperA"; |
|
CharacterCodes[CharacterCodes["UpperZ"] = 90] = "UpperZ"; |
|
CharacterCodes[CharacterCodes["Exclamation"] = 33] = "Exclamation"; |
|
})(CharacterCodes || (CharacterCodes = {})); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isHtml(str) { |
|
var tagStart = str.indexOf('<'); |
|
if (tagStart < 0 || tagStart > str.length - 3) |
|
return false; |
|
var tagChar = str.charCodeAt(tagStart + 1); |
|
return (((tagChar >= CharacterCodes.LowerA && tagChar <= CharacterCodes.LowerZ) || |
|
(tagChar >= CharacterCodes.UpperA && tagChar <= CharacterCodes.UpperZ) || |
|
tagChar === CharacterCodes.Exclamation) && |
|
str.includes('>', tagStart + 2)); |
|
} |
|
exports.isHtml = isHtml; |
|
|