- Notifications
You must be signed in to change notification settings - Fork2
JavaScript implementation of the package url spec
License
MIT, MIT licenses found
Licenses found
SocketDev/socket-packageurl-js
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
TypeScript Package URL (purl) parser and builder. Drop-in replacement forpackageurl-js with full type safety, zero dependencies, and spec compliance with thePackage URL specification.
A Package URL (purl) standardizes how to identify software packages:
pkg:npm/lodash@4.17.21pkg:pypi/requests@2.28.1pkg:maven/org.springframework/spring-core@5.3.21Format breakdown:
pkg:type/namespace/name@version?qualifiers#subpath │ │ │ │ │ │ │ │ │ │ │ │ │ └─ Optional subpath │ │ │ │ │ └──────────── Optional key=value pairs │ │ │ │ └──────────────────── Optional version │ │ │ └───────────────────────── Required package name │ │ └─────────────────────────────────── Optional namespace/scope │ └──────────────────────────────────────── Required package type └──────────────────────────────────────────── Scheme (always "pkg:")Supports 35+ ecosystems: npm, pypi, maven, gem, cargo, nuget, composer, golang, docker, and more.
pnpm install @socketregistry/packageurl-js
Drop-in replacement via package override:
{"pnpm": {"overrides": {"packageurl-js":"npm:@socketregistry/packageurl-js@^1" } }}Requirements: Node >= 18.20.4
Parse purls:
import{PackageURL}from'@socketregistry/packageurl-js'constpurl=PackageURL.fromString('pkg:npm/lodash@4.17.21')console.log(purl.name)// 'lodash'console.log(purl.version)// '4.17.21'
Build purls:
import{PackageURLBuilder}from'@socketregistry/packageurl-js'// npm packagesPackageURLBuilder.npm().name('lodash').version('4.17.21').build()// -> 'pkg:npm/lodash@4.17.21'// Python packagesPackageURLBuilder.pypi().name('requests').version('2.28.1').build()// -> 'pkg:pypi/requests@2.28.1'// Maven with namespace and qualifiersPackageURLBuilder.maven().namespace('org.springframework').name('spring-core').version('5.3.21').qualifier('classifier','sources').build()// -> 'pkg:maven/org.springframework/spring-core@5.3.21?classifier=sources'
Constructor API:
import{PackageURL}from'@socketregistry/packageurl-js'newPackageURL('npm',null,'express','4.18.2')// -> 'pkg:npm/express@4.18.2'// With namespace and subpathnewPackageURL('npm','@babel','runtime','7.18.6',null,'helpers/typeof.js')// -> 'pkg:npm/%40babel/runtime@7.18.6#helpers/typeof.js'
Convert to URLs:
import{UrlConverter}from'@socketregistry/packageurl-js'UrlConverter.toRepositoryUrl(purl)// -> 'https://github.com/lodash/lodash'UrlConverter.toDownloadUrl(purl)// -> 'https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz'
Use type-safe PURL types:
import{PURL_Type,EcosystemString}from'@socketregistry/packageurl-js'// Type-safe enum valuesconsole.log(PURL_Type.NPM)// 'npm'console.log(PURL_Type.PYPI)// 'pypi'console.log(PURL_Type.MAVEN)// 'maven'// Use in type annotationsfunctionprocessPurl(type:EcosystemString){// type is constrained to valid PURL type strings}
| Doc | Description |
|---|---|
| Getting Started | Quick start for contributors (5 min setup) |
| API Reference | Complete API documentation |
| Examples | Common use cases and patterns |
New to the project? See theGetting Started Guide for setup, workflow, and contribution guidelines.
Quick commands:
pnpm install# Install dependenciespnpm build# Buildpnpmtest# Testpnpm check# Lint + typecheck
About
JavaScript implementation of the package url spec
Resources
License
MIT, MIT licenses found
Licenses found
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Languages
- JavaScript51.0%
- TypeScript46.5%
- Shell2.5%