Skip to content

Add additional utility methods to DeclarationReference #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/tsdoc",
"comment": "add utility methods to DeclarationReference components",
"type": "minor"
}
],
"packageName": "@microsoft/tsdoc",
"email": "ron.buckton@microsoft.com"
}
2,557 changes: 2,143 additions & 414 deletions tsdoc/src/beta/DeclarationReference.ts

Large diffs are not rendered by default.

1,767 changes: 1,750 additions & 17 deletions tsdoc/src/beta/__tests__/DeclarationReference.test.ts

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions tsdoc/src/parser/StringChecks.ts
Original file line number Diff line number Diff line change
@@ -132,6 +132,44 @@ export class StringChecks {
return undefined;
}

/**
* Tests whether the input string is a valid scope portion of a scoped NPM package name.
*/
public static explainIfInvalidPackageScope(scopeName: string): string | undefined {
if (scopeName.length === 0) {
return 'An package scope cannot be an empty string';
}

if (scopeName.charAt(0) !== '@') {
return `An package scope must start with '@'`;
}

if (!StringChecks._validPackageNameRegExp.test(`${scopeName}/package`)) {
return `The name ${JSON.stringify(scopeName)} is not a valid package scope`;
}

return undefined;
}

/**
* Tests whether the input string is a valid non-scope portion of a scoped NPM package name.
*/
public static explainIfInvalidUnscopedPackageName(unscopedPackageName: string): string | undefined {
if (unscopedPackageName.length === 0) {
return 'An unscoped package name cannot be an empty string';
}

if (unscopedPackageName.charAt(0) === '@') {
return `An unscoped package name cannot start with '@'`;
}

if (!StringChecks._validPackageNameRegExp.test(`@scope/${unscopedPackageName}`)) {
return `The name ${JSON.stringify(unscopedPackageName)} is not a valid unscoped package name`;
}

return undefined;
}

/**
* Tests whether the input string is a valid declaration reference import path.
*/