UNPKG

@microsoft/api-extractor

Version:

Validate, document, and review the exported API for a TypeScript library

90 lines 4.09 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. Object.defineProperty(exports, "__esModule", { value: true }); const AstItem_1 = require("../ast/AstItem"); /** * Supports the conversion between AstItems that are loaded from AstItem to JSON notation * and vice versa. */ class ApiJsonConverter { /** * Uses the lowercase string that represents 'kind' in an API JSON file, and * converts it to an AstItemKind enum value. * There are two cases we do not include here, (Parameter and StructuredType), * this is intential as we do not expect to be loading these kind of JSON object * from file. */ static convertJsonToKind(jsonItemKind) { switch (jsonItemKind) { case (this._KIND_CONSTRUCTOR): return AstItem_1.AstItemKind.Constructor; case (this._KIND_CLASS): return AstItem_1.AstItemKind.Class; case (this._KIND_ENUM): return AstItem_1.AstItemKind.Enum; case (this._KIND_ENUM_VALUE): return AstItem_1.AstItemKind.EnumValue; case (this._KIND_INTERFACE): return AstItem_1.AstItemKind.Interface; case (this._KIND_FUNCTION): return AstItem_1.AstItemKind.Function; case (this._KIND_PACKAGE): return AstItem_1.AstItemKind.Package; case (this._KIND_PROPERTY): return AstItem_1.AstItemKind.Property; case (this._KIND_METHOD): return AstItem_1.AstItemKind.Method; case (this._KIND_NAMESPACE): return AstItem_1.AstItemKind.Namespace; case (this._KIND_MODULEVARIABLE): return AstItem_1.AstItemKind.ModuleVariable; default: throw new Error('Unsupported kind when converting JSON item kind to API item kind.'); } } /** * Converts the an AstItemKind into a lower-case string that is written to API JSON files. */ static convertKindToJson(astItemKind) { switch (astItemKind) { case (AstItem_1.AstItemKind.Constructor): return this._KIND_CONSTRUCTOR; case (AstItem_1.AstItemKind.Class): return this._KIND_CLASS; case (AstItem_1.AstItemKind.Enum): return this._KIND_ENUM; case (AstItem_1.AstItemKind.EnumValue): return this._KIND_ENUM_VALUE; case (AstItem_1.AstItemKind.Interface): return this._KIND_INTERFACE; case (AstItem_1.AstItemKind.Function): return this._KIND_FUNCTION; case (AstItem_1.AstItemKind.Package): return this._KIND_PACKAGE; case (AstItem_1.AstItemKind.Property): return this._KIND_PROPERTY; case (AstItem_1.AstItemKind.Method): return this._KIND_METHOD; case (AstItem_1.AstItemKind.Namespace): return this._KIND_NAMESPACE; case (AstItem_1.AstItemKind.ModuleVariable): return this._KIND_MODULEVARIABLE; default: throw new Error('Unsupported API item kind when converting to string used in API JSON file.'); } } } ApiJsonConverter._KIND_CONSTRUCTOR = 'constructor'; ApiJsonConverter._KIND_CLASS = 'class'; ApiJsonConverter._KIND_ENUM = 'enum'; ApiJsonConverter._KIND_ENUM_VALUE = 'enum value'; ApiJsonConverter._KIND_INTERFACE = 'interface'; ApiJsonConverter._KIND_FUNCTION = 'function'; ApiJsonConverter._KIND_PACKAGE = 'package'; ApiJsonConverter._KIND_PROPERTY = 'property'; ApiJsonConverter._KIND_METHOD = 'method'; ApiJsonConverter._KIND_NAMESPACE = 'namespace'; ApiJsonConverter._KIND_MODULEVARIABLE = 'module variable'; exports.ApiJsonConverter = ApiJsonConverter; //# sourceMappingURL=ApiJsonConverter.js.map