{"library":"packageurl-js","title":"Package URL JavaScript Library","description":"The `packageurl-js` library provides a JavaScript implementation for parsing, constructing, and validating Package URLs (purls) according to the official purl specification (https://github.com/package-url/purl-spec). Currently at version 2.0.1, it is a microlibrary focused solely on handling purl strings and objects. It offers a `PackageURL` class for object-oriented manipulation, static methods for string parsing, and helper objects like `PurlComponent` and `PurlType` for component-level validation and normalization. Its primary differentiator is strict adherence to the purl specification, ensuring consistent and correct handling of package identifiers across different ecosystems. Given its nature as a specification implementation, release cadence is typically driven by updates to the purl specification itself or critical bug fixes.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install packageurl-js"],"cli":null},"imports":["import { PackageURL } from 'packageurl-js'","import { PurlComponent } from 'packageurl-js'","import { PurlType } from 'packageurl-js'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { PackageURL } from 'packageurl-js';\n\n// Example 1: Parsing a PURL string into an object\nconst purlStr = 'pkg:maven/org.springframework.integration/spring-integration-jms@5.5.5?repository_url=https://repo.maven.apache.org/maven2&arch=amd64#subpath/file';\nconst parsedPurl = PackageURL.fromString(purlStr);\nconsole.log('Parsed PURL object:', parsedPurl);\nconsole.log('PURL type:', parsedPurl.type);\nconsole.log('PURL version:', parsedPurl.version);\n\n// Example 2: Constructing a PackageURL object programmatically\nconst newPkg = new PackageURL(\n    'npm',\n    'my-scope',\n    'my-package',\n    '1.2.3',\n    { os: 'linux', dist: 'es2020' },\n    'dist/main.js'\n);\nconsole.log('Constructed PURL string:', newPkg.toString());\n\n// Example 3: Error handling for invalid PURL inputs\ntry {\n    PackageURL.fromString('not-a-valid-purl-string');\n} catch (e: any) {\n    console.error('Error parsing invalid PURL:', e.message);\n}","lang":"typescript","description":"Demonstrates parsing a Package URL string, constructing a `PackageURL` object programmatically, converting it back to a string, and robust error handling for invalid purl inputs.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}