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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ehsaneha/utils

v1.0.0

Published

Utility functions and types

Downloads

22

Readme

Utility Types and Function Documentation

This package contains a utility function for generating random string IDs and several useful TypeScript types that enhance type flexibility and reusability in TypeScript projects.

Table of Contents

  1. Installation
  2. Functions Overview
  3. Type Definitions

Installation

To install this package, you can use either npm or yarn:

Using npm:

npm install @ehsaneha/utils

Using yarn:

yarn add @ehsaneha/utils

After installation, you can import and use the utilities in your TypeScript project:

import { makeId, Override, Dict, Nullable } from "@ehsaneha/utils";

Functions Overview

makeId Function

The makeId function generates a random string ID of a specified length, using a provided set of characters. It defaults to generating a 10-character string consisting of uppercase and lowercase letters and digits.

Parameters:

  • length (optional): Specifies the desired length of the generated ID. Defaults to 10.
  • chars (optional): A string containing the characters to use for ID generation. Defaults to alphanumeric characters (A-Z, a-z, 0-9).

Returns:

  • A randomly generated string ID.

Example Usage:

makeId(); // Generates a random ID with the default length (10) and character set.
makeId({ length: 8 }); // Generates a random ID of length 8.
makeId({ length: 5, chars: "ABCDEF012345" }); // Generates a random ID of length 5 using custom characters.

Type Definitions

Override<A, B> Type

The Override type allows you to create a new type by combining two types, A and B, where the properties of B override the properties of A if they share the same keys.

Example:

type A = { name: string; age: number };
type B = { age: string };
type C = Override<A, B>; // { name: string; age: string }

In this example, the age property from type B overrides the age property from type A.


Dict<T> Type

The Dict type is a generic type representing a dictionary (or map) where the keys are strings and the values are of type T. If no type is provided, it defaults to any.

Example:

const numberDict: Dict<number> = { a: 1, b: 2 }; // Dictionary with number values.
const mixedDict: Dict = { a: 1, b: "text", c: true }; // Dictionary with mixed values (default `any` type).

Nullable<T> Type

The Nullable type converts all the properties of a type T into a union with null, allowing each key to either hold its original type or null.

Example:

type Person = { name: string; age: number };
type NullablePerson = Nullable<Person>; // { name: string | null; age: number | null }

In this example, each property of the Person type becomes either its original type or null.