Giter Site home page Giter Site logo

packageurl-js's Introduction

@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

packageurl-js's People

Contributors

aniruth37 avatar chriswininger avatar darthhater avatar declanhunter avatar dependabot[bot] avatar isasmendiagus avatar jdalton avatar jkowalleck avatar mcombuechen avatar moullisha avatar mscudlik avatar pombredanne avatar satanshiro avatar smorimoto avatar steven-esser avatar topaztee avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.