What is packageurl-js?
The packageurl-js npm package is a JavaScript implementation of the Package URL (purl) specification. It allows you to parse, construct, and manipulate package URLs, which are used to identify and locate software packages in a standardized way.
What are packageurl-js's main functionalities?
Parsing a Package URL
This feature allows you to parse a package URL string into its components. The code sample demonstrates how to parse a package URL for the Angular core package.
const { PackageURL } = require('packageurl-js');
const purl = PackageURL.fromString('pkg:npm/%40angular/core@12.0.0');
console.log(purl);
Constructing a Package URL
This feature allows you to construct a package URL from its components. The code sample demonstrates how to create a package URL for the Angular core package.
const { PackageURL } = require('packageurl-js');
const purl = new PackageURL('npm', '@angular', 'core', '12.0.0', null, null);
console.log(purl.toString());
Manipulating a Package URL
This feature allows you to manipulate the components of a package URL. The code sample demonstrates how to change the version of an existing package URL.
const { PackageURL } = require('packageurl-js');
let purl = new PackageURL('npm', '@angular', 'core', '12.0.0', null, null);
purl.version = '12.1.0';
console.log(purl.toString());
Other packages similar to packageurl-js
url-parse
The url-parse npm package is a more general-purpose URL parsing library. While it can handle package URLs, it is not specifically designed for them and lacks some of the specialized features of packageurl-js.
parse-package-name
The parse-package-name npm package focuses on parsing package names and versions from strings. It provides some similar functionality but is more limited in scope compared to packageurl-js.
packageurl-js
Installing:
To install packageurl-js
in your project, simply run:
npm install packageurl-js
This command will download the packageurl-js
npm package for use in your application.
Local Development:
Clone the packageurl-js
repo and cd
into the directory.
Then run:
npm install
Testing
To run the test suite:
npm test