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

mohitkhare

v1.0.0

Published

Developer utilities for text processing, token estimation, and data transformation by Mohit Khare

Readme

mohitkhare

Developer utilities for text processing, token estimation, and data transformation by Mohit Khare.

Zero-dependency collection of helpers for everyday JavaScript and Node.js development. Includes text processing, LLM token estimation, async control flow, and object manipulation.

Installation

npm install mohitkhare

Usage

Text Processing

const mk = require("mohitkhare");

mk.slugify("Hello World! This is a Test");
// => "hello-world-this-is-a-test"

mk.unslugify("hello-world");
// => "Hello World"

mk.truncate("A very long paragraph that needs trimming...", 30);
// => "A very long paragraph that..."

mk.stripHtml("<p>Hello <b>world</b></p>");
// => "Hello world"

mk.wordCount("The quick brown fox jumps"); // 5
mk.readingTime(longArticle); // 7 (minutes)

Token Estimation (LLM)

mk.estimateTokens("Hello, how are you doing today?");
// => 8 (character-based estimate)

mk.estimateTokens("Hello, how are you doing today?", "words");
// => 9 (word-based estimate)

mk.estimateCost(1000, 500);
// => 0.0105 (USD at default pricing)

mk.estimateCost(1000, 500, { input: 0.15, output: 0.60 });
// => 0.00045 (USD at budget pricing)

Async Utilities

// Retry with exponential backoff
const data = await mk.retry(
  () => fetch(url).then(r => r.json()),
  { retries: 3, delay: 1000, factor: 2 }
);

// Sleep
await mk.sleep(2000);

// Batch process with concurrency control
const results = await mk.batchProcess(
  urls,
  url => fetch(url).then(r => r.json()),
  5 // max 5 concurrent requests
);

Data Transformation

// Flatten nested objects
mk.flatten({ a: { b: 1, c: { d: 2 } } });
// => { "a.b": 1, "a.c.d": 2 }

// Unflatten back
mk.unflatten({ "a.b": 1, "a.c.d": 2 });
// => { a: { b: 1, c: { d: 2 } } }

// Pick / omit keys
mk.pick({ a: 1, b: 2, c: 3 }, ["a", "c"]); // { a: 1, c: 3 }
mk.omit({ a: 1, b: 2, c: 3 }, ["b"]);      // { a: 1, c: 3 }

// Group by key
mk.groupBy(
  [{ type: "a", v: 1 }, { type: "b", v: 2 }, { type: "a", v: 3 }],
  "type"
);
// => { a: [{...}, {...}], b: [{...}] }

// De-duplicate
mk.unique([1, 2, 2, 3]); // [1, 2, 3]
mk.unique(items, item => item.id); // by key function

// Deep clone
const copy = mk.deepClone(complexObject);

API Reference

Text

  • slugify(text) - Convert to URL-safe slug.
  • unslugify(slug) - Convert slug back to title case.
  • truncate(text, maxLength?, suffix?) - Truncate at word boundary.
  • stripHtml(html) - Remove HTML tags.
  • wordCount(text) - Count words.
  • readingTime(text, wpm?) - Estimate reading time in minutes.

Token Estimation

  • estimateTokens(text, method?) - Estimate LLM token count.
  • estimateCost(inputTokens, outputTokens, pricing?) - Estimate API call cost in USD.

Async

  • retry(fn, options?) - Retry with exponential backoff.
  • sleep(ms) - Wait for N milliseconds.
  • batchProcess(items, fn, batchSize?) - Process array items with concurrency control.

Data

  • flatten(obj) - Flatten nested object to dot-notation keys.
  • unflatten(obj) - Restore nested structure from dot-notation.
  • deepClone(obj) - Deep copy any value.
  • pick(obj, keys) - Keep only specified keys.
  • omit(obj, keys) - Remove specified keys.
  • groupBy(arr, key) - Group array items by a key.
  • unique(arr, keyFn?) - Remove duplicates.

TypeScript

Type definitions are included.

import { slugify, retry, RetryOptions } from "mohitkhare";

Links

License

MIT. See LICENSE for details.