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

@jonahsnider/util

v11.0.0

Published

A useful collection of optimized utility functions

Downloads

5,478

Readme

@jonahsnider/util

A collection of simple, optimized utility functions that help you spend more time implementing real features instead of writing the same snippets over and over.

Written in TypeScript with strong typesafety in mind (more on that below).

Works in Node.js, mostly works in browsers.

View the docs here.

If you're considering using the library I recommend taking a glance at the docs to see if anything seems helpful to you.

Build Status XO code style Codecov

Get started

yarn add @jonahsnider/util
# or
npm install @jonahsnider/util

then

import {shuffle} from '@jonahsnider/util';
// or
import * as util from '@jonahsnider/util';

const {shuffle} = require('@jonahsnider/util');
// or
const util = require('@jonahsnider/util');

Why you should use this library

There's 3 main benefits this library offers:

  1. Readability

    Because JavaScript lacks a proper standard library, you will find yourself writing the same snippets again and again. Let's look at sorting an array in ascending order (low to high) as an example:

    // Sort ascending
    array.sort((a, b) => a - b);

    As an experienced dev you've probably seen this snippet in some form hundreds of times before. If you're a beginner you might not even be able to tell if this is an ascending or descending sort without the comment.

    The alternative:

    import {Sort} from '@jonahsnider/util';
    
    array.sort(Sort.ascending);

    If you were skimming through a file and saw this you can immediately understand what this code does.

    This library works perfectly with existing idiomatic JavaScript and doesn't force you to change the way you write code.

    (also - fun fact: the first snippet doesn't work with bigints, the second snippet does)

  2. Safety

    Writing your own snippets doesn't just slow you down, it can introduce bugs.

    Every function is tested with 100% coverage, ensuring bug-free code.

  3. Features

    This library isn't just 1-liners you could copy-paste yourself.

    Want to do a binary search on an array? We've got you covered.

    Combine a bunch of regular expressions into one? No problem.

    Need a deck of cards? Only one import away.

TypeScript

In addition to all the useful functions this library provides, a major effort has been made to ensure the best possible experience for TypeScript users.

  • Functions accept many types of arguments, either as a generic T or a union of related types like number | bigint (mostly useful in the math functions)
  • Iterables and ArrayLikes are used instead of Arrays whenever possible, broader types ensure compatibility with your projects and let you avoid ugly type assertions
  • When an array is needed, it's always readonly T[] unless mutation is required

There's also a few types exported that can be handy in certain situations (ex. NonEmptyArray or Nullish).

My personal favorite is the TypedEventEmitter which lets you ensure typesafety in event listeners.