UNPKG

autolinker

Version:

Utility to automatically link the URLs, email addresses, phone numbers, hashtags, and mentions (Twitter, Instagram) in a given block of text/HTML

1 lines 3.42 kB
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAOA,8BAEC;AAYD,4BAcC;AAaD,kDAMC;AAOD,kCAEC;AA/DY,QAAA,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AAE9D;;;;GAIG;AACH,SAAgB,SAAS,CAAC,KAAc;IACpC,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC;AACtC,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAC,GAAW,EAAE,WAAmB,EAAE,aAAsB;IAC7E,IAAI,cAAsB,CAAC;IAE3B,IAAI,GAAG,CAAC,MAAM,GAAG,WAAW,EAAE,CAAC;QAC3B,IAAI,aAAa,IAAI,IAAI,EAAE,CAAC;YACxB,aAAa,GAAG,UAAU,CAAC;YAC3B,cAAc,GAAG,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACJ,cAAc,GAAG,aAAa,CAAC,MAAM,CAAC;QAC1C,CAAC;QAED,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,GAAG,cAAc,CAAC,GAAG,aAAa,CAAC;IACzE,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CAAI,GAAQ,EAAE,EAAwB;IACrE,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACtB,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACrB,CAAC;IACL,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,0BAA0B;AAC1B,SAAgB,WAAW,CAAC,QAAe;IACvC,MAAM,IAAI,KAAK,CAAC,qCAA8B,QAAQ,MAAG,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["export const hasOwnProperty = Object.prototype.hasOwnProperty;\n\n/**\n * Simpler helper method to check for a boolean type simply for the benefit of\n * gaining better compression when minified by not needing to have multiple\n * `typeof` comparisons in the codebase.\n */\nexport function isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean';\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 let ellipsisLength: number;\n\n if (str.length > truncateLen) {\n if (ellipsisChars == null) {\n ellipsisChars = '&hellip;';\n ellipsisLength = 3;\n } else {\n ellipsisLength = ellipsisChars.length;\n }\n\n str = str.substring(0, truncateLen - ellipsisLength) + ellipsisChars;\n }\n return str;\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 prevent\n * creating many new arrays in memory for filtering.\n *\n * @param arr The array to remove elements from. This array is mutated.\n * @param fn The predicate function which should return `true` to remove an\n * element.\n */\nexport function removeWithPredicate<T>(arr: T[], fn: (item: T) => boolean) {\n for (let i = arr.length - 1; i >= 0; i--) {\n if (fn(arr[i]) === true) {\n arr.splice(i, 1);\n }\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 */\n/* istanbul ignore next */\nexport function assertNever(theValue: never): never {\n throw new Error(`Unhandled case for value: '${theValue}'`);\n}\n"]}