UNPKG

531 BJavaScriptView Raw
1/**
2 * @fileoverview Shared utilities for error messages.
3 * @author Josh Goldberg
4 */
5
6"use strict";
7
8/**
9 * Converts a value to a string that may be printed in errors.
10 * @param {any} value The invalid value.
11 * @param {number} indentation How many spaces to indent
12 * @returns {string} The value, stringified.
13 */
14function stringifyValueForError(value, indentation) {
15 return value ? JSON.stringify(value, null, 4).replace(/\n/gu, `\n${" ".repeat(indentation)}`) : `${value}`;
16}
17
18module.exports = { stringifyValueForError };