utils.d.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { DomUtils } from 'htmlparser2';
  2. import { Node } from 'domhandler';
  3. import type { Cheerio } from './cheerio';
  4. /**
  5. * Check if the DOM element is a tag.
  6. *
  7. * `isTag(type)` includes `<script>` and `<style>` tags.
  8. *
  9. * @private
  10. * @category Utils
  11. * @param type - DOM node to check.
  12. * @returns Whether the node is a tag.
  13. */
  14. export declare const isTag: typeof DomUtils.isTag;
  15. /**
  16. * Checks if an object is a Cheerio instance.
  17. *
  18. * @category Utils
  19. * @param maybeCheerio - The object to check.
  20. * @returns Whether the object is a Cheerio instance.
  21. */
  22. export declare function isCheerio<T>(maybeCheerio: any): maybeCheerio is Cheerio<T>;
  23. /**
  24. * Convert a string to camel case notation.
  25. *
  26. * @private
  27. * @category Utils
  28. * @param str - String to be converted.
  29. * @returns String in camel case notation.
  30. */
  31. export declare function camelCase(str: string): string;
  32. /**
  33. * Convert a string from camel case to "CSS case", where word boundaries are
  34. * described by hyphens ("-") and all characters are lower-case.
  35. *
  36. * @private
  37. * @category Utils
  38. * @param str - String to be converted.
  39. * @returns String in "CSS case".
  40. */
  41. export declare function cssCase(str: string): string;
  42. /**
  43. * Iterate over each DOM element without creating intermediary Cheerio instances.
  44. *
  45. * This is indented for use internally to avoid otherwise unnecessary memory
  46. * pressure introduced by _make.
  47. *
  48. * @category Utils
  49. * @param array - Array to iterate over.
  50. * @param fn - Function to call.
  51. * @returns The original instance.
  52. */
  53. export declare function domEach<T extends Node, Arr extends ArrayLike<T> = Cheerio<T>>(array: Arr, fn: (elem: T, index: number) => void): Arr;
  54. /**
  55. * Create a deep copy of the given DOM structure. Sets the parents of the copies
  56. * of the passed nodes to `null`.
  57. *
  58. * @private
  59. * @category Utils
  60. * @param dom - The htmlparser2-compliant DOM structure.
  61. * @returns - The cloned DOM.
  62. */
  63. export declare function cloneDom<T extends Node>(dom: T | T[]): T[];
  64. /**
  65. * Check if string is HTML.
  66. *
  67. * @private
  68. * @category Utils
  69. * @param str - String to check.
  70. * @returns Indicates if `str` is HTML.
  71. */
  72. export declare function isHtml(str: string): boolean;
  73. //# sourceMappingURL=utils.d.ts.map