sniffer.d.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. export declare enum ResultType {
  2. BOM = 0,
  3. PASSED = 1,
  4. XML_PREFIX = 2,
  5. META_TAG = 3,
  6. XML_ENCODING = 4,
  7. DEFAULT = 5
  8. }
  9. export declare const STRINGS: {
  10. UTF8_BOM: Uint8Array;
  11. UTF16LE_BOM: Uint8Array;
  12. UTF16BE_BOM: Uint8Array;
  13. UTF16LE_XML_PREFIX: Uint8Array;
  14. UTF16BE_XML_PREFIX: Uint8Array;
  15. XML_DECLARATION: Uint8Array;
  16. ENCODING: Uint8Array;
  17. META: Uint8Array;
  18. HTTP_EQUIV: Uint8Array;
  19. CONTENT: Uint8Array;
  20. CONTENT_TYPE: Uint8Array;
  21. CHARSET: Uint8Array;
  22. COMMENT_START: Uint8Array;
  23. COMMENT_END: Uint8Array;
  24. };
  25. export interface SnifferOptions {
  26. /**
  27. * The maximum number of bytes to sniff.
  28. *
  29. * @default 1024
  30. */
  31. maxBytes?: number;
  32. /**
  33. * The encoding specified by the user.
  34. */
  35. userEncoding?: string;
  36. /**
  37. * The encoding specified by the transport layer.
  38. */
  39. transportLayerEncodingLabel?: string;
  40. /**
  41. * The default encoding to use.
  42. *
  43. * @default "windows-1252"
  44. */
  45. defaultEncoding?: string;
  46. }
  47. export declare class Sniffer {
  48. /** The maximum number of bytes to sniff. */
  49. private readonly maxBytes;
  50. /** The offset of the previous buffers. */
  51. private offset;
  52. private state;
  53. private sectionIndex;
  54. private attribType;
  55. /**
  56. * Indicates if the `http-equiv` is `content-type`.
  57. *
  58. * Initially `null`, a boolean when a value is found.
  59. */
  60. private gotPragma;
  61. private needsPragma;
  62. private inMetaTag;
  63. encoding: string;
  64. resultType: ResultType;
  65. private setResult;
  66. constructor({ maxBytes, userEncoding, transportLayerEncodingLabel, defaultEncoding, }?: SnifferOptions);
  67. private stateBegin;
  68. private stateBeginLT;
  69. private stateUTF16BE_XML_PREFIX;
  70. private stateUTF16LE_XML_PREFIX;
  71. private stateBOM16LE;
  72. private stateBOM16BE;
  73. private stateBOM8;
  74. private stateBeforeTag;
  75. /**
  76. * We have seen a `<`, and now have to figure out what to do.
  77. *
  78. * Options:
  79. * - `<meta`
  80. * - Any other tag
  81. * - A closing tag
  82. * - `<!--`
  83. * - An XML declaration
  84. *
  85. */
  86. private stateBeforeTagName;
  87. private stateBeforeCloseTagName;
  88. private stateCommentStart;
  89. private stateCommentEnd;
  90. /**
  91. * Any section starting with `<!`, `<?`, `</`, without being a closing tag or comment.
  92. */
  93. private stateWeirdTag;
  94. /**
  95. * Advances the section, ignoring upper/lower case.
  96. *
  97. * Make sure the section has left-over characters before calling.
  98. *
  99. * @returns `false` if we did not match the section.
  100. */
  101. private advanceSectionIC;
  102. /**
  103. * Advances the section.
  104. *
  105. * Make sure the section has left-over characters before calling.
  106. *
  107. * @returns `false` if we did not match the section.
  108. */
  109. private advanceSection;
  110. private stateTagNameMeta;
  111. private stateTagNameOther;
  112. private stateBeforeAttribute;
  113. private handleMetaAttrib;
  114. private stateMetaAttribHttpEquiv;
  115. private stateMetaAttribC;
  116. private stateMetaAttribCharset;
  117. private stateMetaAttribContent;
  118. private stateMetaAttribAfterName;
  119. private stateAnyAttribName;
  120. private stateAfterAttributeName;
  121. private quoteCharacter;
  122. private readonly attributeValue;
  123. private stateBeforeAttributeValue;
  124. private stateMetaAttribHttpEquivValue;
  125. private handleMetaContentValue;
  126. private handleAttributeValue;
  127. private stateAttributeValueUnquoted;
  128. private findMetaContentEncoding;
  129. private stateMetaContentValueUnquotedBeforeEncoding;
  130. private stateMetaContentValueUnquotedBeforeValue;
  131. private stateMetaContentValueUnquotedValueQuoted;
  132. private stateMetaContentValueUnquotedValueUnquoted;
  133. private stateMetaContentValueQuotedValueUnquoted;
  134. private stateMetaContentValueQuotedValueQuoted;
  135. private stateMetaContentValueQuotedBeforeEncoding;
  136. private stateMetaContentValueQuotedAfterEncoding;
  137. private stateMetaContentValueQuotedBeforeValue;
  138. private stateAttributeValueQuoted;
  139. private stateXMLDeclaration;
  140. private stateXMLDeclarationBeforeEncoding;
  141. private stateXMLDeclarationAfterEncoding;
  142. private stateXMLDeclarationBeforeValue;
  143. private stateXMLDeclarationValue;
  144. write(buffer: Uint8Array): void;
  145. }
  146. /** Get the encoding for the passed buffer. */
  147. export declare function getEncoding(buffer: Uint8Array, options?: SnifferOptions): string;
  148. //# sourceMappingURL=sniffer.d.ts.map