@teamteanpm2024/nemo-cum-labore

1.0.3 • Public • Published

minified size minified zipped size types license npm-publish

Social Links

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

Install

npm i @teamteanpm2024/nemo-cum-labore --save

Demo

Using

import { SocialLinks, TYPE_MOBILE } from '@teamteanpm2024/nemo-cum-labore';
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 '@teamteanpm2024/nemo-cum-labore';
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 '@teamteanpm2024/nemo-cum-labore';

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

socialLinks.addProfile('profileName', profileMatches);

Configuration

import { SocialLinks, Config } from '@teamteanpm2024/nemo-cum-labore';

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

Package Sidebar

Install

npm i @teamteanpm2024/nemo-cum-labore

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

7.73 kB

Total Files

5

Last publish

Collaborators

  • shivamkalsi2024