Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
feat: accept more social media patterns (#1286)
Kristýna Lhoťanovád1fdf65974a4
diff --git a/src/utils_social.js b/src/utils_social.jsindex d0002e7fd..706c530a6 100644--- a/src/utils_social.js+++ b/src/utils_social.js@@ -4,8 +4,6 @@ import cheerio from 'cheerio';import log from './utils_log';import { publicUtils } from './utils';-// TODO: We could support URLs like https://www.linkedin.com/company/some-company-inc-// Regex inspired by https://zapier.com/blog/extract-links-email-phone-regex/// eslint-disable-next-line max-lenconst EMAIL_REGEX_STRING = '(?:[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\\])';@@ -81,6 +79,9 @@ const PHONE_REGEXS_STRINGS = [// 1(262) 955-95-79 or 1(262)955.95.79'([0-9]{1,4}( )?)?\\([0-9]{2,4}\\)( )?[0-9]{2,4}(( )?(-|.))?( )?[0-9]{2,6}',+ // (51) 5667-9987 or (19)94138-9398+ '\\([0-9]{2}\\)( )?[0-9]{4,5}-[0-9]{4}',+// 413-577-1234-564'[0-9]{2,4}-[0-9]{2,4}-[0-9]{2,4}-[0-9]{2,6}',// 413-577-1234@@ -179,11 +180,10 @@ const phonesFromUrls = (urls) => {// They are used to prevent matching URLs in strings like "blahttps://www.example.com"// eslint-disable-next-line max-len-const LINKEDIN_REGEX_STRING = '(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:(?:[a-z]+\\.)?linkedin\\.com\\/in\\/)([a-z0-9\\-_%]{2,60})(?![a-z0-9\\-_%])(?:/)?';+const LINKEDIN_REGEX_STRING = '(?<!\\w)(?:(?:http(?:s)?:\\/\\/)?(?:(?:(?:[a-z]+\\.)?linkedin\\.com\\/(?:in|company)\\/)([a-z0-9\\-_%=]{2,60})(?![a-z0-9\\-_%=])))(?:\\/)?';-// TODO: Skip https://www.instagram.com/explore/ !!! and "https://www.instagram.com/_n/", "https://www.instagram.com/_u/"// eslint-disable-next-line max-len-const INSTAGRAM_REGEX_STRING = '(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:(?:www\\.)?(?:instagram\\.com|instagr\\.am)\\/)([a-z0-9_.]{2,30})(?![a-z0-9_.])(?:/)?';+const INSTAGRAM_REGEX_STRING = '(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:(?:www\\.)?(?:instagram\\.com|instagr\\.am)\\/)(?!explore|_n|_u)([a-z0-9_.]{2,30})(?![a-z0-9_.])(?:/)?';const TWITTER_RESERVED_PATHS = 'oauth|account|tos|privacy|signup|home|hashtag|search|login|widgets|i|settings|start|share|intent|oct';// eslint-disable-next-line max-len, quotes@@ -193,8 +193,18 @@ const TWITTER_REGEX_STRING = `(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:www.)?(?:twitter.const FACEBOOK_RESERVED_PATHS = 'rsrc\\.php|apps|groups|events|l\\.php|friends|images|photo.php|chat|ajax|dyi|common|policies|login|recover|reg|help|security|messages|marketplace|pages|live|bookmarks|games|fundraisers|saved|gaming|salesgroups|jobs|people|ads|ad_campaign|weather|offers|recommendations|crisisresponse|onthisday|developers|settings|connect|business|plugins|intern|sharer';// eslint-disable-next-line max-len, quotesconst FACEBOOK_REGEX_STRING = `(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:www.)?(?:facebook.com|fb.com)\\/(?!(?:${FACEBOOK_RESERVED_PATHS})(?:[\\'\\"\\?\\.\\/]|$))(profile\\.php\\?id\\=[0-9]{3,20}|(?!profile\\.php)[a-z0-9\\.]{5,51})(?![a-z0-9\\.])(?:/)?`;++// eslint-disable-next-line max-len, quotes+const YOUTUBE_REGEX_STRING = '(?<!\\w)(?:https?:\\/\\/)?(?:youtu\\.be\\/|(?:www\\.|m\\.)?youtube\\.com(?:\\/(?:watch|v|embed|user|c(?:hannel)?)(?:\\.php)?)?(?:\\?[^ ]*v=|\\/))([a-zA-Z0-9\\-_]{2,100})';++// eslint-disable-next-line max-len, quotes+const TIKTOK_REGEX_STRING = '(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:(?:www|m)\\.)?(?:tiktok\\.com)\\/(((?:(?:v|embed|trending)(?:\\?shareId=|\\/))[0-9]{2,50}(?![0-9]))|(?:@)[a-z0-9\\-_\\.]+((?:\\/video\\/)[0-9]{2,50}(?![0-9]))?)(?:\\/)?';+// eslint-disable-next-line max-len, quotes-const YOUTUBE_REGEX_STRING = '(?:https?:\\/\\/)?(?:youtu\\.be\\/|(?:www\\.|m\\.)?youtube\\.com\\/(?:watch|v|embed|user|c(?:hannel)?)(?:\\.php)?(?:\\?[^ ]*v=|\\/))([a-zA-Z0-9\\-_]+)';+const PINTEREST_REGEX_STRING = '(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:(?:(?:(?:www\\.)?pinterest(?:\\.com|(?:\\.[a-z]{2}){1,2}))|(?:[a-z]{2})\\.pinterest\\.com)(?:\\/))((pin\\/[0-9]{2,50})|((?!pin)[a-z0-9\\-_\\.]+(\\/[a-z0-9\\-_\\.]+)?))(?:\\/)?';++// eslint-disable-next-line max-len, quotes+const DISCORD_REGEX_STRING = '(?<!\\w)(?:https?:\\/\\/)?(?:www\\.)?((?:(?:(?:canary|ptb).)?(?:discord|discordapp)\\.com\\/channels(?:\\/)[0-9]{2,50}(\\/[0-9]{2,50})*)|(?:(?:(?:canary|ptb).)?(?:discord\\.(?:com|me|li|gg|io)|discordapp\\.com)(?:\\/invite)?)\\/(?!channels)[a-z0-9\\-_]{2,50})(?:\\/)?';/** @type RegExp */let LINKEDIN_REGEX;@@ -216,7 +226,17 @@ let FACEBOOK_REGEX_GLOBAL;let YOUTUBE_REGEX;/** @type RegExp */let YOUTUBE_REGEX_GLOBAL;-+/** @type RegExp */+let TIKTOK_REGEX;+/** @type RegExp */+let TIKTOK_REGEX_GLOBAL;+/** @type RegExp */+let PINTEREST_REGEX;+/** @type RegExp */+let PINTEREST_REGEX_GLOBAL;+let DISCORD_REGEX;+/** @type RegExp */+let DISCORD_REGEX_GLOBAL;try {/*** Regular expression to exactly match a single LinkedIn profile URL.@@ -225,6 +245,7 @@ try {* https://www.linkedin.com/in/alan-turing* en.linkedin.com/in/alan-turing* linkedin.com/in/alan-turing+ * https://www.linkedin.com/company/linkedin/* ```** The regular expression does NOT match URLs with additional@@ -251,6 +272,7 @@ try {* https://www.linkedin.com/in/alan-turing* en.linkedin.com/in/alan-turing* linkedin.com/in/alan-turing+ * https://www.linkedin.com/company/linkedin/* ```** If the profile URL contains subdirectories or query parameters, the regular expression@@ -288,6 +310,13 @@ try {* https://www.instagram.com/cristiano/followers* ```*+ * It also does NOT match the following URLs:+ * ```+ * https://www.instagram.com/explore/+ * https://www.instagram.com/_n/+ * https://www.instagram.com/_u/+ * ```+ ** Example usage:* ```* if (Apify.utils.social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague')) {@@ -318,6 +347,13 @@ try {* https://www.instagram.com/cristiano* ```*+ * The regular expression does NOT match the following URLs:+ * ```+ * https://www.instagram.com/explore/+ * https://www.instagram.com/_n/+ * https://www.instagram.com/_u/+ * ```+ ** Example usage:* ```* const matches = text.match(Apify.utils.social.INSTAGRAM_REGEX_GLOBAL);@@ -483,6 +519,141 @@ try {* @memberOf social*/YOUTUBE_REGEX_GLOBAL = new RegExp(YOUTUBE_REGEX_STRING, 'ig');++ /**+ * Regular expression to exactly match a Tiktok video or user account.+ * It has the following form: `/^...$/i` and matches URLs such as:+ * ```+ * https://www.tiktok.com/trending?shareId=123456789+ * https://www.tiktok.com/embed/123456789+ * https://m.tiktok.com/v/123456789+ * https://www.tiktok.com/@user+ * https://www.tiktok.com/@user-account.pro+ * https://www.tiktok.com/@user/video/123456789+ * ```+ *+ * Example usage:+ * ```+ * if (Apify.utils.social.DISCORD_REGEX.test('https://www.tiktok.com/@user')) {+ * console.log('Match!');+ * }+ * ```+ * @type {RegExp}+ * @memberOf social+ */+ TIKTOK_REGEX = new RegExp(`^${TIKTOK_REGEX_STRING}$`, 'i');++ /**+ * Regular expression to find multiple Tiktok videos or user accounts in a text or HTML.+ * It has the following form: `/.../ig` and matches URLs such as:+ * ```+ * https://www.tiktok.com/trending?shareId=123456789+ * https://www.tiktok.com/embed/123456789+ * https://m.tiktok.com/v/123456789+ * https://www.tiktok.com/@user+ * https://www.tiktok.com/@user-account.pro+ * https://www.tiktok.com/@user/video/123456789+ * ```+ *+ * Example usage:+ * ```+ * const matches = text.match(Apify.utils.social.TIKTOK_REGEX_GLOBAL);+ * if (matches) console.log(`${matches.length} TikTok videos and users found!`);+ * ```+ * @type {RegExp}+ * @memberOf social+ */+ TIKTOK_REGEX_GLOBAL = new RegExp(TIKTOK_REGEX_STRING, 'ig');++ /**+ * Regular expression to exactly match a Pinterest pin, user or user's board.+ * It has the following form: `/^...$/i` and matches URLs such as:+ * ```+ * https://pinterest.com/pin/123456789+ * https://www.pinterest.cz/pin/123456789+ * https://www.pinterest.com/user+ * https://uk.pinterest.com/user+ * https://www.pinterest.co.uk/user+ * pinterest.com/user_name.gold+ * https://cz.pinterest.com/user/board+ * ```+ *+ * Example usage:+ * ```+ * if (Apify.utils.social.PINTEREST_REGEX.test('https://www.pinterest.com/user')) {+ * console.log('Match!');+ * }+ * ```+ * @type {RegExp}+ * @memberOf social+ */+ PINTEREST_REGEX = new RegExp(`^${PINTEREST_REGEX_STRING}$`, 'i');++ /**+ * Regular expression to find multiple Pinterest pins, users or boards in a text or HTML.+ * It has the following form: `/.../ig` and matches URLs such as:+ * ```+ * https://pinterest.com/pin/123456789+ * https://www.pinterest.cz/pin/123456789+ * https://www.pinterest.com/user+ * https://uk.pinterest.com/user+ * https://www.pinterest.co.uk/user+ * pinterest.com/user_name.gold+ * https://cz.pinterest.com/user/board+ * ```+ *+ * Example usage:+ * ```+ * const matches = text.match(Apify.utils.social.PINTEREST_REGEX_GLOBAL);+ * if (matches) console.log(`${matches.length} Pinterest pins, users and boards found!`);+ * ```+ * @type {RegExp}+ * @memberOf social+ */+ PINTEREST_REGEX_GLOBAL = new RegExp(PINTEREST_REGEX_STRING, 'ig');++ /**+ * Regular expression to exactly match a Discord invite or channel.+ * It has the following form: `/^...$/i` and matches URLs such as:+ * ```+ * https://discord.gg/discord-developers+ * https://discord.com/invite/jyEM2PRvMU+ * https://discordapp.com/channels/1234+ * https://discord.com/channels/1234/1234+ * discord.gg/discord-developers+ * ```+ *+ * Example usage:+ * ```+ * if (Apify.utils.social.DISCORD_REGEX.test('https://discord.gg/discord-developers')) {+ * console.log('Match!');+ * }+ * ```+ * @type {RegExp}+ * @memberOf social+ */+ DISCORD_REGEX = new RegExp(`^${DISCORD_REGEX_STRING}$`, 'i');++ /**+ * Regular expression to find multiple Discord channels or invites in a text or HTML.+ * It has the following form: `/.../ig` and matches URLs such as:+ * ```+ * https://discord.gg/discord-developers+ * https://discord.com/invite/jyEM2PRvMU+ * https://discordapp.com/channels/1234+ * https://discord.com/channels/1234/1234+ * discord.gg/discord-developers+ * ```+ *+ * Example usage:+ * ```+ * const matches = text.match(Apify.utils.social.DISCORD_REGEX_GLOBAL);+ * if (matches) console.log(`${matches.length} Discord channels found!`);+ * ```+ * @type {RegExp}+ * @memberOf social+ */+ DISCORD_REGEX_GLOBAL = new RegExp(DISCORD_REGEX_STRING, 'ig');} catch (e) {// Older versions of Node don't support negative lookbehind and lookahead expressions.// Show warning instead of failing.@@ -509,6 +680,9 @@ try {* instagrams: String[],* facebooks: String[],* youtubes: String[],+ * tiktoks: String[],+ * pinterests: String[],+ * discords: String[],* }* ```* @typedef SocialHandles@@ -520,6 +694,9 @@ try {* @property {string[]} instagrams* @property {string[]} facebooks* @property {string[]} youtubes+ * @property {string[]} tiktoks+ * @property {string[]} pinterests+ * @property {string[]} discords*//**@@ -564,6 +741,9 @@ const parseHandlesFromHtml = (html, data = null) => {instagrams: [],facebooks: [],youtubes: [],+ tiktoks: [],+ pinterests: [],+ discords: [],};// TODO: maybe extract phone numbers from JSON+LD@@ -595,6 +775,9 @@ const parseHandlesFromHtml = (html, data = null) => {result.instagrams = html.match(INSTAGRAM_REGEX_GLOBAL) || [];result.facebooks = html.match(FACEBOOK_REGEX_GLOBAL) || [];result.youtubes = html.match(YOUTUBE_REGEX_GLOBAL) || [];+ result.tiktoks = html.match(TIKTOK_REGEX_GLOBAL) || [];+ result.pinterests = html.match(PINTEREST_REGEX_GLOBAL) || [];+ result.discords = html.match(DISCORD_REGEX_GLOBAL) || [];// Sort and deduplicate handles// eslint-disable-next-line guard-for-in, no-restricted-syntax@@ -643,4 +826,13 @@ export const socialUtils = {YOUTUBE_REGEX,YOUTUBE_REGEX_GLOBAL,++ TIKTOK_REGEX,+ TIKTOK_REGEX_GLOBAL,++ PINTEREST_REGEX,+ PINTEREST_REGEX_GLOBAL,++ DISCORD_REGEX,+ DISCORD_REGEX_GLOBAL,};diff --git a/test/utils_social.test.js b/test/utils_social.test.jsindex b7aa9ed58..af92fa906 100644--- a/test/utils_social.test.js+++ b/test/utils_social.test.js@@ -315,6 +315,9 @@ describe('utils.social', () => {instagrams: [],facebooks: [],youtubes: [],+ tiktoks: [],+ pinterests: [],+ discords: [],};test('handles invalid arg', () => {@@ -390,12 +393,37 @@ describe('utils.social', () => {<a href="https://youtu.be/kM7YfhfkiEE">Youtube</a><a href="fb.com/dada5678?query=1">link</a>+ https://www.tiktok.com/trending?shareId=1234567890123456789/+ m.tiktok.com/v/1234567890123456789+ <a href="https://tiktok.com/@jack1234">Profile</a>+ <a href="https://www.tiktok.com/@username/video/1234567890123456789">Most popular video</a>+ <a href="https://www.tiktok.com/embed/1234567890123456789/"Embed video</a>+ m.tiktok.com/v/1234567890123456789 duplicate++ <a href="https://www.pinterest.com/jack">Profile</a>+ <a href="https://pinterest.com/pin/10084556789">Top pin</a>+ <a href="https://uk.pinterest.com/user/board/">My board</a>+ pinterest.com/my_username+ <a href="https://pinterest.com/pin/10084556789">My favourite pin</a> duplicate++ <a href="https://discord.com/invite/jyEM2PRvMU/">Join us on Discord</a>+ <a href="discord.gg/discord-developers">Join our Discord community</a></body></html>`)).toEqual({+ discords: [+ 'discord.gg/discord-developers',+ 'https://discord.com/invite/jyEM2PRvMU/',+ ],phones: ['+42077533333'],- phonesUncertain: ['+4207751111111', '+420775222222'],+ phonesUncertain: [+ '+4207751111111',+ '+420775222222',++ // tiktok videos have purely numeric ids so this can't be avoided+ '123456789012345',+ ],linkedIns: ['http://www.linkedin.com/in/nohttps/','https://cz.linkedin.com/in/somecountry',@@ -413,6 +441,19 @@ describe('utils.social', () => {'https://www.instagram.com/york2/','instagram.com/old_prague',],+ pinterests: [+ 'https://pinterest.com/pin/10084556789',+ 'https://uk.pinterest.com/user/board/',+ 'https://www.pinterest.com/jack',+ 'pinterest.com/my_username',+ ],+ tiktoks: [+ 'https://tiktok.com/@jack1234',+ 'https://www.tiktok.com/@username/video/1234567890123456789',+ 'https://www.tiktok.com/embed/1234567890123456789/',+ 'https://www.tiktok.com/trending?shareId=1234567890123456789/',+ 'm.tiktok.com/v/1234567890123456789',+ ],twitters: ['https://www.twitter.com/apify','twitter.com/betasomething',@@ -584,6 +625,9 @@ describe('utils.social', () => {expect(social.INSTAGRAM_REGEX.test('xinstagram.com/old_prague')).toBe(false);expect(social.INSTAGRAM_REGEX.test('_instagram.com/old_prague')).toBe(false);expect(social.INSTAGRAM_REGEX.test('0instagram.com/old_prague')).toBe(false);+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/explore/')).toBe(false);+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/_n/')).toBe(false);+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/_u/')).toBe(false);expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague/?param=bla')).toBe(false);expect(social.INSTAGRAM_REGEX.test('://www.instagram.com/old_prague')).toBe(false);expect(social.INSTAGRAM_REGEX.test('http://www.instagram.com/old_prague http://www.instagram.com/old_brno')).toBe(false);@@ -757,6 +801,7 @@ describe('utils.social', () => {expect(''.match(social.FACEBOOK_REGEX_GLOBAL)).toBe(null);});});+describe('YOUTUBE_REGEX', () => {it('works', () => {expect(_.isRegExp(social.YOUTUBE_REGEX)).toBe(true);@@ -765,12 +810,29 @@ describe('utils.social', () => {expect(social.YOUTUBE_REGEX.flags).toBe('i');expect(social.YOUTUBE_REGEX_GLOBAL.flags).toBe('gi');+ expect(''.match(social.YOUTUBE_REGEX_GLOBAL)).toBe(null);+ expect(' dummy '.match(social.YOUTUBE_REGEX_GLOBAL)).toBe(null);+expect(social.YOUTUBE_REGEX.test('https://www.youtube.com/watch?v=kM7YfhfkiEE')).toBe(true);expect(social.YOUTUBE_REGEX.test('https://youtu.be/kM7YfhfkiEE')).toBe(true);expect(social.YOUTUBE_REGEX.test('https://www.youtube.com/c/TrapNation')).toBe(true);expect(social.YOUTUBE_REGEX.test('https://www.youtube.com/channel/UCklie6BM0fhFvzWYqQVoCTA')).toBe(true);expect(social.YOUTUBE_REGEX.test('https://www.youtube.com/user/pewdiepie')).toBe(true);++ expect(social.YOUTUBE_REGEX.test('://www.youtube.com/c/TrapNation')).toBe(false);+ expect(social.YOUTUBE_REGEX.test('https://youtu.be/kM7YfhfkiEE https://www.youtube.com/user/pewdiepie')).toBe(false);+ expect(social.YOUTUBE_REGEX.test('xyoutu.be/kM7YfhfkiEE')).toBe(false);+ expect(social.YOUTUBE_REGEX.test('-https://www.youtube.com/user/pewdiepie')).toBe(false);++ // Test there is just on matching group for the channel, video or username+ expect('https://www.youtube.com/watch?v=kM7YfhfkiEE'.match(social.YOUTUBE_REGEX)[1]).toBe('kM7YfhfkiEE');+ expect('https://youtu.be/kM7YfhfkiEE'.match(social.YOUTUBE_REGEX)[1]).toBe('kM7YfhfkiEE');+ expect('https://www.youtube.com/c/TrapNation'.match(social.YOUTUBE_REGEX)[1]).toBe('TrapNation');+ expect('https://www.youtube.com/channel/UCklie6BM0fhFvzWYqQVoCTA'.match(social.YOUTUBE_REGEX)[1]).toBe('UCklie6BM0fhFvzWYqQVoCTA');+ expect('https://www.youtube.com/user/pewdiepie'.match(social.YOUTUBE_REGEX)[1]).toBe('pewdiepie');+expect(`+ https://www.youtube.com/apify/-https://www.youtube.com/someusername/youtube.com/jack4567https://www.youtube.com/watch?v=kM7YfhfkiEE@@ -782,6 +844,9 @@ describe('utils.social', () => {youtube.com/user/pewdiepie`.match(social.YOUTUBE_REGEX_GLOBAL)).toEqual([+ 'https://www.youtube.com/apify',+ 'https://www.youtube.com/someusername',+ 'youtube.com/jack4567','https://www.youtube.com/watch?v=kM7YfhfkiEE','www.youtube.com/c/TrapNation','https://www.youtube.com/channel/UCklie6BM0fhFvzWYqQVoCTA',@@ -789,4 +854,159 @@ describe('utils.social', () => {]);});});++ describe('TIKTOK_REGEX', () => {+ it('works', () => {+ expect(_.isRegExp(social.TIKTOK_REGEX)).toBe(true);+ expect(_.isRegExp(social.TIKTOK_REGEX_GLOBAL)).toBe(true);++ expect(social.TIKTOK_REGEX.flags).toBe('i');+ expect(social.TIKTOK_REGEX_GLOBAL.flags).toBe('gi');++ expect(''.match(social.TIKTOK_REGEX_GLOBAL)).toBe(null);+ expect(' dummy '.match(social.TIKTOK_REGEX_GLOBAL)).toBe(null);++ expect(social.TIKTOK_REGEX.test('https://www.tiktok.com/trending?shareId=123456789')).toBe(true);+ expect(social.TIKTOK_REGEX.test('https://www.tiktok.com/embed/123456789')).toBe(true);+ expect(social.TIKTOK_REGEX.test('https://m.tiktok.com/v/123456789')).toBe(true);+ expect(social.TIKTOK_REGEX.test('https://www.tiktok.com/@user')).toBe(true);+ expect(social.TIKTOK_REGEX.test('https://www.tiktok.com/@user/video/123456789')).toBe(true);++ expect(social.TIKTOK_REGEX.test('_https://www.tiktok.com/trending?shareId=123456789')).toBe(false);+ expect(social.TIKTOK_REGEX.test('xtiktok.com/embed/123456789/')).toBe(false);+ expect(social.TIKTOK_REGEX.test('_pinterest.com/someusername')).toBe(false);+ expect(social.TIKTOK_REGEX.test('0https://www.tiktok.com/trending?shareId=123456789')).toBe(false);++ // Test there is just one matching group for video id or username+ expect('https://www.tiktok.com/trending?shareId=123456789'.match(social.TIKTOK_REGEX)[1]).toBe('trending?shareId=123456789');+ expect('www.tiktok.com/embed/123456789/'.match(social.TIKTOK_REGEX)[1]).toBe('embed/123456789');+ expect('tiktok.com/@jack'.match(social.TIKTOK_REGEX)[1]).toBe('@jack');+ expect('https://www.tiktok.com/@username/video/123456789'.match(social.TIKTOK_REGEX)[1]).toBe('@username/video/123456789');++ expect(`+ https://www.tiktok.com/trending?shareId=123456789+ www.tiktok.com/embed/123456789/+ m.tiktok.com/v/123456789+ tiktok.com/@user+ https://www.tiktok.com/@username/video/123456789+ -https://www.tiktok.com/@username/video/82347868+ atiktok.com/embed/123456789/+ _tiktok.com/embed/123456789/+ www.tiktok.com/embed/nonNumericVideoId+ https://www.tiktok.com/@jack1234/invalidSubpath/+ https://www.tiktok.com/trending?shareId=1234567898904582904537057328079034789063454432789054378+ https://www.tiktok.com/@userWithLongVideoName/video/123456789890458290453705732807903478904327890543654645365478+ `.match(social.TIKTOK_REGEX_GLOBAL))+ .toEqual([+ 'https://www.tiktok.com/trending?shareId=123456789',+ 'www.tiktok.com/embed/123456789/',+ 'm.tiktok.com/v/123456789',+ 'tiktok.com/@user',+ 'https://www.tiktok.com/@username/video/123456789',+ 'https://www.tiktok.com/@username/video/82347868',+ 'https://www.tiktok.com/@jack1234/',+ 'https://www.tiktok.com/@userWithLongVideoName/',+ ]);+ });+ });++ describe('PINTEREST_REGEX', () => {+ it('works', () => {+ expect(_.isRegExp(social.PINTEREST_REGEX)).toBe(true);+ expect(_.isRegExp(social.PINTEREST_REGEX_GLOBAL)).toBe(true);++ expect(social.PINTEREST_REGEX.flags).toBe('i');+ expect(social.PINTEREST_REGEX_GLOBAL.flags).toBe('gi');++ expect(''.match(social.PINTEREST_REGEX_GLOBAL)).toBe(null);+ expect(' dummy '.match(social.PINTEREST_REGEX_GLOBAL)).toBe(null);++ expect(social.PINTEREST_REGEX.test('https://pinterest.com/pin/123456789')).toBe(true);+ expect(social.PINTEREST_REGEX.test('https://www.pinterest.cz/pin/123456789')).toBe(true);+ expect(social.PINTEREST_REGEX.test('https://www.pinterest.com/user')).toBe(true);+ expect(social.PINTEREST_REGEX.test('https://www.pinterest.co.uk/user')).toBe(true);+ expect(social.PINTEREST_REGEX.test('pinterest.com/user_name.gold')).toBe(true);+ expect(social.PINTEREST_REGEX.test('https://cz.pinterest.com/user/board')).toBe(true);++ expect(social.PINTEREST_REGEX.test('_https://pinterest.com/pin/123456789')).toBe(false);+ expect(social.PINTEREST_REGEX.test('xpinterest.com/user_name.gold')).toBe(false);+ expect(social.PINTEREST_REGEX.test('_pinterest.com/someusername')).toBe(false);+ expect(social.PINTEREST_REGEX.test('0pinterest.com/someusername')).toBe(false);++ // Test there is just on matching group for the pin, board or username+ expect('https://pinterest.com/pin/123456789'.match(social.PINTEREST_REGEX)[1]).toBe('pin/123456789');+ expect('https://www.pinterest.com/username'.match(social.PINTEREST_REGEX)[1]).toBe('username');+ expect('pinterest.com/user_name.gold'.match(social.PINTEREST_REGEX)[1]).toBe('user_name.gold');+ expect('https://cz.pinterest.com/username/board'.match(social.PINTEREST_REGEX)[1]).toBe('username/board');++ expect(`+ https://pinterest.com/pin/123456789+ -https://pinterest.com/pin/10084556789/+ https://www.pinterest.cz/pin/123456789+ https://www.pinterest.com/user+ https://uk.pinterest.com/user+ https://www.pinterest.co.uk/user+ pinterest.com/user_name.gold+ https://cz.pinterest.com/user/board+ https://www.pinterest.cz/pin/nonNumericPinId+ `.match(social.PINTEREST_REGEX_GLOBAL))+ .toEqual([+ 'https://pinterest.com/pin/123456789',+ 'https://pinterest.com/pin/10084556789/',+ 'https://www.pinterest.cz/pin/123456789',+ 'https://www.pinterest.com/user',+ 'https://uk.pinterest.com/user',+ 'https://www.pinterest.co.uk/user',+ 'pinterest.com/user_name.gold',+ 'https://cz.pinterest.com/user/board',+ ]);+ });+ });++ describe('DISCORD_REGEX', () => {+ it('works', () => {+ expect(_.isRegExp(social.DISCORD_REGEX)).toBe(true);+ expect(_.isRegExp(social.DISCORD_REGEX_GLOBAL)).toBe(true);++ expect(social.DISCORD_REGEX.flags).toBe('i');+ expect(social.DISCORD_REGEX_GLOBAL.flags).toBe('gi');++ expect(''.match(social.DISCORD_REGEX_GLOBAL)).toBe(null);+ expect(' dummy '.match(social.DISCORD_REGEX_GLOBAL)).toBe(null);++ expect(social.DISCORD_REGEX.test('https://discord.gg/discord-developers')).toBe(true);+ expect(social.DISCORD_REGEX.test('https://discord.com/invite/jyEM2PRvMU')).toBe(true);+ expect(social.DISCORD_REGEX.test('https://discordapp.com/channels/231496023303957476')).toBe(true);+ expect(social.DISCORD_REGEX.test('https://discord.com/channels/231496023303957476/2332823543826404586')).toBe(true);+ expect(social.DISCORD_REGEX.test('https://ptb.discord.com/channels/231496023303957476/2332823543826404586')).toBe(true);+ expect(social.DISCORD_REGEX.test('ptb.discord.com/invite/jyEM2PRvMU')).toBe(true);+ expect(social.DISCORD_REGEX.test('canary.discord.com/invite/jyEM2PRvMU')).toBe(true);++ expect(social.DISCORD_REGEX.test('https://discord.com/channels/nonNumbericChannelId')).toBe(false);+ expect(social.DISCORD_REGEX.test('9discord.gg/discord-developers')).toBe(false);+ expect(social.DISCORD_REGEX.test('-discordapp.com/channels/231496023303957476/')).toBe(false);++ // Test there is just on matching group for the channel or invite (matches discord.* / discordapp.* prefix as well as they differ)+ expect('https://discord.gg/discord-developers'.match(social.DISCORD_REGEX)[1]).toBe('discord.gg/discord-developers');+ expect('https://discord.com/invite/jyEM2PRvMU'.match(social.DISCORD_REGEX)[1]).toBe('discord.com/invite/jyEM2PRvMU');+ expect('https://discordapp.com/channels/231496023303957476'.match(social.DISCORD_REGEX)[1]).toBe('discordapp.com/channels/231496023303957476');+ expect('https://discord.com/channels/231496023303957476/2332823543826404586'.match(social.DISCORD_REGEX)[1]).toBe('discord.com/channels/231496023303957476/2332823543826404586');++ expect(`+ https://discord.gg/discord-developers/+ https://discord.com/invite/jyEM2PRvMU+ -https://discordapp.com/channels/231496023303957476/+ https://discord.com/channels/231496023303957476/2332823543826404586+ discord.gg/discord-developers+ https://discordapp.com/channels/nonNumbericChannelId+ `.match(social.DISCORD_REGEX_GLOBAL))+ .toEqual([+ 'https://discord.gg/discord-developers/',+ 'https://discord.com/invite/jyEM2PRvMU',+ 'https://discordapp.com/channels/231496023303957476/',+ 'https://discord.com/channels/231496023303957476/2332823543826404586',+ 'discord.gg/discord-developers',+ ]);+ });+ });});