-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathconstants.mjs
More file actions
64 lines (58 loc) · 2.28 KB
/
constants.mjs
File metadata and controls
64 lines (58 loc) · 2.28 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// On "About this Documentation", we define the stability indices, and thus
// we don't need to check it for stability references
export const IGNORE_STABILITY_STEMS = ['documentation'];
// These are string replacements specific to Node.js API docs for anchor IDs
export const DOC_API_SLUGS_REPLACEMENTS = [
{ from: /node.js/i, to: 'nodejs' }, // Replace Node.js
{ from: /&/, to: '-and-' }, // Replace &
{ from: /[/,:;\\ ]/g, to: '-' }, // Replace /,:;\ and whitespace
{ from: /(?<=[^_])_+/g, to: '-' }, // Replace internal/trailing underscores with a hyphen
{ from: /^-+(?!-*$)/g, to: '' }, // Remove any leading hyphens
{ from: /(?<!^-*)-+$/g, to: '' }, // Remove any trailing hyphens
{ from: /^(?!-+$).*?(--+)/g, to: '-' }, // Replace multiple hyphens
];
// These are regular expressions used to determine if a given Markdown heading
// is a specific type of API Doc entry (e.g., Event, Class, Method, etc)
// and to extract the inner content of said Heading to be used as the API doc entry name
const CAMEL_CASE = '\\w+(?:\\.\\w+)*';
const FUNCTION_CALL = '\\([^)]*\\)';
// Matches "bar":
// Group 1: foo[bar]
// Group 2: foo.bar
const PROPERTY = `${CAMEL_CASE}(?:(\\[[^\\]]+\\])|\\.(\\w+))`;
// An array of objects defining the different types of API doc headings we want to
// capture and their respective regex to match against the heading text.
// The regex are case-insensitive.
export const DOC_API_HEADING_TYPES = [
{
type: 'method',
regex: new RegExp(
`^\`(?:${PROPERTY}|(${CAMEL_CASE}))${FUNCTION_CALL}\`$`,
'i'
),
},
{ type: 'event', regex: /^Event: +`'?([^`]*?)'?`$/i },
{
type: 'class',
regex: new RegExp(
`^Class: +\`(${CAMEL_CASE}(?: extends +${CAMEL_CASE})?)\`$`,
'i'
),
},
{
type: 'ctor',
regex: new RegExp(`^\`new +(${CAMEL_CASE})${FUNCTION_CALL}\`$`, 'i'),
},
{
type: 'classMethod',
regex: new RegExp(`^Static method: +\`${PROPERTY}${FUNCTION_CALL}\`$`, 'i'),
},
{
type: 'property',
regex: new RegExp(`^\`${PROPERTY}\`$`, 'i'),
},
];
// This regex is used to match basic TypeScript generic types (e.g., Promise<string>)
export const TYPE_GENERIC_REGEX = /^([^<]+)<([^>]+)>$/;
// This is the base URL of the Man7 documentation
export const DOC_MAN_BASE_URL = 'http://man7.org/linux/man-pages/man';