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

@sil/id

v0.0.7

Published

Id creation

Downloads

32

Readme

ID

Create a random ID using the characters you prefer and in the format you want.

Installation

npm install @sil/id

Usage

As a composable

import { useId } from "@sil/id";

const id = useId();

// id() can be used anywhere and will create a unique key

Or directly

import { createId } from "@sil/id";

const id = createId();

// id is now a string with a key.

Settings

Alphabet

The alphabet defines the characters which can be used to create any ID. By default an ID can use all letters in upper and lowercase plus the numbers. But you can change this by settings the alphabet.

import { useId, IdAlphabet } from "@sil/id";

const id = useId({
  alphabet: IdAlphabet["A-Z"],
});

Options:

| Option | Value | Description | | -------- | ---------------------------------------------------------------------- | -------------------------------------------------------------------- | | a-z | abcdefghijklmnopqrstuvwxyz | All 26 letters in lowercase | | A-Z | ABCDEFGHIJKLMNOPQRSTUVWXYZ | All 26 letters in uppercase | | 0-9 | 0123456789 | All numbers from 0 to 9 | | a-Z | abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ | All 26 letters in uppercase + lowercase | | a-Z0-9 | abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 | All 26 letters in uppercase + lowercase + all numbers | | a-z0-9 | abcdefghijklmnopqrstuvwxy 0123456789 | All 26 letters in lowercase + all numbers | | A-Z0-9 | ABCDEFGHIJKLMNOPQRSTUVWXY 0123456789 | All 26 letters in uppercase + all numbers | | custom | Any string | You can give a string of any type of charactesr which can be used ID |

Custom alphabet sample

import { useId } from "@sil/id";

const id = useId({
  alphabet: "!@#$%^&*()",
});

// example:  %(%$-&@(@-(@@&-*(*)

Or using another alphabet:

import { useId } from "@sil/id";

const id = useId({
  alphabet: "աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆուև",
});

// example:  բէպո-ֆտիօ-դոպի-րտռս

Total

You can set the total, in this case it will just create an ID without a format with a random string of characters totalling the total defined.

import { useId } from "@sil/id";

const id = useId({
  total: 10,
});

// example: tzeNNbXTnq

Format

By default a format like XXXX-XXXX-XXXX-XXXX is used for an id, you can change this to whatever you like. The X in the format will be replaced by the characters defined in alphabet.

code example:

import { useId } from "@sil/id";

const id = useId({
  format: "XXXX_XX",
});

// example: pKCM_Lr

Custom formats

X Will be replaced by a random letter defined in alphabet or by default a-Z0-9 A Will be replaced by a random uppercase letter from the alphabet a Will be replaced by a random lowercase letter from the alphabet 0 Will be replaced by a random number

code example:

import { useId } from "@sil/id";

const id = useId({
  format: "AAA_aaa_000_XXX",
});

// example: BVR_bcu_629_yc7

[gist=2d9aff65094156a9f52f67594e8000d0]