package_helpers.ts

Package and repository URL helpers.

Generic utilities for building URLs and parsing package/repository metadata. These functions have no framework dependencies and can be used at build-time or runtime.

URL builders: - url_github_file - GitHub file permalink - url_github_org - GitHub organization page - url_npm_package - npm package page - url_well_known - .well-known metadata file

Parsers: - repo_url_parse - extract repo URL from package.json repository field - repo_name_parse - extract repo name from scoped package name - repo_url_github_owner - extract GitHub owner from repo URL

Predicates: - package_is_published - check if package is published to npm

Declarations
#

8 declarations

view source

package_is_published
#

package_helpers.ts view source

(package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; logo?: string | undefined; ... 23 more ...; exports?: string | ... 2 more ... | undefined; }): boolean

Check if a package is published to npm.

A package is considered published if: - It's not marked as private - It has exports defined - Its version is not the initial '0.0.1'

package_json

The package.json object to check

type { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; logo?: string | undefined; ... 23 more ...; exports?: string | ... 2 more ... | undefined; }

returns

boolean

True if the package appears to be published

repo_name_parse
#

package_helpers.ts view source

(name: string): string

Extract repository name without scope from package name.

name

Package name (can be scoped like '@org/package')

type string

returns

string

Repository name without scope

throws

  • Error - if scoped package name is malformed

examples

Example 1
Example 2

repo_url_github_owner
#

repo_url_parse
#

package_helpers.ts view source

(repository: string | { [x: string]: unknown; type: string; url: string; directory?: string | undefined; } | undefined): string | null

Parse repository URL from package.json format.

Handles both string format and object format with url property. Strips common prefixes ('git+') and suffixes ('.git', '/').

repository

The repository field from package.json

type string | { [x: string]: unknown; type: string; url: string; directory?: string | undefined; } | undefined

returns

string | null

Clean repository URL, or null if not provided

examples

Example 1
Example 2
Example 3

url_github_file
#

package_helpers.ts view source

(repo_url: string, file_path: string, line?: number | undefined): string

Build GitHub file URL for a repository.

repo_url

Repository URL (e.g., 'https://github.com/owner/repo')

type string

file_path

Path to the file (leading './' is stripped)

type string

line?

Optional line number for deep linking

type number | undefined
optional

returns

string

Full GitHub URL to the file on the main branch

examples

Example 1
Example 2

url_github_org
#

package_helpers.ts view source

(repo_url: string, repo_name: string): string | null

Build GitHub organization URL from repo URL and repo name.

repo_url

Repository URL (e.g., 'https://github.com/owner/repo')

type string

repo_name

Repository name to strip from the URL

type string

returns

string | null

Organization URL, or null if repo_url doesn't end with repo_name

examples

Example 1

url_npm_package
#

package_helpers.ts view source

(package_name: string): string

Build npm package URL.

package_name

Package name (can be scoped like '@org/package')

type string

returns

string

Full npm package page URL

examples

Example 1

url_well_known
#

package_helpers.ts view source

(homepage_url: string, filename: string): string

Build .well-known URL for package metadata files.

homepage_url

Package homepage URL

type string

filename

Filename in .well-known directory

type string

returns

string

Full URL to the .well-known file

examples

Example 1

Imported by
#