gkucmierz / social-links

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

Cannot add a new profile #20

Closed revivalme closed 3 years ago

revivalme commented 3 years ago

I'm trying to add a new discord profile, but get an error Uncaught TypeError: (intermediate value)(intermediate value)(intermediate value).findIndex is not a function

const { SocialLinks, TYPE_DESKTOP } = require("social-links");

const socialLinks = new SocialLinks();

const discordProfile = {
  name: "discord",
  matches: [
    {
      match: "(https?://)?(www.)?discord.gg/({GENERATED})",
      group: 3,
      pattern: "https://discord.gg/{GENERATED}",
      type: TYPE_DESKTOP
    },
    { match: "({GENERATED})", group: 1 }
  ]
};

socialLinks.addProfile("discord", discordProfile);

const res = socialLinks.isValid("discord", "https://discord.gg/mTpXg2mr");

console.log(res);

Demo: https://codesandbox.io/s/frosty-spence-kosd3

gkucmierz commented 3 years ago

const discordProfileMatches = [
  {
    match: "(https?://)?(www.)?discord.gg/({PROFILE_ID})",
    group: 3,
    pattern: "https://discord.gg/{PROFILE_ID}",
    type: TYPE_DESKTOP
  },
  { match: "({PROFILE_ID})", group: 1 }
];

socialLinks.addProfile("discord", discordProfileMatches);

Try to add matches array only.

https://codesandbox.io/s/nostalgic-night-4mq1g

It needs to be clarified in README.