UNPKG

3.14 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const _ = require("lodash");
4var ParameterHint;
5(function (ParameterHint) {
6 ParameterHint[ParameterHint["File"] = 0] = "File";
7 ParameterHint[ParameterHint["Directory"] = 1] = "Directory";
8})(ParameterHint = exports.ParameterHint || (exports.ParameterHint = {}));
9var ParameterType;
10(function (ParameterType) {
11 ParameterType[ParameterType["String"] = 0] = "String";
12 ParameterType[ParameterType["Number"] = 1] = "Number";
13 ParameterType[ParameterType["Boolean"] = 2] = "Boolean";
14 ParameterType[ParameterType["Map"] = 3] = "Map";
15 ParameterType[ParameterType["Mixed"] = 4] = "Mixed";
16 ParameterType[ParameterType["Array"] = 5] = "Array";
17})(ParameterType = exports.ParameterType || (exports.ParameterType = {}));
18var ParameterScope;
19(function (ParameterScope) {
20 ParameterScope[ParameterScope["TypeDoc"] = 0] = "TypeDoc";
21 ParameterScope[ParameterScope["TypeScript"] = 1] = "TypeScript";
22})(ParameterScope = exports.ParameterScope || (exports.ParameterScope = {}));
23class OptionDeclaration {
24 constructor(data) {
25 this.type = ParameterType.String;
26 this.scope = ParameterScope.TypeDoc;
27 for (let key in data) {
28 this[key] = data[key];
29 }
30 }
31 getNames() {
32 const result = [this.name.toLowerCase()];
33 if (this.short) {
34 result.push(this.short.toLowerCase());
35 }
36 return result;
37 }
38 convert(value, errorCallback) {
39 switch (this.type) {
40 case ParameterType.Number:
41 value = parseInt(value + '', 10);
42 break;
43 case ParameterType.Boolean:
44 value = !!value;
45 break;
46 case ParameterType.String:
47 value = value ? value + '' : '';
48 break;
49 case ParameterType.Array:
50 if (!value) {
51 value = [];
52 }
53 else if (typeof value === 'string') {
54 value = value.split(',');
55 }
56 break;
57 case ParameterType.Map:
58 const map = this.map || {};
59 if (map !== 'object') {
60 const key = value ? (value + '').toLowerCase() : '';
61 const values = _.values(map);
62 if (map instanceof Map) {
63 value = map.has(key) ? map.get(key) : value;
64 }
65 else if (key in map) {
66 value = map[key];
67 }
68 else if (!values.includes(value) && errorCallback) {
69 if (this.mapError) {
70 errorCallback(this.mapError);
71 }
72 else {
73 errorCallback('Invalid value for option "%s".', this.name);
74 }
75 }
76 }
77 break;
78 }
79 return value;
80 }
81}
82exports.OptionDeclaration = OptionDeclaration;
83//# sourceMappingURL=declaration.js.map
\No newline at end of file