# append-type

> Stringify the value with appending its type: 10 → '10 (number)'

Latest version **1.0.2** (published 2019-01-22) · MIT-0 license · 0 weekly downloads

## Install

```sh
npm install append-type
pnpm add append-type
yarn add append-type
bun add append-type
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-01-22 |
| First published | 2016-10-12 |
| Weekly downloads | 0 |
| License | MIT-0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Shinnosuke Watanabe |
| Maintainers | shinnn |
| Keywords | string, stringify, tostring, type, append, concat, join |

## Links

- npm: https://www.npmjs.com/package/append-type
- Repository: https://github.com/shinnn/append-type
- Homepage: https://github.com/shinnn/append-type#readme
- Issues: https://github.com/shinnn/append-type/issues
- npm.io page: https://npm.io/package/append-type

## Recent versions

- 1.0.2 (latest) — 2019-01-22
- 1.0.1 — 2018-02-14
- 1.0.0 — 2016-10-14
- 0.0.0 — 2016-10-12

## README

# append-type

[![npm version](https://img.shields.io/npm/v/append-type.svg)](https://www.npmjs.com/package/append-type)
[![Build Status](https://travis-ci.com/shinnn/append-type.svg?branch=master)](https://travis-ci.com/shinnn/append-type)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/append-type.svg)](https://coveralls.io/r/shinnn/append-type)

Stringify the value with appending its [type](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/typeof): `10` → `'10 (number)'`

```javascript
import appendType from 'append-type';

appendType('123'); //=> '123 (string)'
appendType(123); //=> '123 (number)'
```

## Installation

[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).

```
npm install append-type
```

## API

```javascript
import appendType from 'append-type';
```

### appendType(*value*)

*value*: any type  
Return: `string`

Essentially, it returns `String(value) + ' (' + typeof value + ')'`.

```javascript
appendType(() => {}); //=> '() => {} (function)'
```

When it takes `null` / `undefined`, it returns `'null'` / `'undefined'`.

```javascript
appendType(null); //=> 'null'
appendType(undefined); //=> 'undefined'
```

## Example

This module is useful for making `TypeError` error messages.

```javascript
function reverse(v) {
  if (typeof v !== 'boolean') {
    throw new TypeError(`Expected a Boolean value, but got ${appendType(v)}.`);
  }

  return !v;
};

reverse(1); //=> TypeError: Expected a Boolean value, but got 1 (number).
```

## License

[MIT No Attribution](./LICENSE) © 2019 Shinnosuke Watanabe

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