utils.d.ts 2.2 KB

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