# @mangar2/utils

> Combines JavaScript utilities

Latest version **2.0.2** (published 2024-05-12) · LGPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @mangar2/utils
pnpm add @mangar2/utils
yarn add @mangar2/utils
bun add @mangar2/utils
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2024-05-12 |
| First published | 2020-04-11 |
| Weekly downloads | 0 |
| License | LGPL-3.0-or-later |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 397.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Volker Böhm |
| Maintainers | mangar2 |

## Links

- npm: https://www.npmjs.com/package/@mangar2/utils
- Repository: https://github.com/Mangar2/utils
- Issues: https://github.com/Mangar2/utils/issues
- npm.io page: https://npm.io/package/@mangar2/utils

## Recent versions

- 2.0.2 (latest) — 2024-05-12
- 2.0.1 — 2024-05-12
- 2.0.0 — 2024-05-09
- 1.2.0 — 2022-01-03
- 1.1.0 — 2020-05-01
- 1.0.2 — 2020-04-13
- 1.0.0 — 2020-04-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.

---
_Source: https://npm.io/package/@mangar2/utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
