nope-js-browser
Version:
NoPE Runtime for the Browser. For nodejs please use nope-js-node
143 lines (142 loc) • 4.85 kB
TypeScript
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @desc [description]
*/
export declare const SEPARATOR = "/";
export declare const SINGLE_LEVEL_WILDCARD = "+";
export declare const MULTI_LEVEL_WILDCARD = "#";
export interface TPathCompareResult {
/**
* The Path to access the data. If a pattern is required to extract the
* data, this property is set to false and the property "patternToExtractData"
* is filled with the pattern.
*
* The PathToExtractData is allways false, if the path is smaller then the
* pattern
*
* @example path = "a/b/c"; pattern = "a/#"; => pathToExtractData = "a/b/c"
* @example path = "a"; pattern = "a/b/#"; => pathToExtractData = false
*
* @author M.Karkowski
* @type {(string | false)}
* @memberof TPathCompareResult
*/
pathToExtractData: string | false;
/**
* The Pattern to access the data. If no pattern is required to extract the
* data, this property is set to false and the property "pathToExtractData"
* is filled with the defined path. If the path is longer than the pattern,
* than we need to extract the data.
*
* @example path = "a/b/c"; pattern = "a/#"; => patternToExtractData = "a/#"
* @example path = "a"; pattern = "a/b/#"; => patternToExtractData = "a/b/#"
* @example path = "a"; pattern = "a"; => patternToExtractData = false
* @example path = "a/b"; pattern = "a"; => patternToExtractData = false
*
* @author M.Karkowski
* @type {(string | false)}
*/
patternToExtractData: string | false;
/**
* True if the pattern is shorter / equals the pattern and matches.
* This means, the path changes a child attribue of the data requested
* by the path.
*
* @author M.Karkowski
* @type {boolean}
* @memberof TPathCompareResult
*/
affectedByChild: boolean;
/**
* Generally set to true if the pattern is longer then the
* path, but they still match in the beginning. This means,
* the parent might change the data requested with this pattern
*
* @author M.Karkowski
* @type {boolean}
* @memberof TPathCompareResult
*/
affectedByParent: boolean;
/**
* Generally set to true if the size pf the pattern matches then the
* path. This means the data requested with this pattern if directly
* changed by the path.
*
* @author M.Karkowski
* @type {boolean}
* @memberof TPathCompareResult
*/
affectedOnSameLevel: boolean;
/**
* Shows that there might be matcht. Just the combination of
* affectedByChild | affectedOnSameLevel | affectedByChild
*
* @author M.Karkowski
* @type {boolean}
* @memberof TPathCompareResult
*/
affected: boolean;
/**
* Flag, indicating whether the pattern contains a pattern or is just
* a regular path.
*
* @author M.Karkowski
* @type {boolean}
* @memberof TPathCompareResult
*/
containsWildcards: boolean;
/**
* A Flag showing, that the pattern contains more segments than
*
* @author M.Karkowski
* @type {boolean}
* @memberof TPathCompareResult
*/
patternLengthComparedToPathLength: ">" | "=" | "<";
}
export type TcomparePatternAndPathFunc = (pattern: string, path: string, options?: {
matchTopicsWithoutWildcards?: boolean;
}) => TPathCompareResult;
/**
* Helper to generate a Result.
*
* @author M.Karkowski
* @export
* @param {Partial<TPathCompareResult>} [res={}]
* @return {*} {TPathCompareResult}
*/
export declare function generateResult(res?: Partial<TPathCompareResult>): TPathCompareResult;
/**
* Matches the given path, with the pattern and determines, if the path might affect
* the given pattern.
*
* @example path = "a/b/c"; pattern = "a/#"; => totalPath = "a/b/c"; diffPath = "b/c"
* @author M.Karkowski
* @export
* @param {string} pathPattern The pattern to test
* @param {string} contentPath The path to use as basis
* @return {TPathCompareResult}
*/
export declare function comparePatternAndPath(pathPattern: string, contentPath: string, options?: {
matchTopicsWithoutWildcards?: boolean;
}): TPathCompareResult;
/**
* Determines, whether the given string contains a single level card or not.
*
* @author M.Karkowski
* @export
* @param {string} str String to check
* @return {*} {boolean}
*/
export declare function containsWildcards(str: string): boolean;
/**
* Function to test if a pattern is valid
*
*
* @author M.Karkowski
* @export
* @param {string} str
* @return {*} {boolean}
*/
export declare function patternIsValid(str: string): boolean;