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

@arpansaha13/utils

v0.8.0

Published

A personal collection of utils.

Downloads

19

Readme

Utilities

This package is a compilation of some utility functions that might be needed in general. Some of them are taken from different documentations and articles, and then modifed.

Published as @arpansaha13/utils on npm.

General utilities

classNames

  • Alias: cn

A shorthand for twMerge(clsx(...classes)).

classNames('mx-auto max-w-7xl p-4', primary ? 'bg-indigo-600 text-white' : 'bg-transparent text-gray-900')

Note: clsx is imported from clsx/lite.

deepFreeze

Recursively freeze each non-primitive property of an object.

Source: MDN web docs - Object.freeze()

isNullOrUndefined

Check if a value is null or undefined.

if (!isNullOrUndefined(variable)) {
  // do something
}

random

Generates a random number between the given min and max values.

Source: MDN web docs - Math.random()

random(5, 10)

slugify

Source: Dev.to - 10 Helpful JavaScript Utility Functions

slugify('Hello, World!')
// Expected output: "hello-world"

slugify('Hello, Universe!', '_')
// Expected output: "hello_universe"

trim

Removes the extra spaces in between a string along with the leading and trailing white space and line terminator characters.

Source: Stack Overflow - How to remove the extra spaces in a string?

clamp

Returns a number whose value is limited to the given range.

Source: Stack Overflow - What's the most elegant way to cap a number to a segment?

truncate

Truncate a long string to a specific number of characters.

hasLowerCase

Check whether a string has a lowercase alphabet or not.

Source: Stack Overflow - JavaScript - checking for any lowercase letters in a string

uint8ArrayToJson

Convert Uint8Array readable stream to json.

Source: Stack Overflow - Retrieve data from a ReadableStream object?

sanitize

Sanitize HTML by escaping special characters in a string.

nFormatter

Format a large number by adding suffixes like "k" and "M".

Source: Stack Overflow - Format a number as 2.5K if a thousand or more, otherwise 900

getOrdinalSuffix

Returns the appropriate ordinal suffix for that day (e.g., "st" for 1, "nd" for 2, "rd" for 3, and "th" for the rest).

Browser utilities

These utility functions are only meant to be used in the browser and will raise error if used in node.js environment.

getCookie

Returns the value of the cookie if it exists, else returns an empty string.

isTouchDevice

Detect whether the device has a touch screen.

Source: Stack Overflow - What's the best way to detect a 'touch screen' device using JavaScript?

Node utilities

These utility functions are only meant to be used in node.js environment and will raise error if used in the browser environment.

readJsonFile

A shorthand for JSON.parse(await readFile(path, 'utf8')).

readJsonFile('path/to/file')

writeJsonFile

A shorthand for writeFile(path, JSON.stringify(json, null, 2)).

writeJsonFile('path/to/file', { ... })

createEmptyFile

Creates an empty file. If the filePath already exists, an error is thrown.

Source: Stack Overflow - Create an empty file in Node.js?

createEmptyFile('path/to/file')