Skip to content

JavaScript implementation of the package url spec

License

Notifications You must be signed in to change notification settings

SocketDev/packageurl-js

 
 

Repository files navigation

@jdalton/packageurl-js

Installing

To install @jdalton/packageurl-js in your project, simply run:

npm install @jdalton/packageurl-js

This command will download the @jdalton/packageurl-js npm package for use in your application.

Local Development

Clone the @jdalton/packageurl-js repo and cd into the directory.

Then run:

npm install

Testing

To run the test suite:

npm test

Usage Examples

Importing

As an ES6 module

import { PackageURL } from '@jdalton/packageurl-js'

As a CommonJS module

const { PackageURL } = require('@jdalton/packageurl-js')

Parsing

const purlStr = 'pkg:maven/org.springframework.integration/[email protected]'
console.log(PackageURL.fromString(purlStr))
console.log(new PackageURL(...PackageURL.parseString(purlStr)))

will both log

PackageURL {
    type: 'maven',
    name: 'spring-integration-jms',
    namespace: 'org.springframework.integration',
    version: '5.5.5',
    qualifiers: undefined,
    subpath: undefined
}

Constructing

const pkg = new PackageURL(
    'maven',
    'org.springframework.integration',
    'spring-integration-jms',
    '5.5.5'
)
console.log(pkg.toString())

=>

pkg:maven/org.springframework.integration/[email protected]

Error Handling

try {
    PackageURL.fromString('not-a-purl')
} catch (e) {
    console.error(e.message)
}

=>

Invalid purl: missing required "pkg" scheme component

Helper Objects

Helpers for encoding, normalizing, and validating purl components and types can be imported directly from the module or found on the PackageURL class as static properties.

import {
    PackageURL,
    PurlComponent,
    PurlType
} from '@jdalton/packageurl-js'

PurlComponent === PackageURL.Component // => true
PurlType === PackageURL.Type // => true

PurlComponent

Contains the following properties each with their own encode, normalize, and validate methods, e.g. PurlComponent.name.validate(nameStr):

  • type
  • namespace
  • name
  • version
  • qualifiers
  • qualifierKey
  • qualifierValue
  • subpath

PurlType

Contains the following properties each with their own normalize, and validate methods, e.g. PurlType.npm.validate(purlObj):

  • alpm
  • apk
  • bitbucket
  • bitnami
  • composer
  • conan
  • cran
  • deb
  • github
  • gitlab
  • golang
  • hex
  • huggingface
  • luarocks
  • maven
  • mlflow
  • npm
  • oci
  • pub
  • pypi
  • qpkg
  • rpm
  • swift

About

JavaScript implementation of the package url spec

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%