# tap-console

> A console.log alternative that makes your life easier only a bit

Latest version **0.1.0** (published 2018-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install tap-console
pnpm add tap-console
yarn add tap-console
bun add tap-console
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2018-10-17 |
| First published | 2018-10-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | autologie |
| Maintainers | autologie |
| Keywords | console, logger, functional |

## Links

- npm: https://www.npmjs.com/package/tap-console
- Repository: https://github.com/autologie/tap-console
- Issues: https://github.com/autologie/tap-console/issues
- npm.io page: https://npm.io/package/tap-console

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.1.0 (latest) — 2018-10-17

## README

# tap-console

A functional programming in mind `console.log` alternative that makes your life easier only a bit, inspired by Elm language's `Debug.log`

## Install

```sh
npm i tap-console
```

or

```sh
yarn add tap-console
```

## Motivation

### The Problem

ES6 arrow function (`=>`) made it easy to write function literals.
However, putting a debugging code in it sometimes turns out to be too painful in contrast to what you hope to do.

Suppose you're working with a code like this

```js
const compare = (one, another) => Math.abs(one) - Math.abs(another);

arr.sort((a, b) => compare(a, b));
```

And you want to be sure that `compare` works as you expected.

You're to print what `compare` returns like this

```js
...
arr.sort((a, b) => {
  const result = compare(a, b);
  console.log(a, b, result);
  return result;
});
```

or this

```js
const compare = (one, another) => {
  const result = Math.abs(one) - Math.abs(another);
  console.log(one, another, result);
  return result;
};
...
```

or this (ok, it's just a debugging...)

```js
...
arr.sort((a, b) => console.log(a, b, compare(a, b)) || compare(a, b));
```

Aren't these too tedious...?

### A solution

Instead, using this library, do one of these

```js
import { log } from "tap-console";
...
arr.sort((a, b) => log(a, b, compare(a, b)));
```

```js
import { log } from "tap-console";

const compare = (one, another) =>
	log(one, another, Math.abs(one) - Math.abs(another));
...
```

```js
...
arr.sort((a, b) => require("tap-console").log(a, b, compare(a, b)));
```

```js
...
// shorthand for log() method
arr.sort((a, b) => require("tap-console")(a, b, compare(a, b)));
```

## Usage

The only difference between the logger object that this library exports and the built-in `console` object is that each method of the former returns the **last** argument passed to it.

All the methods that the built-in `console` supports are supported.
For example,

```js
import tc from "tap-console";
...
const squares = tc.table([1, 3, 5].map(i => i * i)); // returns [1, 9, 25]
```

### `create` method

This method allows you to create a custom print function.

```js
import {create} from 'tap-console';

const show = create(value => window.alert(value));
const sum = show(1) + show(2); // returns 3
```

### `first` method

Different from other methods, this method calls `console.log` internally and then returns the **first** argument.
Useful when dealing with array methods such as `map` and `filter`.

```js
[1, 2, 3, 4].map(tc.first); // returns [1, 2, 3, 4]
```

## License

MIT.

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