interface SMHelperDictionaryType { [key: string]: any; } /** * Collection of utilities */ declare namespace SMHelper { /** * From a dictionary, build the querystring part of a URL. * Resulting string can be appended to URLs after the `?` character. * * Source: http://stackoverflow.com/a/1714899/192024 * * @param obj - Dictionary with keys and values * @returns The querystring that can be appended to URLs */ function buildQuerystring(obj: SMHelperDictionaryType): string; /** * Build a full HTTP/S URL from the various fragments. * * @param base - Base of the URL, including the protocol (e.g. `http://foo.bar/`) * @param parts - Path, either as string or array (e.g. 'api/create' or ['api', 'create']) * @param args - Dictionary with GET parameters * @returns The full URL */ function buildUrl(base: string, parts?: string | string[], args?: SMHelperDictionaryType): string; /** * Clone a JS object, deeply. * * @param obj - The object to clone (any scalar or non-scalar type) * @returns The cloned object */ function cloneObject(obj: any): any; /** * Remove all empty properties from an object. * If "onlyNull", remove all `null` value only. * The object `obj`, which is passed by reference, is modified. * * @param obj - Object to compact * @param onlyNull - If true, remove only values that are strictly `null` (default: false) */ function compactObject(obj: SMHelperDictionaryType, onlyNull?: boolean): void; /** * Get a nested property from a dictionary or array, referenced by a string in "dot notation". * For example: "key1.key2.0" * * @param obj - Object containing the property * @param desc - Name of the nested property * @returns Value of the referenced property or `undefined` */ function getDescendantProperty(obj: SMHelperDictionaryType, desc: string): any; /** * Check if a value is numeric. * * @param obj - Value to analyze * @returns True if value is numeric */ function isNumeric(obj: any): boolean; /** * Check if a value is a plain object. * * @param obj - Value to analyze * @returns True if value is a plain object */ function isPlainObject(obj: any): boolean; /** * Check if a value is of a scalar type (string, number, boolean). * * @param obj - Value to analyze * @returns True if value is of a scalar type */ function isScalar(obj: any): boolean; /** * Flatten a dictionary to the "dot notation", as used by MongoDB. * If preserveArrays is true, arrays are not transformed to the "dot notation". * * @param obj - Dictionary to convert * @param preserveArrays - If true, arrays are not transformed to the "dot notation" (default: false) * @returns Flattened dictionary in "dot notation" */ function objectToDotNotation(obj: SMHelperDictionaryType, preserveArrays?: boolean): SMHelperDictionaryType; /** * Take `str` and put a backslash in front of every character that is part of the regular expression syntax. * Port of the PHP function "preg_quote". See also: http://php.net/preg_quote * * @param str - String to escape * @param delimiter - If the optional delimiter is specified, it will also be escaped. This is useful for escaping the delimiter that is required by the regular expressions. The / is the most commonly used delimiter. * @returns Quoted (escaped) string */ function pregQuote(str: string, delimiter?: string): string; /** * Determine if a given string matches a pattern, allowing * as wildcard. * * @param pattern - Pattern to search in value * @param value - String in which the pattern is searched * @returns True if value matches pattern */ function strIs(pattern: string, value: string): boolean; /** * Convert strings with dashes or underscores (eg. 'foo-bar' or 'foo_bar') to camelCase ('fooBar') * * @param str - Dashed string * @returns String converted to camelCase */ function stringToCamel(str: string): string; /** * Strip HTML tags, except allowed ones. * This function is a port of the PHP strip_tags function: http://php.net/strip_tags * * @param input - Input string * @param allowed - String listing allowed HTML tags, for example `
` * @returns String with HTML tags stripped */ function stripTags(input: string, allowed?: string): string; /** * Convert a value to string, ensuring that the number 0 and the boolean false are treated correctly. * * @param val - Value to convert * @returns String value */ function toStringSafe(val: any): string; /** * Update a property (represented in the "dot notation") in an object. * The object `obj`, which is passed by reference, is modified. * * @param obj - Object to the be updated * @param property - Name of the property to update, in "dot notation" * @param value - New value for the matched property */ function updatePropertyInObject(obj: SMHelperDictionaryType, property: string, value: any): void; } export default SMHelper;