@satisfactory-dev/docdown 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +33 -0
- package/bin/docdown.js +86 -0
- package/index.js +53 -0
- package/lib/alias.js +220 -0
- package/lib/entry.js +676 -0
- package/lib/generator.js +404 -0
- package/lib/util.js +136 -0
- package/package.json +37 -0
package/lib/generator.js
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* docdown
|
|
3
|
+
* Copyright 2011-2016 John-David Dalton
|
|
4
|
+
* Copyright 2026 SignpostMarv
|
|
5
|
+
* Available under MIT license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import Entry from './entry.js';
|
|
9
|
+
import util from './util.js';
|
|
10
|
+
|
|
11
|
+
const getEntries = Entry.getEntries;
|
|
12
|
+
|
|
13
|
+
var
|
|
14
|
+
specialCategories = ['Methods', 'Properties'],
|
|
15
|
+
token = '@@token@@';
|
|
16
|
+
|
|
17
|
+
var reCode = /`.*?`/g,
|
|
18
|
+
reToken = /@@token@@/g;
|
|
19
|
+
|
|
20
|
+
var htmlEscapes = {
|
|
21
|
+
'*': '*',
|
|
22
|
+
'[': '[',
|
|
23
|
+
']': ']'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/*----------------------------------------------------------------------------*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Escape special Markdown characters in a string.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {string} string The string to escape.
|
|
33
|
+
* @returns {string} Returns the escaped string.
|
|
34
|
+
*/
|
|
35
|
+
function escape(string) {
|
|
36
|
+
var snippets = [];
|
|
37
|
+
|
|
38
|
+
// Replace all code snippets with a token.
|
|
39
|
+
string = string.replace(reCode, function(match) {
|
|
40
|
+
snippets.push(match);
|
|
41
|
+
return token;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
for (const [chr, replacement] of Object.entries(htmlEscapes)) {
|
|
45
|
+
string = string.replace(RegExp('(\\\\?)\\' + chr, 'g'), function(match, backslash) {
|
|
46
|
+
return backslash ? match : replacement;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Replace all tokens with code snippets.
|
|
51
|
+
return string.replace(reToken, function(match) {
|
|
52
|
+
return snippets.shift();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Get the seperator (`.` or `.prototype.`)
|
|
58
|
+
*
|
|
59
|
+
* @private
|
|
60
|
+
* @param {Entry} Entry object to get selector for.
|
|
61
|
+
* @returns {string} Returns the member seperator.
|
|
62
|
+
*/
|
|
63
|
+
function getSeparator(entry) {
|
|
64
|
+
return entry.isPlugin() ? '.prototype.' : '.';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Modify a string by replacing named tokens with matching associated object values.
|
|
69
|
+
*
|
|
70
|
+
* @private
|
|
71
|
+
* @param {string} string The string to modify.
|
|
72
|
+
* @param {Object} data The template data object.
|
|
73
|
+
* @returns {string} Returns the modified string.
|
|
74
|
+
*/
|
|
75
|
+
function interpolate(string, data) {
|
|
76
|
+
function tagged(_, string) {
|
|
77
|
+
let result = string;
|
|
78
|
+
|
|
79
|
+
for (const [key, value] of Object.entries(data)) {
|
|
80
|
+
result = result.replaceAll(`\${${key}}`, value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return util.format(tagged`${string}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Make an anchor link.
|
|
91
|
+
*
|
|
92
|
+
* @private
|
|
93
|
+
* @param {string} href The anchor href.
|
|
94
|
+
* @param {string} text The anchor text.
|
|
95
|
+
* @returns {string} Returns the anchor HTML.
|
|
96
|
+
*/
|
|
97
|
+
function makeAnchor(href, text) {
|
|
98
|
+
return `<a href="${href}">${text}</a>`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/*----------------------------------------------------------------------------*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Generates the documentation from JS source.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} The source code to generate the documentation for.
|
|
107
|
+
* @param {object} The options object.
|
|
108
|
+
* @returns {string} Returns the documentation markdown.
|
|
109
|
+
*
|
|
110
|
+
* @todo look into why tocLink doesn't seem to work on GitHub
|
|
111
|
+
*/
|
|
112
|
+
function generateDoc(source, options) {
|
|
113
|
+
/** @type {Entry[]} */
|
|
114
|
+
const api = [];
|
|
115
|
+
var
|
|
116
|
+
byCategories = options.toc == 'categories',
|
|
117
|
+
entries = getEntries(source),
|
|
118
|
+
/** @type {Object<string, Entry[]>} */
|
|
119
|
+
organized = Object.create(null),
|
|
120
|
+
sortEntries = options.sort,
|
|
121
|
+
style = options.style,
|
|
122
|
+
url = options.url;
|
|
123
|
+
|
|
124
|
+
// Add entries and aliases to the API list.
|
|
125
|
+
entries.forEach(function(entryStr) {
|
|
126
|
+
const entry = new Entry(entryStr, source);
|
|
127
|
+
api.push(entry);
|
|
128
|
+
api.push(...entry.getAliases())
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Build the list of categories for the TOC and generate content for each entry.
|
|
132
|
+
api.forEach(function(entry) {
|
|
133
|
+
// Exit early if the entry is private or has no name.
|
|
134
|
+
var name = entry.getName();
|
|
135
|
+
if (!name || entry.isPrivate()) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
var tocGroup,
|
|
139
|
+
member = entry.getMembers(0) || '',
|
|
140
|
+
separator = member ? getSeparator(entry) : '';
|
|
141
|
+
|
|
142
|
+
// Add the entry to the TOC.
|
|
143
|
+
if (byCategories) {
|
|
144
|
+
var category = entry.getCategory();
|
|
145
|
+
tocGroup = organized[category] || (organized[category] = []);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
var memberGroup;
|
|
149
|
+
if (!member ||
|
|
150
|
+
entry.isCtor() ||
|
|
151
|
+
(entry.getType() == 'Object' &&
|
|
152
|
+
!/[=:]\s*(?:null|undefined)\s*[,;]?$/gi.test(entry.entry))
|
|
153
|
+
) {
|
|
154
|
+
memberGroup = (member ? member + getSeparator(entry) : '') + name;
|
|
155
|
+
} else if (entry.isStatic()) {
|
|
156
|
+
memberGroup = member;
|
|
157
|
+
} else if (!entry.isCtor()) {
|
|
158
|
+
memberGroup = member + getSeparator(entry).slice(0, -1);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!(memberGroup in organized)) {
|
|
162
|
+
organized[memberGroup] = [];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
tocGroup = organized[memberGroup];
|
|
166
|
+
}
|
|
167
|
+
tocGroup.push(entry);
|
|
168
|
+
|
|
169
|
+
// Skip aliases.
|
|
170
|
+
if (entry.isAlias()) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
// Start markdown for the entry.
|
|
174
|
+
var entryMarkdown = ['\n<!-- div -->\n'];
|
|
175
|
+
|
|
176
|
+
var entryData = {
|
|
177
|
+
'call': entry.getCall(),
|
|
178
|
+
'category': entry.getCategory(),
|
|
179
|
+
'entryHref': '#${hash}',
|
|
180
|
+
'entryLink': options.entryLink || (style == 'github' ? '' : '<a href="${entryHref}">#</a> '),
|
|
181
|
+
'hash': entry.getHash(style),
|
|
182
|
+
'member': member,
|
|
183
|
+
'name': name,
|
|
184
|
+
'separator': separator,
|
|
185
|
+
'sourceHref': url + '#L' + entry.getLineNumber(),
|
|
186
|
+
'sourceLink': (
|
|
187
|
+
options.sourceLink || (
|
|
188
|
+
options.style === 'github'
|
|
189
|
+
? '${sourceHref}'
|
|
190
|
+
: '[Ⓢ](${sourceHref} "View in source")'
|
|
191
|
+
)
|
|
192
|
+
),
|
|
193
|
+
'tocHref': '1',
|
|
194
|
+
'tocLink': (
|
|
195
|
+
(
|
|
196
|
+
'tocLink' in options &&
|
|
197
|
+
false === options.tocLink
|
|
198
|
+
)
|
|
199
|
+
? ''
|
|
200
|
+
: (options.tocLink || '[Ⓣ][${tocHref}]')
|
|
201
|
+
)
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
[
|
|
205
|
+
'entryHref', 'sourceHref', 'tocHref',
|
|
206
|
+
'entryLink', 'sourceLink', 'tocLink'
|
|
207
|
+
].forEach(function(option) {
|
|
208
|
+
entryData[option] = interpolate(entryData[option], entryData);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const {
|
|
212
|
+
hash,
|
|
213
|
+
entryLink,
|
|
214
|
+
call,
|
|
215
|
+
} = entryData;
|
|
216
|
+
|
|
217
|
+
// Add the heading.
|
|
218
|
+
entryMarkdown.push(
|
|
219
|
+
util.format(`<h3 id="${hash}">${entryLink}<code>${member}${separator}${call}</code></h3>`) +
|
|
220
|
+
'\n' +
|
|
221
|
+
interpolate(
|
|
222
|
+
[
|
|
223
|
+
'${sourceLink}',
|
|
224
|
+
options.sublinks || [],
|
|
225
|
+
'${tocLink}'
|
|
226
|
+
]
|
|
227
|
+
.flatMap((e) => e)
|
|
228
|
+
.filter((maybe) => !!maybe)
|
|
229
|
+
.join(' '),
|
|
230
|
+
entryData
|
|
231
|
+
)
|
|
232
|
+
.replace(/ {2,}/g, ' '),
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
// Add the description.
|
|
236
|
+
entryMarkdown.push('\n' + entry.getDesc() + '\n');
|
|
237
|
+
|
|
238
|
+
// Add optional related.
|
|
239
|
+
var relatedItems = entry.getRelated();
|
|
240
|
+
if (relatedItems.length) {
|
|
241
|
+
entryMarkdown.push(
|
|
242
|
+
'#### Related',
|
|
243
|
+
relatedItems.join(', '),
|
|
244
|
+
''
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
// Add optional since version.
|
|
248
|
+
var since = entry.getSince();
|
|
249
|
+
if (since.length) {
|
|
250
|
+
entryMarkdown.push(
|
|
251
|
+
'#### Since',
|
|
252
|
+
since,
|
|
253
|
+
''
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
// Add optional aliases.
|
|
257
|
+
var aliases = entry.getAliases();
|
|
258
|
+
if (aliases.length) {
|
|
259
|
+
entryMarkdown.push(
|
|
260
|
+
'#### Aliases',
|
|
261
|
+
'*' +
|
|
262
|
+
aliases.map(function(alias) {
|
|
263
|
+
return util.format(`${member}${separator}${alias.getName()}`);
|
|
264
|
+
}).join(', ') +
|
|
265
|
+
'*',
|
|
266
|
+
''
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
// Add optional function parameters.
|
|
270
|
+
var params = entry.getParams();
|
|
271
|
+
if (params.length) {
|
|
272
|
+
entryMarkdown.push('#### Arguments');
|
|
273
|
+
params.forEach(function(param, index) {
|
|
274
|
+
var paramType = param[0];
|
|
275
|
+
if (paramType.startsWith('(')) {
|
|
276
|
+
paramType = util.deparenthesize(paramType);
|
|
277
|
+
}
|
|
278
|
+
entryMarkdown.push(
|
|
279
|
+
util.format(`${index + 1}. \`${param[1]}\` (${escape(paramType)}): ${escape(param[2])}`),
|
|
280
|
+
);
|
|
281
|
+
});
|
|
282
|
+
entryMarkdown.push('');
|
|
283
|
+
}
|
|
284
|
+
// Add optional functions returns.
|
|
285
|
+
var returns = entry.getReturns();
|
|
286
|
+
if (returns.length) {
|
|
287
|
+
var returnType = returns[0];
|
|
288
|
+
if (returnType.startsWith('(')) {
|
|
289
|
+
returnType = util.deparenthesize(returnType);
|
|
290
|
+
}
|
|
291
|
+
entryMarkdown.push(
|
|
292
|
+
'#### Returns',
|
|
293
|
+
util.format(`(${escape(returnType)}): ${escape(returns[1])}`),
|
|
294
|
+
''
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
// Add optional function example.
|
|
298
|
+
var example = entry.getExample();
|
|
299
|
+
if (example) {
|
|
300
|
+
entryMarkdown.push('#### Example', example);
|
|
301
|
+
}
|
|
302
|
+
// End markdown for the entry.
|
|
303
|
+
entryMarkdown.push('---\n\n<!-- /div -->');
|
|
304
|
+
|
|
305
|
+
entry.markdown = entryMarkdown.join('\n');
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// Add TOC headers.
|
|
309
|
+
var tocGroups = Object.keys(organized);
|
|
310
|
+
if (byCategories) {
|
|
311
|
+
// Remove special categories before sorting.
|
|
312
|
+
var catogoriesUsed = tocGroups.filter((maybe) => specialCategories.includes(maybe));
|
|
313
|
+
tocGroups = tocGroups.filter((maybe) => !catogoriesUsed.includes(maybe))
|
|
314
|
+
|
|
315
|
+
// Sort categories and add special categories back.
|
|
316
|
+
if (sortEntries) {
|
|
317
|
+
tocGroups.sort(util.compareNatural);
|
|
318
|
+
}
|
|
319
|
+
tocGroups.push(...catogoriesUsed);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
tocGroups.sort(util.compareNatural);
|
|
323
|
+
}
|
|
324
|
+
// Start markdown for TOC categories.
|
|
325
|
+
var tocMarkdown = ['<!-- div class="toc-container" -->\n'];
|
|
326
|
+
tocGroups.forEach(function(group) {
|
|
327
|
+
tocMarkdown.push(
|
|
328
|
+
'<!-- div -->\n',
|
|
329
|
+
'## `' + group + '`'
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
if (sortEntries && organized[group]) {
|
|
333
|
+
// Sort the TOC groups.
|
|
334
|
+
organized[group].sort(function(value, other) {
|
|
335
|
+
var valMember = value.getMembers(0),
|
|
336
|
+
othMember = other.getMembers(0);
|
|
337
|
+
|
|
338
|
+
return util.compareNatural(
|
|
339
|
+
(valMember ? (valMember + getSeparator(value)) : '') + value.getName(),
|
|
340
|
+
(othMember ? (othMember + getSeparator(other)) : '') + other.getName()
|
|
341
|
+
);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
// Add TOC entries for each category.
|
|
345
|
+
organized[group].forEach(function(entry) {
|
|
346
|
+
var member = entry.getMembers(0) || '',
|
|
347
|
+
name = entry.getName(),
|
|
348
|
+
sep = getSeparator(entry),
|
|
349
|
+
title = escape((member ? (member + sep) : '') + name);
|
|
350
|
+
|
|
351
|
+
if (entry.isAlias()) {
|
|
352
|
+
// An alias has a more complex html structure.
|
|
353
|
+
var owner = entry.getOwner();
|
|
354
|
+
tocMarkdown.push(
|
|
355
|
+
'* <a href="#' + owner.getHash(style) + '" class="alias">`' +
|
|
356
|
+
title + '` -> `' + owner.getName() + '`' +
|
|
357
|
+
'</a>'
|
|
358
|
+
);
|
|
359
|
+
} else {
|
|
360
|
+
// Add a simple TOC entry.
|
|
361
|
+
tocMarkdown.push(
|
|
362
|
+
'* ' +
|
|
363
|
+
makeAnchor(
|
|
364
|
+
'#' + entry.getHash(style),
|
|
365
|
+
'`' + title + '`'
|
|
366
|
+
)
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
tocMarkdown.push('\n<!-- /div -->\n');
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// End markdown for the TOC.
|
|
374
|
+
tocMarkdown.push('<!-- /div -->\n');
|
|
375
|
+
|
|
376
|
+
var docMarkdown = ['# '+ options.title + '\n'];
|
|
377
|
+
docMarkdown.push(...tocMarkdown);
|
|
378
|
+
docMarkdown.push('<!-- div class="doc-container" -->\n');
|
|
379
|
+
|
|
380
|
+
tocGroups.forEach(function(group) {
|
|
381
|
+
docMarkdown.push('<!-- div -->\n');
|
|
382
|
+
if (byCategories && !specialCategories.includes(group)) {
|
|
383
|
+
var groupName = '“' + group + '” Methods';
|
|
384
|
+
}
|
|
385
|
+
docMarkdown.push('## `' + (groupName || group) + '`');
|
|
386
|
+
organized[group].forEach(function(entry) {
|
|
387
|
+
if (entry.markdown) {
|
|
388
|
+
docMarkdown.push(entry.markdown);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
docMarkdown.push('\n<!-- /div -->\n');
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
docMarkdown.push('<!-- /div -->\n');
|
|
395
|
+
|
|
396
|
+
// Add link back to the top of the TOC.
|
|
397
|
+
var tocHref = options.tocHref || ('#' + (tocGroups[0] || '').toLowerCase());
|
|
398
|
+
if (tocHref) {
|
|
399
|
+
docMarkdown.push(' [1]: ' + tocHref + ' "Jump back to the TOC."\n');
|
|
400
|
+
}
|
|
401
|
+
return docMarkdown.join('\n');
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export default generateDoc;
|
package/lib/util.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* docdown
|
|
3
|
+
* Copyright 2011-2016 John-David Dalton
|
|
4
|
+
* Copyright 2026 SignpostMarv
|
|
5
|
+
* Available under MIT license
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
parseComment,
|
|
10
|
+
} from '@es-joy/jsdoccomment';
|
|
11
|
+
|
|
12
|
+
var reCode = /`.*?`/g,
|
|
13
|
+
reToken = /@@token@@/g,
|
|
14
|
+
token = '@@token@@';
|
|
15
|
+
|
|
16
|
+
/*----------------------------------------------------------------------------*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The `Array#sort` comparator to produce a
|
|
20
|
+
* [natural sort order](https://en.wikipedia.org/wiki/Natural_sort_order).
|
|
21
|
+
*
|
|
22
|
+
* @memberOf util
|
|
23
|
+
* @param {string} value The value to compare.
|
|
24
|
+
* @param {string} other The other value to compare.
|
|
25
|
+
* @returns {-1|0|1} Returns the sort order indicator for `value`.
|
|
26
|
+
*/
|
|
27
|
+
function compareNatural(value, other) {
|
|
28
|
+
var index = -1,
|
|
29
|
+
valParts = value.split('.'),
|
|
30
|
+
valLength = valParts.length,
|
|
31
|
+
othParts = other.split('.'),
|
|
32
|
+
othLength = othParts.length,
|
|
33
|
+
length = Math.min(valLength, othLength);
|
|
34
|
+
|
|
35
|
+
while (++index < length) {
|
|
36
|
+
var valPart = valParts[index],
|
|
37
|
+
othPart = othParts[index];
|
|
38
|
+
|
|
39
|
+
if (valPart > othPart && othPart != 'prototype') {
|
|
40
|
+
return 1;
|
|
41
|
+
} else if (valPart < othPart && valPart != 'prototype') {
|
|
42
|
+
return -1;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return valLength > othLength ? 1 : (valLength < othLength ? -1 : 0);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Performs common string formatting operations.
|
|
50
|
+
*
|
|
51
|
+
* @memberOf util
|
|
52
|
+
* @param {string|undefined} string The string to format.
|
|
53
|
+
* @returns {string} Returns the formatted string.
|
|
54
|
+
*/
|
|
55
|
+
function format(string) {
|
|
56
|
+
string = `${string || ''}`;
|
|
57
|
+
|
|
58
|
+
// Replace all code snippets with a token.
|
|
59
|
+
var snippets = [];
|
|
60
|
+
string = string.replace(reCode, function(match) {
|
|
61
|
+
snippets.push(match);
|
|
62
|
+
return token;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return string
|
|
66
|
+
// Add line breaks.
|
|
67
|
+
.replace(/:\n(?=[\t ]*\S)/g, ':<br>\n')
|
|
68
|
+
.replace(/\n( *)[-*](?=[\t ]+\S)/g, '\n<br>\n$1*')
|
|
69
|
+
.replace(/^[\t ]*\n/gm, '<br>\n<br>\n')
|
|
70
|
+
// Normalize whitespace.
|
|
71
|
+
.replace(/\n +/g, ' ')
|
|
72
|
+
// Italicize parentheses.
|
|
73
|
+
.replace(/(^|\s)(\(.+\))/g, '$1*$2*')
|
|
74
|
+
// Mark numbers as inline code.
|
|
75
|
+
.replace(/[\t ](-?\d+(?:.\d+)?)(?!\.[^\n])/g, ' `$1`')
|
|
76
|
+
// Replace all tokens with code snippets.
|
|
77
|
+
.replace(reToken, function(match) {
|
|
78
|
+
return snippets.shift();
|
|
79
|
+
})
|
|
80
|
+
.trim();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Parses the JSDoc `comment` into an object.
|
|
85
|
+
*
|
|
86
|
+
* @memberOf util
|
|
87
|
+
* @param {string} comment The comment to parse.
|
|
88
|
+
* @returns {Object} Returns the parsed object.
|
|
89
|
+
*/
|
|
90
|
+
function parse(comment) {
|
|
91
|
+
try {
|
|
92
|
+
return parseComment(comment);
|
|
93
|
+
} catch {
|
|
94
|
+
return Object.create(null);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Trims leading and trailing parentheses from a string
|
|
100
|
+
*
|
|
101
|
+
* @param {string} str
|
|
102
|
+
*
|
|
103
|
+
* @returns {string}
|
|
104
|
+
*/
|
|
105
|
+
function deparenthesize(str) {
|
|
106
|
+
return str.replace(/^[()]*([^()].*[^()])[()]*$/, '$1')
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get the specified index of RegExpExecArray or an empty string
|
|
111
|
+
*
|
|
112
|
+
* @param {RegExp} regex regex to exec against
|
|
113
|
+
* @param {string} string string to exec against
|
|
114
|
+
* @param {number} [index] defaults to 1
|
|
115
|
+
*/
|
|
116
|
+
function regexExecIndex(regex, string, index = 1) {
|
|
117
|
+
const match = regex.exec(string);
|
|
118
|
+
|
|
119
|
+
return match ? match[index] : '';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export default {
|
|
123
|
+
compareNatural,
|
|
124
|
+
format,
|
|
125
|
+
parse,
|
|
126
|
+
deparenthesize,
|
|
127
|
+
regexExecIndex,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export {
|
|
131
|
+
compareNatural,
|
|
132
|
+
format,
|
|
133
|
+
parse,
|
|
134
|
+
deparenthesize,
|
|
135
|
+
regexExecIndex,
|
|
136
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@satisfactory-dev/docdown",
|
|
3
|
+
"description": "A simple JSDoc to Markdown documentation generator.",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"docdown": "bin/docdown.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"documentation",
|
|
12
|
+
"jsdoc",
|
|
13
|
+
"markdown"
|
|
14
|
+
],
|
|
15
|
+
"author": "SignpostMarv",
|
|
16
|
+
"contributors": [
|
|
17
|
+
"John-David Dalton <john.david.dalton@gmail.com>",
|
|
18
|
+
"Mathias Bynens <mathias@qiwi.be>"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/satisfactory-dev/docdown.git"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@es-joy/jsdoccomment": "^0.81.0",
|
|
26
|
+
"jsdoc-type-pratt-parser": "^7.0.0"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20.20.0"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"index.js",
|
|
33
|
+
"bin",
|
|
34
|
+
"lib"
|
|
35
|
+
],
|
|
36
|
+
"version": "0.1.0"
|
|
37
|
+
}
|