ngx-dynamic-hooks
Version:
Automatically insert live Angular components into a dynamic string of content (based on their selector or any pattern of your choice) and render the result in the DOM.
54 lines (53 loc) • 2.82 kB
TypeScript
import { HookPosition } from '../../interfacesPublic';
import { Logger } from './logger';
import { ParseOptions } from '../settings/options';
import * as i0 from "@angular/core";
/**
* A utility service to easily parse hooks from text content
*/
export declare class HookFinder {
private logger;
constructor(logger: Logger);
/**
* Finds all text hooks in a piece of content, e.g. <hook>...</hook>, and returns their positions
*
* @param content - The text to parse
* @param openingTagRegex - The regex for the opening tag
* @param closingTagRegex - The regex for the closing tag
* @param includeNested - Whether to include nested hooks in the result
* @param options - The current ParseOptions
*/
find(content: string, openingTagRegex: RegExp, closingTagRegex?: RegExp, includeNested?: boolean, options?: ParseOptions): HookPosition[];
/**
* Finds all text hooks that are non-enclosing in a piece of text, e.g. <hook>
*
* @param content - The text to search
* @param hookRegex - The regex to use for the hook
*/
findSingletagHooks(content: string, hookRegex: RegExp): HookPosition[];
/**
* Finds all text hooks that are enclosing in a piece of text, e.g. <hook>...</hook>
*
* Correctly finding enclosing hooks requires a programmatic parser rather then just regex alone, as regex cannot handle
* patterns that are potentially nested within themselves.
*
* - If the content between the opening and closing is lazy (.*?), it would take the first closing tag after the opening tag,
* regardless if it belongs to the opening tag or actually a nested hook. This would falsely match the first and third tag
* in this example: '<hook><hook></hook></hook>'
*
* - If the content between the opening and closing is greedy (.*), it would only end on the last closing tag in the string,
* ignoring any previous closing tags. This would falsely match the first and fourth tag in this example:
* '<hook></hook><hook></hook>'
*
* There is no regex that works for both scenarios. This method therefore manually counts and compares the opening tags with the closing tags.
*
* @param content - The text to parse
* @param openingTagRegex - The regex for the opening tag
* @param closingTagRegex - The regex for the closing tag
* @param includeNested - Whether to include nested hooks in the result
* @param options - The current parseOptions
*/
findEnclosingHooks(content: string, openingTagRegex: RegExp, closingTagRegex: RegExp, includeNested?: boolean, options?: ParseOptions): HookPosition[];
static ɵfac: i0.ɵɵFactoryDeclaration<HookFinder, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<HookFinder>;
}