Skip to content
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

docs: add jsdoc #56

Merged
merged 1 commit into from
Aug 26, 2024
Merged
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
18 changes: 16 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const dependentsRegex = /^network[/]dependents[/]?$/;
const dependenciesRegex = /^network[/]dependencies[/]?$/;
const wikiRegex = /^wiki[/](.+)$/;

/** @type {(searchParameters: URLSearchParams, pathname: string) => string} */
function pullQueryOut(searchParameters, pathname) {
let query = searchParameters.get('q');

Expand All @@ -32,6 +33,7 @@ function pullQueryOut(searchParameters, pathname) {
return ` (${query.replaceAll(/\s+/g, ' ').trim()})`;
}

/** @param revision {string} */
function styleRevision(revision) {
if (!revision) {
return;
Expand All @@ -45,6 +47,7 @@ function styleRevision(revision) {
return `<code>${revision}</code>`;
}

/** @param hash {string} */
function commentIndicator(hash) {
if (hash.startsWith('#issue-') || hash.startsWith('#commitcomment-')) {
return ' (comment)';
Expand All @@ -57,11 +60,18 @@ function commentIndicator(hash) {
return '';
}

// Filter out null values
/**
* Filter out null values
* @type {(array: string[], delimiter?: string) => string}
*/
function joinValues(array, delimiter = '/') {
return array.filter(Boolean).join(delimiter);
}

/**
* @param href {string}
* @param currentUrl {string}
*/
function shortenRepoUrl(href, currentUrl = 'https://github.com') {
if (!href) {
return;
Expand Down Expand Up @@ -268,7 +278,10 @@ function shortenRepoUrl(href, currentUrl = 'https://github.com') {
return pathname.replaceAll(/^[/]|[/]$/g, '') + url.search + hash + query;
}

// Without this, <a>%%</a> would throw an error
/**
* Without this, <a>%%</a> would throw an error
* @type {(url: string) => string}
*/
function safeDecode(url) {
try {
return decodeURIComponent(url);
Expand All @@ -277,6 +290,7 @@ function safeDecode(url) {
}
}

/** @type {(a: HTMLAnchorElement, currentUrl: string) => boolean} */
export function applyToLink(a, currentUrl) {
// Shorten only if the link name hasn't been customized.
// .href automatically adds a / to naked origins so that needs to be tested too
Expand Down