# social-links

> Validate & sanitize social links

Latest version **1.15.1** (published 2025-02-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install social-links
pnpm add social-links
yarn add social-links
bun add social-links
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.15.1 |
| Published | 2025-02-05 |
| First published | 2020-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 185.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 32 |
| Author | Grzegorz Kucmierz |
| Maintainers | gkucmierz |
| Keywords | behance, dev_to, dribbble, exercism, expression, facebook, github, instagram, is-valid, keybase, lemmy_world, linkedin, links, linktree, manipulation, mastodon, media, medium, patreon, pinterest, regex, regexp, regular, regular expression, sanitization, sanitize, social, social-links, social-media, stackoverflow, string, substack, telegram, tiktok, trim, twitch, twitter, url, validate, validation, vk, x, youtube |

## Links

- npm: https://www.npmjs.com/package/social-links
- Repository: https://github.com/gkucmierz/social-links
- Homepage: https://github.com/gkucmierz/social-links#readme
- Issues: https://github.com/gkucmierz/social-links/issues
- npm.io page: https://npm.io/package/social-links

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.15.1 (latest) — 2025-02-05
- 1.15.0 — 2025-01-30
- 1.14.0 — 2023-09-24
- 1.13.8 — 2023-08-01
- 1.13.6 — 2023-08-01
- 1.13.3 — 2023-08-01
- 1.10.1 — 2023-08-01
- 1.10.0 — 2022-11-02
- 1.9.0 — 2022-10-06
- 1.8.1 — 2022-09-29
- 1.8.0 — 2022-09-29
- 1.7.4 — 2022-09-27
- 1.7.3 — 2022-09-26
- 1.7.2 — 2022-09-26
- 1.7.1 — 2022-09-26
- … 37 more at https://npm.io/package/social-links/versions

## README

![minified size](https://badgen.net/bundlephobia/min/social-links) ![minified zipped size](https://badgen.net/bundlephobia/minzip/social-links) ![types](https://badgen.net/npm/types/social-links) ![license](https://badgen.net/npm/license/social-links) [![npm-publish](https://github.com/gkucmierz/social-links/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/gkucmierz/social-links/actions/workflows/npm-publish.yml)

# Social Links

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

### Install
```bash
npm i social-links --save
```

### Demo

- https://awesome-web-tools.web.app/social-links - Example use case
- https://gkucmierz.github.io/social-links-app - Detect profile demo (v1.7.0)

### Using
```js
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:
```js
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
```js
import { SocialLinks, Profile } from 'social-links';

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

socialLinks.addProfile('profileName', profileMatches);
```

### Configuration
```js
import { SocialLinks, Config } from 'social-links';

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

### Build

Watch, *tsc* build
```bash
npm run start
```

### Tests

Just *jest* tests
```bash
npm run test
```
or
```bash
npm run test:watch
```

### Contributing

[CONTRIBUTING.md](CONTRIBUTING.md)

---
_Source: https://npm.io/package/social-links · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
