@shelf/table-of-contents 0.0.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/default-settings.d.ts +1 -1
- package/lib/default-settings.js +31 -40
- package/lib/helpers/anchor.js +15 -22
- package/lib/helpers/anchorize.d.ts +1 -1
- package/lib/helpers/anchorize.js +51 -63
- package/lib/helpers/getDataWithoutNestedAnchors.d.ts +1 -1
- package/lib/helpers/getDataWithoutNestedAnchors.js +28 -45
- package/lib/helpers/process.d.ts +1 -1
- package/lib/helpers/process.js +11 -19
- package/lib/helpers/toc.d.ts +1 -1
- package/lib/helpers/toc.js +35 -45
- package/lib/helpers/unique.js +9 -16
- package/lib/helpers/untag.js +3 -9
- package/lib/index.d.ts +14 -14
- package/lib/index.js +23 -64
- package/lib/types.d.ts +4 -4
- package/lib/types.js +1 -5
- package/package.json +24 -22
package/lib/default-settings.js
CHANGED
|
@@ -1,41 +1,32 @@
|
|
|
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
|
-
// TOC part templates.
|
|
31
|
-
openUL: '<ul>',
|
|
32
|
-
closeUL: '</ul>',
|
|
33
|
-
openLI: '<li><a href="#<%= anchor %>"><%= text %></a>',
|
|
34
|
-
// openLI: '<li><a href="#<%= anchor %>"><%= text %></a> (<%= depth %> / H<%= level %>)',
|
|
35
|
-
closeLI: '</li>',
|
|
36
|
-
// Main TOC template.
|
|
37
|
-
TOC: '<div class="toc"><%= toc %></div>'
|
|
1
|
+
import defaults from 'lodash.defaults';
|
|
2
|
+
export const DEFAULT_SETTINGS = {
|
|
3
|
+
// DEFAULTS FOR toc.process()
|
|
4
|
+
//
|
|
5
|
+
// RegExp to replace with generated TOC.
|
|
6
|
+
placeholder: /<!--\s*toc\s*-->/gi,
|
|
7
|
+
// DEFAULTS FOR toc.anchorize()
|
|
8
|
+
//
|
|
9
|
+
// Match H? headers and all their contents.
|
|
10
|
+
headers: /<h(\d)(\s*[^>]*)>([\s\S]+?)<\/h\1>/gi,
|
|
11
|
+
// Min and max headers to add to TOC.
|
|
12
|
+
tocMin: 2,
|
|
13
|
+
tocMax: 6,
|
|
14
|
+
// Min and max headers to anchorize.
|
|
15
|
+
anchorMin: 2,
|
|
16
|
+
anchorMax: 6,
|
|
17
|
+
// Anchorized header template.
|
|
18
|
+
header: '<h<%= level %><%= attrs %>><a href="#<%= anchor %>" name="<%= anchor %>"><%= header %></a></h<%= level %>>',
|
|
19
|
+
// DEFAULTS FOR toc.toc()
|
|
20
|
+
//
|
|
21
|
+
// TOC part templates.
|
|
22
|
+
openUL: '<ul>',
|
|
23
|
+
closeUL: '</ul>',
|
|
24
|
+
openLI: '<li><a href="#<%= anchor %>"><%= text %></a>',
|
|
25
|
+
// openLI: '<li><a href="#<%= anchor %>"><%= text %></a> (<%= depth %> / H<%= level %>)',
|
|
26
|
+
closeLI: '</li>',
|
|
27
|
+
// Main TOC template.
|
|
28
|
+
TOC: '<div class="toc"><%= toc %></div>',
|
|
38
29
|
};
|
|
39
|
-
function getSettings(settingsOverride) {
|
|
40
|
-
|
|
41
|
-
}
|
|
30
|
+
export function getSettings(settingsOverride) {
|
|
31
|
+
return defaults({}, settingsOverride, DEFAULT_SETTINGS);
|
|
32
|
+
}
|
package/lib/helpers/anchor.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
s = (0, _slug["default"])(s);
|
|
17
|
-
s = s.replace(/[:\\(\\)]+/gi, '-');
|
|
18
|
-
s = s.replace(/[\s\\-]*([\\.])[\s\\-]*/g, '$1');
|
|
19
|
-
s = s.replace(/-+/g, '-');
|
|
20
|
-
s = s.replace(/^-+|-+$/g, '');
|
|
21
|
-
return s;
|
|
22
|
-
}
|
|
1
|
+
import { decode } from 'entities';
|
|
2
|
+
import slug from 'slug';
|
|
3
|
+
import { untag } from './untag.js';
|
|
4
|
+
export function anchor(s) {
|
|
5
|
+
s = untag(s);
|
|
6
|
+
s = s.toLowerCase();
|
|
7
|
+
s = decode(s);
|
|
8
|
+
s = s.replace(/['"!]|[\\.]+$/g, '');
|
|
9
|
+
s = slug(s);
|
|
10
|
+
s = s.replace(/[:\\(\\)]+/gi, '-');
|
|
11
|
+
s = s.replace(/[\s\\-]*([\\.])[\s\\-]*/g, '$1');
|
|
12
|
+
s = s.replace(/-+/g, '-');
|
|
13
|
+
s = s.replace(/^-+|-+$/g, '');
|
|
14
|
+
return s;
|
|
15
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Header, Settings } from '../types';
|
|
1
|
+
import type { Header, Settings } from '../types.js';
|
|
2
2
|
export declare function anchorize(src: string, settingsOverride?: Partial<Pick<Settings, 'headers' | 'tocMin' | 'tocMax' | 'anchorMin' | 'anchorMax' | 'header'>>): {
|
|
3
3
|
src: string;
|
|
4
4
|
html: string;
|
package/lib/helpers/anchorize.js
CHANGED
|
@@ -1,64 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
var _lodash = _interopRequireDefault(require("lodash.template"));
|
|
8
|
-
var _defaultSettings = require("../default-settings");
|
|
9
|
-
var _untag = require("./untag");
|
|
10
|
-
var _unique = require("./unique");
|
|
11
|
-
var _anchor = require("./anchor");
|
|
12
|
-
var _getDataWithoutNestedAnchors = require("./getDataWithoutNestedAnchors");
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
1
|
+
import template from 'lodash.template';
|
|
2
|
+
import { getSettings } from '../default-settings.js';
|
|
3
|
+
import { untag } from './untag.js';
|
|
4
|
+
import { unique } from './unique.js';
|
|
5
|
+
import { anchor } from './anchor.js';
|
|
6
|
+
import { getDataWithoutNestedAnchors } from './getDataWithoutNestedAnchors.js';
|
|
14
7
|
// Parse HTML, returning an array of header objects and anchorized HTML.
|
|
15
|
-
function anchorize(src, settingsOverride) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
src: src,
|
|
61
|
-
html: html,
|
|
62
|
-
headers: headers
|
|
63
|
-
};
|
|
64
|
-
}
|
|
8
|
+
export function anchorize(src, settingsOverride) {
|
|
9
|
+
// Normalize options and compile template(s).
|
|
10
|
+
settingsOverride = getSettings(settingsOverride);
|
|
11
|
+
const headerTemplate = template(settingsOverride.header);
|
|
12
|
+
// Process HTML, "anchorizing" headers as-specified.
|
|
13
|
+
const headers = [];
|
|
14
|
+
const names = {};
|
|
15
|
+
const html = src.replace(settingsOverride.headers, function (all, level, attrs, header) {
|
|
16
|
+
level = Number(level);
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const tocLevel = level >= settingsOverride.tocMin && level <= settingsOverride.tocMax;
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const anchorLevel = level >= settingsOverride.anchorMin && level <= settingsOverride.anchorMax;
|
|
21
|
+
let data;
|
|
22
|
+
if (tocLevel || anchorLevel) {
|
|
23
|
+
// This data is passed into the specified "header" template function.
|
|
24
|
+
data = {
|
|
25
|
+
// The header level number in <H?>...</H?>
|
|
26
|
+
level: level,
|
|
27
|
+
// Any attributes in the open H? tag.
|
|
28
|
+
attrs: attrs,
|
|
29
|
+
// Header HTML contents.
|
|
30
|
+
header: header,
|
|
31
|
+
// Un-tagged header HTML contents.
|
|
32
|
+
text: untag(header),
|
|
33
|
+
// Unique anchor name for this header.
|
|
34
|
+
anchor: unique(names, anchor(header)),
|
|
35
|
+
// All HTML (including tags) matched by the "headers" RegExp.
|
|
36
|
+
all: all,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (tocLevel) {
|
|
40
|
+
headers.push(data);
|
|
41
|
+
}
|
|
42
|
+
if (anchorLevel) {
|
|
43
|
+
return getDataWithoutNestedAnchors(data, headerTemplate);
|
|
44
|
+
}
|
|
45
|
+
return all;
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
src: src,
|
|
49
|
+
html: html,
|
|
50
|
+
headers: headers,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -1,46 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
const parser = new DOMParser();
|
|
2
|
+
const hasAnchorTagsInHeader = (data) => {
|
|
3
|
+
const doc = parser.parseFromString(data.header, 'text/xml');
|
|
4
|
+
// Extract any existing anchor tags from the header variable
|
|
5
|
+
const anchorElement = doc.querySelector('a');
|
|
6
|
+
return anchorElement?.outerHTML;
|
|
7
|
+
};
|
|
8
|
+
export const getDataWithoutNestedAnchors = (data, headerTemplate) => {
|
|
9
|
+
const results = headerTemplate(data);
|
|
10
|
+
if (!hasAnchorTagsInHeader(data)) {
|
|
11
|
+
return headerTemplate(data);
|
|
12
|
+
}
|
|
13
|
+
const doc = parser.parseFromString(results, 'text/xml');
|
|
14
|
+
// get Toc pointer anchor node
|
|
15
|
+
const firstAnchorElement = doc.querySelector(`a[href="#${data.anchor}"]`);
|
|
16
|
+
// get all content nodes from Toc pointer anchor node
|
|
17
|
+
const contentArray = Array.from(firstAnchorElement?.childNodes ?? []);
|
|
18
|
+
const parentNode = firstAnchorElement?.parentElement;
|
|
19
|
+
// remove all content nodes from Toc pointer anchor node
|
|
20
|
+
contentArray.forEach(node => {
|
|
21
|
+
firstAnchorElement?.removeChild(node);
|
|
22
|
+
});
|
|
23
|
+
if (firstAnchorElement) {
|
|
24
|
+
firstAnchorElement.innerHTML = '<wbr/>';
|
|
25
|
+
}
|
|
26
|
+
const newContentArray = [firstAnchorElement, ...contentArray];
|
|
27
|
+
parentNode?.replaceChildren(...newContentArray);
|
|
28
|
+
return parentNode?.outerHTML || results;
|
|
20
29
|
};
|
|
21
|
-
var getDataWithoutNestedAnchors = exports.getDataWithoutNestedAnchors = function getDataWithoutNestedAnchors(data, headerTemplate) {
|
|
22
|
-
var _firstAnchorElement$c;
|
|
23
|
-
var results = headerTemplate(data);
|
|
24
|
-
if (!hasAnchorTagsInHeader(data)) {
|
|
25
|
-
return headerTemplate(data);
|
|
26
|
-
}
|
|
27
|
-
var doc = parser.parseFromString(results, 'text/xml');
|
|
28
|
-
|
|
29
|
-
// get Toc pointer anchor node
|
|
30
|
-
var firstAnchorElement = doc.querySelector("a[href=\"#".concat(data.anchor, "\"]"));
|
|
31
|
-
|
|
32
|
-
// get all content nodes from Toc pointer anchor node
|
|
33
|
-
var contentArray = Array.from((_firstAnchorElement$c = firstAnchorElement === null || firstAnchorElement === void 0 ? void 0 : firstAnchorElement.childNodes) !== null && _firstAnchorElement$c !== void 0 ? _firstAnchorElement$c : []);
|
|
34
|
-
var parentNode = firstAnchorElement === null || firstAnchorElement === void 0 ? void 0 : firstAnchorElement.parentElement;
|
|
35
|
-
|
|
36
|
-
// remove all content nodes from Toc pointer anchor node
|
|
37
|
-
contentArray.forEach(function (node) {
|
|
38
|
-
firstAnchorElement === null || firstAnchorElement === void 0 ? void 0 : firstAnchorElement.removeChild(node);
|
|
39
|
-
});
|
|
40
|
-
if (firstAnchorElement) {
|
|
41
|
-
firstAnchorElement.innerHTML = '<wbr/>';
|
|
42
|
-
}
|
|
43
|
-
var newContentArray = [firstAnchorElement].concat(contentArray);
|
|
44
|
-
parentNode === null || parentNode === void 0 ? void 0 : parentNode.replaceChildren.apply(parentNode, _toConsumableArray(newContentArray));
|
|
45
|
-
return (parentNode === null || parentNode === void 0 ? void 0 : parentNode.outerHTML) || results;
|
|
46
|
-
};
|
package/lib/helpers/process.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { anchorize } from './anchorize';
|
|
1
|
+
import { anchorize } from './anchorize.js';
|
|
2
2
|
export declare function process(src: string, settingsOverride?: Parameters<typeof anchorize>[1]): string;
|
package/lib/helpers/process.js
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.process = process;
|
|
7
|
-
var _defaultSettings = require("../default-settings");
|
|
8
|
-
var _anchorize = require("./anchorize");
|
|
9
|
-
var _toc = require("./toc");
|
|
10
1
|
// Anchorize all headers and inline a generated TOC, returning processed HTML.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
import { getSettings } from '../default-settings.js';
|
|
3
|
+
import { anchorize } from './anchorize.js';
|
|
4
|
+
import { toc } from './toc.js';
|
|
5
|
+
export function process(src, settingsOverride) {
|
|
6
|
+
// Get anchorized HTML and headers array.
|
|
7
|
+
const anchorized = anchorize(src, settingsOverride);
|
|
8
|
+
// Generate TOC from headers array.
|
|
9
|
+
const tocHtml = toc(anchorized.headers);
|
|
10
|
+
// Insert the generated TOC into the anchorized HTML.
|
|
11
|
+
return anchorized.html.replace(getSettings(settingsOverride).placeholder, tocHtml);
|
|
12
|
+
}
|
package/lib/helpers/toc.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Header, Settings } from '../types';
|
|
1
|
+
import type { Header, Settings } from '../types.js';
|
|
2
2
|
export declare function toc(headers: Header[], settingsOverride?: Partial<Settings>): string;
|
package/lib/helpers/toc.js
CHANGED
|
@@ -1,45 +1,35 @@
|
|
|
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
|
-
tocs[cursor] += templates.closeLI(header);
|
|
37
|
-
}
|
|
38
|
-
tocs[cursor] += templates.openLI(header);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// eslint-disable-next-line new-cap
|
|
42
|
-
return templates.TOC({
|
|
43
|
-
toc: tocs.join('')
|
|
44
|
-
});
|
|
45
|
-
}
|
|
1
|
+
import template from 'lodash.template';
|
|
2
|
+
import { getSettings } from '../default-settings.js';
|
|
3
|
+
export function toc(headers, settingsOverride) {
|
|
4
|
+
settingsOverride = getSettings(settingsOverride);
|
|
5
|
+
const templates = {
|
|
6
|
+
TOC: template(settingsOverride.TOC),
|
|
7
|
+
openUL: template(settingsOverride.openUL),
|
|
8
|
+
closeUL: template(settingsOverride.closeUL),
|
|
9
|
+
openLI: template(settingsOverride.openLI),
|
|
10
|
+
closeLI: template(settingsOverride.closeLI),
|
|
11
|
+
};
|
|
12
|
+
// Build TOC
|
|
13
|
+
let cursor = 0;
|
|
14
|
+
const levels = [];
|
|
15
|
+
const tocs = [''];
|
|
16
|
+
headers.forEach(function (header) {
|
|
17
|
+
while (header.level < levels[0]) {
|
|
18
|
+
levels.shift();
|
|
19
|
+
cursor++;
|
|
20
|
+
}
|
|
21
|
+
if (levels.length === 0 || header.level > levels[0]) {
|
|
22
|
+
levels.unshift(header.level);
|
|
23
|
+
header.depth = levels.length;
|
|
24
|
+
tocs[cursor] += templates.openUL(header);
|
|
25
|
+
tocs.push(templates.closeLI(header) + templates.closeUL(header));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
header.depth = levels.length;
|
|
29
|
+
tocs[cursor] += templates.closeLI(header);
|
|
30
|
+
}
|
|
31
|
+
tocs[cursor] += templates.openLI(header);
|
|
32
|
+
});
|
|
33
|
+
// eslint-disable-next-line new-cap
|
|
34
|
+
return templates.TOC({ toc: tocs.join('') });
|
|
35
|
+
}
|
package/lib/helpers/unique.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.unique = unique;
|
|
7
1
|
// Get a unique name and store the returned name in names for future
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
2
|
+
export function unique(names, name) {
|
|
3
|
+
let result = name;
|
|
4
|
+
let count = 0;
|
|
5
|
+
while (names[result]) {
|
|
6
|
+
result = name + --count;
|
|
7
|
+
}
|
|
8
|
+
names[result] = true;
|
|
9
|
+
return result;
|
|
10
|
+
}
|
package/lib/helpers/untag.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { anchor } from './helpers/anchor';
|
|
2
|
-
import { anchorize } from './helpers/anchorize';
|
|
3
|
-
import { process } from './helpers/process';
|
|
4
|
-
import { toc } from './helpers/toc';
|
|
5
|
-
import { unique } from './helpers/unique';
|
|
6
|
-
import { untag } from './helpers/untag';
|
|
7
|
-
export { anchor } from './helpers/anchor';
|
|
8
|
-
export { anchorize } from './helpers/anchorize';
|
|
9
|
-
export { process } from './helpers/process';
|
|
10
|
-
export { toc } from './helpers/toc';
|
|
11
|
-
export { unique } from './helpers/unique';
|
|
12
|
-
export { untag } from './helpers/untag';
|
|
13
|
-
export { DEFAULT_SETTINGS } from './default-settings';
|
|
1
|
+
import { anchor } from './helpers/anchor.js';
|
|
2
|
+
import { anchorize } from './helpers/anchorize.js';
|
|
3
|
+
import { process } from './helpers/process.js';
|
|
4
|
+
import { toc } from './helpers/toc.js';
|
|
5
|
+
import { unique } from './helpers/unique.js';
|
|
6
|
+
import { untag } from './helpers/untag.js';
|
|
7
|
+
export { anchor } from './helpers/anchor.js';
|
|
8
|
+
export { anchorize } from './helpers/anchorize.js';
|
|
9
|
+
export { process } from './helpers/process.js';
|
|
10
|
+
export { toc } from './helpers/toc.js';
|
|
11
|
+
export { unique } from './helpers/unique.js';
|
|
12
|
+
export { untag } from './helpers/untag.js';
|
|
13
|
+
export { DEFAULT_SETTINGS } from './default-settings.js';
|
|
14
14
|
declare const TOC: {
|
|
15
|
-
DEFAULT_SETTINGS: import("./types").Settings;
|
|
15
|
+
DEFAULT_SETTINGS: import("./types.js").Settings;
|
|
16
16
|
anchor: typeof anchor;
|
|
17
17
|
anchorize: typeof anchorize;
|
|
18
18
|
process: typeof process;
|
package/lib/index.js
CHANGED
|
@@ -1,65 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
exports["default"] = void 0;
|
|
25
|
-
Object.defineProperty(exports, "process", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function get() {
|
|
28
|
-
return _process.process;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(exports, "toc", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function get() {
|
|
34
|
-
return _toc.toc;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(exports, "unique", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function get() {
|
|
40
|
-
return _unique.unique;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
Object.defineProperty(exports, "untag", {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function get() {
|
|
46
|
-
return _untag.untag;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
var _anchor = require("./helpers/anchor");
|
|
50
|
-
var _anchorize = require("./helpers/anchorize");
|
|
51
|
-
var _process = require("./helpers/process");
|
|
52
|
-
var _toc = require("./helpers/toc");
|
|
53
|
-
var _unique = require("./helpers/unique");
|
|
54
|
-
var _untag = require("./helpers/untag");
|
|
55
|
-
var _defaultSettings = require("./default-settings");
|
|
56
|
-
var TOC = {
|
|
57
|
-
DEFAULT_SETTINGS: _defaultSettings.DEFAULT_SETTINGS,
|
|
58
|
-
anchor: _anchor.anchor,
|
|
59
|
-
anchorize: _anchorize.anchorize,
|
|
60
|
-
process: _process.process,
|
|
61
|
-
toc: _toc.toc,
|
|
62
|
-
unique: _unique.unique,
|
|
63
|
-
untag: _untag.untag
|
|
1
|
+
import { anchor } from './helpers/anchor.js';
|
|
2
|
+
import { anchorize } from './helpers/anchorize.js';
|
|
3
|
+
import { process } from './helpers/process.js';
|
|
4
|
+
import { toc } from './helpers/toc.js';
|
|
5
|
+
import { unique } from './helpers/unique.js';
|
|
6
|
+
import { untag } from './helpers/untag.js';
|
|
7
|
+
import { DEFAULT_SETTINGS } from './default-settings.js';
|
|
8
|
+
export { anchor } from './helpers/anchor.js';
|
|
9
|
+
export { anchorize } from './helpers/anchorize.js';
|
|
10
|
+
export { process } from './helpers/process.js';
|
|
11
|
+
export { toc } from './helpers/toc.js';
|
|
12
|
+
export { unique } from './helpers/unique.js';
|
|
13
|
+
export { untag } from './helpers/untag.js';
|
|
14
|
+
export { DEFAULT_SETTINGS } from './default-settings.js';
|
|
15
|
+
const TOC = {
|
|
16
|
+
DEFAULT_SETTINGS,
|
|
17
|
+
anchor,
|
|
18
|
+
anchorize,
|
|
19
|
+
process,
|
|
20
|
+
toc,
|
|
21
|
+
unique,
|
|
22
|
+
untag,
|
|
64
23
|
};
|
|
65
|
-
|
|
24
|
+
export default TOC;
|
package/lib/types.d.ts
CHANGED
package/lib/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shelf/table-of-contents",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Fork of node-toc to reduce bundle size & rewritten in TypeScript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -8,18 +8,20 @@
|
|
|
8
8
|
"email": "vlad@shelf.io",
|
|
9
9
|
"url": "https://shelf.io"
|
|
10
10
|
},
|
|
11
|
-
"
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"type": "module",
|
|
13
|
+
"exports": "./lib/index.js",
|
|
14
|
+
"module": "./lib/index.js",
|
|
12
15
|
"types": "lib/index.d.ts",
|
|
13
16
|
"files": [
|
|
14
17
|
"lib"
|
|
15
18
|
],
|
|
16
19
|
"scripts": {
|
|
17
|
-
"build": "rm -rf lib/ &&
|
|
18
|
-
"build:code": "babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts' && find ./lib -name '*.test.d.ts' -delete",
|
|
19
|
-
"build:types": "tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib",
|
|
20
|
+
"build": "rm -rf lib/ && tsc",
|
|
20
21
|
"coverage": "yarn test --coverage",
|
|
21
22
|
"lint": "eslint . --ext .js,.ts,.json --fix",
|
|
22
23
|
"lint:ci": "eslint . --ext .js,.ts,.json",
|
|
24
|
+
"lint:size": "size-limit",
|
|
23
25
|
"prepack": "yarn build",
|
|
24
26
|
"test": "TZ=UTC jest src",
|
|
25
27
|
"type-check": "tsc --noEmit",
|
|
@@ -33,9 +35,6 @@
|
|
|
33
35
|
"eslint --fix"
|
|
34
36
|
]
|
|
35
37
|
},
|
|
36
|
-
"babel": {
|
|
37
|
-
"extends": "@shelf/babel-config/frontend-library"
|
|
38
|
-
},
|
|
39
38
|
"prettier": "@shelf/prettier-config",
|
|
40
39
|
"dependencies": {
|
|
41
40
|
"entities": "4.5.0",
|
|
@@ -44,24 +43,27 @@
|
|
|
44
43
|
"slug": "8.2.3"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
|
-
"@
|
|
48
|
-
"@babel/core": "7.22.10",
|
|
49
|
-
"@shelf/babel-config": "1.2.0",
|
|
50
|
-
"@shelf/eslint-config": "2.26.0",
|
|
46
|
+
"@shelf/eslint-config": "3.10.0",
|
|
51
47
|
"@shelf/prettier-config": "1.0.0",
|
|
52
48
|
"@shelf/tsconfig": "0.0.11",
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"@types/
|
|
58
|
-
"
|
|
49
|
+
"@size-limit/esbuild-why": "10.0.1",
|
|
50
|
+
"@size-limit/preset-small-lib": "10.0.1",
|
|
51
|
+
"@swc/core": "1.3.95",
|
|
52
|
+
"@swc/jest": "0.2.29",
|
|
53
|
+
"@types/jest": "29.5.6",
|
|
54
|
+
"@types/lodash.defaults": "4.2.8",
|
|
55
|
+
"@types/lodash.template": "4.5.2",
|
|
56
|
+
"@types/node": "20.8.9",
|
|
57
|
+
"@types/slug": "5.0.6",
|
|
58
|
+
"eslint": "8.52.0",
|
|
59
59
|
"husky": "8.0.3",
|
|
60
|
-
"jest": "29.
|
|
60
|
+
"jest": "29.7.0",
|
|
61
61
|
"jest-environment-jsdom": "^29.7.0",
|
|
62
|
-
"lint-staged": "
|
|
63
|
-
"prettier": "
|
|
64
|
-
"
|
|
62
|
+
"lint-staged": "15.0.2",
|
|
63
|
+
"prettier": "3.0.3",
|
|
64
|
+
"size-limit": "10.0.1",
|
|
65
|
+
"ts-jest-resolver": "2.0.1",
|
|
66
|
+
"typescript": "5.2.2"
|
|
65
67
|
},
|
|
66
68
|
"engines": {
|
|
67
69
|
"node": ">=14"
|