[SignalingServer] Optimize dependent modules
[platform/framework/web/wrtjs.git] / device_home / node_modules / express / node_modules / optionator / lib / help.js
1 // Generated by LiveScript 1.2.0
2 (function(){
3   var ref$, id, find, sort, min, max, map, partition, unlines, nameToRaw, dasherize, wordwrap, getPreText, setHelpStyleDefaults, generateHelpForOption, generateHelp;
4   ref$ = require('prelude-ls'), id = ref$.id, find = ref$.find, sort = ref$.sort, min = ref$.min, max = ref$.max, map = ref$.map, partition = ref$.partition, unlines = ref$.unlines;
5   ref$ = require('./util'), nameToRaw = ref$.nameToRaw, dasherize = ref$.dasherize;
6   wordwrap = require('wordwrap');
7   getPreText = function(option, arg$, maxWidth){
8     var mainName, aliases, ref$, type, description, aliasSeparator, typeSeparator, initialIndent, shortNames, longNames, names, namesString, namesStringLen, typeSeparatorString, typeSeparatorStringLen, typeString, that, wrap;
9     mainName = option.option, aliases = (ref$ = option.aliases) != null
10       ? ref$
11       : [], type = option.type, description = option.description;
12     aliasSeparator = arg$.aliasSeparator, typeSeparator = arg$.typeSeparator, initialIndent = arg$.initialIndent;
13     ref$ = partition(function(it){
14       return it.length === 1;
15     }, aliases), shortNames = ref$[0], longNames = ref$[1];
16     names = mainName.length === 1
17       ? [mainName].concat(shortNames, longNames)
18       : shortNames.concat([mainName], longNames);
19     namesString = map(nameToRaw, names).join(aliasSeparator);
20     namesStringLen = namesString.length;
21     typeSeparatorString = mainName === 'NUM' ? '::' : typeSeparator;
22     typeSeparatorStringLen = typeSeparatorString.length;
23     typeString = (that = option['enum']) ? "One of: " + that.join(', ') : type;
24     if (maxWidth != null && !option.boolean && initialIndent + namesStringLen + typeSeparatorStringLen + typeString.length > maxWidth) {
25       wrap = wordwrap(initialIndent + namesStringLen + typeSeparatorStringLen, maxWidth);
26       return namesString + "" + typeSeparatorString + wrap(typeString).replace(/^\s+/, '');
27     } else {
28       return namesString + "" + (option.boolean
29         ? ''
30         : typeSeparatorString + "" + typeString);
31     }
32   };
33   setHelpStyleDefaults = function(helpStyle){
34     helpStyle.aliasSeparator == null && (helpStyle.aliasSeparator = ', ');
35     helpStyle.typeSeparator == null && (helpStyle.typeSeparator = ' ');
36     helpStyle.descriptionSeparator == null && (helpStyle.descriptionSeparator = '  ');
37     helpStyle.initialIndent == null && (helpStyle.initialIndent = 2);
38     helpStyle.secondaryIndent == null && (helpStyle.secondaryIndent = 4);
39     helpStyle.maxPadFactor == null && (helpStyle.maxPadFactor = 1.5);
40   };
41   generateHelpForOption = function(getOption, arg$){
42     var stdout, helpStyle, ref$;
43     stdout = arg$.stdout, helpStyle = (ref$ = arg$.helpStyle) != null
44       ? ref$
45       : {};
46     setHelpStyleDefaults(helpStyle);
47     return function(optionName){
48       var maxWidth, wrap, option, e, pre, defaultString, restPositionalString, description, fullDescription, that, preDescription, descriptionString, exampleString, examples, seperator;
49       maxWidth = stdout != null && stdout.isTTY ? stdout.columns - 1 : null;
50       wrap = maxWidth ? wordwrap(maxWidth) : id;
51       try {
52         option = getOption(dasherize(optionName));
53       } catch (e$) {
54         e = e$;
55         return e.message;
56       }
57       pre = getPreText(option, helpStyle);
58       defaultString = option['default'] ? "\ndefault: " + option['default'] : '';
59       restPositionalString = option.restPositional ? 'Everything after this option is considered a positional argument, even if it looks like an option.' : '';
60       description = option.longDescription || option.description && sentencize(option.description);
61       fullDescription = description && restPositionalString
62         ? description + " " + restPositionalString
63         : (that = description || restPositionalString) ? that : '';
64       preDescription = 'description:';
65       descriptionString = !fullDescription
66         ? ''
67         : maxWidth && fullDescription.length - 1 - preDescription.length > maxWidth
68           ? "\n" + preDescription + "\n" + wrap(fullDescription)
69           : "\n" + preDescription + " " + fullDescription;
70       exampleString = (that = option.example) ? (examples = [].concat(that), examples.length > 1
71         ? "\nexamples:\n" + unlines(examples)
72         : "\nexample: " + examples[0]) : '';
73       seperator = defaultString || descriptionString || exampleString ? "\n" + repeatString$('=', pre.length) : '';
74       return pre + "" + seperator + defaultString + descriptionString + exampleString;
75     };
76   };
77   generateHelp = function(arg$){
78     var options, prepend, append, helpStyle, ref$, stdout, aliasSeparator, typeSeparator, descriptionSeparator, maxPadFactor, initialIndent, secondaryIndent;
79     options = arg$.options, prepend = arg$.prepend, append = arg$.append, helpStyle = (ref$ = arg$.helpStyle) != null
80       ? ref$
81       : {}, stdout = arg$.stdout;
82     setHelpStyleDefaults(helpStyle);
83     aliasSeparator = helpStyle.aliasSeparator, typeSeparator = helpStyle.typeSeparator, descriptionSeparator = helpStyle.descriptionSeparator, maxPadFactor = helpStyle.maxPadFactor, initialIndent = helpStyle.initialIndent, secondaryIndent = helpStyle.secondaryIndent;
84     return function(arg$){
85       var ref$, showHidden, interpolate, maxWidth, output, out, data, optionCount, totalPreLen, preLens, i$, len$, item, that, pre, desc, preLen, sortedPreLens, maxPreLen, preLenMean, x, padAmount, descSepLen, fullWrapCount, partialWrapCount, descLen, totalLen, initialSpace, wrapAllFull, i, wrap;
86       ref$ = arg$ != null
87         ? arg$
88         : {}, showHidden = ref$.showHidden, interpolate = ref$.interpolate;
89       maxWidth = stdout != null && stdout.isTTY ? stdout.columns - 1 : null;
90       output = [];
91       out = function(it){
92         return output.push(it != null ? it : '');
93       };
94       if (prepend) {
95         out(interpolate ? interp(prepend, interpolate) : prepend);
96         out();
97       }
98       data = [];
99       optionCount = 0;
100       totalPreLen = 0;
101       preLens = [];
102       for (i$ = 0, len$ = (ref$ = options).length; i$ < len$; ++i$) {
103         item = ref$[i$];
104         if (showHidden || !item.hidden) {
105           if (that = item.heading) {
106             data.push({
107               type: 'heading',
108               value: that
109             });
110           } else {
111             pre = getPreText(item, helpStyle, maxWidth);
112             desc = item['default']
113               ? (that = item.description) != null
114                 ? that + " - default: " + item['default']
115                 : "default: " + item['default']
116               : (that = item.description) != null ? that : '';
117             data.push({
118               type: 'option',
119               pre: pre,
120               desc: desc,
121               descLen: desc.length
122             });
123             preLen = pre.length;
124             optionCount++;
125             totalPreLen += preLen;
126             preLens.push(preLen);
127           }
128         }
129       }
130       sortedPreLens = sort(preLens);
131       maxPreLen = sortedPreLens[sortedPreLens.length - 1];
132       preLenMean = initialIndent + totalPreLen / optionCount;
133       x = optionCount > 2 ? min(preLenMean * maxPadFactor, maxPreLen) : maxPreLen;
134       for (i$ = sortedPreLens.length - 1; i$ >= 0; --i$) {
135         preLen = sortedPreLens[i$];
136         if (preLen <= x) {
137           padAmount = preLen;
138           break;
139         }
140       }
141       descSepLen = descriptionSeparator.length;
142       if (maxWidth != null) {
143         fullWrapCount = 0;
144         partialWrapCount = 0;
145         for (i$ = 0, len$ = data.length; i$ < len$; ++i$) {
146           item = data[i$];
147           if (item.type === 'option') {
148             pre = item.pre, desc = item.desc, descLen = item.descLen;
149             if (descLen === 0) {
150               item.wrap = 'none';
151             } else {
152               preLen = max(padAmount, pre.length) + initialIndent + descSepLen;
153               totalLen = preLen + descLen;
154               if (totalLen > maxWidth) {
155                 if (descLen / 2.5 > maxWidth - preLen) {
156                   fullWrapCount++;
157                   item.wrap = 'full';
158                 } else {
159                   partialWrapCount++;
160                   item.wrap = 'partial';
161                 }
162               } else {
163                 item.wrap = 'none';
164               }
165             }
166           }
167         }
168       }
169       initialSpace = repeatString$(' ', initialIndent);
170       wrapAllFull = optionCount > 1 && fullWrapCount + partialWrapCount * 0.5 > optionCount * 0.5;
171       for (i$ = 0, len$ = data.length; i$ < len$; ++i$) {
172         i = i$;
173         item = data[i$];
174         if (item.type === 'heading') {
175           if (i !== 0) {
176             out();
177           }
178           out(item.value + ":");
179         } else {
180           pre = item.pre, desc = item.desc, descLen = item.descLen, wrap = item.wrap;
181           if (maxWidth != null) {
182             if (wrapAllFull || wrap === 'full') {
183               wrap = wordwrap(initialIndent + secondaryIndent, maxWidth);
184               out(initialSpace + "" + pre + "\n" + wrap(desc));
185               continue;
186             } else if (wrap === 'partial') {
187               wrap = wordwrap(initialIndent + descSepLen + max(padAmount, pre.length), maxWidth);
188               out(initialSpace + "" + pad(pre, padAmount) + descriptionSeparator + wrap(desc).replace(/^\s+/, ''));
189               continue;
190             }
191           }
192           if (descLen === 0) {
193             out(initialSpace + "" + pre);
194           } else {
195             out(initialSpace + "" + pad(pre, padAmount) + descriptionSeparator + desc);
196           }
197         }
198       }
199       if (append) {
200         out();
201         out(interpolate ? interp(append, interpolate) : append);
202       }
203       return unlines(output);
204     };
205   };
206   function pad(str, num){
207     var len, padAmount;
208     len = str.length;
209     padAmount = num - len;
210     return str + "" + repeatString$(' ', padAmount > 0 ? padAmount : 0);
211   }
212   function sentencize(str){
213     var first, rest, period;
214     first = str.charAt(0).toUpperCase();
215     rest = str.slice(1);
216     period = /[\.!\?]$/.test(str) ? '' : '.';
217     return first + "" + rest + period;
218   }
219   function interp(string, object){
220     return string.replace(/{{([a-zA-Z$_][a-zA-Z$_0-9]*)}}/g, function(arg$, key){
221       var ref$;
222       return (ref$ = object[key]) != null
223         ? ref$
224         : "{{" + key + "}}";
225     });
226   }
227   module.exports = {
228     generateHelp: generateHelp,
229     generateHelpForOption: generateHelpForOption
230   };
231   function repeatString$(str, n){
232     for (var r = ''; n > 0; (n >>= 1) && (str += str)) if (n & 1) r += str;
233     return r;
234   }
235 }).call(this);