Skip to content

Commit 806defa

Browse files
refactoring (#1376)
* refactor: replace leftPad on native implementation padStart * refactor: migrate on new Buffer API
1 parent 2997254 commit 806defa

File tree

5 files changed

+12
-27
lines changed

5 files changed

+12
-27
lines changed

__tests__/fixture/custom_theme/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function(comments, options, callback) {
99
new File({
1010
base: '/',
1111
path: '/index.html',
12-
contents: new Buffer('Hello world')
12+
contents: Buffer.from('Hello world')
1313
})
1414
]);
1515
};

__tests__/lib/server.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@ const jsFile = new File({
77
cwd: '/',
88
base: '/test/',
99
path: '/test/file.js',
10-
contents: new Buffer('var test = 123;')
10+
contents: Buffer.from('var test = 123;')
1111
});
1212

1313
const coffeeFile = new File({
1414
cwd: '/',
1515
base: '/test/',
1616
path: '/test/file.coffee',
17-
contents: new Buffer('test = 123')
17+
contents: Buffer.from('test = 123')
1818
});
1919

2020
const indexFile = new File({
2121
cwd: '/',
2222
base: '/test/',
2323
path: '/test/index.html',
24-
contents: new Buffer('<html>')
24+
contents: Buffer.from('<html>')
2525
});
2626

27-
test('server - throws on bad port', function() {
28-
expect(function() {
27+
test('server - throws on bad port', function () {
28+
expect(function () {
2929
const server = new Server('${port}');
3030
}).toThrow();
31-
expect(function() {
31+
expect(function () {
3232
const server = new Server();
3333
}).toThrow();
3434
});
3535

36-
test('server', async function() {
36+
test('server', async function () {
3737
const port = await getPort();
3838
const server = new Server(port, true);
3939
expect(server).toBeTruthy();

src/default_theme/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ module.exports = function (comments, config) {
115115
files.concat(
116116
new File({
117117
path: 'index.html',
118-
contents: new Buffer(
118+
contents: Buffer.from(
119119
pageTemplate({
120120
docs: comments,
121121
config

src/parsers/javascript.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@ const debuglog = util.debuglog('documentation');
88
const findTarget = require('../infer/finders').findTarget;
99
const { parseToAst } = require('./parse_to_ast');
1010

11-
/**
12-
* Left-pad a string so that it can be sorted lexicographically. We sort
13-
* comments to keep them in order.
14-
* @param {string} str the string
15-
* @param {number} width the width to pad to
16-
* @returns {string} a padded string with the correct width
17-
* @private
18-
*/
19-
function leftPad(str, width) {
20-
str = str.toString();
21-
while (str.length < width) {
22-
str = '0' + str;
23-
}
24-
return str;
25-
}
26-
2711
/**
2812
* Receives a module-dep item,
2913
* reads the file, parses the JavaScript, and parses the JSDoc.
@@ -77,7 +61,8 @@ function _addComment(
7761
}*/ = {
7862
loc: nodeLoc,
7963
file: data.file,
80-
sortKey: data.sortKey + ' ' + leftPad(nodeLoc.start.line, 8)
64+
sortKey:
65+
data.sortKey + ' ' + nodeLoc.start.line.toString().padStart(8, '0')
8166
};
8267

8368
if (includeContext) {

src/serve/error_page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function errorPage(error) {
3333
}
3434
return new File({
3535
path: 'index.html',
36-
contents: new Buffer(template + errorText)
36+
contents: Buffer.from(template + errorText)
3737
});
3838
}
3939

0 commit comments

Comments
 (0)