append-type
Stringify the value with appending its type: 10
→ '10 (number)'
; ; //=> '123 (string)'; //=> '123 (number)'
Installation
npm install append-type
API
;
appendType(value)
value: any type
Return: string
Essentially, it returns String(value) + ' (' + typeof value + ')'
.
; //=> '() => {} (function)'
When it takes null
/ undefined
, it returns 'null'
/ 'undefined'
.
; //=> 'null'; //=> 'undefined'
Example
This module is useful for making TypeError
error messages.
{ if typeof v !== 'boolean' throw `Expected a Boolean value, but got .`; return !v;}; ; //=> TypeError: Expected a Boolean value, but got 1 (number).
License
MIT No Attribution © 2019 Shinnosuke Watanabe