shared.js 531 B

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