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

@mangar2/utils

v2.0.2

Published

Combines JavaScript utilities

Downloads

11

Readme

Abstract

This package includes several small utilities I use in JavaScript/TypeScript development.

  • @author Volker Böhm
  • @copyright Copyright (c) 2024 Volker Böhm

Utilities

A collection of utilities

callbacks

A class to add callbacks registered with "on" to your class

config

A class to read configuration files for example from a file passed as command line parameter

deep-merge

A class to deep merge two objects

delay

A class to delay the execution of code

errorlog

Small functions to log errors (usually in the catch block)

persist

File io to persist data

retry

Functions used to retry operations that might fail

shutdown

Functions to handle shutdown (usually when pressing ^C)

sun

Sunrise, Sunset calculation

taskqueue

A simple queue running callbacks (tasks) with delay inbetween

time

Some functions handling time strings that I couldn´t find in Date()

types

Type check functions like isArray, isObject, ... that I use everywhere (because of consistent syntax). They work for typescript

Unit Tests

Here we have two classes for unittests.

UnitTest

A Unittest class with typical methods like assertEqual, ... It also contains helper functions to compare two objects in detail and it records all "success" and "fail" to provide a test result at the end. I use it for simple tests

TestRun

My way to run unit tests. I never found unit test libraries that I like. The concept is to provide all test cases in test case files (JSON like in .js files). The structure is Array of Testcases with initialization and Array of tests. The TestRun is able to run tests from many files and in each file many testcases and in each testcase several tests.

  • The tests can run sequentially or in parallel (e.g. if there are tests waiting for something, ...)
  • The tests can be repeated automatically. If a test fails, all tests are restarted from the beginning until the failed test. The faild test is then executed by a function "runAgain". The idea is to set a breakpoint in this function. As a result you can set one breakpoint and the debugger halts there whenever a test fails and you have the situation right BEFORE the test fails. I use this often and I like it very much.
  • Tests are usually producing an Object (Record<string, unknown>) as result. It will be compared to an "expectedResult" you provide with the test case defintion. Only properties in "expectedResult" are checked agains the result. The idea is to test only what is important to the current test case and not to provide the whole complexity of the current result in "expected result". This also allows you to skip things like timestamps from the test.

Overall I like it much, but it is not straight foreward and very easy to understand.