JSPM

  • Created
  • Published
  • Downloads 3419
  • Score
    100M100P100Q152881F
  • License MIT

Validate & sanitize social links

Package Exports

  • social-links

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (social-links) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

minified size minified zipped size types license

Social Links

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

Install

npm i social-links --save

Demo

https://awesome-web-tools.web.app/social-links - Example use case

Using

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

const link = 'http://www.linkedin.com/in/gkucmierz';
console.log(socialLinks.isValid('linkedin', link)); // true

console.log(socialLinks.sanitize('linkedin', link)); // 'https://linkedin.com/in/gkucmierz'

console.log(socialLinks.sanitize('linkedin', 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 profile: Profile = { ... };

socialLinks.addProfile('profileName', profile);

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