UNPKG

clientnode

Version:

upgrade to object orientated rock solid plugins

290 lines (289 loc) 14.2 kB
import { CompilationResult, EvaluationResult, Mapping, PlainObject, StringMarkOptions, QueryParameters } from './type'; export declare const ALLOWED_VARIABLE_SYMBOLS = "0-9a-zA-Z_$"; export declare const ALLOWED_STARTING_VARIABLE_SYMBOLS = "a-zA-Z_$"; export declare const FIX_ENCODING_ERROR_MAPPING: readonly [readonly ["Ã\\x84", "Ä"], readonly ["Ã\\x96", "Ö"], readonly ["Ã\\x9c", "Ü"], readonly ["ä", "ä"], readonly ["ö", "ö"], readonly ["ü", "ü"], readonly ["\\x96", "-"], readonly ["é", "é"], readonly ["è", "e"], readonly ["ô", "o"], readonly ["à ", "á"], readonly ["ø", "ø"], readonly ["Ã\\x9f", "ß"], readonly ["Ã", "ß"]]; /** * Translates given string into the regular expression validated * representation. * @param value - String to convert. * @param excludeSymbols - Symbols not to escape. * @returns Converted string. */ export declare const escapeRegularExpressions: (value: string, excludeSymbols?: Array<string>) => string; /** * Translates given name into a valid javaScript one. * @param name - Name to convert. * @returns Converted name is returned. */ export declare const convertToValidVariableName: (name: string) => string; /** * This method is intended for encoding *key* or *value* parts of query * component. We need a custom method because "encodeURIComponent()" is too * aggressive and encodes stuff that doesn't have to be encoded per * "http://tools.ietf.org/html/rfc3986:". * @param url - URL to encode. * @param encodeSpaces - Indicates whether given url should encode * whitespaces as "+" or "%20". * @returns Encoded given url. */ export declare const encodeURIComponentExtended: (url: string, encodeSpaces?: boolean) => string; /** * Appends a path selector to the given path if there isn't one yet. * @param path - The path for appending a selector. * @param pathSeparator - The selector for appending to path. * @returns The appended path. */ export declare const addSeparatorToPath: (path: string, pathSeparator?: string) => string; /** * Checks if given path has given path prefix. * @param prefix - Path prefix to search for. * @param path - Path to search in. * @param separator - Delimiter to use in path (default is the posix * conform slash). * @returns Value "true" if given prefix occur and "false" otherwise. */ export declare const hasPathPrefix: (prefix?: unknown, path?: string, separator?: string) => boolean; /** * Extracts domain name from given url. If no explicit domain name given * current domain name will be assumed. If no parameter given current * domain name will be determined. * @param url - The url to extract domain from. * @param fallback - The fallback host name if no one exits in given url * (default is current hostname). * @returns Extracted domain. */ export declare const getDomainName: (url?: string, fallback?: string) => string; /** * Extracts port number from given url. If no explicit port number given * and no fallback is defined current port number will be assumed for local * links. For external links 80 will be assumed for http protocols and 443 * for https protocols. * @param url - The url to extract port from. * @param fallback - Fallback port number if no explicit one was found. * Default is derived from current protocol name. * @returns Extracted port number. */ export declare const getPortNumber: (url?: string, fallback?: null | number) => null | number; /** * Extracts protocol name from given url. If no explicit url is given, * current protocol will be assumed. If no parameter given current protocol * number will be determined. * @param url - The url to extract protocol from. * @param fallback - Fallback port to use if no protocol exists in given * url (default is current protocol). * @returns Extracted protocol. */ export declare const getProtocolName: (url?: string, fallback?: string) => string; /** * Read a page's GET URL variables and return them as an associative array * and preserves ordering. * @param keyToGet - If provided the corresponding value for given key is * returned or full object otherwise. * @param allowDuplicates - Indicates whether to return arrays of values or * single values. If set to "false" (default) last values will overwrite * preceding values. * @param givenInput - An alternative input to the url search parameter. If * "#" is given the complete current hashtag will be interpreted as url and * search parameter will be extracted from there. If "&" is given classical * search parameter and hash parameter will be taken in account. If a search * string is given this will be analyzed. The default is to take given search * part into account. * @param subDelimiter - Defines which sequence indicates the start of * parameter in a hash part of the url. * @param hashedPathIndicator - If defined and given hash starts with this * indicator given hash will be interpreted as path containing search and * hash parts. * @param givenSearch - Search part to take into account defaults to * current url search part. * @param givenHash - Hash part to take into account defaults to current * url hash part. * @returns Returns the current get array or requested value. If requested * key doesn't exist "undefined" is returned. */ export declare const getURLParameter: (keyToGet?: null | string, allowDuplicates?: boolean, givenInput?: null | string, subDelimiter?: string, hashedPathIndicator?: string, givenSearch?: null | string, givenHash?: null | string) => Array<string> | null | QueryParameters | string; /** * Checks if given url points to another "service" than second given url. * If no second given url provided current url will be assumed. * @param url - URL to check against second url. * @param referenceURL - URL to check against first url. * @returns Returns "true" if given first url has same domain as given * second (or current). */ export declare const serviceURLEquals: (url: string, referenceURL?: string) => boolean; /** * Normalized given website url. * @param givenURL - Uniform resource locator to normalize. * @returns Normalized result. */ export declare const normalizeURL: (givenURL: unknown) => string; /** * Represents given website url. * @param url - Uniform resource locator to represent. * @returns Represented result. */ export declare const representURL: (url: unknown) => string; /** * Converts a camel cased string to its delimited string version. * @param value - The string to format. * @param delimiter - Defines delimiter string. * @param abbreviations - Collection of shortcut words to represent uppercased. * @returns The formatted string. */ export declare const camelCaseToDelimited: (value: string, delimiter?: string, abbreviations?: Array<string> | null) => string; /** * Converts a string to its capitalize representation. * @param string - The string to format. * @returns The formatted string. */ export declare const capitalize: (string: string) => string; /** * Compresses given style attribute value. * @param styleValue - Style value to compress. * @returns The compressed value. */ export declare const compressStyleValue: (styleValue: string) => string; /** * Decodes all html symbols in text nodes in given html string. * @param htmlString - HTML string to decode. * @returns Decoded html string. */ export declare const decodeHTMLEntities: (htmlString: string) => null | string; /** * Converts a delimited string to its camel case representation. * @param value - The string to format. * @param delimiter - Delimiter string to use. * @param abbreviations - Collection of shortcut words to represent uppercased. * @param preserveWrongFormattedAbbreviations - If set to "True" wrong * formatted camel case abbreviations will be ignored. * @param removeMultipleDelimiter - Indicates whether a series of delimiter * should be consolidated. * @returns The formatted string. */ export declare const delimitedToCamelCase: (value: string, delimiter?: string, abbreviations?: Array<string> | null, preserveWrongFormattedAbbreviations?: boolean, removeMultipleDelimiter?: boolean) => string; /** * Compiles a given string as expression with given scope names. * @param expression - The string to interpret. * @param scope - Scope to extract names from. * @param execute - Indicates whether to execute or evaluate. * @param removeGlobalScope - Indicates whether to shadow global variables via * "undefined". * @param binding - Object to apply as "this" in evaluation scope. * @returns Object of prepared scope name mappings and compiled function or * error string message if given expression couldn't be compiled. */ export declare const compile: <T = string, N extends Array<string> = Array<string>>(expression: string, scope?: Mapping<unknown, N[number]> | N | N[number] | string, execute?: boolean, removeGlobalScope?: boolean, binding?: unknown) => CompilationResult<T, N>; /** * Evaluates a given string as expression against given scope. * @param expression - The string to interpret. * @param scope - Scope to render against. * @param execute - Indicates whether to execute or evaluate. * @param removeGlobalScope - Indicates whether to shadow global variables via * "undefined". * @param binding - Object to apply as "this" in evaluation scope. * @returns Object with error message during parsing / running or result. */ export declare const evaluate: <T = string, S extends object = object>(expression: string, scope?: S, execute?: boolean, removeGlobalScope?: boolean, binding?: unknown) => EvaluationResult<T>; /** * Finds the string match of given query in given target text by applying given * normalisation function to target and query. * @param target - Target to search in. * @param query - Search string to search for. * @param normalizer - Function to use as normalisation for queries and search * targets. * @param skipTagDelimitedParts - Indicates whether to for example ignore html * tags via "['<', '>']" (the default). * @returns Start and end index of matching range. */ export declare const findNormalizedMatchRange: (target: unknown, query: unknown, normalizer?: (value: unknown) => string, skipTagDelimitedParts?: null | [string, string]) => Array<number> | null; /** * Fixes known encoding problems in given data. * @param data - To process. * @returns Processed data. */ export declare const fixKnownEncodingErrors: (data: string) => string; /** * Performs a string formation. Replaces every placeholder "{i}" with the i'th * argument. * @param string - The string to format. * @param additionalArguments - Additional arguments are interpreted as * replacements for string formatting. * @returns The formatted string. */ export declare const format: (string: string, ...additionalArguments: Array<unknown>) => string; /** * Calculates the edit (levenstein) distance between two given strings. * @param first - First string to compare. * @param second - Second string to compare. * @returns The distance as number. */ export declare const getEditDistance: (first: string, second: string) => number; /** * Validates the current string for using in a regular expression pattern. * Special regular expression chars will be escaped. * @param value - The string to format. * @returns The formatted string. */ export declare const maskForRegularExpression: (value: string) => string; /** * Converts a string to its lower case representation. * @param string - The string to format. * @returns The formatted string. */ export declare const lowerCase: (string: string) => string; /** * Wraps given mark strings in given target with given marker. * @param target - String to search for marker. * @param givenWords - String or array of strings to search in target for. * @param givenOptions - Defines highlighting behavior. * @param givenOptions.marker - HTML template string to mark. * @param givenOptions.normalizer - Pure normalisation function to use before * searching for matches. * @param givenOptions.skipTagDelimitedParts - Indicates whether to for example * ignore html tags via "['<', '>']" (the default). * @returns Processed result. */ export declare const mark: (target: unknown, givenWords?: Array<string> | string, givenOptions?: Partial<StringMarkOptions>) => unknown; /** * Normalizes given phone number for automatic dialing or comparison. * @param value - Number to normalize. * @param dialable - Indicates whether the result should be dialed or * represented as lossless data. * @returns Normalized number. */ export declare const normalizePhoneNumber: (value: unknown, dialable?: boolean) => string; /** * Normalizes given zip code for automatic address processing. * @param value - Number to normalize. * @returns Normalized number. */ export declare const normalizeZipCode: (value: unknown) => string; /** * Converts given serialized, base64 encoded or file path given object into a * native javaScript one if possible. * @param serializedObject - Object as string. * @param scope - An optional scope which will be used to evaluate given object * in. * @param name - The name under given scope will be available. * @returns The parsed object if possible and null otherwise. */ export declare const parseEncodedObject: <T = PlainObject>(serializedObject: string, scope?: Mapping<unknown>, name?: string) => null | T; /** * Represents given phone number. NOTE: Currently only support german phone * numbers. * @param value - Number to format. * @returns Formatted number. */ export declare const representPhoneNumber: (value: unknown) => string; /** * Slices all none numbers but preserves last separator. * @param value - String to process. * @returns - Sliced given value. */ export declare const sliceAllExceptNumberAndLastSeparator: (value: string) => string; /** * Converts a dom selector to a prefixed dom selector string. * @param selector - A dom node selector. * @param selectorPrefix - A dom node selector prefix to take into account. * @returns Returns given selector prefixed. */ export declare const normalizeDomNodeSelector: (selector: string, selectorPrefix?: string) => string;