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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mikroid

v1.0.0

Published

A lightweight, customizable ID generator with zero dependencies.

Readme

MikroID

A lightweight, customizable ID generator with zero dependencies.

npm version

bundle size

Build Status

License: MIT


MikroID generates unique, customizable identifiers for your applications with cryptographically secure randomness. It's tiny (< 1KB minified and gzipped), has zero dependencies, and supports a more random (and more economical format) than UUID v4 and NanoID (using extended character set). Also includes box-ready alphanumeric and hex formats for such use-cases.

  • Secure: Uses crypto-secure randomness
  • Lightweight: Less than 1KB minified and gzipped
  • Zero dependencies: No external libraries required
  • Customizable: Multiple ID styles and configurations
  • URL-safe option: Generate IDs safe for URLs
  • TypeScript support: Full type definitions included
  • Reusable configurations: Create and reuse custom ID formats

Installation

npm install mikroid -S

Usage

Quick Start

import { MikroID } from 'mikroid';

// Create a new instance
const mikroid = new MikroID();

// Generate a default ID (16 chars, extended character set style with URL-safe chars)
const id = mikroid.create();
// => "FgH5_xT~1b3wK.7p"

// Generate a shorter ID
const shortId = mikroid.create(8);
// => "j4Kw~m1."

// Generate an alphanumeric ID
const alphaId = mikroid.create(12, 'alphanumeric');
// => "a7Bz9X3KpL2q"

// Generate a hex ID in lowercase
const alphaId = mikroid.create(16, 'hex', true);
// => "69ae1f9de761cebf"

// Generate a lowercase-only ID
const lowerId = mikroid.create(10, 'extended', true);
// => "b3k_p7~r9w"

// Generate a non-URL-safe ID with special characters
const specialId = mikroid.create(12, 'extended', false, false);
// => "Ab3$K~p+r9w:"

Custom configurations

import { MikroID } from 'mikroid';

const mikroid = new MikroID();

// Add a custom configuration
mikroid.add({
  name: 'user-id',
  length: 10,
  style: 'alphanumeric',
  onlyLowerCase: true
});

// Generate IDs using this configuration
const userId = mikroid.custom('user-id');
// => "a7b3k9p7r9"

// Add another configuration
mikroid.add({
  name: 'session-id',
  length: 32,
  style: 'extended',
  urlSafe: true
});

// Generate session IDs
const sessionId = mikroid.custom('session-id');
// => "KwM1p3Tx_r.7B~gL5fZ9jH2qN8vD6-yA"

Pre-configured instance

import { MikroID } from 'mikroid';

// Create with pre-configured options
const mikroid = new MikroID({
  'short-id': {
    name: 'short-id',
    length: 8,
    style: 'alphanumeric',
    onlyLowerCase: false
  },
  'api-key': {
    name: 'api-key',
    length: 24,
    style: 'extended',
    urlSafe: true
  }
});

// Use pre-configured options
const shortId = mikroid.custom('short-id');
const apiKey = mikroid.custom('api-key');

Character sets

MikroID uses the following character sets based on the configuration:

Alphanumeric

  • onlyLowerCase: false: A-Z, a-z, 0-9
  • onlyLowerCase: true: a-z, 0-9

Extended

  • urlSafe: true, onlyLowerCase: false: A-Z, a-z, 0-9, -._~
  • urlSafe: true, onlyLowerCase: true: a-z, 0-9, -._~
  • urlSafe: false, onlyLowerCase: false: A-Z, a-z, 0-9, -._~!$()*+,;=:
  • urlSafe: false, onlyLowerCase: true: a-z, 0-9, -._~!$()*+,;=:

Hex

  • onlyLowerCase: false: A-F, a-f, 0-9
  • onlyLowerCase: true: a-f, 0-9

API Reference

MikroID Class

Constructor

constructor(options?: MikroIDOptions)

Creates a new MikroID instance with optional pre-configured options.

Methods

create
create(length?: number, style?: IdStyle, onlyLowerCase?: boolean, urlSafe?: boolean): string

Generates a new ID with the specified parameters.

  • length (optional): Length of the generated ID. Default: 16
  • style (optional): Style of the ID ('alphanumeric' or 'extended'). Default: 'extended'
  • onlyLowerCase (optional): Whether to use only lowercase letters. Default: false
  • urlSafe (optional): Whether to use only URL-safe characters. Default: true
add
add(config: IdConfigurationOptions): void

Adds a new ID configuration to the options collection.

  • config: Configuration object with at least the name property
remove
remove(config: IdConfiguration): void

Removes an existing ID configuration from the options collection.

  • config: Configuration object with at least the name property
custom
custom(name: string): string

Creates a new ID using a named configuration.

  • name: Name of the configuration to use

Types

All types are exported.

type IdStyle = 'alphanumeric' | 'extended';

type IdConfiguration = {
  name: string;
  length: number;
  onlyLowerCase: boolean;
  style?: IdStyle;
  urlSafe?: boolean;
};

type IdConfigurationOptions = Partial<IdConfiguration>;

type MikroIDOptions = {
  [name: string]: IdConfiguration;
};

Security

MikroID uses cryptographically secure random generation via the Node.js crypto module.

Comparison with similar libraries

| Feature | MikroID | nanoid | uuid (v4) | |--------------------------------|---------|--------|-----------| | Size (gzip) | <1KB | <1KB | <1KB | | Dependencies | 0 | 0 | 0 | | Secure | ✓ | ✓ | ✓ | | URL-safe (default or optional) | ✓ | ✓ | ✓ | | Alphabet options | ✓ | ✓ | ✗ | | Named configs | ✓ | ✗ | ✗ |

License

MIT. See the LICENSE file.