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

@impactor/javascript

v5.0.0

Published

javascript utils

Downloads

299

Readme

Javascript utils

  • It provides tools to work with arrays, objects, strings and other types.

Clipboard

// add data to the clipboard

copy("hello world!");

// using template interpolation
copy("hello {{name}}", { name: "world" });

Objects

// check if a container contains an element
// the container can be a string, object, an array, or a RegExp
includes(["a", "b"], "b"); //true
includes({ a: true, b: true }, "b"); //true
includes("x", "xyz"); //true
includes(/x/, "xyz"); // true
includes(/x/, ["x", "y", "z"]); // true

// divide an array into chunks
chunk(["a", "b", "c", "d", "e"], 2); // [["a", "b"], ["c", "d"], ["e"]]

// filter objects
filterObjectByKeys({ a: 1, b: 2, c: 3 }, ["a", "c"]); // { a: 1, c: 3 }

// convert dot notation style into a real object
dotNotationToObject("a.b.c", "value"); // {a: {b:{ c: "value"}}}

// converts an object-like string into a plain object
parseObject("k1=v1,k2=v2"); // {k1: "v1", k2: "v2"}
parseObject('["value"]'); // {value: true}
parseObject('{k1:"v1", k2:"v2"}'); // {k1: "v1", k2: "v2"}

// rename object key
renameObjectKey({ a: 1, b: 2 }, "a", "x"); // {x:1, b: 2}
renameObjectKeys({ a: 1, b: 2 }, { a: "x", b: "y" }); // {x:1, y: 2}

// remove comments from a json string
let content = readFileSync("./tsconfig.json", "utf8");
let json = cleanJson(content);

Arrays

replace(["a", "b", "c"], "b", "x"); // ["a", "x", "c"]

Fetch

request("https://api.example.com/test", { status: "ok" });
  • As the HTTP method not specified, it will considered as POST if the body is not empty, otherwise it will be considered as GET.
  • You don't need to stringify the JSON body.
  • It returns the JSON response directly, if the response content type is json (the default), you don't need to use res.json()

The function is a thin wrapper around the built-in fetch() to make the requests too much easier.

RegExp

// convert a string into a regexp
toRegExp(".+(\d)", "i");

// merge patterns
mergePatterns(/x/, /y/); // /xy/
mergePatterns(/x/, /y/, { delimiter: "|", flags: "i" }); // /x|y/i

also, there are many ready to use patterns, such as ip, ipv6, email, phone, url, domain, link, strongPassword, hashtag, ...

Strings

  • toCamelCase(): convert kabab-case strings into camelCase
  • toKababCase()
  • toUpperCaseFirst(): capitalize the first letter
  • cleanString(): remove comments, break lines and trim the string from multi-line strings
  • replaceAsync() and replaceRecursive()

Time

// measure the execution's duration.
timer("connection");
await connect();
let duration = timer("connection");
console.log(`connected in ${duration / 1000} seconds`);

// pause a function execution
await sleep(1000);

Types

objectType("text"); // string
objectType({x: 1}); // object
objectType([1, 2, 3]); // array
objectType(1); // number
...

isPlainObject({x: 1}); // true
objectType(new Date()); // object
isPlainObject(new Date()); // false

// check if the element is iterable, but not a string.
isIterable([1, 2, 3]); //true
isIterable({x: 1}); //true

// check if the object a promise or a promise-like
isPromise(new Promise(...)); //true

isEmpty(undefined); // true
isEmpty(null); // true
isEmpty(""); // true
isEmpty("        "); // true
isEmpty([]); // true
isEmpty({}); // true
isEmpty(false); // false
isEmpty("0"); // false

URL

  • queryToObject(): converts query params to a plain object
  • objectToQueryParams()