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","sourcesContent":["/**\n * Assigns (shallow copies) the properties of `src` onto `dest`, if the\n * corresponding property on `dest` === `undefined`.\n *\n * @param {Object} dest The destination object.\n * @param {Object} src The source object.\n * @return {Object} The destination object (`dest`)\n */\nexport function defaults( dest: any, src: any ) {\n\tfor( let prop in src ) {\n\t\tif( src.hasOwnProperty( prop ) && dest[ prop ] === undefined ) {\n\t\t\tdest[ prop ] = src[ prop ];\n\t\t}\n\t}\n\n\treturn dest;\n}\n\n\n/**\n * Truncates the `str` at `len - ellipsisChars.length`, and adds the `ellipsisChars` to the\n * end of the string (by default, two periods: '..'). If the `str` length does not exceed\n * `len`, the string will be returned unchanged.\n *\n * @param {String} str The string to truncate and add an ellipsis to.\n * @param {Number} truncateLen The length to truncate the string at.\n * @param {String} [ellipsisChars=...] The ellipsis character(s) to add to the end of `str`\n * when truncated. Defaults to '...'\n */\nexport function ellipsis( str: string, truncateLen: number, ellipsisChars?: string ) {\n\tlet ellipsisLength: number;\n\n\tif( str.length > truncateLen ) {\n\t\tif(ellipsisChars == null) {\n\t\t ellipsisChars = '…';\n\t\t ellipsisLength = 3;\n\t\t} else {\n\t\t ellipsisLength = ellipsisChars.length;\n\t\t}\n\n\t\tstr = str.substring( 0, truncateLen - ellipsisLength ) + ellipsisChars;\n\t}\n\treturn str;\n}\n\n\n/**\n * Supports `Array.prototype.indexOf()` functionality for old IE (IE8 and below).\n *\n * @param {Array} arr The array to find an element of.\n * @param {*} element The element to find in the array, and return the index of.\n * @return {Number} The index of the `element`, or -1 if it was not found.\n */\nexport function indexOf( arr: T[], element: T ) {\n\t// @ts-ignore - As far as TypeScript is concerned, this method will always\n\t// exist (lowest \"lib\" in TS is \"ES5\"). Hence we need to ignore this error\n\t// to support IE8 which only implements ES3 and doesn't have this method\n\tif( Array.prototype.indexOf ) {\n\t\treturn arr.indexOf( element );\n\n\t} else {\n\t\tfor( let i = 0, len = arr.length; i < len; i++ ) {\n\t\t\tif( arr[ i ] === element ) return i;\n\t\t}\n\t\treturn -1;\n\t}\n}\n\n\n/**\n * Removes array elements based on a filtering function. Mutates the input\n * array.\n *\n * Using this instead of the ES5 Array.prototype.filter() function, to allow\n * Autolinker compatibility with IE8, and also to prevent creating many new\n * arrays in memory for filtering.\n *\n * @param {Array} arr The array to remove elements from. This array is\n * mutated.\n * @param {Function} fn A function which should return `true` to\n * remove an element.\n * @return {Array} The mutated input `arr`.\n */\nexport function remove( arr: T[], fn: ( item: T ) => boolean ) {\n\tfor( let i = arr.length - 1; i >= 0; i-- ) {\n\t\tif( fn( arr[ i ] ) === true ) {\n\t\t\tarr.splice( i, 1 );\n\t\t}\n\t}\n}\n\n\n/**\n * Performs the functionality of what modern browsers do when `String.prototype.split()` is called\n * with a regular expression that contains capturing parenthesis.\n *\n * For example:\n *\n * // Modern browsers:\n * \"a,b,c\".split( /(,)/ ); // --> [ 'a', ',', 'b', ',', 'c' ]\n *\n * // Old IE (including IE8):\n * \"a,b,c\".split( /(,)/ ); // --> [ 'a', 'b', 'c' ]\n *\n * This method emulates the functionality of modern browsers for the old IE case.\n *\n * @param {String} str The string to split.\n * @param {RegExp} splitRegex The regular expression to split the input `str` on. The splitting\n * character(s) will be spliced into the array, as in the \"modern browsers\" example in the\n * description of this method.\n * Note #1: the supplied regular expression **must** have the 'g' flag specified.\n * Note #2: for simplicity's sake, the regular expression does not need\n * to contain capturing parenthesis - it will be assumed that any match has them.\n * @return {String[]} The split array of strings, with the splitting character(s) included.\n */\nexport function splitAndCapture( str: string, splitRegex: RegExp ) {\n\tif( !splitRegex.global ) throw new Error( \"`splitRegex` must have the 'g' flag set\" );\n\n\tlet result: string[] = [],\n\t lastIdx = 0,\n\t match: RegExpExecArray | null;\n\n\twhile( match = splitRegex.exec( str ) ) {\n\t\tresult.push( str.substring( lastIdx, match.index ) );\n\t\tresult.push( match[ 0 ] ); // push the splitting char(s)\n\n\t\tlastIdx = match.index + match[ 0 ].length;\n\t}\n\tresult.push( str.substring( lastIdx ) );\n\n\treturn result;\n}\n\n\n/**\n * Function that should never be called but is used to check that every\n * enum value is handled using TypeScript's 'never' type.\n */\nexport function throwUnhandledCaseError( theValue: never ) {\n\tthrow new Error( `Unhandled case for value: '${theValue}'` );\n}"]}