import { Node , cloneNode , Document } from 'domhandler' ; import type { Cheerio } from './cheerio' ; private category param type returns export { isTag } from 'domhandler' ; category param maybeCheerio returns export function isCheerio < T > ( maybeCheerio ) { return maybeCheerio . cheerio != null ; } private category param str returns export function camelCase ( str ) { return str . replace ( /[_.-](\w|$)/g , ( _ , x ) => x . toUpperCase ( ) ) ; } private category param str returns export function cssCase ( str ) { return str . replace ( /[A-Z]/g , '-$&' ) . toLowerCase ( ) ; } category param array param fn returns export function domEach < T extends Node , Arr extends ArrayLike < T > = Cheerio < T > > ( array , fn ) { const len = array . length ; for ( let i = 0 ; i < len ; i ++ ) fn ( array [ i ] , i ) ; return array ; } private category param dom returns export function cloneDom < T extends Node > ( dom ) { const clone = 'length' in dom ? ( Array . prototype . map . call ( dom , ( el ) => cloneNode ( el , true ) ) as T [ ] ) : [ cloneNode ( dom , true ) ] ; const root = new Document ( clone ) ; clone . forEach ( ( node ) => { node . parent = root ; } ) ; return clone ; } private category param str returns export function isHtml ( str ) { const tagStart = str . indexOf ( '<' ) ; if ( tagStart < 0 || tagStart > str . length - 3 ) return false ; const tagChar = str . charAt ( tagStart + 1 ) ; return ( ( ( tagChar >= 'a' && tagChar <= 'z' ) || ( tagChar >= 'A' && tagChar <= 'Z' ) ) && str . includes ( '>' , tagStart + 2 ) ) ; }