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

ytid

v1.3.0

Published

Create URL friendly short IDs just like YouTube

Downloads

612

Readme

Create URL friendly short IDs just like YouTube.

Suitable for generating -

  • short IDs for new users.
  • referral code for a user in an affiliate program.
  • file names for user uploaded documents / resources.
  • short URLs (like bitly) for sharing links on social media platforms.
  • URL slug for dynamically generated content like blog posts, articles, or product pages.

Works with ES6 (ECMAScript):

as well as with CommonJS:

Installation

Using npm:

npm i ytid

Using yarn:

yarn add ytid

Using pnpm:

pnpm i ytid

Usage

With ES6 (ECMAScript):

import { ytid } from "ytid";

console.log(ytid()); // gocwRvLhDf8

With CommonJS:

const { ytid } = require("ytid");

console.log(ytid()); // dQw4w9WgXcQ

FAQs

What are the possible characters in the ID?

YouTube uses 0-9, A-Z, a-z, _ and - as possible characters for the IDs. This makes each position in the ID have one of these 64 characters. However, as capital I and lowercase l appear very similar in the URLs (I → I, l → l), ytid excludes them.

Hence, ytid uses 0-9, A-H, J-Z, a-k, m-z, _ and - as possible characters in the ID.

Why should URL IDs be short?

A Backlinko's study, based on an analysis of 11.8 million Google search results, found that short URLs rank above long URLs.

And a Brafton study found a correlation between short URLs and more social shares, especially on platforms such as Twitter which have character limits.

These studies highlight the benefits of short URLs over long ones.

What if the ID contains any offensive word or phrase?

All the generated IDs are checked against a dataset of offensive / profane words to ensure they do not contain any inappropriate language.

As a result, ytid doesn't generate IDs like 7-GoToHell3 or shit9RcYjcM.

The dataset of offensive / profane words is a combination of various datasets -

These datasets undergo the following preprocessing steps -

  1. Firstly, all the datasets are combined into a single dataset.
  2. Then the duplicate instances are removed.
  3. Then two new datasets are created -
    1. A dataset in which all spaces are replaced with -.
    2. A dataset in which all spaces are replaced with _.
  4. These two datasets are then combined to form a new dataset.This ensures that the dataset contains phrases with spaces in the form of hyphen separated words as well as underscore separated words.
  5. Then, duplicate values are removed from this new dataset.
  6. Finally, only the instances that match the regex pattern ^[A-Za-z0-9_-]{0,11}$ are kept, while the rest are removed. This keeps the number of instances to a minimum by removing unnecessary words or phrases.

Preprocessing yields a dataset of 3656 instances, that helps ensure the generated IDs are safe for using in URLs and for sharing on social media platforms.

The preprocessing was done on this Colab Jupyter notebook.

Future release(s) will expand the dataset to include words / phrases from other languages (that use English alphabets).

Stargazers

License

Apache-2.0