File: generate-api-toc.js

package info (click to toggle)
node-code 5.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 208 kB
  • sloc: makefile: 5; sh: 2
file content (36 lines) | stat: -rwxr-xr-x 870 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
// From https://github.com/hapijs/joi/blob/master/generate-readme-toc.js

// Load modules

const Toc = require('markdown-toc');
const Fs = require('fs');
const Package = require('./package.json');

// Declare internals

const internals = {
    filename: './API.md'
};


internals.generate = function () {

    const api = Fs.readFileSync(internals.filename, 'utf8');
    const tocOptions = {
        bullets: '-',
        slugify: function (text) {

            return text.toLowerCase()
                .replace(/\s/g, '-')
                .replace(/[^\w-]/g, '');
        }
    };

    const output = Toc.insert(api, tocOptions)
        .replace(/<!-- version -->(.|\n)*<!-- versionstop -->/, '<!-- version -->\n# ' + Package.version + ' API Reference\n<!-- versionstop -->');

    Fs.writeFileSync(internals.filename, output);
};

internals.generate();