Skip to content

Commit 97dfe72

Browse files
committed
Add generate-toc from joi
1 parent 3778151 commit 97dfe72

File tree

3 files changed

+87
-45
lines changed

3 files changed

+87
-45
lines changed

API.md

+46-43
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,53 @@
33
<!-- versionstop -->
44

55
<!-- toc -->
6+
67
- [Code](#code)
7-
- Grammar
8-
- Flags
9-
- [`expect(value, [prefix])`](#expectvalue-prefix)
10-
- Types
11-
- [`arguments()`](#arguments)
12-
- [`array()`](#array)
13-
- [`boolean()`](#boolean)
14-
- [`buffer()`](#buffer)
15-
- [`date()`](#date)
16-
- [`function()`](#function)
17-
- [`number()`](#number)
18-
- [`regexp()`](#regexp)
19-
- [`string()`](#string)
20-
- [`object()`](#object)
21-
- Values
22-
- [`true()`](#true)
23-
- [`false()`](#false)
24-
- [`null()`](#null)
25-
- [`undefined()`](#undefined)
26-
- [`include(values)`](#includevalues)
27-
- [`startWith(value)`](#startwithvalue)
28-
- [`endWith(value)`](#endwithvalue)
29-
- [`exist()`](#exist)
30-
- [`empty()`](#empty)
31-
- [`length(size)`](#lengthsize)
32-
- [`equal(value[, options])`](#equalvalue-options)
33-
- [`above(value)`](#abovevalue)
34-
- [`least(value)`](#leastvalue)
35-
- [`below(value)`](#belowvalue)
36-
- [`most(value)`](#mostvalue)
37-
- [`within(from, to)`](#withinfrom-to)
38-
- [`between(from, to)`](#betweenfrom-to)
39-
- [`about(value, delta)`](#aboutvalue-delta)
40-
- [`instanceof(type)`](#instanceoftype)
41-
- [`match(regex)`](#matchregex)
42-
- [`satisfy(validator)`](#satisfyvalidator)
43-
- [`throw([type], [message])`](#throwtype-message)
44-
- [`fail(message)`](#failmessage)
45-
- [`count()`](#count)
46-
- [`incomplete()`](#incomplete)
47-
- [Settings](#settings)
48-
- [`truncateMessages`](#truncatemessages)
49-
- [`comparePrototypes`](#compareprototypes)
8+
- [Grammar](#grammar)
9+
- [Flags](#flags)
10+
- [`expect(value, [prefix])`](#expectvalue-prefix)
11+
- [Types](#types)
12+
- [`arguments()`](#arguments)
13+
- [`array()`](#array)
14+
- [`boolean()`](#boolean)
15+
- [`buffer()`](#buffer)
16+
- [`date()`](#date)
17+
- [`function()`](#function)
18+
- [`number()`](#number)
19+
- [`regexp()`](#regexp)
20+
- [`string()`](#string)
21+
- [`object()`](#object)
22+
- [Values](#values)
23+
- [`true()`](#true)
24+
- [`false()`](#false)
25+
- [`null()`](#null)
26+
- [`undefined()`](#undefined)
27+
- [`include(values)`](#includevalues)
28+
- [`startWith(value)`](#startwithvalue)
29+
- [`endWith(value)`](#endwithvalue)
30+
- [`exist()`](#exist)
31+
- [`empty()`](#empty)
32+
- [`length(size)`](#lengthsize)
33+
- [`equal(value[, options])`](#equalvalue-options)
34+
- [`above(value)`](#abovevalue)
35+
- [`least(value)`](#leastvalue)
36+
- [`below(value)`](#belowvalue)
37+
- [`most(value)`](#mostvalue)
38+
- [`within(from, to)`](#withinfrom-to)
39+
- [`between(from, to)`](#betweenfrom-to)
40+
- [`about(value, delta)`](#aboutvalue-delta)
41+
- [`instanceof(type)`](#instanceoftype)
42+
- [`match(regex)`](#matchregex)
43+
- [`satisfy(validator)`](#satisfyvalidator)
44+
- [`throw([type], [message])`](#throwtype-message)
45+
- [`fail(message)`](#failmessage)
46+
- [`count()`](#count)
47+
- [`incomplete()`](#incomplete)
48+
- [Settings](#settings)
49+
- [`truncateMessages`](#truncatemessages)
50+
- [`comparePrototypes`](#compareprototypes)
51+
52+
<!-- tocstop -->
5053

5154
## Code
5255

generate-api-toc.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
// From https://github.com/hapijs/joi/blob/master/generate-readme-toc.js
3+
4+
// Load modules
5+
6+
const Toc = require('markdown-toc');
7+
const Fs = require('fs');
8+
const Package = require('./package.json');
9+
10+
// Declare internals
11+
12+
const internals = {
13+
filename: './API.md'
14+
};
15+
16+
17+
internals.generate = function () {
18+
19+
const api = Fs.readFileSync(internals.filename, 'utf8');
20+
const tocOptions = {
21+
bullets: '-',
22+
slugify: function (text) {
23+
24+
return text.toLowerCase()
25+
.replace(/\s/g, '-')
26+
.replace(/[^\w-]/g, '');
27+
}
28+
};
29+
30+
const output = Toc.insert(api, tocOptions)
31+
.replace(/<!-- version -->(.|\n)*<!-- versionstop -->/, '<!-- version -->\n# ' + Package.version + ' API Reference\n<!-- versionstop -->');
32+
33+
Fs.writeFileSync(internals.filename, output);
34+
};
35+
36+
internals.generate();

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
"hoek": "3.x.x"
1717
},
1818
"devDependencies": {
19-
"lab": "7.x.x"
19+
"lab": "8.x.x",
20+
"markdown-toc": "^0.12.3"
2021
},
2122
"scripts": {
2223
"test": "lab -v -t 100 -L",
23-
"test-cov-html": "lab -L -r html -o coverage.html"
24+
"test-cov-html": "lab -L -r html -o coverage.html",
25+
"toc": "node generate-api-toc.js",
26+
"version": "npm run toc && git add API.md"
2427
},
2528
"license": "BSD-3-Clause"
2629
}

0 commit comments

Comments
 (0)