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

@0x26e/utils

v1.0.5

Published

A TypeScript Utility Collection Similar to Laravel Helpers

Downloads

7

Readme

@0x26e/utils

A TypeScript Utility Collection Similar to Laravel Helpers.

Instalation

npm install @0x26e/utils

Available Methods

Arrays & Objects

crossJoin

toCssClasses

Miscellaneous

blank sleep usleep tap until clamp

Arrays & Objects

crossJoin()

Returns the Cartesian product of the given arrays. The Cartesian product of multiple sets is a set of all possible combinations where each combination contains one element from each input array.

const result = crossJoin([1, 2], ['a', 'b']);
console.log(result);
// Output: [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]

toCssClasses()

The toCssClasses function conditionally compiles a CSS class string. The method accepts an object of classes where the object key contains the class or classes you wish to add, while the value is a boolean expression. If the object key has a numeric key, it will always be included in the rendered class list:

const isActive = false;
const hasError = true;
const classes = toCssClasses([
  'p-4',
  { 'font-bold': isActive, 'bg-red': hasError },
]);
console.log(classes);
// Output: 'p-4 bg-red'

Miscellaneous

blank()

The blank function determines whether the given value is "blank":

blank('');
blank('   ');
blank(null);
blank(collect());

// true

blank(0);
blank(true);
blank(false);

// false

sleep()

Pauses the execution for a specified number of seconds

await sleep(2); // Pauses execution for 2 seconds.

usleep()

Pauses the execution for a specified number of milliseconds.

await usleep(500); // Pauses execution for 500 milliseconds.

tap()

Invokes an interceptor function with a provided value and returns the result.

const tappedValue = tap(5, (n) => n * 2); // tappedValue = 10

until()

Continuously attempts a function until a condition is met.

const result = await until(
  () => isConditionTrue(),
  () => fetchData(),
  2,
);

clamp()

Returns a value clamped to the inclusive range of min and max. This function ensures that the value falls within the specified range. If the value is less than min, it returns min. If the value is greater than max, it returns max. Otherwise, it returns the value itself.

const clamped1 = clamp(5, 1, 10);
console.log(clamped1); // 5

const clamped2 = clamp(15, 1, 10);
console.log(clamped2); // 10 (since 15 is greater than max 10)
const clamped3 = clamp(-5, 1, 10);
console.log(clamped3); // 1 (since -5 is less than min 1)