
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
get-pkg-repo
Advanced tools
Get repository user and project information from package.json file contents.
The get-pkg-repo npm package is designed to extract repository information from a package.json file. This can be useful for various tasks such as automating repository-related workflows, generating documentation, or integrating with other tools that require repository details.
Extract Repository URL
This feature allows you to extract the repository URL from a package.json file. The code sample demonstrates how to require the get-pkg-repo package, read the package.json file, and then extract and log the repository URL.
const getPkgRepo = require('get-pkg-repo');
const pkg = require('./package.json');
const repo = getPkgRepo(pkg);
console.log(repo.url);
Extract Repository Type
This feature allows you to extract the type of repository (e.g., git) from a package.json file. The code sample shows how to extract and log the repository type.
const getPkgRepo = require('get-pkg-repo');
const pkg = require('./package.json');
const repo = getPkgRepo(pkg);
console.log(repo.type);
Extract Repository Directory
This feature allows you to extract the directory within the repository if specified in the package.json file. The code sample demonstrates how to extract and log the repository directory.
const getPkgRepo = require('get-pkg-repo');
const pkg = require('./package.json');
const repo = getPkgRepo(pkg);
console.log(repo.directory);
The normalize-package-data package is used to normalize package metadata, including repository information. It provides a more comprehensive solution for handling package.json data but may be overkill if you only need repository details.
The parse-package-name package is designed to parse package names and extract information such as scope and name. While it doesn't specifically focus on repository information, it can be used in conjunction with other tools to achieve similar results.
The read-pkg package is used to read and parse package.json files. It provides a simple way to access package metadata, including repository information, but requires additional logic to extract specific details like repository URL or type.
Get repository SCM platform, domain, user, and project information from package.json file contents.
Extracts information from the repository
field contained in the content of a package.json
file using @hbetts/parse-repository-url
and hosted-git-info
.
browse
function that returns URL usable in a browser. (Similar to hosted-git-info
)domain
property containing the fully qualified domain name and port.project
property.type
property indicating the SCM host, such as github
or gitlab
.user
property.*Note: Returns
null
for any property where the information could not be extracted from the repository URL.
To install the get-pkg-repo
tool please run the following command:
yarn [global] add [--dev] get-pkg-repo
There are two ways to use github-metadata-sync
, either as a CLI tool, or programmatically.
Programmatically
Package data must be passed as an object to get-pkg-repo
function. If the contents of the package.json
are a string, please
pass it through JSON.parse
first.
const getPkgRepo = require(`get-pkg-repo`);
/* Assume the `package.json` file contains the following:
{
"repository": {
"url": `https://github.com/conventional-changelog/get-pkg-repo`
}
}
*/
fs.readFile(`package.json`, (err, packageData) => {
if (err) {
...
}
// {domain: `github.com`, project: `get-pkg-repo`, type: `github`, user: `conventional-changelog`}
const repository = getPkgRepo(JSON.parse(packageData));
repository.browse(); // https://github.com/conventional-changelog/get-pkg-repo
});
CLI Tool
After you've installed get-pkg-repo
, you can call the tool based on whether you installed it globally or locally:
Globally
get-pkg-repo package.json
Locally
$(yarn bin)/$ get-pkg-repo package.json
$ get-pkg-repo package.json
{
domain: `github.com`,
project: `get-pkg-repo`,
type: `github`,
user: `conventional-changelog`
}
The contents of the package.json
can also be piped to get-pkg-repo
:
$ cat package.json | get-pkg-repo
{
domain: `github.com`,
project: `get-pkg-repo`,
type: `github`,
user: `conventional-changelog`
}
To assist users of get-pkg-repo
with debugging the behavior of this module we use the debug utility package to print information about the publish process to the console. To enable debug message printing, the environment variable DEBUG
, which is the variable used by the debug
package, must be set to a value configured by the package containing the debug messages to be printed.
To print debug messages on a unix system set the environment variable DEBUG
with the name of this package prior to executing get-pkg-repo
:
DEBUG=get-pkg-repo get-pkg-repo
On the Windows command line you may do:
set DEBUG=get-pkg-repo
get-pkg-repo
We only support Long-Term Support versions of Node.
We specifically limit our support to LTS versions of Node, not because this package won't work on other versions, but because we have a limited amount of time, and supporting LTS offers the greatest return on that investment.
It's possible this package will work correctly on newer versions of Node. It may even be possible to use this package on older versions of Node, though that's more unlikely as we'll make every effort to take advantage of features available in the oldest LTS version we support.
As each Node LTS version reaches its end-of-life we will remove that version from the node
engines
property of our package's package.json
file. Removing a Node version is considered a breaking change and will entail the publishing of a new major version of this package. We will not accept any requests to support an end-of-life version of Node. Any merge requests or issues supporting an end-of-life version of Node will be closed.
We will accept code that allows this package to run on newer, non-LTS, versions of Node. Furthermore, we will attempt to ensure our own changes work on the latest version of Node. To help in that commitment, our continuous integration setup runs against all LTS versions of Node in addition the most recent Node release; called current.
JavaScript package managers should allow you to install this package with any version of Node, with, at most, a warning if your version of Node does not fall within the range specified by our node
engines
property. If you encounter issues installing this package, please report the issue to your package manager.
Please read our contributing guide on how you can help improve this project.
FAQs
Get repository user and project information from package.json file contents.
The npm package get-pkg-repo receives a total of 1,371,294 weekly downloads. As such, get-pkg-repo popularity was classified as popular.
We found that get-pkg-repo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.