Skip to content

Commit 205bf57

Browse files
committed
docs: provide complete table of contents
1 parent a696735 commit 205bf57

File tree

3 files changed

+95
-6
lines changed

3 files changed

+95
-6
lines changed

Readme.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,32 @@
1616
- [Community](#community)
1717
- [Establishing connections](#establishing-connections)
1818
- [Connection options](#connection-options)
19-
- [SSL options](#ssl-options)
19+
- [SSL options](#ssl-options)
2020
- [Terminating connections](#terminating-connections)
2121
- [Pooling connections](#pooling-connections)
2222
- [Pool options](#pool-options)
2323
- [Pool events](#pool-events)
24+
- [acquire](#acquire)
25+
- [connection](#connection)
26+
- [enqueue](#enqueue)
27+
- [release](#release)
2428
- [Closing all the connections in a pool](#closing-all-the-connections-in-a-pool)
2529
- [PoolCluster](#poolcluster)
26-
- [PoolCluster options](#poolcluster-options)
30+
- [PoolCluster options](#poolcluster-options)
2731
- [Switching users and altering connection state](#switching-users-and-altering-connection-state)
2832
- [Server disconnects](#server-disconnects)
2933
- [Performing queries](#performing-queries)
3034
- [Escaping query values](#escaping-query-values)
3135
- [Escaping query identifiers](#escaping-query-identifiers)
32-
- [Preparing Queries](#preparing-queries)
33-
- [Custom format](#custom-format)
36+
- [Preparing Queries](#preparing-queries)
37+
- [Custom format](#custom-format)
3438
- [Getting the id of an inserted row](#getting-the-id-of-an-inserted-row)
3539
- [Getting the number of affected rows](#getting-the-number-of-affected-rows)
3640
- [Getting the number of changed rows](#getting-the-number-of-changed-rows)
3741
- [Getting the connection ID](#getting-the-connection-id)
3842
- [Executing queries in parallel](#executing-queries-in-parallel)
3943
- [Streaming query rows](#streaming-query-rows)
40-
- [Piping results with Streams](#piping-results-with-streams)
44+
- [Piping results with Streams](#piping-results-with-streams)
4145
- [Multiple statement queries](#multiple-statement-queries)
4246
- [Stored procedures](#stored-procedures)
4347
- [Joins with overlapping column names](#joins-with-overlapping-column-names)
@@ -47,11 +51,21 @@
4751
- [Error handling](#error-handling)
4852
- [Exception Safety](#exception-safety)
4953
- [Type casting](#type-casting)
54+
- [Number](#number)
55+
- [Date](#date)
56+
- [Buffer](#buffer)
57+
- [String](#string)
58+
- [Custom type casting](#custom-type-casting)
5059
- [Connection Flags](#connection-flags)
60+
- [Example](#example)
61+
- [Default Flags](#default-flags)
62+
- [Other Available Flags](#other-available-flags)
5163
- [Debugging and reporting problems](#debugging-and-reporting-problems)
5264
- [Security issues](#security-issues)
5365
- [Contributing](#contributing)
5466
- [Running tests](#running-tests)
67+
- [Running unit tests](#running-unit-tests)
68+
- [Running integration tests](#running-integration-tests)
5569
- [Todo](#todo)
5670

5771
## Install

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"node": ">= 0.6"
3838
},
3939
"scripts": {
40-
"lint": "eslint .",
40+
"lint": "eslint . && node tool/lint-readme.js",
4141
"test": "node test/run.js",
4242
"test-ci": "node tool/install-nyc.js --nyc-optional --reporter=text -- npm test",
4343
"test-cov": "node tool/install-nyc.js --reporter=html --reporter=text -- npm test",

tool/lint-readme.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
var util = require('util');
4+
5+
var MARKDOWN_SECTION_REGEXP = /^(#+) (.+)$/;
6+
var NEWLINE_REGEXP = /\r?\n/;
7+
var README_PATH = path.join(__dirname, '..', 'Readme.md');
8+
var README_CONTENTS = fs.readFileSync(README_PATH, 'utf-8');
9+
var TOC_SECTION_NAME = 'Table of Contents';
10+
11+
var currentSectionLevel = null;
12+
var currentSectionName = null;
13+
var currentToc = [];
14+
var expectedToc = [];
15+
var tocOffset = 0;
16+
17+
README_CONTENTS.split(NEWLINE_REGEXP).forEach(function (line, index) {
18+
var match = MARKDOWN_SECTION_REGEXP.exec(line);
19+
20+
if (match) {
21+
currentSectionLevel = match[1].length;
22+
currentSectionName = match[2];
23+
24+
if (currentSectionName === TOC_SECTION_NAME) {
25+
tocOffset = index;
26+
}
27+
28+
if (currentSectionLevel > 1 && currentSectionName !== TOC_SECTION_NAME) {
29+
expectedToc.push(util.format('%s- [%s](%s)',
30+
repeat(' ', (currentSectionLevel - 2)), currentSectionName, toAnchor(currentSectionName)));
31+
}
32+
} else if (currentSectionName === TOC_SECTION_NAME) {
33+
currentToc.push(line);
34+
}
35+
});
36+
37+
var index = 0;
38+
39+
if (currentToc[index++].length !== 0) {
40+
expect((tocOffset + index), 'blank line', currentToc[index - 1]);
41+
}
42+
43+
expectedToc.forEach(function (expectedLine) {
44+
var currentLine = currentToc[index++] || '';
45+
46+
if (expectedLine !== currentLine) {
47+
var currentIndex = currentToc.indexOf(expectedLine);
48+
49+
expect((tocOffset + index), ('"' + expectedLine + '"'), currentLine);
50+
51+
if (currentIndex !== -1) {
52+
index = currentIndex + 1;
53+
}
54+
}
55+
});
56+
57+
function expect (lineidx, message, line) {
58+
console.log('Expected %s on line %d', message, (lineidx + 1));
59+
console.log(' Got: %s', line);
60+
process.exitCode = 1;
61+
}
62+
63+
function repeat (str, num) {
64+
var s = '';
65+
66+
for (var i = 0; i < num; i++) {
67+
s += str;
68+
}
69+
70+
return s;
71+
}
72+
73+
function toAnchor (section) {
74+
return '#' + section.toLowerCase().replace(/ /g, '-');
75+
}

0 commit comments

Comments
 (0)