npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@667/socialitejs

v0.0.6-2

Published

Social network URL parsing for aristocrats

Downloads

20

Readme

Socialite

License: ISC

Socialite is a quick and easy way to parse a url: string to determine:

  1. What social network it belongs to.
  2. What the user handle is.
  3. What the social prefix is (if relevant).
  4. What each url segment is, broken up into groups.

The minimum criteria for parsing a url is:

  1. domain: https://www.{{domain}}.com/path
  2. tldomain: https://www.domain{{.com}}/path

Installation

Simply install via the command-line or include in your package.json, just like any other dependency.

# Alternatively install with `yarn` or `pnpm`
npm install socialitejs

How to use

By default, Socialite includes only a small collection of the most common social networks. The exact networks included can be found in the defaultSocialiteNetworks array. A typical use case looks like:

import {Socialite} from 'socialitejs';

const socialiteInstance = new Socialite();
const mySocialUrl = 'https://www.twitter.com/@SomeFakeUserHandle';
const parsedSocialUrl = socialiteInstance.parseProfile(mySocialUrl);

console.log(parsedSocialUrl);

The above will log the following SocialiteProfile (object) to the console:

{
  id: 'twitter',
  prefix: '@',
  user: 'SomeFakeUserHandle',
  originalUrl: 'https://www.twitter.com/@SomeFakeUserHandle',
  preferredUrl: 'https://twitter.com/@SomeFakeUserHandle',
  appUrl: 'https://mobile.twitter.com/@SomeFakeUserHandle',
  urlGroups: {
    scheme: 'https://',
    subdomain: 'www.',
    domain: 'twitter',
    tldomain: '.com',
    path: '/@SomeFakeUserHandle',
    // Other url parts are omitted if `undefined`
  },
}

For a more robust collection of social networks, you can import the socialiteNetworks object and use it (at least) one of two ways:

import {Socialite, socialiteNetworks, type SocialiteId} from 'socialitejs';

// Adding all social networks in bulk:
const allNetworksInstance = new Socialite(Object.values(socialiteNetworks));

// Logs to the console all social networks included in the code base.
console.log(allNetworksInstance.getAllNetworks());

// Initializing `Socialite` without any networks (pass empty `array`):
const selectiveNetworksInstance = new Socialite([]);
const excludedNetworks: SocialiteId[] = ['discord', 'facebook', 'reddit'];

Object.keys(socialiteNetworks).forEach((network) => {
  if (!excludedNetworks.includes(network.id)) {
    selectiveNetworksInstance.addNetwork(network);
  }
});

// Logs to the console all social networks not found in `excludedNetworks`.
console.log(selectiveNetworksInstance.getAllNetworks());

Features

...this section is incomplete... check back later for API documentation.