UNPKG

@cowwoc/requirements

Version:

A fluent API for enforcing design contracts with automatic message generation.

26 lines 829 B
import { requireThatValueIsNotNull } from "../../internal.mjs"; /** * A section of key-pair pairs that contain contextual information related to a validation failure. */ class ContextSection { value; constructor(value) { requireThatValueIsNotNull(value, "value"); this.value = value; } getMaxKeyLength() { let maxKeyLength = 0; for (const key of this.value.keys()) maxKeyLength = Math.max(maxKeyLength, key.length); return maxKeyLength; } getLines(maxKeyLength) { // Align the colons vertically const lines = []; for (const [key, value] of this.value.entries()) lines.push(key.padEnd(maxKeyLength) + ": " + value); return lines; } } export { ContextSection }; //# sourceMappingURL=ContextSection.mjs.map