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

append-type

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

append-type

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

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

append-type

npm version Build Status Coverage Status

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

import appendType from 'append-type';

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

Installation

Use npm.

npm install append-type

API

import appendType from 'append-type';

appendType(value)

value: any type
Return: string

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

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

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

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

Example

This module is useful for making TypeError error messages.

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 © 2019 Shinnosuke Watanabe

Keywords

FAQs

Package last updated on 22 Jan 2019

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