gkucmierz / social-links

Validate & sanitize social links
https://npmjs.com/package/social-links
MIT License
28 stars 14 forks source link

detect links only w/o profiles #26

Open VinSpee opened 2 years ago

VinSpee commented 2 years ago

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.

gkucmierz commented 2 years ago

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 ?

VinSpee commented 2 years ago

I think that nails it. Looks good! Thanks.