append-type
Stringify the value with appending its type: 10
→ '10 (number)'
import appendType from 'append-type';
appendType('123');
appendType(123);
Installation
npm install append-type
bower install append-type
API
appendType(value)
value: any type
Return: String
Essentially, it returns String(value) + ' (' + typeof value + ')'
.
appendType(() => {});
When it takes null
/ undefined
, it returns 'null'
/ 'undefined'
.
appendType(null);
appendType(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);
License
Copyright (c) 2016 Shinnosuke Watanabe
Licensed under the MIT License.