Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@node-core/doc-kit",
"type": "module",
"version": "1.3.6",
"version": "1.3.7",
"repository": {
"type": "git",
"url": "git+https://github.com/nodejs/doc-kit.git"
Expand Down
55 changes: 55 additions & 0 deletions src/utils/queries/__tests__/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,61 @@ describe('QUERIES', () => {
strictEqual(QUERIES.standardYamlFrontmatter.test(content), false);
});
});

describe('normalizeTypes', () => {
it('matches basic types', () => {
const content = '{string}';
QUERIES.normalizeTypes.lastIndex = 0;
ok(QUERIES.normalizeTypes.test(content));
});

it('matches complex types with generics', () => {
const content1 = '{Readonly<object>}';
const content2 = '{Map<string, "ignore"|null>}';

QUERIES.normalizeTypes.lastIndex = 0;
ok(
QUERIES.normalizeTypes.test(content1),
'Should match Readonly<object>'
);
QUERIES.normalizeTypes.lastIndex = 0;
ok(QUERIES.normalizeTypes.test(content2), 'Should match Map<...>');
});

it('matches complex union types with parentheses', () => {
const content = '{(string|number)}';
QUERIES.normalizeTypes.lastIndex = 0;
ok(
QUERIES.normalizeTypes.test(content),
'Should match union with parentheses'
);
});
});

describe('linksWithTypes', () => {
it('matches basic type links', () => {
const content = '[`<string>`](https://mdn...)';
QUERIES.linksWithTypes.lastIndex = 0;
ok(QUERIES.linksWithTypes.test(content));
});

it('matches complex type links with generics', () => {
const content1 =
'[`<Readonly>`](https://mdn...)<[`<object>`](https://mdn...)>';
QUERIES.linksWithTypes.lastIndex = 0;
ok(
QUERIES.linksWithTypes.test(content1),
'Should match generic type link'
);
});

it('matches complex type links with unions', () => {
const content2 =
'<([`<string>`](https://mdn...)|[`<number>`](https://mdn...))>';
QUERIES.linksWithTypes.lastIndex = 0;
ok(QUERIES.linksWithTypes.test(content2), 'Should match union type link');
});
});
});

describe('UNIST', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/queries/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export const QUERIES = {
// Fixes the references to Markdown pages into the API documentation
markdownUrl: /^(?![+a-zA-Z]+:)([^#?]+)\.md(#.+)?$/,
// ReGeX to match the {Type}<Type> (API type references)
normalizeTypes: /(\{|<)(?! )[^<({})>]+(?! )(\}|>)/g,
normalizeTypes: /(\{|<)(?! )[^{}]+(?! )(\}|>)/g,
// ReGex to match the type API type references that got already parsed
// so that they can be transformed into HTML links
linksWithTypes: /\[`<[^<({})>]+>`\]\((\S+)\)/g,
linksWithTypes: /\[`<[^{}]+>`\]\((\S+)\)/g,
// ReGeX for handling Stability Indexes Metadata
stabilityIndex: /^Stability: ([0-5](?:\.[0-3])?)(?:\s*-\s*)?(.*)$/s,
// ReGeX for handling the Stability Index Prefix
Expand Down
Loading