Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/package-url/packageurl-js
JavaScript implementation of the package url spec
https://github.com/package-url/packageurl-js
javascript library package-url purl
Last synced: 3 months ago
JSON representation
JavaScript implementation of the package url spec
- Host: GitHub
- URL: https://github.com/package-url/packageurl-js
- Owner: package-url
- License: mit
- Created: 2018-02-15T08:06:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-16T23:57:30.000Z (3 months ago)
- Last Synced: 2024-08-17T02:17:45.962Z (3 months ago)
- Topics: javascript, library, package-url, purl
- Language: JavaScript
- Homepage:
- Size: 242 KB
- Stars: 24
- Watchers: 4
- Forks: 21
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# packageurl-js
### Installing
To install `packageurl-js` in your project, simply run:
```bash
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:
```bash
npm install
```### Testing
To run the test suite:
```bash
npm test
```### Usage Examples
#### Importing
As an ES6 module
```js
import { PackageURL } from 'packageurl-js'
```As a CommonJS module
```js
const { PackageURL } = require('packageurl-js')
```#### Parsing
```js
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
```js
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
```js
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.
```js
import {
PackageURL,
PurlComponent,
PurlType
} from '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