@ng-doc/builder
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>
57 lines • 2.36 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPlaygroundComponentInputs = getPlaygroundComponentInputs;
exports.getPlaygroundPipeInputs = getPlaygroundPipeInputs;
const ts_morph_1 = require("ts-morph");
const angular_1 = require("../angular");
const get_js_doc_1 = require("../get-js-doc");
const typescript_1 = require("../typescript");
/**
*
* @param declaration
*/
function getPlaygroundComponentInputs(declaration) {
return (0, angular_1.getComponentInputs)(declaration).reduce((properties, property) => {
const inputName = (0, angular_1.getInputName)(property);
return { ...properties, ...propOrParamToPlaygroundProperty(property, inputName) };
}, {});
}
/**
*
* @param declaration
*/
function getPlaygroundPipeInputs(declaration) {
return declaration
.getMethodOrThrow('transform')
.getParameters()
.slice(1)
.reduce((properties, parameter) => {
return { ...properties, ...propOrParamToPlaygroundProperty(parameter) };
}, {});
}
/**
*
* @param propOrParam
* @param inputName
*/
function propOrParamToPlaygroundProperty(propOrParam, inputName) {
const inputType = ts_morph_1.Node.isPropertyDeclaration(propOrParam)
? (0, angular_1.getInputType)(propOrParam)
: propOrParam.getType();
const type = (0, typescript_1.formatType)(inputType, ts_morph_1.TypeFormatFlags.NoTruncation | ts_morph_1.TypeFormatFlags.UseSingleQuotesForStringLiteralType);
return {
[propOrParam.getName()]: {
inputName: inputName ?? propOrParam.getName(),
type,
description: ts_morph_1.Node.isPropertyDeclaration(propOrParam) ||
ts_morph_1.Node.isGetAccessorDeclaration(propOrParam) ||
ts_morph_1.Node.isSetAccessorDeclaration(propOrParam)
? (0, get_js_doc_1.getJsDocDescription)(propOrParam)
: (0, get_js_doc_1.getJsDocParam)(propOrParam.getParentIfKindOrThrow(ts_morph_1.SyntaxKind.MethodDeclaration), propOrParam.getName()),
options: inputType
.getUnionTypes()
.map((type) => type.getText(undefined, ts_morph_1.TypeFormatFlags.NoTruncation | ts_morph_1.TypeFormatFlags.UseSingleQuotesForStringLiteralType)),
},
};
}
//# sourceMappingURL=get-playground-inputs.js.map
;