Socket
Socket
Sign inDemoInstall

social-links

Package Overview
Dependencies
0
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    social-links

Validate & sanitize social links


Version published
Weekly downloads
2.7K
decreased by-19.49%
Maintainers
1
Install size
182 kB
Created
Weekly downloads
 

Readme

Source

minified size minified zipped size types license npm-publish

Social Links is helping to detect, validate and sanitize social (desktop & mobile) links

Install

npm i social-links --save

Demo

Using

import { SocialLinks, TYPE_MOBILE } from 'social-links';
const socialLinks = new SocialLinks();

const link = 'http://www.linkedin.com/in/gkucmierz';
const profileName = socialLinks.detectProfile(link); // 'linkedin'

console.log(socialLinks.isValid(profileName, link)); // true
console.log(socialLinks.sanitize(profileName, link)); // 'https://linkedin.com/in/gkucmierz'
console.log(socialLinks.sanitize(profileName, link, TYPE_MOBILE)); // 'https://linkedin.com/mwlite/in/gkucmierz'

Above examples works based on predefined linkedin profile:

import { Profile } from 'social-links';
const linkedinProfile: Profile =
{ name: 'linkedin',
    matches: [
      {
        match: '(https?://)?(www.)?linkedin.com/in/({PROFILE_ID})', group: 3, type: TYPE_DESKTOP,
        pattern: 'https://linkedin.com/in/{PROFILE_ID}'
      },
      {
        match: '(https?://)?(www.)?linkedin.com/mwlite/in/({PROFILE_ID})', group: 3, type: TYPE_MOBILE,
        pattern: 'https://linkedin.com/mwlite/in/{PROFILE_ID}'
      },
      { match: '({PROFILE_ID})', group: 1 },
    ]
};

Add new profile

import { SocialLinks, Profile } from 'social-links';

const socialLinks = new SocialLinks();
const profileMatches: ProfileMatch[] = [ ... ];

socialLinks.addProfile('profileName', profileMatches);

Configuration

import { SocialLinks, Config } from 'social-links';

const config: Config = {
  usePredefinedProfiles: true,
  trimInput: true,
  allowQueryParams: false,
};
const socialLinks = new SocialLinks(config);

Build

Watch, tsc build

npm run start

Tests

Just jest tests

npm run test

or

npm run test:watch

Contributing

CONTRIBUTING.md

Keywords

FAQs

Last updated on 24 Sep 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc