fined), $(false) if (!selector) { return new LoadedCheerio(undefined, rootInstance, options); } const elements = typeof selector === 'string' && (0, utils_js_1.isHtml)(selector) ? // $() parse(selector, options, false, null).children : isNode(selector) ? // $(dom) [selector] : Array.isArray(selector) ? // $([dom]) selector : undefined; const instance = new LoadedCheerio(elements, rootInstance, options); if (elements) { return instance; } if (typeof selector !== 'string') { throw new TypeError('Unexpected type of selector'); } // We know that our selector is a string now. let search = selector; const searchContext = context ? // If we don't have a context, maybe we have a root, from loading typeof context === 'string' ? (0, utils_js_1.isHtml)(context) ? // $('li', '') new LoadedCheerio([parse(context, options, false, null)], rootInstance, options) : // $('li', 'ul') ((search = `${context} ${search}`), rootInstance) : (0, utils_js_1.isCheerio)(context) ? // $('li', $) context : // $('li', node), $('li', [nodes]) new LoadedCheerio(Array.isArray(context) ? context : [context], rootInstance, options) : rootInstance; // If we still don't have a context, return if (!searchContext) return instance; /* * #id, .class, tag */ return searchContext.find(search); } // Add in static methods & properties Object.assign(initialize, staticMethods, { load, // `_root` and `_options` are used in static methods. _root: initialRoot, _options: internalOpts, // Add `fn` for plugins fn: LoadedCheerio.prototype, // Add the prototype here to maintain `instanceof` behavior. prototype: LoadedCheerio.prototype, }); return initialize; }; } function isNode(obj) { return ( // @ts-expect-error: TS doesn't know about the `name` property. !!obj.name || // @ts-expect-error: TS doesn't know about the `type` property. obj.type === htmlparser2_1.ElementType.Root || // @ts-expect-error: TS doesn't know about the `type` property. obj.type === htmlparser2_1.ElementType.Text || // @ts-expect-error: TS doesn't know about the `type` property. obj.type === htmlparser2_1.ElementType.Comment); } //# sourceMappingURL=load.js.map