UNPKG

macoolka-type-model

Version:

`macoolka-type-model` is a library for define model in TypeScript. It easily build a type contain field and method to your Application. It provide a generation model for type and validition

151 lines 5.37 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatCode = void 0; /** * Helper fro print code * @desczh * 打印代码的帮助函数 * @file */ var Monoid_1 = require("fp-ts/Monoid"); var pipeable_1 = require("fp-ts/pipeable"); var macoolka_predicate_1 = require("macoolka-predicate"); var A = __importStar(require("fp-ts/Array")); var fold = (0, Monoid_1.fold)(Monoid_1.monoidString); var indentations = { 1: ' ', 2: ' ', 3: ' ', 4: ' ', 5: ' ', 6: ' ', 7: ' ', 8: ' ', 9: ' ' }; var standIndent = function (i) { if (i === 0) { return ''; } return (0, macoolka_predicate_1.notMaybe)(indentations[i]) ? indentations[i] : new Array(i).join(" "); }; /** * The provide a helper about build `block` `line` `item` document. * Block containers head and content and end * Line mean a statement * Item maen a statement and description * @desczh * 提供一些帮助方法在建立`block` `line` `item` * * block包含头尾内容,一般用于interface * line是一条语句 * item是包含注释的语句 * @since 0.2.0 */ var formatCode = function (_a) { var _b = _a.indentMake, indentMake = _b === void 0 ? standIndent : _b, _c = _a.line, line = _c === void 0 ? '\n' : _c; /** * * */ var formatBlock = function (_a) { var begin = _a.begin, end = _a.end, indent = _a.indent, content = _a.content, _b = _a.split, split = _b === void 0 ? '' : _b; return (0, pipeable_1.pipe)([ (0, macoolka_predicate_1.notEmpty)(begin) ? (indentMake(indent) + begin) : '', (0, pipeable_1.pipe)(content.join(split)), formatLine(indent)(end) ], fold); }; var formatLine = function (i) { return function (content) { return (indentMake(i) + content + line); }; }; var formatItem = function (i, desc) { if (desc === void 0) { desc = true; } return function (_a) { var content = _a.content, docs = _a.docs; var doc = documentableToString(docs); return (0, pipeable_1.pipe)([ desc ? printDescription(i)(doc) : '', (0, macoolka_predicate_1.notEmpty)(content) ? formatLine(i)(content) : '' ], fold); }; }; function printDescription(indent) { return function (content) { return content.length > 0 ? formatBlock({ begin: "/**" + line, end: ' */', indent: indent, content: content.map(function (a) { return (0, pipeable_1.pipe)(indentMake(indent) + ' * ' + a, formatLine(0)); }) }) : ''; }; } function documentableToString(_a) { var deprecated = _a.deprecated, description = _a.description, descriptions = _a.descriptions, ignore = _a.ignore, since = _a.since, examples = _a.examples, reason = _a.reason; var content = A.copy(description); if ((0, macoolka_predicate_1.notMaybe)(descriptions)) { Object.entries(descriptions).map(function (_a) { var key = _a[0], value = _a[1]; var desc = value; if (desc.length > 0) { content.push("@desc".concat(key)); content = content.concat(desc); } }); } if ((0, macoolka_predicate_1.notEmpty)(examples)) { content.push("@examples"); content = content.concat(examples); } if (deprecated) { content.push('@deprecated'); if ((0, macoolka_predicate_1.notMaybe)(reason)) { content = content.concat(reason); } } if (ignore) { content.push('@ignore'); } if ((0, macoolka_predicate_1.notMaybe)(since)) { content.push("@since ".concat(since)); } return content; } return { formatLine: formatLine, formatBlock: formatBlock, formatItem: formatItem, fold: fold }; }; exports.formatCode = formatCode; //# sourceMappingURL=utils.js.map