/** * Append an incrementing Number to given String to make it unique * @param {string} string * @return {string} string - appended/incremented with a number at the end */ export function appendNumber(string: string): string; /** * Find the common String Subsequence from list of strings. * Complexity is O(nm) with storage of O(2n) * * @example: * longestCommonSubstring("abc d", "10,000 bc") * >>> 'bc' * * @param {string} str1 * @param {string} str2 * @returns {string} string - can be empty string */ export function longestCommonSubstring(str1: string, str2: string): string; /** * Escape String for use in Regex Expression * @see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping * @param {String} string - to be sanitized * @returns {String} string - escaped for Regex use */ export function escapeRegExp(string: string): string; /** * Escape/Replace string for given characters * @param {string} str - to escape * @param {{[old: string]: string}} charsMap - maps of old string as key, and new string as value * @returns {string} escaped string */ export function escapeString(str: string, charsMap?: { [old: string]: string; }): string; /** * Convert String to RegexExp (with given String being escaped first) * @param {String} string - to be converted to Regex * @param {string} [flags] - to be passed to RegexExp initialization */ export function regexExp(string: string, flags?: string | undefined): RegExp; /** * Get Cookie Value by Name from Cookie String * * @example: * const cookie = 'KEY=value; KEY2=value2' * getCookie(cookie, KEY) * >>> 'value' * * @param {String} cookie - whole cookie string to get value from * @param {String} key - cookie name to get value for * @return {String} value - cookie */ export function getCookie(cookie: string, key: string): string; /** * Get Query Parameter Value by its Key from URL String * @example: * // URL is: https://example.com?foo=man&bar=&baz * var foo = getParameterByKey('foo'); // "man" * var bar = getParameterByKey('bar'); // "" (present with empty value) * var baz = getParameterByKey('baz'); // "" (present with no value) * var qux = getParameterByKey('qux'); // undefined (absent) * * @param {String} key - query parameter to extract from current URL * @param {String} [url] - string to search query parameters, defaults to current browser URL * @returns {String|Undefined} - value if found, else undefined */ export function getParamByKey(key: string, url?: string | undefined): string | undefined; /** * Get URI from given URL string * @param {String} url - to extract URI * @returns {String} URI */ export function pathURI(url: string): string; /** * Check that given value is a string and is not empty * * @param {*} value - to check * @returns {Boolean} true - if given value is non-empty string */ export function hasStringValue(value: any): boolean; /** * Check that string has correctly closed brackets * @example: * isClosedBrackets('ab[as)c') * >>> false * isClosedBrackets('ab[as])c') * >>> false * isClosedBrackets('{}ab([as])c') * >>> true * isClosedBrackets('abc') * >>> true * * @param {string} string - to check * @returns {boolean} true - if no brackets exist or all are properly closed */ export function isClosedBrackets(string: string): boolean; /** * Checks to see if the search param exists within the string param. * * @param {string} string - haystack * @param {string} search - needle * @return {boolean} */ export function isInString(string: string, search: string): boolean; /** * Checks to see if any of the searches params exist within the string param. * * @param {string} string - haystack * @param searches - needles * @return {boolean} */ export function isInStringAny(string: string, ...searches: any[]): boolean; /** * Insert Value to String at Specified Index * * @param {string} string - the string to be inserted to * @param {number} index - the position to insert * @param {string|number} value - the string to insert * @returns {string} */ export function insertToString(string: string, index: number, value: string | number): string; /** * Check if Given Value is a Base64 Encoded String * @note: cache regex pattern for faster search on large strings * @param {String} string - value to check * @returns {Boolean} true - if it is a valid Base64 encoded string */ export function isBase64(string: string): boolean; /** * Check if given string is a File URL or Path. * Helps to determine if File.src is URL or Path string vs. base64 encoded string. * @param {String} string - to check * @returns {Boolean} true - if string contains a dot '.', because a file always needs extension */ export function isFileSrc(string: string): boolean; /** * Check if Given String is a Valid IP v4 Address * * @param {*} address - value to check * @returns {Boolean} true - if value given is a valid IP address string */ export function isIpAddress(address: any): boolean; /** * Check if given string is a valid Phone Number * * @param {String} string - value to check * @returns {Boolean} true - if is valid phone number */ export function isPhoneNumber(string: string): boolean; /** * Interpolate a Template String with given Variables * @example: * interpolateString('key.{id}.name', {id: 'user'}) * >>> 'key.user.name' * * interpolateString('key.{state.id}.name', {state: {id: 'user'}}) * >>> 'key.user.name' * * interpolateString('key.{state.id,0}.name', {}) * >>> 'key.0.name' * * interpolateString('key.{id}.name', {$id: 'user'}, {formatKey: '$key'}) * >>> 'key.user.name' * * @param {String} string - template with '{placeholders}' to interpolate * @param {Object} variables - object containing keys matching the names of placeholders to interpolate * @param {String} [formatKey] - key format to match in given 'variables' (e.g. format = '$key') * @param {String} [name] - function name to use in case error is thrown * @param {Boolean} [suppressError] - whether to ignore error when replacement string not found, and leave as is * @return {String} output - with interpolated variables */ export function interpolateString(string: string, variables?: Object, { formatKey, name, suppressError }?: string | undefined): string; /** * Remove brackets around strings (add a dot before it, except when bracket is the first character) * * @example: * formatKeyPath('object[string]') // 'object.string' * * @param {string} keyPath - the path string to format */ export function formatKeyPath(keyPath: string): string; /** * Get File Name Format Extension from String * * @param {string} fileName - full file name with format extension (ex. 'image.png') * @returns {string} extension - file format if exists (ex. 'png') or empty string if it does not */ export function fileFormat(fileName: string): string; /** * Get File Extension used in Backend from User submitted file name * * @param {String|Null|Undefined} fileName - to extract extension * @returns {String|Undefined} file format extension, or empty string, or undefined */ export function fileFormatNormalized(fileName: string | null | undefined): string | undefined; /** * Get File Name without Extension String * * @param {string} fileName - full file name with extension */ export function fileNameWithoutExt(fileName: string): string; /** * Convert Data URL, such as Base64 Image string to JS File object * @param {String} dataUrl * @param {String} filename * @returns {File} file - object */ export function fileFromDataUrl(dataUrl: string, filename: string): File; /** * Get File Mime Type from Data URL * @param {String} dataUrl - see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs * @returns {String|undefined} mime type */ export function mimeTypeFromDataUrl(dataUrl: string): string | undefined; /** * Get hostname from URL string * * @param {string} url - to extract hostname * @return {string} - hostname */ export function hostname(url: string): string; /** * Get the first Matching Substring Between Two Strings * * @example: * matchBetween('cool_black__hat', '_', '__') * >>> 'black' * * @param {string} string - to match against * @param {string} before - string preceding the match (can be a Regex pattern by default) * @param {string} after - string succeeding the match (can be a Regex pattern by default) * @param {object} [options]: * - {boolean} esc - whether to escape Regex the `before` and `after` strings and treat them literally * - {boolean} inclusive - whether to include the `before` and `after` strings in the result * @returns {string} - matching string between `before` and `after` strings if found, or an empty string if not */ export function matchBetween(string: string, before: string, after: string, { esc, inclusive }?: object | undefined): string; /** * Convert two strings or numbers into one scrambled string, deterministically * * @param {string|number} str1 * @param {string|number} str2 * @returns {string} - scrambled characters from provided values */ export function mergeStrings(str1: string | number, str2: string | number): string; /** * Pad Left given String with Template String * * @param {String} string - to be padded, example 7 * @param {String} padTemplate - example: '000' * @return {String} padded with template - example: '007' */ export function padStringLeft(string: string, padTemplate: string): string; /** * Pad Right given String with Template String * * @param {String} string - to be padded, example 7 * @param {String} padTemplate - example: '000' * @return {String} padded with template - example: '700' */ export function padStringRight(string: string, padTemplate: string): string; /** * Converts the given singular word to it's plural version * * @example * plural('butterfly') * >>> 'butterflies' * * @uses pluralize * @see {@link https://github.com/blakeembrey/pluralize} for further information * * @param {string} string */ export function plural(string: string): any; /** * Pluralize or singularize a word based on count * * @uses pluralize * @see {@link https://github.com/blakeembrey/pluralize} for further information * * @param {string} word - The word to pluralize/singularize * @param {number} count - A count * @param {boolean} [shouldIncludeCount] - If true will prefix the given count to the word * @return {string} - A new string */ export function pluralize(word: string, count: number, shouldIncludeCount?: boolean | undefined): string; /** * Get a random Character from provided string * * @param {String} string * @returns {String} character */ export function randomFromString(string: string): string; /** * Create a Random ASCII String with Random length within given min - max range * * @param {Number} [min] - length * @param {Number} [max] - length * @param {Boolean} [alphaNum] - whether to create alphanumeric string only * @param {Boolean} [hex] - whether to create hex string only * @returns {String} random - ASCII compliant string */ export function randomString(min?: number | undefined, max?: number | undefined, { alphaNum, hex }?: boolean | undefined): string; export namespace randomString { const history: any[]; } /** * Hash ASCII String using SHA256 * * @param {String} ascii - compliant * @returns {String} digest - hashed to 64 characters long */ export function sha256(ascii: string): string; /** * Encode given String to HEX format * * @param {String} string - to encode * @returns {String} hex - encoded string */ export function toHex(string: string): string; /** * Convert String to Alpha Numeric Characters * * @param {String} string - to convert * @returns {String} - with alpha numeric characters only */ export function toAlphaNum(string: string): string; /** * Convert String to Alpha Numeric Characters with dashes and underscores * * @param {String} string - to convert * @returns {String} - with alpha numeric characters, dash and underscore only */ export function toAlphaNumId(string: string): string; /** * Sanitize String for use as URI without encoding. * * By default, this is not suitable for use as full URL, because it converts `:` to `-`, * unless a different Regex pattern is used. * * @example: * toURI(' Test dot: count!?123 4567*&^% \n".png') * >>> 'test-dot-count-123-4567-.png' * * @param {string} string - to sanitize, can contain any characters * @param {object} options: * {RegExp} [pattern] - Regex pattern of characters to replace with hyphen * @returns {string} URI - sanitized for browser URL, without encoding/decoding */ export function toURI(string: string, { replacePattern }?: object): string; /** * Truncate a String to Given Character Length, Showing the Last n Characters at the End * * @param {String} string - to truncate with ellipses * @param {Number} [length] - number of characters to keep in total * @param {Number} [lastChars] - number of characters to keep at the end * @returns {String} string - truncated to given total length */ export function truncate(string: string, length?: number | undefined, lastChars?: number | undefined): string; /** * Convert String to CapCase (ie. Capitalize each word, remove spaces, and optionally remove symbols). * Note that the underscore character is not considered as symbol, it is part of Regex `\w+` match. * @example: * toCapCase('firstName') * >>> 'FirstName' * * toCapCase('-webkit-scrollbar') * >>> 'WebkitScrollbar' * * toCapCase('__FOO_BAR__') * >>> '__FOO_BAR__' * * * @param {string} string - value to convert * @param {object} [options]: * {boolean|string} keepSymbols - false by default -> all symbols are removed (good for code variable) * @returns {string} - CapCased */ export function toCapCase(string: string, { keepSymbols }?: object | undefined): string; /** * Convert All Characters to lower case * @param {String|*} string - value to make lower case * @returns {String|*} - in lower case */ export function toLowerCase(string: string | any): string | any; /** * Convert Any Value type to lower case String * @param {*} value - make lower case * @returns {String} value - in lower case */ export function toLowerCaseAny(value: any): string; /** * Convert All Characters to UPPER CASE * @param {String|*} string - value to make upper case * @returns {String|*} - in upper case */ export function toUpperCase(string: string | any): string | any; /** * Convert Any Value type to UPPER CASE String * @param {*} value - make UPPER CASE * @returns {String} value - in UPPER CASE */ export function toUpperCaseAny(value: any): string; /** * Convert String to 'Title Case' (ie. Capitalize each word and add space between words) * @example: * toCapCase('firstName') * >>> 'First Name' * * toCapCase('-webkit-scrollbar') * >>> '-Webkit-Scrollbar' * * toCapCase('__FOO_BAR__') * >>> '__FOO_BAR__' * * * @param {string} string - value to convert * @param {object} [options]: * {boolean|string} keepSymbols - true by default, else symbols are replaced with spaces * @returns {string} - Title Cased */ export function toTitleCase(string: string, { keepSymbols }?: object | undefined): string; /** * Trim spaces at the start and end of String, and convert multiples spaces, * including tabs, newline, etc. in between to a single space. * @param {String|*} string - to trim * @returns {String|*} string - trimmed */ export function trimSpaces(string: string | any): string | any; /** * Create RFC4122 Complaint Version 4 UUID * * @see: https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript * @returns {String} uuid - in this format 'xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx' */ export function uuid(): string; /** * @example: * // Sanitize the string to contain only alphanumeric characters * str.replace(nonAlphaNumPattern, '') * * @note: * - Regex with `/g` flag must be reset in between `exec` or .test(), or it can return false * => see https://stackoverflow.com/a/2630538 * - Cached regex is only good for replacement or when it is without `/g` flag */ export const alphaNumWordsPattern: RegExp; export const nonAlphaNumPattern: RegExp; export const nonAlphaNumIdPattern: RegExp; export const nonAlphaNumURIPattern: RegExp; export const nonAlphaNumVarPattern: RegExp; export const nonJSVarPattern: RegExp; export const nonUnderscoreCharsPattern: RegExp; /** * Split CapCased String. * This uses Regex Lookbehind, which may not work in Safari or IE: * - `/(?<=[a-z])(?=[A-Z0-9])/` - splits between lowercase and Uppercase `lower|UPPER` * - `/(?=[A-Z0-9][a-z])/` - splits when Uppercase is followed by lowercase `UPPER|Lower` * - Combining these results in a nice split pattern for `camelCase` or `CapCase` strings. * - `?<=` causes error in Safari, so storing as string instead for use in backend * @see https://stackoverflow.com/a/51568859 * * @example: * const capCaseSplitPattern = new RegExp(capCaseSplitPatternStr) * 'getMy1st3DGlasses XMLHttpRequest'.split(capCaseSplitPattern).join('-') * >>> 'get-My-1st-3D-Glasses XML-Http-Request' */ export const capCaseSplitPatternStr: "(?<=[a-z])(?=[A-Z0-9])|(?=[A-Z0-9][a-z])"; export const capCaseLetterSplitPatternStr: "(?<=[a-z])(?=[A-Z])|(?=[A-Z][a-z])"; export const emptyBracketsPattern: RegExp; export const nonBracketsPattern: RegExp; export const escapeRegExpPattern: RegExp; export const fileNameWithoutExtPattern: RegExp; export const hyphensPattern: RegExp; export const hyphensTrimPattern: RegExp; export const isBase64Pattern: RegExp; export const spacesPattern: RegExp; export const wordsPattern: RegExp; export const getParamByKeyPattern: RegExp; export const getParamByKeySpacePattern: RegExp; export const isIpAddressPattern: RegExp; export const isPhoneNumberPattern: RegExp; /** * Interpolate a Template String with given Variables * @example: * interpolateString('key.{id}.name', {id: 'user'}) * >>> 'key.user.name' * * interpolateString('key.{state.id}.name', {state: {id: 'user'}}) * >>> 'key.user.name' * * interpolateString('key.{state.id,0}.name', {}) * >>> 'key.0.name' * * interpolateString('key.{id}.name', {$id: 'user'}, {formatKey: '$key'}) * >>> 'key.user.name' * * @param {String} string - template with '{placeholders}' to interpolate * @param {Object} variables - object containing keys matching the names of placeholders to interpolate * @param {String} [formatKey] - key format to match in given 'variables' (e.g. format = '$key') * @param {String} [name] - function name to use in case error is thrown * @param {Boolean} [suppressError] - whether to ignore error when replacement string not found, and leave as is * @return {String} output - with interpolated variables */ export function ips(string: string, variables?: Object, { formatKey, name, suppressError }?: string | undefined): string; export const interpolateStringPattern: RegExp; export const formatKeyPathPattern: RegExp; export { capitalize };