social-links icon indicating copy to clipboard operation
social-links copied to clipboard

detect links only w/o profiles

Open VinSpee opened this issue 3 years ago • 2 comments

Hi! I'm wondering if it's possible to detect social links only, not profiles. For example:

const detectSocialLink = (url: string) =>
  networks.reduce<[network: typeof networks[number] | 'url', url: string]>(
    (prev, network) => {
      try {
        if (socialLinks.isValid(network, url)) {
          return [network, socialLinks.sanitize(network, url)];
        }
      } catch (err) {
        return prev;
      }

      return prev;
    },
    ['url', url],
  );


expect(detectSocialLink('https://instagram.com/vinspee')).toBe(['instagram', 'https://instagram.com/vinspee'])
expect(detectSocialLink('vinspee').toBe(['url', 'vinspee'])

i'd like to take user input and determine which network was detected. When "profile" names match, essentially everything becomes a match until it looks like a URL.

VinSpee avatar Feb 24 '22 04:02 VinSpee

Good point.

I added detectProfile in v1.7.0

I can also automatically detect profile in following functions when profileName is omitted. getProfileId getLink isValid sanitize

What do you think about this @VinSpee ?

gkucmierz avatar Sep 26 '22 21:09 gkucmierz

I think that nails it. Looks good! Thanks.

VinSpee avatar Sep 26 '22 22:09 VinSpee