Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jonahsnider/util

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jonahsnider/util

A useful collection of optimized utility functions

  • 11.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@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.

FAQs

Package last updated on 30 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc