File size: 2,515 Bytes
a8063bc | 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | /**
* Checks if an object is a Cheerio instance.
*
* @category Utils
* @param maybeCheerio - The object to check.
* @returns Whether the object is a Cheerio instance.
*/
export function isCheerio(maybeCheerio) {
return maybeCheerio.cheerio != null;
}
/**
* Convert a string to camel case notation.
*
* @private
* @category Utils
* @param str - The string to be converted.
* @returns String in camel case notation.
*/
export function camelCase(str) {
return str.replace(/[._-](\w|$)/g, (_, x) => x.toUpperCase());
}
/**
* Convert a string from camel case to "CSS case", where word boundaries are
* described by hyphens ("-") and all characters are lower-case.
*
* @private
* @category Utils
* @param str - The string to be converted.
* @returns String in "CSS case".
*/
export function cssCase(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.
*
* @category Utils
* @param array - The array to iterate over.
* @param fn - Function to call.
* @returns The original instance.
*/
export function domEach(array, fn) {
const len = array.length;
for (let i = 0; i < len; i++)
fn(array[i], i);
return array;
}
var CharacterCode;
(function (CharacterCode) {
CharacterCode[CharacterCode["LowerA"] = 97] = "LowerA";
CharacterCode[CharacterCode["LowerZ"] = 122] = "LowerZ";
CharacterCode[CharacterCode["UpperA"] = 65] = "UpperA";
CharacterCode[CharacterCode["UpperZ"] = 90] = "UpperZ";
CharacterCode[CharacterCode["Exclamation"] = 33] = "Exclamation";
})(CharacterCode || (CharacterCode = {}));
/**
* Check if string is HTML.
*
* Tests for a `<` within a string, immediate followed by a letter and
* eventually followed by a `>`.
*
* @private
* @category Utils
* @param str - The string to check.
* @returns Indicates if `str` is HTML.
*/
export function isHtml(str) {
const tagStart = str.indexOf('<');
if (tagStart === -1 || tagStart > str.length - 3)
return false;
const tagChar = str.charCodeAt(tagStart + 1);
return (((tagChar >= CharacterCode.LowerA && tagChar <= CharacterCode.LowerZ) ||
(tagChar >= CharacterCode.UpperA && tagChar <= CharacterCode.UpperZ) ||
tagChar === CharacterCode.Exclamation) &&
str.includes('>', tagStart + 2));
}
//# sourceMappingURL=utils.js.map |