this function prepares a string representation of the provided args, in a manner similar to how console.log would print them out.
Important
although the returned string is pretty close to console.log in terms or representation, there are still many inconsistencies,
in addition to the fact that no line breaks are added, nor are long enumerations of array items trimmed to fit in the preview.
see the documentation comment of string_repr to see how individual items would typical transform under this function.
why would anyone have a need for such a function?
well, for my use case, I need it for printing out prettified Error exceptions (via throw_error),
since the Error constructor only takes in a single string parameter.
and having to do string interpolation for each error, in addition to using a ton of JSON.stringify, gets tiresome really quickly.
this function prepares a string representation of the provided
args
, in a manner similar to howconsole.log
would print them out.although the returned string is pretty close to
console.log
in terms or representation, there are still many inconsistencies, in addition to the fact that no line breaks are added, nor are long enumerations of array items trimmed to fit in the preview. see the documentation comment of string_repr to see how individual items would typical transform under this function.why would anyone have a need for such a function? well, for my use case, I need it for printing out prettified
Error
exceptions (via throw_error), since theError
constructor only takes in a single string parameter. and having to do string interpolation for each error, in addition to using a ton ofJSON.stringify
, gets tiresome really quickly.