Skip to content

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.

Improvements in Apify.utils.social functions and tests

Jan Curnb883e66ef181
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 64ae00742..073e33d08 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+0.9.9 / 2018-11-24
+==================
+- Improvements in `Apify.utils.social` functions and tests
+
0.9.8 / 2018-11-24
==================
- Added new `Apify.utils.social` namespace with function to extract emails, phone and social profile URLs
diff --git a/src/utils_social.js b/src/utils_social.js
index 1b73500a9..ae44ed8d3 100644
--- a/src/utils_social.js
+++ b/src/utils_social.js
@@ -73,6 +73,7 @@ const PHONE_URL_PREFIX_REGEX = /^(tel|phone|telephone):(\/)?(\/)?/i;
// It's pretty much impossible (and unmaintainable) to have just one large regular expression for all possible phone numbers.
// So here we define various regular expression for typical phone number patterns, which are then used to compile
// a single large regular expressions. Add more patterns as needed.
+// NOTE: The patterns are tested in the order as written below, so the longer ones should be before the shorter ones!
const PHONE_REGEXS_STRINGS = [
// 775123456
'[0-9]{6,15}',
@@ -98,7 +99,7 @@ const PHONE_REGEXS_STRINGS = [
'[0-9]{2,4}\\.[0-9]{2,6}',
// 413 577 1234 564
- '[0-9]{2,4}\\.[0-9]{2,4}\\.[0-9]{2,4}\\.[0-9]{2,6}',
+ '[0-9]{2,4} [0-9]{2,4} [0-9]{2,4} [0-9]{2,6}',
// 413 577 1234
'[0-9]{2,4} [0-9]{2,4} [0-9]{2,6}',
// 123 4567
@@ -184,19 +185,19 @@ 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_PROFILE_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\\/)([a-z0-9\\-_%]{2,60})(?![a-z0-9\\-_%])(?:/)?';
// eslint-disable-next-line max-len
-const INSTAGRAM_PROFILE_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)\\/)([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
-const TWITTER_PROFILE_REGEX_STRING = `(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:www.)?(?:twitter.com)\\/(?!(?:${TWITTER_RESERVED_PATHS})(?:[\\'\\"\\?\\.\\/]|$))([a-z0-9_]{1,15})(?![a-z0-9_])(?:/)?`;
+const TWITTER_REGEX_STRING = `(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:www.)?(?:twitter.com)\\/(?!(?:${TWITTER_RESERVED_PATHS})(?:[\\'\\"\\?\\.\\/]|$))([a-z0-9_]{1,15})(?![a-z0-9_])(?:/)?`;
// eslint-disable-next-line max-len, quotes
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';
// eslint-disable-next-line max-len, quotes
-const FACEBOOK_PROFILE_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\\.])(?:/)?`;
+const 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\\.])(?:/)?`;
/**
@@ -210,7 +211,7 @@ const FACEBOOK_PROFILE_REGEX_STRING = `(?<!\\w)(?:http(?:s)?:\\/\\/)?(?:www.)?(?
* @type {RegExp}
* @memberOf utils.social
*/
-const LINKEDIN_PROFILE_REGEX = new RegExp(`^${LINKEDIN_PROFILE_REGEX_STRING}$`, 'i');
+const LINKEDIN_REGEX = new RegExp(`^${LINKEDIN_REGEX_STRING}$`, 'i');
/**
* Regular expression to find multiple LinkedIn profile URLs in a text.
@@ -218,7 +219,7 @@ const LINKEDIN_PROFILE_REGEX = new RegExp(`^${LINKEDIN_PROFILE_REGEX_STRING}$`,
* @type {RegExp}
* @memberOf utils.social
*/
-const LINKEDIN_PROFILE_REGEX_GLOBAL = new RegExp(LINKEDIN_PROFILE_REGEX_STRING, 'ig');
+const LINKEDIN_REGEX_GLOBAL = new RegExp(LINKEDIN_REGEX_STRING, 'ig');
/**
@@ -227,7 +228,7 @@ const LINKEDIN_PROFILE_REGEX_GLOBAL = new RegExp(LINKEDIN_PROFILE_REGEX_STRING,
* @type {RegExp}
* @memberOf utils.social
*/
-const INSTAGRAM_PROFILE_REGEX = new RegExp(`^${INSTAGRAM_PROFILE_REGEX_STRING}$`, 'i');
+const INSTAGRAM_REGEX = new RegExp(`^${INSTAGRAM_REGEX_STRING}$`, 'i');
/**
* Regular expression to find multiple Instagram profile URLs in a text.
@@ -235,7 +236,7 @@ const INSTAGRAM_PROFILE_REGEX = new RegExp(`^${INSTAGRAM_PROFILE_REGEX_STRING}$`
* @type {RegExp}
* @memberOf utils.social
*/
-const INSTAGRAM_PROFILE_REGEX_GLOBAL = new RegExp(INSTAGRAM_PROFILE_REGEX_STRING, 'ig');
+const INSTAGRAM_REGEX_GLOBAL = new RegExp(INSTAGRAM_REGEX_STRING, 'ig');
/**
@@ -244,7 +245,7 @@ const INSTAGRAM_PROFILE_REGEX_GLOBAL = new RegExp(INSTAGRAM_PROFILE_REGEX_STRING
* @type {RegExp}
* @memberOf utils.social
*/
-const TWITTER_PROFILE_REGEX = new RegExp(`^${TWITTER_PROFILE_REGEX_STRING}$`, 'i');
+const TWITTER_REGEX = new RegExp(`^${TWITTER_REGEX_STRING}$`, 'i');
/**
* Regular expression to find multiple Instagram profile URLs in a text.
@@ -252,7 +253,7 @@ const TWITTER_PROFILE_REGEX = new RegExp(`^${TWITTER_PROFILE_REGEX_STRING}$`, 'i
* @type {RegExp}
* @memberOf utils.social
*/
-const TWITTER_PROFILE_REGEX_GLOBAL = new RegExp(TWITTER_PROFILE_REGEX_STRING, 'ig');
+const TWITTER_REGEX_GLOBAL = new RegExp(TWITTER_REGEX_STRING, 'ig');
/**
* Regular expression to exactly match a single Facebook user profile URL.
@@ -260,7 +261,7 @@ const TWITTER_PROFILE_REGEX_GLOBAL = new RegExp(TWITTER_PROFILE_REGEX_STRING, 'i
* @type {RegExp}
* @memberOf utils.social
*/
-const FACEBOOK_PROFILE_REGEX = new RegExp(`^${FACEBOOK_PROFILE_REGEX_STRING}$`, 'i');
+const FACEBOOK_REGEX = new RegExp(`^${FACEBOOK_REGEX_STRING}$`, 'i');
/**
* Regular expression to find multiple Instagram profile URLs in a text.
@@ -268,7 +269,7 @@ const FACEBOOK_PROFILE_REGEX = new RegExp(`^${FACEBOOK_PROFILE_REGEX_STRING}$`,
* @type {RegExp}
* @memberOf utils.social
*/
-const FACEBOOK_PROFILE_REGEX_GLOBAL = new RegExp(FACEBOOK_PROFILE_REGEX_STRING, 'ig');
+const FACEBOOK_REGEX_GLOBAL = new RegExp(FACEBOOK_REGEX_STRING, 'ig');
/**
@@ -284,10 +285,10 @@ const FACEBOOK_PROFILE_REGEX_GLOBAL = new RegExp(FACEBOOK_PROFILE_REGEX_STRING,
* {
* emails: String[],
* phones: String[],
- * linkedInUrls: String[],
- * twitterProfiles: String[],
- * instagramProfiles: String[],
- * facebookProfiles: String[],
+ * linkedIns: String[],
+ * twitters: String[],
+ * instagrams: String[],
+ * facebooks: String[],
* }
* ```
*/
@@ -295,10 +296,10 @@ const parseHandlesFromHtml = (html, data = null) => {
const result = {
emails: [],
phones: [],
- linkedInProfiles: [],
- twitterProfiles: [],
- instagramProfiles: [],
- facebookProfiles: [],
+ linkedIns: [],
+ twitters: [],
+ instagrams: [],
+ facebooks: [],
};
if (!_.isString(html)) return result;
@@ -306,9 +307,11 @@ const parseHandlesFromHtml = (html, data = null) => {
// We use ignoreHref and ignoreImage options so that the text doesn't contain links,
// since their parts can be interpreted as e.g. phone numbers.
const text = htmlToText.fromString(html, { ignoreHref: true, ignoreImage: true }) || '';
+ if (data) data.text = text;
// TODO: Both html-to-text and cheerio use htmlparser2, the parsing could be done only once to improve performance
const $ = cheerio.load(html, { decodeEntities: true });
+ if (data) data.$ = $;
// Find all <a> links with href tag
const linkUrls = [];
@@ -316,8 +319,6 @@ const parseHandlesFromHtml = (html, data = null) => {
if (elem) linkUrls.push($(elem).attr('href'));
});
- // TODO: We should probably normalize all the handles to lower-case
-
result.emails = emailsFromUrls(linkUrls).concat(emailsFromText(text));
result.phones = phonesFromUrls(linkUrls).concat(phonesFromText(text));
@@ -325,10 +326,10 @@ const parseHandlesFromHtml = (html, data = null) => {
// https://www.linkedin.com/in/carl-newman-123456a/detail/recent-activity/
// they match just:
// https://www.linkedin.com/in/carl-newman-123456a
- result.linkedInProfiles = html.match(LINKEDIN_PROFILE_REGEX_GLOBAL) || [];
- result.twitterProfiles = html.match(TWITTER_PROFILE_REGEX_GLOBAL) || [];
- result.instagramProfiles = html.match(INSTAGRAM_PROFILE_REGEX_GLOBAL) || [];
- result.facebookProfiles = html.match(FACEBOOK_PROFILE_REGEX_GLOBAL) || [];
+ result.linkedIns = html.match(LINKEDIN_REGEX_GLOBAL) || [];
+ result.twitters = html.match(TWITTER_REGEX_GLOBAL) || [];
+ result.instagrams = html.match(INSTAGRAM_REGEX_GLOBAL) || [];
+ result.facebooks = html.match(FACEBOOK_REGEX_GLOBAL) || [];
// Sort and deduplicate handles
// eslint-disable-next-line guard-for-in, no-restricted-syntax
@@ -337,11 +338,6 @@ const parseHandlesFromHtml = (html, data = null) => {
result[key] = _.uniq(result[key], true);
}
- if (data) {
- data.text = text;
- data.$ = $;
- }
-
return result;
};
@@ -370,15 +366,15 @@ export const socialUtils = {
EMAIL_REGEX,
EMAIL_REGEX_GLOBAL,
- LINKEDIN_PROFILE_REGEX,
- LINKEDIN_PROFILE_REGEX_GLOBAL,
+ LINKEDIN_REGEX,
+ LINKEDIN_REGEX_GLOBAL,
- INSTAGRAM_PROFILE_REGEX,
- INSTAGRAM_PROFILE_REGEX_GLOBAL,
+ INSTAGRAM_REGEX,
+ INSTAGRAM_REGEX_GLOBAL,
- TWITTER_PROFILE_REGEX,
- TWITTER_PROFILE_REGEX_GLOBAL,
+ TWITTER_REGEX,
+ TWITTER_REGEX_GLOBAL,
- FACEBOOK_PROFILE_REGEX,
- FACEBOOK_PROFILE_REGEX_GLOBAL,
+ FACEBOOK_REGEX,
+ FACEBOOK_REGEX_GLOBAL,
};
diff --git a/test/utils_social.js b/test/utils_social.js
index 59dfeb986..fedda5bcd 100644
--- a/test/utils_social.js
+++ b/test/utils_social.js
@@ -10,730 +10,741 @@ const { social } = Apify.utils;
/* global process, describe, it */
-describe('utils.social.emailsFromText()', () => {
- const testEmailsFromText = (text, phones) => {
- expect(social.emailsFromText(text)).to.eql(phones);
- };
-
- it('works with arg with no emails or invalid', () => {
- expect(social.emailsFromText()).to.eql([]);
- testEmailsFromText('', []);
- testEmailsFromText(null, []);
- testEmailsFromText(undefined, []);
- testEmailsFromText({}, []);
- testEmailsFromText(' ', []);
- testEmailsFromText(' \n\n\r\t\n ', []);
- });
+describe('utils.social', () => {
+ describe('emailsFromText()', () => {
+ const testEmailsFromText = (text, phones) => {
+ expect(social.emailsFromText(text)).to.eql(phones);
+ };
+
+ it('works with arg with no emails or invalid', () => {
+ expect(social.emailsFromText()).to.eql([]);
+ testEmailsFromText('', []);
+ testEmailsFromText(null, []);
+ testEmailsFromText(undefined, []);
+ testEmailsFromText({}, []);
+ testEmailsFromText(' ', []);
+ testEmailsFromText(' \n\n\r\t\n ', []);
+ });
+
+ it('extracts emails correctly', () => {
+ testEmailsFromText(' [email protected] ', ['[email protected]']);
+
+ testEmailsFromText(`
+ `, [
+ ]);
+
+ testEmailsFromText(`
+ this'is'also'valid'[email protected]
+ not @ an.email.com
+ @also.not.an.email
+ `, [
+ 'this\'is\'also\'valid\'[email protected]',
+ ]);
- it('extracts emails correctly', () => {
- testEmailsFromText(' [email protected] ', ['[email protected]']);
-
- testEmailsFromText(`
- `, [
- ]);
-
- testEmailsFromText(`
- this'is'also'valid'[email protected]
- not @ an.email.com
- @also.not.an.email
- `, [
- 'this\'is\'also\'valid\'[email protected]',
- ]);
-
- testEmailsFromText(' [email protected] ',
+ testEmailsFromText(' [email protected] ',
+ });
});
-});
+ describe('emailsFromUrls()', () => {
+ it('throws on invalid arg', () => {
+ expect(() => {
+ social.emailsFromUrls();
+ }).to.throw(/must be an array/);
+
+ expect(() => {
+ social.emailsFromUrls({});
+ }).to.throw(/must be an array/);
-describe('utils.social.emailsFromUrls()', () => {
- it('throws on invalid arg', () => {
- expect(() => {
- social.emailsFromUrls();
- }).to.throw(/must be an array/);
+ expect(() => {
+ social.emailsFromUrls('fwefwef');
+ }).to.throw(/must be an array/);
- expect(() => {
- social.emailsFromUrls({});
- }).to.throw(/must be an array/);
+ expect(() => {
+ social.emailsFromUrls(12345);
+ }).to.throw(/must be an array/);
+ });
- expect(() => {
- social.emailsFromUrls('fwefwef');
- }).to.throw(/must be an array/);
+ it('extracts emails correctly', () => {
+ expect(social.emailsFromUrls([])).to.eql([]);
+ expect(social.emailsFromUrls([1, 2, {}, 'fwef', null, undefined])).to.eql([]);
- expect(() => {
- social.emailsFromUrls(12345);
- }).to.throw(/must be an array/);
- });
+ expect(social.emailsFromUrls([
+ 'mailto:[email protected]',
+ ])).to.eql([
+ ]);
+
+ expect(social.emailsFromUrls([
+ 'http://www.example.com',
+ 'mailto:[email protected]',
+ 'mailto:[email protected]',
+ '',
+ '\n\n\n',
+ ])).to.eql([
+ ]);
- it('extracts emails correctly', () => {
- expect(social.emailsFromUrls([])).to.eql([]);
- expect(social.emailsFromUrls([1, 2, {}, 'fwef', null, undefined])).to.eql([]);
-
- expect(social.emailsFromUrls([
- 'mailto:[email protected]',
- ])).to.eql([
- ]);
-
- expect(social.emailsFromUrls([
- 'http://www.example.com',
- 'mailto:[email protected]',
- 'mailto:[email protected]',
- '',
- '\n\n\n',
- ])).to.eql([
- ]);
-
- expect(social.emailsFromUrls([
- 'http://www.example.com',
- 'mailto:[email protected]',
- 'mailto:[email protected]',
- '',
- '\n\n\n',
- ])).to.eql([
- ]);
+ expect(social.emailsFromUrls([
+ 'http://www.example.com',
+ 'mailto:[email protected]',
+ 'mailto:[email protected]',
+ '',
+ '\n\n\n',
+ ])).to.eql([
+ ]);
+ });
});
-});
+ describe('phonesFromText()', () => {
+ const testPhonesFromText = (text, phones) => {
+ expect(social.phonesFromText(text)).to.eql(phones);
+ };
-describe('utils.social.phonesFromText()', () => {
- const testPhonesFromText = (text, phones) => {
- expect(social.phonesFromText(text)).to.eql(phones);
- };
+ it('works with arg with no phones or invalid', () => {
+ expect(social.phonesFromText()).to.eql([]);
- it('works with arg with no phones or invalid', () => {
- expect(social.phonesFromText()).to.eql([]);
+ testPhonesFromText('', []);
+ testPhonesFromText(null, []);
+ testPhonesFromText(undefined, []);
+ testPhonesFromText({}, []);
+ testPhonesFromText(' ', []);
+ testPhonesFromText(' \n\n\r\t\n ', []);
+ });
- testPhonesFromText('', []);
- testPhonesFromText(null, []);
- testPhonesFromText(undefined, []);
- testPhonesFromText({}, []);
- testPhonesFromText(' ', []);
- testPhonesFromText(' \n\n\r\t\n ', []);
- });
+ it('extracts phones correctly', () => {
+ testPhonesFromText(`
+ +420775123456 +420775123456
+
+ +420 775 123 456
+
+ 775123456 775123456 \n\n
+ 00420775123456
+ 1234567 1234567890
+ +44 7911 123456
+ `, [
+ '+420775123456',
+ '+420775123456',
+ '+420 775 123 456',
+ '775123456',
+ '775123456',
+ '00420775123456',
+ '1234567',
+ '1234567890',
+ '+44 7911 123456',
+ ]);
- it('extracts phones correctly', () => {
- testPhonesFromText(`
- +420775123456 +420775123456
- 775123456 775123456 \n\n
- 00420775123456
- 1234567 1234567890
- +44 7911 123456
- `, [
- '+420775123456',
- '+420775123456',
- '775123456',
- '775123456',
- '00420775123456',
- '1234567',
- '1234567890',
- '+44 7911 123456',
- ]);
-
- testPhonesFromText(`
- 413-577-1234
- 00413-577-1234
- 981-413-777-8888
- 413.233.2343 +413.233.2343 or 413 233 2343
- 562-3113
- 123456789 401 311 7898 123456789
- `, [
- '413-577-1234',
- '00413-577-1234',
- '981-413-777-8888',
- '413.233.2343',
- '+413.233.2343',
- '413 233 2343',
- '562-3113',
- '123456789',
- '401 311 7898',
- '123456789',
- ]);
-
- testPhonesFromText(`
- 1 (413) 555-2378
- +1 (413) 555-2378
- 1(413)555-2378
- 001 (413) 555-2378 1 (413) 555 2378
- 1(413)555-2378 or 1(413)555.2378 or 1 (413) 555-2378 or 1 (413) 555 2378 or (303) 494-2320
- `, [
- '1 (413) 555-2378',
- '+1 (413) 555-2378',
- '1(413)555-2378',
- '001 (413) 555-2378',
- '1 (413) 555 2378',
- '1(413)555-2378',
- '1(413)555.2378',
- '1 (413) 555-2378',
- '1 (413) 555 2378',
- '(303) 494-2320',
- ]);
-
- testPhonesFromText(`
- 123-456-789
- 123 456 789
- 123.456.789
- 123.456.789.123
- +123.456.789.123
- `, [
- '123-456-789',
- '123 456 789',
- '123.456.789',
- '123.456.789.123',
- '+123.456.789.123',
- ]);
-
- testPhonesFromText(`
- (000)000-0000
- (000)000 0000
- (000)000.0000
- (000) 000-0000
- (000) 000 0000
- (000) 000.0000
- `, [
- '(000)000-0000',
- '(000)000 0000',
- '(000)000.0000',
- '(000) 000-0000',
- '(000) 000 0000',
- '(000) 000.0000',
- ]);
-
- testPhonesFromText(`
- 000-0000
- 000 0000
- 000.0000
-
- 0000000
- 0000000000
- (000)0000000
- `, [
- '000-0000',
- '000 0000',
- '000.0000',
- '0000000',
- '0000000000',
- '(000)0000000',
- ]);
- });
+ testPhonesFromText(`
+ 413-577-1234
+ 00413-577-1234
+ 981-413-777-8888
+ 413.233.2343 +413.233.2343 or 413 233 2343
+ 562-3113
+ 123456789 401 311 7898 123456789
+ `, [
+ '413-577-1234',
+ '00413-577-1234',
+ '981-413-777-8888',
+ '413.233.2343',
+ '+413.233.2343',
+ '413 233 2343',
+ '562-3113',
+ '123456789',
+ '401 311 7898',
+ '123456789',
+ ]);
- it('skips invalid phones', () => {
- testPhonesFromText(`
- 2018-10-11 123
- 456789 345
- 1 2 3 4 5 6 7 8
- `, []);
+ testPhonesFromText(`
+ 1 (413) 555-2378
+ +1 (413) 555-2378
+ 1(413)555-2378
+ 001 (413) 555-2378 1 (413) 555 2378
+ 1(413)555-2378 or 1(413)555.2378 or 1 (413) 555-2378 or 1 (413) 555 2378 or (303) 494-2320
+ `, [
+ '1 (413) 555-2378',
+ '+1 (413) 555-2378',
+ '1(413)555-2378',
+ '001 (413) 555-2378',
+ '1 (413) 555 2378',
+ '1(413)555-2378',
+ '1(413)555.2378',
+ '1 (413) 555-2378',
+ '1 (413) 555 2378',
+ '(303) 494-2320',
+ ]);
+
+ testPhonesFromText(`
+ 123-456-789
+ 123 456 789
+ 123.456.789
+ 123.456.789.123
+ +123.456.789.123
+ `, [
+ '123-456-789',
+ '123 456 789',
+ '123.456.789',
+ '123.456.789.123',
+ '+123.456.789.123',
+ ]);
+
+ testPhonesFromText(`
+ (000)000-0000
+ (000)000 0000
+ (000)000.0000
+ (000) 000-0000
+ (000) 000 0000
+ (000) 000.0000
+ `, [
+ '(000)000-0000',
+ '(000)000 0000',
+ '(000)000.0000',
+ '(000) 000-0000',
+ '(000) 000 0000',
+ '(000) 000.0000',
+ ]);
+
+ testPhonesFromText(`
+ 000-0000
+ 000 0000
+ 000.0000
+
+ 0000000
+ 0000000000
+ (000)0000000
+ `, [
+ '000-0000',
+ '000 0000',
+ '000.0000',
+ '0000000',
+ '0000000000',
+ '(000)0000000',
+ ]);
+ });
+
+ it('skips invalid phones', () => {
+ testPhonesFromText(`
+ 2018-10-11 123
+ 456789 345
+ 1 2 3 4 5 6 7 8
+ `, []);
+ });
});
-});
+ describe('phonesFromUrls()', () => {
+ it('throws on invalid arg', () => {
+ expect(() => {
+ social.phonesFromUrls();
+ }).to.throw(/must be an array/);
-describe('utils.social.phonesFromUrls()', () => {
- it('throws on invalid arg', () => {
- expect(() => {
- social.phonesFromUrls();
- }).to.throw(/must be an array/);
+ expect(() => {
+ social.phonesFromUrls({});
+ }).to.throw(/must be an array/);
- expect(() => {
- social.phonesFromUrls({});
- }).to.throw(/must be an array/);
+ expect(() => {
+ social.phonesFromUrls('fwefwef');
+ }).to.throw(/must be an array/);
- expect(() => {
- social.phonesFromUrls('fwefwef');
- }).to.throw(/must be an array/);
+ expect(() => {
+ social.phonesFromUrls(12345);
+ }).to.throw(/must be an array/);
+ });
- expect(() => {
- social.phonesFromUrls(12345);
- }).to.throw(/must be an array/);
- });
+ it('extracts phones correctly', () => {
+ expect(social.phonesFromUrls([])).to.eql([]);
+ expect(social.phonesFromUrls([1, 2, {}, 'fwef', null, undefined])).to.eql([]);
+
+ expect(social.phonesFromUrls([
+ 'tel:12345678',
+ 'tel:/22345678', //
+ 'tel://32345678',
+ 'phone:42345678', //
+ 'phone:/52345678',
+ 'phone://62345678',
+ 'telephone:72345678',
+ 'telephone:/82345678',
+ 'telephone://92345678',
+ ])).to.eql([
+ '12345678',
+ '22345678',
+ '32345678',
+ '42345678',
+ '52345678',
+ '62345678',
+ '72345678',
+ '82345678',
+ '92345678',
+ ]);
- it('extracts phones correctly', () => {
- expect(social.phonesFromUrls([])).to.eql([]);
- expect(social.phonesFromUrls([1, 2, {}, 'fwef', null, undefined])).to.eql([]);
-
- expect(social.phonesFromUrls([
- 'tel:12345678',
- 'tel:/22345678', //
- 'tel://32345678',
- 'phone:42345678', //
- 'phone:/52345678',
- 'phone://62345678',
- 'telephone:72345678',
- 'telephone:/82345678',
- 'telephone://92345678',
- ])).to.eql([
- '12345678',
- '22345678',
- '32345678',
- '42345678',
- '52345678',
- '62345678',
- '72345678',
- '82345678',
- '92345678',
- ]);
-
- expect(social.phonesFromUrls([
- 'https://www.example.com',
- 'ftp://www.example.com',
- '1234567',
- '+42055555567',
- 'tel://+42012345678',
- 'tel://+420.123.456',
- 'http://www.example.com',
- ])).to.eql([
- '+42012345678',
- '+420.123.456',
- ]);
+ expect(social.phonesFromUrls([
+ 'https://www.example.com',
+ 'ftp://www.example.com',
+ '1234567',
+ '+42055555567',
+ 'tel://+42012345678',
+ 'tel://+420.123.456',
+ 'http://www.example.com',
+ ])).to.eql([
+ '+42012345678',
+ '+420.123.456',
+ ]);
+ });
});
-});
-describe('utils.social.parseHandlesFromHtml()', () => {
- const EMPTY_RESULT = {
- emails: [],
- phones: [],
- linkedInProfiles: [],
- twitterProfiles: [],
- instagramProfiles: [],
- facebookProfiles: [],
- };
-
- it('handles invalid arg', () => {
- expect(social.parseHandlesFromHtml()).to.eql(EMPTY_RESULT);
- expect(social.parseHandlesFromHtml(undefined)).to.eql(EMPTY_RESULT);
- expect(social.parseHandlesFromHtml(null)).to.eql(EMPTY_RESULT);
- expect(social.parseHandlesFromHtml({})).to.eql(EMPTY_RESULT);
- expect(social.parseHandlesFromHtml(1234)).to.eql(EMPTY_RESULT);
- });
+ describe('parseHandlesFromHtml()', () => {
+ const EMPTY_RESULT = {
+ emails: [],
+ phones: [],
+ linkedIns: [],
+ twitters: [],
+ instagrams: [],
+ facebooks: [],
+ };
+
+ it('handles invalid arg', () => {
+ expect(social.parseHandlesFromHtml()).to.eql(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml(undefined)).to.eql(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml(null)).to.eql(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml({})).to.eql(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml(1234)).to.eql(EMPTY_RESULT);
+ });
- it('works', () => {
- expect(social.parseHandlesFromHtml('')).to.eql(EMPTY_RESULT);
- expect(social.parseHandlesFromHtml(' ')).to.eql(EMPTY_RESULT);
-
- expect(social.parseHandlesFromHtml(`
- <html>
- <head>
- <title>Bla</title>
- </head>
- <a>
- [email protected] testing skipping duplicates xxx@blabla
- <p>carl&#64;example.com</p>
- <a href="mailto:[email protected]"></a>
- <a href="mailto:david&#64;example.com"></a>
-
- <a href="[email protected]"></a>
- <img src="http://somewhere.com/ [email protected] " />
- <a href="http://somewhere.com/ [email protected] "></a>
-
- &#43;420775222222
- +4207751111111
- +4207751111111 test duplicate
- 1 2 3 4 5 6 7 8 9 0
- <a href="skip.this.one: +42099999999"></a>
- <a href="tel://+42077533333"></a>
-
- https://www.linkedin.com/in/bobnewman
- https://www.linkedin.com/in/alicenewman/
- https://www.linkedin.com/in/alicenewman/ duplicate
- http://www.linkedin.com/in/nohttps/
- https://cz.linkedin.com/in/somecountry
- https://www.linkedin.com/in/carl-newman/ignored-sub-link
- https://www.linkedin.com/in/first-last-123456a
- <a href="https://www.linkedin.com/in/jancurn">Profile</a>
- <a href="https://www.linkedin.com/in/carl-newman-5555555a/detail/recent-activity/">Sub-link</a>
-
- https://www.instagram.com/old_prague/
- https://www.instagram.com/old_prague/ duplicate
- instagram.com/old_prague
- https://www.instagram.com/newyorkarea/
- <a href="https://www.instagram.com/york">link</a>
- <a href="https://www.instagram.com/york2/something">sub-link</a>
-
- <a href="twitter.com/betasomething">link</a>
- https://www.twitter.com/apify
- https://www.twitter.com/apify duplicate
- <a href="twitter.com/cblabla/sub-dir/">link</a>
-
- <a href="facebook.com/carl.username123/sub-dir/">link</a>
- https://www.facebook.com/bob.username123/
- https://www.facebook.com/bob.username123/ duplicate
- http://www.facebook.com/alice.username123
- <a href="https://www.facebook.com/profile.php?id=1155802082&xxx=5">link x</a>
- <a href="fb.com/dada5678?query=1">link</a>
-
- </body>
- </html>
- `)).to.eql({
- phones: ['+4207751111111', '+420775222222', '+42077533333'],
- linkedInProfiles: [
- 'http://www.linkedin.com/in/nohttps/',
- 'https://cz.linkedin.com/in/somecountry',
- 'https://www.linkedin.com/in/alicenewman/',
- 'https://www.linkedin.com/in/bobnewman',
- 'https://www.linkedin.com/in/carl-newman-5555555a/',
- 'https://www.linkedin.com/in/carl-newman/',
- 'https://www.linkedin.com/in/first-last-123456a',
- 'https://www.linkedin.com/in/jancurn',
- ],
- instagramProfiles: [
- 'https://www.instagram.com/newyorkarea/',
- 'https://www.instagram.com/old_prague/',
- 'https://www.instagram.com/york',
- 'https://www.instagram.com/york2/',
- 'instagram.com/old_prague',
- ],
- twitterProfiles: [
- 'https://www.twitter.com/apify',
- 'twitter.com/betasomething',
- 'twitter.com/cblabla/',
- ],
- facebookProfiles: [
- 'facebook.com/carl.username123/',
- 'fb.com/dada5678',
- 'http://www.facebook.com/alice.username123',
- 'https://www.facebook.com/bob.username123/',
- 'https://www.facebook.com/profile.php?id=1155802082',
- ],
+ it('works', () => {
+ expect(social.parseHandlesFromHtml('')).to.eql(EMPTY_RESULT);
+ expect(social.parseHandlesFromHtml(' ')).to.eql(EMPTY_RESULT);
+
+ expect(social.parseHandlesFromHtml(`
+ <html>
+ <head>
+ <title>Bla</title>
+ </head>
+ <a>
+ [email protected] testing skipping duplicates xxx@blabla
+ <p>carl&#64;example.com</p>
+ <a href="mailto:[email protected]"></a>
+ <a href="mailto:david&#64;example.com"></a>
+
+ <a href="[email protected]"></a>
+ <img src="http://somewhere.com/ [email protected] " />
+ <a href="http://somewhere.com/ [email protected] "></a>
+
+ &#43;420775222222
+ +4207751111111
+ +4207751111111 test duplicate
+ 1 2 3 4 5 6 7 8 9 0
+ <a href="skip.this.one: +42099999999"></a>
+ <a href="tel://+42077533333"></a>
+
+ https://www.linkedin.com/in/bobnewman
+ https://www.linkedin.com/in/alicenewman/
+ https://www.linkedin.com/in/alicenewman/ duplicate
+ http://www.linkedin.com/in/nohttps/
+ https://cz.linkedin.com/in/somecountry
+ https://www.linkedin.com/in/carl-newman/ignored-sub-link
+ https://www.linkedin.com/in/first-last-123456a
+ <a href="https://www.linkedin.com/in/jancurn">Profile</a>
+ <a href="https://www.linkedin.com/in/carl-newman-5555555a/detail/recent-activity/">Sub-link</a>
+
+ https://www.instagram.com/old_prague/
+ https://www.instagram.com/old_prague/ duplicate
+ instagram.com/old_prague
+ https://www.instagram.com/newyorkarea/
+ <a href="https://www.instagram.com/york">link</a>
+ <a href="https://www.instagram.com/york2/something">sub-link</a>
+
+ <a href="twitter.com/betasomething">link</a>
+ https://www.twitter.com/apify
+ https://www.twitter.com/apify duplicate
+ <a href="twitter.com/cblabla/sub-dir/">link</a>
+
+ <a href="facebook.com/carl.username123/sub-dir/">link</a>
+ https://www.facebook.com/bob.username123/
+ https://www.facebook.com/bob.username123/ duplicate
+ http://www.facebook.com/alice.username123
+ <a href="https://www.facebook.com/profile.php?id=1155802082&xxx=5">link x</a>
+ <a href="fb.com/dada5678?query=1">link</a>
+
+ </body>
+ </html>
+ `)).to.eql({
+ phones: ['+4207751111111', '+420775222222', '+42077533333'],
+ linkedIns: [
+ 'http://www.linkedin.com/in/nohttps/',
+ 'https://cz.linkedin.com/in/somecountry',
+ 'https://www.linkedin.com/in/alicenewman/',
+ 'https://www.linkedin.com/in/bobnewman',
+ 'https://www.linkedin.com/in/carl-newman-5555555a/',
+ 'https://www.linkedin.com/in/carl-newman/',
+ 'https://www.linkedin.com/in/first-last-123456a',
+ 'https://www.linkedin.com/in/jancurn',
+ ],
+ instagrams: [
+ 'https://www.instagram.com/newyorkarea/',
+ 'https://www.instagram.com/old_prague/',
+ 'https://www.instagram.com/york',
+ 'https://www.instagram.com/york2/',
+ 'instagram.com/old_prague',
+ ],
+ twitters: [
+ 'https://www.twitter.com/apify',
+ 'twitter.com/betasomething',
+ 'twitter.com/cblabla/',
+ ],
+ facebooks: [
+ 'facebook.com/carl.username123/',
+ 'fb.com/dada5678',
+ 'http://www.facebook.com/alice.username123',
+ 'https://www.facebook.com/bob.username123/',
+ 'https://www.facebook.com/profile.php?id=1155802082',
+ ],
+ });
});
- });
- it('data is set correctly', () => {
- const data = {};
- social.parseHandlesFromHtml(`
- <html>
- <head>
- <title>Bla</title>
- </head>
- <body>
- Body content
- </body>
- </html>
- `, data);
-
- expect(data.$('body').text().trim()).to.eql('Body content');
- expect(data.text.trim()).to.eql('Body content');
+ it('data is set correctly', () => {
+ const data = {};
+ social.parseHandlesFromHtml(`
+ <html>
+ <head>
+ <title>Bla</title>
+ </head>
+ <body>
+ Body content
+ </body>
+ </html>
+ `, data);
+
+ expect(data.$('body').text().trim()).to.eql('Body content');
+ expect(data.text.trim()).to.eql('Body content');
+ });
});
-});
-describe('utils.social', () => {
- it('EMAIL_REGEX', () => {
- expect(_.isRegExp(social.EMAIL_REGEX)).to.eql(true);
- expect(_.isRegExp(social.EMAIL_REGEX_GLOBAL)).to.eql(true);
+ describe('EMAIL_REGEX', () => {
+ it('works', () => {
+ expect(_.isRegExp(social.EMAIL_REGEX)).to.eql(true);
+ expect(_.isRegExp(social.EMAIL_REGEX_GLOBAL)).to.eql(true);
- expect(social.EMAIL_REGEX.flags).to.eql('i');
- expect(social.EMAIL_REGEX_GLOBAL.flags).to.eql('gi');
+ expect(social.EMAIL_REGEX.flags).to.eql('i');
+ expect(social.EMAIL_REGEX_GLOBAL.flags).to.eql('gi');
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
- expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
+ expect(social.EMAIL_REGEX.test('[email protected]')).to.eql(true);
- expect(social.EMAIL_REGEX.test('a [email protected]')).to.eql(false);
- expect(social.EMAIL_REGEX.test('[email protected] [email protected]')).to.eql(false);
- expect(social.EMAIL_REGEX.test('')).to.eql(false);
- expect(social.EMAIL_REGEX.test('dummy')).to.eql(false);
+ expect(social.EMAIL_REGEX.test('a [email protected]')).to.eql(false);
+ expect(social.EMAIL_REGEX.test('[email protected] [email protected]')).to.eql(false);
+ expect(social.EMAIL_REGEX.test('')).to.eql(false);
+ expect(social.EMAIL_REGEX.test('dummy')).to.eql(false);
- expect(social.EMAIL_REGEX_GLOBAL.test('[email protected]')).to.eql(true);
- expect('[email protected] [email protected]'.match(social.EMAIL_REGEX_GLOBAL))
+ expect(social.EMAIL_REGEX_GLOBAL.test('[email protected]')).to.eql(true);
+ expect('[email protected] [email protected]'.match(social.EMAIL_REGEX_GLOBAL))
- expect(''.match(social.EMAIL_REGEX_GLOBAL)).to.eql(null);
- expect(' dummy '.match(social.EMAIL_REGEX_GLOBAL)).to.eql(null);
+ expect(''.match(social.EMAIL_REGEX_GLOBAL)).to.eql(null);
+ expect(' dummy '.match(social.EMAIL_REGEX_GLOBAL)).to.eql(null);
+ });
});
- it('LINKEDIN_PROFILE_REGEX', () => {
- expect(_.isRegExp(social.LINKEDIN_PROFILE_REGEX)).to.eql(true);
- expect(_.isRegExp(social.LINKEDIN_PROFILE_REGEX_GLOBAL)).to.eql(true);
-
- expect(social.LINKEDIN_PROFILE_REGEX.flags).to.eql('i');
- expect(social.LINKEDIN_PROFILE_REGEX_GLOBAL.flags).to.eql('gi');
-
- expect(social.LINKEDIN_PROFILE_REGEX.test('https://www.linkedin.com/in/bobnewman')).to.eql(true);
- expect(social.LINKEDIN_PROFILE_REGEX.test('https://www.linkedin.com/in/bobnewman/')).to.eql(true);
- expect(social.LINKEDIN_PROFILE_REGEX.test('http://www.linkedin.com/in/bobnewman')).to.eql(true);
- expect(social.LINKEDIN_PROFILE_REGEX.test('http://ie.linkedin.com/in/bobnewman')).to.eql(true);
- expect(social.LINKEDIN_PROFILE_REGEX.test('https://linkedin.com/in/bobnewman')).to.eql(true);
- expect(social.LINKEDIN_PROFILE_REGEX.test('https://www.linkedin.com/in/carl-newman')).to.eql(true);
- expect(social.LINKEDIN_PROFILE_REGEX.test('https://www.linkedin.com/in/first-last-123456a')).to.eql(true);
- expect(social.LINKEDIN_PROFILE_REGEX.test('https://www.linkedin.com/in/first_last_1%23456a')).to.eql(true);
- expect(social.LINKEDIN_PROFILE_REGEX.test('HTTPS://WWW.LINKEDIN.COM/IN/CARL-NEWMAN')).to.eql(true);
- expect(social.LINKEDIN_PROFILE_REGEX.test('www.linkedin.com/in/bobnewman')).to.eql(true);
- expect(social.LINKEDIN_PROFILE_REGEX.test('linkedin.com/in/bobnewman')).to.eql(true);
-
- // Test there is just on matching group for the username
- expect('https://www.linkedin.com/in/bobnewman/'.match(social.LINKEDIN_PROFILE_REGEX)[1]).to.eql('bobnewman');
- expect('http://www.linkedin.com/in/bobnewman'.match(social.LINKEDIN_PROFILE_REGEX)[1]).to.eql('bobnewman');
- expect('www.linkedin.com/in/bobnewman/'.match(social.LINKEDIN_PROFILE_REGEX)[1]).to.eql('bobnewman');
- expect('linkedin.com/in/bobnewman'.match(social.LINKEDIN_PROFILE_REGEX)[1]).to.eql('bobnewman');
-
- expect(social.LINKEDIN_PROFILE_REGEX.test('')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('dummy')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('a https://www.linkedin.com/in/bobnewman')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('https://linkedin.com/in/bobnewman/sub-page')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('xhttps://www.linkedin.com/in/carl-newman')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('0https://www.linkedin.com/in/carl-newman')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('_https://www.linkedin.com/in/carl-newman')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('xlinkedin.com/in/bobnewman')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('_linkedin.com/in/bobnewman')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('0linkedin.com/in/bobnewman')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('https://www.linkedin.com/in/bobnewman/?param=bla')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('://linkedin.com/in/bobnewman')).to.eql(false);
- expect(social.LINKEDIN_PROFILE_REGEX.test('https://www.linkedin.com/in/bob https://www.linkedin.com/in/alice')).to.eql(false);
-
- expect(social.LINKEDIN_PROFILE_REGEX_GLOBAL.test('https://www.linkedin.com/in/bobnewman')).to.eql(true);
- expect(`
- https://www.linkedin.com/in/bobnewman
- "http://ie.linkedin.com/in/alicenewman"
- https://www.linkedin.com/in/someverylongnamesomeverylongnamesomeverylongnamesomeverylongnamesomeverylongnamesomeverylongname
- linkedin.com/in/carlnewman
- `.match(social.LINKEDIN_PROFILE_REGEX_GLOBAL))
- .to.eql([
- 'https://www.linkedin.com/in/bobnewman',
- 'http://ie.linkedin.com/in/alicenewman',
- 'linkedin.com/in/carlnewman',
- ]);
- expect(`
- -https://www.linkedin.com/in/bobnewman/sub-dir
- :http://ie.linkedin.com/in/alicenewman?param=1
- xlinkedin.com/in/carlnewman
- alinkedin.com/in/carlnewman
- _linkedin.com/in/carlnewman
- `.match(social.LINKEDIN_PROFILE_REGEX_GLOBAL))
- .to.eql([
- 'https://www.linkedin.com/in/bobnewman/',
- 'http://ie.linkedin.com/in/alicenewman',
- ]);
- expect(''.match(social.LINKEDIN_PROFILE_REGEX_GLOBAL)).to.eql(null);
+ describe('LINKEDIN_REGEX', () => {
+ it('works', () => {
+ expect(_.isRegExp(social.LINKEDIN_REGEX)).to.eql(true);
+ expect(_.isRegExp(social.LINKEDIN_REGEX_GLOBAL)).to.eql(true);
+
+ expect(social.LINKEDIN_REGEX.flags).to.eql('i');
+ expect(social.LINKEDIN_REGEX_GLOBAL.flags).to.eql('gi');
+
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bobnewman')).to.eql(true);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bobnewman/')).to.eql(true);
+ expect(social.LINKEDIN_REGEX.test('http://www.linkedin.com/in/bobnewman')).to.eql(true);
+ expect(social.LINKEDIN_REGEX.test('http://ie.linkedin.com/in/bobnewman')).to.eql(true);
+ expect(social.LINKEDIN_REGEX.test('https://linkedin.com/in/bobnewman')).to.eql(true);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/carl-newman')).to.eql(true);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/first-last-123456a')).to.eql(true);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/first_last_1%23456a')).to.eql(true);
+ expect(social.LINKEDIN_REGEX.test('HTTPS://WWW.LINKEDIN.COM/IN/CARL-NEWMAN')).to.eql(true);
+ expect(social.LINKEDIN_REGEX.test('www.linkedin.com/in/bobnewman')).to.eql(true);
+ expect(social.LINKEDIN_REGEX.test('linkedin.com/in/bobnewman')).to.eql(true);
+
+ // Test there is just on matching group for the username
+ expect('https://www.linkedin.com/in/bobnewman/'.match(social.LINKEDIN_REGEX)[1]).to.eql('bobnewman');
+ expect('http://www.linkedin.com/in/bobnewman'.match(social.LINKEDIN_REGEX)[1]).to.eql('bobnewman');
+ expect('www.linkedin.com/in/bobnewman/'.match(social.LINKEDIN_REGEX)[1]).to.eql('bobnewman');
+ expect('linkedin.com/in/bobnewman'.match(social.LINKEDIN_REGEX)[1]).to.eql('bobnewman');
+
+ expect(social.LINKEDIN_REGEX.test('')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('dummy')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('a https://www.linkedin.com/in/bobnewman')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('https://linkedin.com/in/bobnewman/sub-page')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('xhttps://www.linkedin.com/in/carl-newman')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('0https://www.linkedin.com/in/carl-newman')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('_https://www.linkedin.com/in/carl-newman')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('xlinkedin.com/in/bobnewman')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('_linkedin.com/in/bobnewman')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('0linkedin.com/in/bobnewman')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bobnewman/?param=bla')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('://linkedin.com/in/bobnewman')).to.eql(false);
+ expect(social.LINKEDIN_REGEX.test('https://www.linkedin.com/in/bob https://www.linkedin.com/in/alice')).to.eql(false);
+
+ expect(social.LINKEDIN_REGEX_GLOBAL.test('https://www.linkedin.com/in/bobnewman')).to.eql(true);
+ expect(`
+ https://www.linkedin.com/in/bobnewman
+ "http://ie.linkedin.com/in/alicenewman"
+ https://www.linkedin.com/in/someverylongnamesomeverylongnamesomeverylongnamesomeverylongnamesomeverylongnamesomeverylongname
+ linkedin.com/in/carlnewman
+ `.match(social.LINKEDIN_REGEX_GLOBAL))
+ .to.eql([
+ 'https://www.linkedin.com/in/bobnewman',
+ 'http://ie.linkedin.com/in/alicenewman',
+ 'linkedin.com/in/carlnewman',
+ ]);
+ expect(`
+ -https://www.linkedin.com/in/bobnewman/sub-dir
+ :http://ie.linkedin.com/in/alicenewman?param=1
+ xlinkedin.com/in/carlnewman
+ alinkedin.com/in/carlnewman
+ _linkedin.com/in/carlnewman
+ `.match(social.LINKEDIN_REGEX_GLOBAL))
+ .to.eql([
+ 'https://www.linkedin.com/in/bobnewman/',
+ 'http://ie.linkedin.com/in/alicenewman',
+ ]);
+ expect(''.match(social.LINKEDIN_REGEX_GLOBAL)).to.eql(null);
+ });
});
- it('INSTAGRAM_PROFILE_REGEX', () => {
- expect(_.isRegExp(social.INSTAGRAM_PROFILE_REGEX)).to.eql(true);
- expect(_.isRegExp(social.INSTAGRAM_PROFILE_REGEX_GLOBAL)).to.eql(true);
-
- expect(social.INSTAGRAM_PROFILE_REGEX.flags).to.eql('i');
- expect(social.INSTAGRAM_PROFILE_REGEX_GLOBAL.flags).to.eql('gi');
-
- expect(social.INSTAGRAM_PROFILE_REGEX.test('https://www.instagram.com/old_prague')).to.eql(true);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('https://www.instagram.com/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('http://www.instagram.com/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('https://instagram.com/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('HTTPS://INSTAGR.AM/OLD_PRAGUE/')).to.eql(true);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('http://instagr.am/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('https://www.instagr.am/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('www.instagram.com/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('instagram.com/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('www.instagr.am/old_prague/')).to.eql(true);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('instagr.am/old_prague/')).to.eql(true);
-
- // Test there is just on matching group for the username
- expect('https://www.instagram.com/old_prague/'.match(social.INSTAGRAM_PROFILE_REGEX)[1]).to.eql('old_prague');
- expect('http://www.instagram.com/old_prague/'.match(social.INSTAGRAM_PROFILE_REGEX)[1]).to.eql('old_prague');
- expect('www.instagram.com/old_prague'.match(social.INSTAGRAM_PROFILE_REGEX)[1]).to.eql('old_prague');
- expect('instagram.com/old_prague'.match(social.INSTAGRAM_PROFILE_REGEX)[1]).to.eql('old_prague');
-
- expect(social.INSTAGRAM_PROFILE_REGEX.test('')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('dummy')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('a https://www.instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('https://www.instagram.com/a')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('https://www.instagram.com/old_prague/sub-page')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('xhttps://www.instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('0https://www.instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('_https://www.instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('xinstagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('_instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('0instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('https://www.instagram.com/old_prague/?param=bla')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('://www.instagram.com/old_prague')).to.eql(false);
- expect(social.INSTAGRAM_PROFILE_REGEX.test('http://www.instagram.com/old_prague http://www.instagram.com/old_brno')).to.eql(false);
-
- expect(social.INSTAGRAM_PROFILE_REGEX_GLOBAL.test('https://www.instagram.com/old_prague')).to.eql(true);
- expect(`
- https://www.instagram.com/old_prague
- https://www.instagram.com/someverylongusernamethatisnotgood
- "instagram.com/old_brno"
- http://instagr.am/old_plzen
- `.match(social.INSTAGRAM_PROFILE_REGEX_GLOBAL))
- .to.eql([
- 'https://www.instagram.com/old_prague',
- 'instagram.com/old_brno',
- 'http://instagr.am/old_plzen',
- ]);
- expect(`
- -https://www.instagram.com/old_prague/sub-dir
- instagr.am/old_plzen?param=1
- xinstagram.com/old_brno
- ainstagram.com/old_brno
- _instagram.com/old_brno
- `.match(social.INSTAGRAM_PROFILE_REGEX_GLOBAL))
- .to.eql([
- 'https://www.instagram.com/old_prague/',
- 'instagr.am/old_plzen',
- ]);
- expect(''.match(social.INSTAGRAM_PROFILE_REGEX_GLOBAL)).to.eql(null);
+ describe('INSTAGRAM_REGEX', () => {
+ it('works', () => {
+ expect(_.isRegExp(social.INSTAGRAM_REGEX)).to.eql(true);
+ expect(_.isRegExp(social.INSTAGRAM_REGEX_GLOBAL)).to.eql(true);
+
+ expect(social.INSTAGRAM_REGEX.flags).to.eql('i');
+ expect(social.INSTAGRAM_REGEX_GLOBAL.flags).to.eql('gi');
+
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague')).to.eql(true);
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague/')).to.eql(true);
+ expect(social.INSTAGRAM_REGEX.test('http://www.instagram.com/old_prague/')).to.eql(true);
+ expect(social.INSTAGRAM_REGEX.test('https://instagram.com/old_prague/')).to.eql(true);
+ expect(social.INSTAGRAM_REGEX.test('HTTPS://INSTAGR.AM/OLD_PRAGUE/')).to.eql(true);
+ expect(social.INSTAGRAM_REGEX.test('http://instagr.am/old_prague/')).to.eql(true);
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagr.am/old_prague/')).to.eql(true);
+ expect(social.INSTAGRAM_REGEX.test('www.instagram.com/old_prague/')).to.eql(true);
+ expect(social.INSTAGRAM_REGEX.test('instagram.com/old_prague/')).to.eql(true);
+ expect(social.INSTAGRAM_REGEX.test('www.instagr.am/old_prague/')).to.eql(true);
+ expect(social.INSTAGRAM_REGEX.test('instagr.am/old_prague/')).to.eql(true);
+
+ // Test there is just on matching group for the username
+ expect('https://www.instagram.com/old_prague/'.match(social.INSTAGRAM_REGEX)[1]).to.eql('old_prague');
+ expect('http://www.instagram.com/old_prague/'.match(social.INSTAGRAM_REGEX)[1]).to.eql('old_prague');
+ expect('www.instagram.com/old_prague'.match(social.INSTAGRAM_REGEX)[1]).to.eql('old_prague');
+ expect('instagram.com/old_prague'.match(social.INSTAGRAM_REGEX)[1]).to.eql('old_prague');
+
+ expect(social.INSTAGRAM_REGEX.test('')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('dummy')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('a https://www.instagram.com/old_prague')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/a')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague/sub-page')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('xhttps://www.instagram.com/old_prague')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('0https://www.instagram.com/old_prague')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('_https://www.instagram.com/old_prague')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('xinstagram.com/old_prague')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('_instagram.com/old_prague')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('0instagram.com/old_prague')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('https://www.instagram.com/old_prague/?param=bla')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('://www.instagram.com/old_prague')).to.eql(false);
+ expect(social.INSTAGRAM_REGEX.test('http://www.instagram.com/old_prague http://www.instagram.com/old_brno')).to.eql(false);
+
+ expect(social.INSTAGRAM_REGEX_GLOBAL.test('https://www.instagram.com/old_prague')).to.eql(true);
+ expect(`
+ https://www.instagram.com/old_prague
+ https://www.instagram.com/someverylongusernamethatisnotgood
+ "instagram.com/old_brno"
+ http://instagr.am/old_plzen
+ `.match(social.INSTAGRAM_REGEX_GLOBAL))
+ .to.eql([
+ 'https://www.instagram.com/old_prague',
+ 'instagram.com/old_brno',
+ 'http://instagr.am/old_plzen',
+ ]);
+ expect(`
+ -https://www.instagram.com/old_prague/sub-dir
+ instagr.am/old_plzen?param=1
+ xinstagram.com/old_brno
+ ainstagram.com/old_brno
+ _instagram.com/old_brno
+ `.match(social.INSTAGRAM_REGEX_GLOBAL))
+ .to.eql([
+ 'https://www.instagram.com/old_prague/',
+ 'instagr.am/old_plzen',
+ ]);
+ expect(''.match(social.INSTAGRAM_REGEX_GLOBAL)).to.eql(null);
+ });
});
- it('TWITTER_PROFILE_REGEX', () => {
- expect(_.isRegExp(social.TWITTER_PROFILE_REGEX)).to.eql(true);
- expect(_.isRegExp(social.TWITTER_PROFILE_REGEX_GLOBAL)).to.eql(true);
-
- expect(social.TWITTER_PROFILE_REGEX.flags).to.eql('i');
- expect(social.TWITTER_PROFILE_REGEX_GLOBAL.flags).to.eql('gi');
-
- expect(social.TWITTER_PROFILE_REGEX.test('https://www.twitter.com/apify')).to.eql(true);
- expect(social.TWITTER_PROFILE_REGEX.test('https://www.twitter.com/apify/')).to.eql(true);
- expect(social.TWITTER_PROFILE_REGEX.test('https://www.twitter.com/aa_bb_123')).to.eql(true);
- expect(social.TWITTER_PROFILE_REGEX.test('http://www.twitter.com/apify')).to.eql(true);
- expect(social.TWITTER_PROFILE_REGEX.test('https://twitter.com/apify')).to.eql(true);
- expect(social.TWITTER_PROFILE_REGEX.test('http://twitter.com/apify')).to.eql(true);
- expect(social.TWITTER_PROFILE_REGEX.test('www.twitter.com/apify')).to.eql(true);
- expect(social.TWITTER_PROFILE_REGEX.test('twitter.com/apify')).to.eql(true);
-
- // Test there is just on matching group for the username
- expect('https://www.twitter.com/apify/'.match(social.TWITTER_PROFILE_REGEX)[1]).to.eql('apify');
- expect('http://www.twitter.com/apify'.match(social.TWITTER_PROFILE_REGEX)[1]).to.eql('apify');
- expect('www.twitter.com/apify'.match(social.TWITTER_PROFILE_REGEX)[1]).to.eql('apify');
- expect('twitter.com/apify'.match(social.TWITTER_PROFILE_REGEX)[1]).to.eql('apify');
-
- expect(social.TWITTER_PROFILE_REGEX.test('')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('dummy')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('a https://www.twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('https://www.twitter.com/apify/sub-page')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('xhttps://www.twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('0https://www.twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('_https://www.twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('xtwitter.com/apify')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('_twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('0twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('https://www.twitter.com/apify?param=bla')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('://www.twitter.com/apify')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('https://www.twitter.com/apify https://www.twitter.com/jack')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('https://www.twitter.com/oauth')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('https://www.twitter.com/account')).to.eql(false);
- expect(social.TWITTER_PROFILE_REGEX.test('https://www.twitter.com/privacy/')).to.eql(false);
-
- expect(social.TWITTER_PROFILE_REGEX_GLOBAL.test('https://www.twitter.com/apify')).to.eql(true);
- expect(`
- https://www.twitter.com/apify
- www.twitter.com/jack/sub-dir
- www.twitter.com/invalidverylongtwitterhandlenotgood
- twitter.com/bob123?param=1
- `.match(social.TWITTER_PROFILE_REGEX_GLOBAL))
- .to.eql([
- 'https://www.twitter.com/apify',
- 'www.twitter.com/jack/',
- 'twitter.com/bob123',
- ]);
- expect(`
- -https://www.twitter.com/apify
- twitter.com/jack
- twitter.com/carl123
- xtwitter.com/bob
- atwitter.com/bob
- _twitter.com/bob
- `.match(social.TWITTER_PROFILE_REGEX_GLOBAL))
- .to.eql([
- 'https://www.twitter.com/apify',
- 'twitter.com/jack',
- 'twitter.com/carl123',
- ]);
- expect(''.match(social.TWITTER_PROFILE_REGEX_GLOBAL)).to.eql(null);
+ describe('TWITTER_REGEX', () => {
+ it('works', () => {
+ expect(_.isRegExp(social.TWITTER_REGEX)).to.eql(true);
+ expect(_.isRegExp(social.TWITTER_REGEX_GLOBAL)).to.eql(true);
+
+ expect(social.TWITTER_REGEX.flags).to.eql('i');
+ expect(social.TWITTER_REGEX_GLOBAL.flags).to.eql('gi');
+
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify')).to.eql(true);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify/')).to.eql(true);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/aa_bb_123')).to.eql(true);
+ expect(social.TWITTER_REGEX.test('http://www.twitter.com/apify')).to.eql(true);
+ expect(social.TWITTER_REGEX.test('https://twitter.com/apify')).to.eql(true);
+ expect(social.TWITTER_REGEX.test('http://twitter.com/apify')).to.eql(true);
+ expect(social.TWITTER_REGEX.test('www.twitter.com/apify')).to.eql(true);
+ expect(social.TWITTER_REGEX.test('twitter.com/apify')).to.eql(true);
+
+ // Test there is just on matching group for the username
+ expect('https://www.twitter.com/apify/'.match(social.TWITTER_REGEX)[1]).to.eql('apify');
+ expect('http://www.twitter.com/apify'.match(social.TWITTER_REGEX)[1]).to.eql('apify');
+ expect('www.twitter.com/apify'.match(social.TWITTER_REGEX)[1]).to.eql('apify');
+ expect('twitter.com/apify'.match(social.TWITTER_REGEX)[1]).to.eql('apify');
+
+ expect(social.TWITTER_REGEX.test('')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('dummy')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('a https://www.twitter.com/apify')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify/sub-page')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('xhttps://www.twitter.com/apify')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('0https://www.twitter.com/apify')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('_https://www.twitter.com/apify')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('xtwitter.com/apify')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('_twitter.com/apify')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('0twitter.com/apify')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify?param=bla')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('://www.twitter.com/apify')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/apify https://www.twitter.com/jack')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/oauth')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/account')).to.eql(false);
+ expect(social.TWITTER_REGEX.test('https://www.twitter.com/privacy/')).to.eql(false);
+
+ expect(social.TWITTER_REGEX_GLOBAL.test('https://www.twitter.com/apify')).to.eql(true);
+ expect(`
+ https://www.twitter.com/apify
+ www.twitter.com/jack/sub-dir
+ www.twitter.com/invalidverylongtwitterhandlenotgood
+ twitter.com/bob123?param=1
+ `.match(social.TWITTER_REGEX_GLOBAL))
+ .to.eql([
+ 'https://www.twitter.com/apify',
+ 'www.twitter.com/jack/',
+ 'twitter.com/bob123',
+ ]);
+ expect(`
+ -https://www.twitter.com/apify
+ twitter.com/jack
+ twitter.com/carl123
+ xtwitter.com/bob
+ atwitter.com/bob
+ _twitter.com/bob
+ `.match(social.TWITTER_REGEX_GLOBAL))
+ .to.eql([
+ 'https://www.twitter.com/apify',
+ 'twitter.com/jack',
+ 'twitter.com/carl123',
+ ]);
+ expect(''.match(social.TWITTER_REGEX_GLOBAL)).to.eql(null);
+ });
});
- it('FACEBOOK_PROFILE_REGEX', () => {
- expect(_.isRegExp(social.FACEBOOK_PROFILE_REGEX)).to.eql(true);
- expect(_.isRegExp(social.FACEBOOK_PROFILE_REGEX_GLOBAL)).to.eql(true);
-
- expect(social.FACEBOOK_PROFILE_REGEX.flags).to.eql('i');
- expect(social.FACEBOOK_PROFILE_REGEX_GLOBAL.flags).to.eql('gi');
-
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.facebook.com/someusername')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.facebook.com/someusername/')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('http://www.facebook.com/some.username123')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('www.facebook.com/someusername')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('facebook.com/someusername')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.fb.com/someusername')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.fb.com/someusername/')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('http://www.fb.com/some.username123')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('www.fb.com/someusername')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('fb.com/someusername')).to.eql(true);
-
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.facebook.com/profile.php?id=1155802082')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('http://www.facebook.com/profile.php?id=1155802082')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('www.facebook.com/profile.php?id=1155802082')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('facebook.com/profile.php?id=1155802082')).to.eql(true);
- expect(social.FACEBOOK_PROFILE_REGEX.test('fb.com/profile.php?id=1155802082')).to.eql(true);
-
- // Test there is just on matching group for the username
- expect('https://www.facebook.com/someusername/'.match(social.FACEBOOK_PROFILE_REGEX)[1]).to.eql('someusername');
- expect('https://www.facebook.com/someusername'.match(social.FACEBOOK_PROFILE_REGEX)[1]).to.eql('someusername');
- expect('https://www.facebook.com/profile.php?id=1155802082'.match(social.FACEBOOK_PROFILE_REGEX)[1]).to.eql('profile.php?id=1155802082');
- expect('fb.com/someusername'.match(social.FACEBOOK_PROFILE_REGEX)[1]).to.eql('someusername');
-
- expect(social.FACEBOOK_PROFILE_REGEX.test('')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('dummy')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('a https://www.facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.facebook.com/a')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.facebook.com/someusername/sub-page')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('http://www.facebook.com/profile.php')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('xhttps://www.facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('0https://www.facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('_https://www.facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('xfacebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('_facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('0facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.facebook.com/someusername?param=bla')).to.eql(false);
-
- expect(social.FACEBOOK_PROFILE_REGEX.test('://www.facebook.com/someusername')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.facebook.com/someusername https://www.facebook.com/jack')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.facebook.com/groups')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.facebook.com/events')).to.eql(false);
- expect(social.FACEBOOK_PROFILE_REGEX.test('https://www.facebook.com/policies/')).to.eql(false);
-
- expect(social.FACEBOOK_PROFILE_REGEX_GLOBAL.test('https://www.facebook.com/someusername')).to.eql(true);
- expect(`
- https://www.facebook.com/someusername?param=123
- www.facebook.com/another123/sub-dir
- https://www.facebook.com/waytoolongusernamewaytoolongusernamewaytoolongusernamewaytoolongusernamewaytoolongusername
- fb.com/bob123
- `.match(social.FACEBOOK_PROFILE_REGEX_GLOBAL))
- .to.eql([
- 'https://www.facebook.com/someusername',
- 'www.facebook.com/another123/',
- 'fb.com/bob123',
- ]);
- expect(`
- -https://www.facebook.com/someusername/
- facebook.com/jack4567
- fb.com/carl123
- xfacebook.com/bob
- afacebook.com/bob
- _facebook.com/bob
- `.match(social.FACEBOOK_PROFILE_REGEX_GLOBAL))
- .to.eql([
- 'https://www.facebook.com/someusername/',
- 'facebook.com/jack4567',
- 'fb.com/carl123',
- ]);
- expect(''.match(social.FACEBOOK_PROFILE_REGEX_GLOBAL)).to.eql(null);
+ describe('FACEBOOK_REGEX', () => {
+ it('works', () => {
+ expect(_.isRegExp(social.FACEBOOK_REGEX)).to.eql(true);
+ expect(_.isRegExp(social.FACEBOOK_REGEX_GLOBAL)).to.eql(true);
+
+ expect(social.FACEBOOK_REGEX.flags).to.eql('i');
+ expect(social.FACEBOOK_REGEX_GLOBAL.flags).to.eql('gi');
+
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername/')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('http://www.facebook.com/some.username123')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('www.facebook.com/someusername')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('facebook.com/someusername')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('https://www.fb.com/someusername')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('https://www.fb.com/someusername/')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('http://www.fb.com/some.username123')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('www.fb.com/someusername')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('fb.com/someusername')).to.eql(true);
+
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/profile.php?id=1155802082')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('http://www.facebook.com/profile.php?id=1155802082')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('www.facebook.com/profile.php?id=1155802082')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('facebook.com/profile.php?id=1155802082')).to.eql(true);
+ expect(social.FACEBOOK_REGEX.test('fb.com/profile.php?id=1155802082')).to.eql(true);
+
+ // Test there is just on matching group for the username
+ expect('https://www.facebook.com/someusername/'.match(social.FACEBOOK_REGEX)[1]).to.eql('someusername');
+ expect('https://www.facebook.com/someusername'.match(social.FACEBOOK_REGEX)[1]).to.eql('someusername');
+ expect('https://www.facebook.com/profile.php?id=1155802082'.match(social.FACEBOOK_REGEX)[1]).to.eql('profile.php?id=1155802082');
+ expect('fb.com/someusername'.match(social.FACEBOOK_REGEX)[1]).to.eql('someusername');
+
+ expect(social.FACEBOOK_REGEX.test('')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('dummy')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('a https://www.facebook.com/someusername')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/a')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername/sub-page')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('http://www.facebook.com/profile.php')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('xhttps://www.facebook.com/someusername')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('0https://www.facebook.com/someusername')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('_https://www.facebook.com/someusername')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('xfacebook.com/someusername')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('_facebook.com/someusername')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('0facebook.com/someusername')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername?param=bla')).to.eql(false);
+
+ expect(social.FACEBOOK_REGEX.test('://www.facebook.com/someusername')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/someusername https://www.facebook.com/jack')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/groups')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/events')).to.eql(false);
+ expect(social.FACEBOOK_REGEX.test('https://www.facebook.com/policies/')).to.eql(false);
+
+ expect(social.FACEBOOK_REGEX_GLOBAL.test('https://www.facebook.com/someusername')).to.eql(true);
+ expect(`
+ https://www.facebook.com/someusername?param=123
+ www.facebook.com/another123/sub-dir
+ https://www.facebook.com/waytoolongusernamewaytoolongusernamewaytoolongusernamewaytoolongusernamewaytoolongusername
+ fb.com/bob123
+ `.match(social.FACEBOOK_REGEX_GLOBAL))
+ .to.eql([
+ 'https://www.facebook.com/someusername',
+ 'www.facebook.com/another123/',
+ 'fb.com/bob123',
+ ]);
+ expect(`
+ -https://www.facebook.com/someusername/
+ facebook.com/jack4567
+ fb.com/carl123
+ xfacebook.com/bob
+ afacebook.com/bob
+ _facebook.com/bob
+ `.match(social.FACEBOOK_REGEX_GLOBAL))
+ .to.eql([
+ 'https://www.facebook.com/someusername/',
+ 'facebook.com/jack4567',
+ 'fb.com/carl123',
+ ]);
+ expect(''.match(social.FACEBOOK_REGEX_GLOBAL)).to.eql(null);
+ });
});
});