shared.js 546 B

1234567891011121314151617181920212223
  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
  14. ? JSON.stringify(value, null, 4).replace(
  15. /\n/gu,
  16. `\n${" ".repeat(indentation)}`,
  17. )
  18. : `${value}`;
  19. }
  20. module.exports = { stringifyValueForError };