UNPKG

@html-validate/plugin-utils

Version:

Plugin utilities and helpers for writing plugins to HTML-Validate

76 lines (70 loc) 2.11 kB
import { Source } from 'html-validate'; /** * Represents line and column. * * @public * @since 1.0.0 */ export declare interface Position { /** Line number (First line is 1) */ line: number; /** Column number (first column is 1) */ column: number; } /** * Given an offset into a source, calculate the corresponding line and column. * * @public * @since 1.0.0 */ export declare function positionFromOffset(text: string, offset: number): [line: number, column: number]; /** * Compute source offset from line and column and the given markup. * * @public * @since 1.0.0 * @param position - Line and column. * @param data - Source markup. * @returns The byte offset into the markup which line and column corresponds to. */ export declare function positionToOffset(position: Position, data: string): number; /** * @public * @since 1.0.0 */ export declare class TemplateExtractor { private ast; private filename; private data; private constructor(); /** * Create a new [[TemplateExtractor]] from javascript source code. * * `Source` offsets will be relative to the string, i.e. offset 0 is the first * character of the string. If the string is only a subset of a larger string * the offsets must be adjusted manually. * * @param source - Source code. * @param filename - Optional filename to set in the resulting * `Source`. Defauls to `"inline"`. */ static fromString(source: string, filename?: string): TemplateExtractor; /** * Extract object properties. * * Given a key `"template"` this method finds all objects literals with a * `"template"` property and creates a [[Source]] instance with proper offsets * with the value of the property. For instance: * * ``` * const myObj = { * foo: 'bar', * }; * ``` * * The above snippet would yield a `Source` with the content `bar`. * */ extractObjectProperty(key: string): Source[]; } export { }