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

handyutility

v1.0.1

Published

a set of Javascript supplements utilities and functions

Downloads

63

Readme

Installation

You can install Handy Utility using npm:

npm install handyutility

Alternatively, you can use the CDN script to include the hu.min.js in your HTML file

<script src="https://unpkg.com/browse/handyutility@latest/dist/hu.min.cjs"></script>

Alternatively, you can use the CDN script to include the hu.min.js in your HTML file

<!-- VIA: jsdelivr CDN -->
<script src="https://cdn.jsdelivr.net/npm/handyutility@latest/dist/hu.min.js"></script>
<!-- VIA: unpkg CDN -->
<script src="https://unpkg.com/handyutility@latest/dist/hu.min.js"></script>

Otherwise, you can download the hu.min.js file from the dist directory and include it in your HTML file, or click here to download it directly

<script src="path/to/hu.min.js"></script>

Usage

Once you have installed or included the hu.min.js file, you can start using the functions in your code.

// Import the handyutility
import Utils from "handyutility";
// explicitly use the handy, operators and promises ...
import { Handy, Operators, Promises  } from "handyutility"

Utils.handy.IPify().then((ip) => {
  console.log(ip);
});

Handy.IPify().then((ip) => {
  console.log(ip);
});

Utilities

Handy

Utils.handy.IPify()

Retrieve the IP address of the current machine.

const url = new URL("https://www.google.com/search?q=handyscript");
Utils.handy.searchParamsSerializer(url: URL) // {q: "handyscript"}

Extract the search params from a URL

There is more to discover ✨

Operators

Utils.operators.is(1, 1) // true
Utils.operators.is("hello", "hi") // false
// Objects are compared by their keys recursively
const obj1 = {name: "john", age: 20};
const obj2 = {name: "john", age: 20};
Utils.operators.is(obj1, obj2) // true

// Functions and Regular expressions are compared by their source code
const fn1 = () => console.log("hello");
const fn2 = () => console.log("hi");
Utils.operators.is(fn1, fn2) // false

const reg1 = /hello/;
const reg2 = /hi/;
Utils.operators.is(reg1, reg2) // false

// Dates are compared by their millisecond representation
const date1 = new Date();
const date2 = new Date(date1.getTime());
Utils.operators.is(date1, date2) // true

The is function is used to compare values if they are truly equal

There is more to discover ✨

Promises

async function simulateAsyncOperation(attempt: number): Promise<number> {
  const randomSuccess = Math.random() < 0.5; // Simulate a success or failure randomly
  if (randomSuccess) {
    return attempt;
  } else {
    throw new Error(`Attempt ${attempt} failed`);
  }
}

async function main() {
  const maxAttempts = 5;
  const delayMs = 1000;

  try {
    const result = await Utils.promises.retry(async () => {
      const attempt = await simulateAsyncOperation(1); // Start with the first attempt
      if (attempt < maxAttempts) {
        throw new Error('Retry');
      }
      return attempt;
    }, maxAttempts, delayMs);

    console.log(`Operation succeeded on attempt ${result}`);
  } catch (error) {
    console.error(`Operation failed: ${error.message}`);
  }
}

main();

The retry function facilitates robust handling of transient failures in asynchronous operations, employing exponential backoff with a specified maximum retry limit

There is more to discover ✨

Contributing

Contributions are welcome, feel free to submit a pull request or an issue.