UNPKG

1.91 kBTypeScriptView Raw
1import { SyntaxType } from '../config';
2export interface ExtractOptions {
3 /**
4 * Allow parser to look ahead of `pos` index for searching of missing
5 * abbreviation parts. Most editors automatically inserts closing braces for
6 * `[`, `{` and `(`, which will most likely be right after current caret position.
7 * So in order to properly expand abbreviation, user must explicitly move
8 * caret right after auto-inserted braces. With this option enabled, parser
9 * will search for closing braces right after `pos`. Default is `true`
10 */
11 lookAhead: boolean;
12 /**
13 * Type of context syntax of expanded abbreviation.
14 * In 'stylesheet' syntax, brackets `[]` and `{}` are not supported thus
15 * not extracted.
16 */
17 type: SyntaxType;
18 /**
19 * A string that should precede abbreviation in order to make it successfully
20 * extracted. If given, the abbreviation will be extracted from the nearest
21 * `prefix` occurrence.
22 */
23 prefix: string;
24}
25export interface ExtractedAbbreviation {
26 /** Extracted abbreviation */
27 abbreviation: string;
28 /** Location of abbreviation in input string */
29 location: number;
30 /** Start location of matched abbreviation, including prefix */
31 start: number;
32 /** End location of extracted abbreviation */
33 end: number;
34}
35/**
36 * Extracts Emmet abbreviation from given string.
37 * The goal of this module is to extract abbreviation from current editor’s line,
38 * e.g. like this: `<span>.foo[title=bar|]</span>` -> `.foo[title=bar]`, where
39 * `|` is a current caret position.
40 * @param line A text line where abbreviation should be expanded
41 * @param pos Caret position in line. If not given, uses end of line
42 * @param options Extracting options
43 */
44export default function extractAbbreviation(line: string, pos?: number, options?: Partial<ExtractOptions>): ExtractedAbbreviation | undefined;