typed-aws
Version:
Helps you write AWS CloudFormation in TypeScript
45 lines (44 loc) • 1.52 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.concatWith = exports.groupByArray = exports.formatDoc = void 0;
const word_wrap_1 = __importDefault(require("word-wrap"));
function formatDoc(content) {
if (!content)
return '';
return ('/**\n * ' +
(0, word_wrap_1.default)(replaceHtml(removeBreakline(content.trim())).trim(), {
width: 70,
})
.replace(/\n */g, '\n * ')
.trim() +
'\n */\n');
}
exports.formatDoc = formatDoc;
function replaceHtml(content) {
return content
.replace(/<p>/gi, '')
.replace(/<note>/gi, '\n')
.replace(/<\/p>|<\/note>/gi, '\n')
.replace(/\n\n+/g, '\n');
}
function removeBreakline(content) {
if (!content)
return content;
return content.replace(/\s*(\r\n|\r|\n)\s*/gm, ' ').trim();
}
function groupByArray(array, key) {
return Array.from(array
.reduce((entryMap, e) => entryMap.set(key(e), [...(entryMap.get(key(e)) || []), e]), new Map())
.values());
}
exports.groupByArray = groupByArray;
function concatWith({ prefix, joiner, suffix, defaultValue = '' }, ...items) {
const all = items.filter((item) => !item);
if (all.length)
return defaultValue;
return (prefix || '') + items.join(joiner || '') + (suffix || '');
}
exports.concatWith = concatWith;