Skip to content

Commit c26c4ab

Browse files
chore: added some jsdoc (#2418)
* added some jsdoc * Update src/helpers.js Co-authored-by: Tony Brix <tony@brix.ninja> * Update src/Renderer.js Co-authored-by: Tony Brix <tony@brix.ninja> Co-authored-by: Tony Brix <tony@brix.ninja>
1 parent 56ac198 commit c26c4ab

File tree

7 files changed

+91
-7
lines changed

7 files changed

+91
-7
lines changed

bin/marked.js

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ function getStdin() {
188188
});
189189
}
190190

191+
/**
192+
* @param {string} text
193+
*/
191194
function camelize(text) {
192195
return text.replace(/(\w)-(\w)/g, function(_, a, b) {
193196
return a + b.toUpperCase();

build-docs.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { join, dirname, parse, format } from 'path';
33
import { parse as marked } from './lib/marked.esm.js';
44
import { HighlightJS } from 'highlight.js';
55
import titleize from 'titleize';
6+
67
const { mkdir, rm, readdir, stat, readFile, writeFile, copyFile } = promises;
78
const { highlight, highlightAuto } = HighlightJS;
89
const cwd = process.cwd();

src/Lexer.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { repeatString } from './helpers.js';
55

66
/**
77
* smartypants text replacement
8+
* @param {string} text
89
*/
910
function smartypants(text) {
1011
return text
@@ -26,6 +27,7 @@ function smartypants(text) {
2627

2728
/**
2829
* mangle email addresses
30+
* @param {string} text
2931
*/
3032
function mangle(text) {
3133
let out = '',

src/Renderer.js

+45-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export class Renderer {
3838
+ '</code></pre>\n';
3939
}
4040

41+
/**
42+
* @param {string} quote
43+
*/
4144
blockquote(quote) {
4245
return '<blockquote>\n' + quote + '</blockquote>\n';
4346
}
@@ -46,6 +49,12 @@ export class Renderer {
4649
return html;
4750
}
4851

52+
/**
53+
* @param {string} text
54+
* @param {string} level
55+
* @param {string} raw
56+
* @param {any} slugger
57+
*/
4958
heading(text, level, raw, slugger) {
5059
if (this.options.headerIds) {
5160
return '<h'
@@ -73,6 +82,9 @@ export class Renderer {
7382
return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
7483
}
7584

85+
/**
86+
* @param {string} text
87+
*/
7688
listitem(text) {
7789
return '<li>' + text + '</li>\n';
7890
}
@@ -85,10 +97,17 @@ export class Renderer {
8597
+ '> ';
8698
}
8799

100+
/**
101+
* @param {string} text
102+
*/
88103
paragraph(text) {
89104
return '<p>' + text + '</p>\n';
90105
}
91106

107+
/**
108+
* @param {string} header
109+
* @param {string} body
110+
*/
92111
table(header, body) {
93112
if (body) body = '<tbody>' + body + '</tbody>';
94113

@@ -100,6 +119,9 @@ export class Renderer {
100119
+ '</table>\n';
101120
}
102121

122+
/**
123+
* @param {string} content
124+
*/
103125
tablerow(content) {
104126
return '<tr>\n' + content + '</tr>\n';
105127
}
@@ -112,15 +134,24 @@ export class Renderer {
112134
return tag + content + '</' + type + '>\n';
113135
}
114136

115-
// span level renderer
137+
/**
138+
* span level renderer
139+
* @param {string} text
140+
*/
116141
strong(text) {
117142
return '<strong>' + text + '</strong>';
118143
}
119144

145+
/**
146+
* @param {string} text
147+
*/
120148
em(text) {
121149
return '<em>' + text + '</em>';
122150
}
123151

152+
/**
153+
* @param {string} text
154+
*/
124155
codespan(text) {
125156
return '<code>' + text + '</code>';
126157
}
@@ -129,10 +160,18 @@ export class Renderer {
129160
return this.options.xhtml ? '<br/>' : '<br>';
130161
}
131162

163+
/**
164+
* @param {string} text
165+
*/
132166
del(text) {
133167
return '<del>' + text + '</del>';
134168
}
135169

170+
/**
171+
* @param {string} href
172+
* @param {string} title
173+
* @param {string} text
174+
*/
136175
link(href, title, text) {
137176
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
138177
if (href === null) {
@@ -146,6 +185,11 @@ export class Renderer {
146185
return out;
147186
}
148187

188+
/**
189+
* @param {string} href
190+
* @param {string} title
191+
* @param {string} text
192+
*/
149193
image(href, title, text) {
150194
href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
151195
if (href === null) {

src/Slugger.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export class Slugger {
66
this.seen = {};
77
}
88

9+
/**
10+
* @param {string} value
11+
*/
912
serialize(value) {
1013
return value
1114
.toLowerCase()
@@ -19,6 +22,8 @@ export class Slugger {
1922

2023
/**
2124
* Finds the next safe (unique) slug to use
25+
* @param {string} originalSlug
26+
* @param {boolean} isDryRun
2227
*/
2328
getNextSafeSlug(originalSlug, isDryRun) {
2429
let slug = originalSlug;
@@ -39,8 +44,9 @@ export class Slugger {
3944

4045
/**
4146
* Convert string to unique id
42-
* @param {object} options
43-
* @param {boolean} options.dryrun Generates the next unique slug without updating the internal accumulator.
47+
* @param {object} [options]
48+
* @param {boolean} [options.dryrun] Generates the next unique slug without
49+
* updating the internal accumulator.
4450
*/
4551
slug(value, options = {}) {
4652
const slug = this.serialize(value);

src/helpers.js

+31-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export function escape(html, encode) {
2929

3030
const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
3131

32+
/**
33+
* @param {string} html
34+
*/
3235
export function unescape(html) {
3336
// explicitly match decimal, hex, and named HTML entities
3437
return html.replace(unescapeTest, (_, n) => {
@@ -44,8 +47,13 @@ export function unescape(html) {
4447
}
4548

4649
const caret = /(^|[^\[])\^/g;
50+
51+
/**
52+
* @param {string | RegExp} regex
53+
* @param {string} opt
54+
*/
4755
export function edit(regex, opt) {
48-
regex = regex.source || regex;
56+
regex = typeof regex === 'string' ? regex : regex.source;
4957
opt = opt || '';
5058
const obj = {
5159
replace: (name, val) => {
@@ -63,6 +71,12 @@ export function edit(regex, opt) {
6371

6472
const nonWordAndColonTest = /[^\w:]/g;
6573
const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
74+
75+
/**
76+
* @param {boolean} sanitize
77+
* @param {string} base
78+
* @param {string} href
79+
*/
6680
export function cleanUrl(sanitize, base, href) {
6781
if (sanitize) {
6882
let prot;
@@ -93,6 +107,10 @@ const justDomain = /^[^:]+:\/*[^/]*$/;
93107
const protocol = /^([^:]+:)[\s\S]*$/;
94108
const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
95109

110+
/**
111+
* @param {string} base
112+
* @param {string} href
113+
*/
96114
export function resolveUrl(base, href) {
97115
if (!baseUrls[' ' + base]) {
98116
// we can ignore everything in base after the last slash of its path component,
@@ -177,9 +195,14 @@ export function splitCells(tableRow, count) {
177195
return cells;
178196
}
179197

180-
// Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
181-
// /c*$/ is vulnerable to REDOS.
182-
// invert: Remove suffix of non-c chars instead. Default falsey.
198+
/**
199+
* Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
200+
* /c*$/ is vulnerable to REDOS.
201+
*
202+
* @param {string} str
203+
* @param {string} c
204+
* @param {boolean} invert Remove suffix of non-c chars instead. Default falsey.
205+
*/
183206
export function rtrim(str, c, invert) {
184207
const l = str.length;
185208
if (l === 0) {
@@ -233,6 +256,10 @@ export function checkSanitizeDeprecation(opt) {
233256
}
234257

235258
// copied from https://stackoverflow.com/a/5450113/806777
259+
/**
260+
* @param {string} pattern
261+
* @param {number} count
262+
*/
236263
export function repeatString(pattern, count) {
237264
if (count < 1) {
238265
return '';

src/marked.js

+1
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ marked.walkTokens = function(tokens, callback) {
289289

290290
/**
291291
* Parse Inline
292+
* @param {string} src
292293
*/
293294
marked.parseInline = function(src, opt) {
294295
// throw error in case of non string input

0 commit comments

Comments
 (0)