@prismatic-io/spectral
Version:
Utility library for building Prismatic connectors and code-native integrations
40 lines (39 loc) • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addPunctuation = exports.addLine = exports.DOC_BLOCK_DEFAULT = void 0;
const escapeSpecialCharacters_1 = require("../utils/escapeSpecialCharacters");
const DOC_BLOCK_DEFAULT = (input) => {
const comments = (0, exports.addPunctuation)(input.comments);
const onPrem = input.onPremControlled || input.onPremiseControlled
? " This input will be supplied when using an on prem resource."
: "";
return ((0, exports.addLine)({ raw: "/**" }) +
(0, exports.addLine)({ value: input.label }) +
(0, exports.addLine)({ value: comments + onPrem }) +
(0, exports.addLine)({ raw: "*" }) +
(0, exports.addLine)({ key: "default", value: input.default }) +
(0, exports.addLine)({ key: "example", value: input.example }) +
(0, exports.addLine)({ key: "placeholder", value: input.placeholder }) +
(0, exports.addLine)({ raw: "*/" }));
};
exports.DOC_BLOCK_DEFAULT = DOC_BLOCK_DEFAULT;
const addLine = ({ key, value, raw }) => {
if (raw) {
return ` ${raw}\n`;
}
if (typeof value === "undefined" || value === null || value === "") {
return "";
}
const sanitizedValue = (0, escapeSpecialCharacters_1.escapeSpecialCharacters)(JSON.stringify(value)
.replace(/(^"|"$)|(^'|'$)/g, "")
.trim());
return ` * ${key ? `@${key} ${sanitizedValue}` : sanitizedValue}\n`;
};
exports.addLine = addLine;
const addPunctuation = (value) => {
if (typeof value === "undefined" || value === null || value === "") {
return "";
}
return value.endsWith(".") || value.endsWith("!") || value.endsWith("?") ? value : `${value}.`;
};
exports.addPunctuation = addPunctuation;