UNPKG

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.

103 lines (102 loc) 5.11 kB
import { DataTypeEncoder } from './dataTypeEncoder'; import { Logger } from './logger'; import { ParseOptions } from '../settings/options'; import * as i0 from "@angular/core"; /** * A parser that can evaluate stringified variables and turn them into their corresponding data types */ export declare class DataTypeParser { private dataTypeEncoder; private logger; constructor(dataTypeEncoder: DataTypeEncoder, logger: Logger); /** * Takes a string containing a Javascript data type as it would appear in code, such a number ('15'), a string ('"hello"'), * an array ('[1,2,3]'), an object ('{prop: "something"}') etc., and evaluates it to be an an actual variable. * * Note: This function works without invoking eval() and instead uses JSON.parse() for the heavy lifting. As such, it should be safe * to use and should cover most forms of input. * * @param dataTypeString - The string to parse * @param context - (optional) A context object to load variables from * @param event - (optional) An event object to place $event vars with * @param unescapeStrings - (optional) Whether to unescape strings or not * @param trackContextVariables - (optional) An object that will be filled out with all found context vars * @param allowContextFunctionCalls - (optional) Whether to allow function calls in context vars * @param options - (optional) The current parseOptions */ evaluate(dataTypeString: string, context?: any, event?: any, unescapeStrings?: boolean, trackContextVariables?: any, allowContextFunctionCalls?: boolean, options?: ParseOptions): any; /** * Encodes a data type string * * @param dataTypeString - The string to encode */ encodeDataTypeString(dataTypeString: string): string; /** * Decodes a data type string * * @param dataTypeString - The string to decode */ decodeDataTypeString(dataTypeString: string): string; /** * In order to successfully parse a data type string with JSON.parse(), it needs to follow certain formatting rules. * This function ensures that these are followed and corrects the input if not. * * @param JSONString - The string to be given to JSON.parse() * @param unescapeStrings - Whether to unescape the strings of this JSON */ private parseAsJSON; /** * Given a stringified json and a json value regex, allows you to replace all occurences * of those values in the json via a callback function. * * IMPORTANT: JSONString must be already encoded via this.encodeDataTypeString() for this to work. * * @param JSONString - The stringified JSON * @param valueRegex - The values to find * @param callbackFn - A callback fn that returns what you want to replace them with */ private replaceValuesInJSONString; /** * Decodes all 'normal' strings without special meaning in a JSON-like object * * @param jsonLevel - The current level of parsing * @param unescapeStrings - Whether to unescape the decoded strings as well */ private decodeJSONStrings; /** * Travels a JSON-like object to find all context vars and event objects and replaces their placeholders with the actual values * * @param arrayOrObject - The property of the JSON to analyze * @param context - The current context object, if any * @param event - The current event object, if any * @param unescapeStrings - Whether to unescape strings or not * @param trackContextVariables - Whether to unescape strings or not * @param allowContextFunctionCalls - Whether function calls in context vars are allowed * @param options - The current parseOptions */ private loadJSONVariables; /** * Takes a context variable string and evaluates it to get the desired value * * IMPORTANT: To correctly parse variables, their substrings, subfunction and subbrackets must be encoded (done in evaluate()) * * @param contextVar - The context var * @param context - The context object * @param event - An event object, if available * @param unescapeStrings - Whether to unescape strings or not * @param trackContextVariables - An optional object that will be filled out with all found context vars * @param allowContextFunctionCalls - Whether function calls in context vars are allowed * @param options - The current parseOptions */ loadContextVariable(contextVar: string, context?: any, event?: any, unescapeStrings?: boolean, trackContextVariables?: any, allowContextFunctionCalls?: boolean, options?: ParseOptions): any; /** * Recursively travels an object with the help of a path array and returns the specified value, * or undefined if not found * * @param contextLevel - The object to travel * @param path - The property path array */ private fetchContextVariable; static ɵfac: i0.ɵɵFactoryDeclaration<DataTypeParser, never>; static ɵprov: i0.ɵɵInjectableDeclaration<DataTypeParser>; }